Optimize unknown-tests query with NOT EXISTS and partition pruning#3640
Optimize unknown-tests query with NOT EXISTS and partition pruning#3640mstaeble wants to merge 1 commit into
Conversation
|
Skipping CI for Draft Pull Request. |
|
Pipeline controller notification For optional jobs, comment This repository is configured in: automatic mode |
Walkthrough
ChangesNew test detection query optimization and batch filtering
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 18 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (18 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: mstaeble The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pkg/sippyserver/pr_new_tests_worker.go`:
- Around line 363-370: The cache for "not new" tests in ntf.notNewTests is keyed
only by test_id, but the database query that determines whether tests are "not
new" is scoped by prow_job_run_release, causing cache entries to leak across
releases. Modify the cache key to include the release information alongside the
test_id in all three affected locations: where the cache is checked with
ntf.notNewTests.Has() around line 367, where the query is executed with release
filtering around line 386, and where cache results are stored around line
395-397. This ensures the cache properly respects release boundaries and
prevents genuinely new tests from being incorrectly suppressed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 9c12e448-3333-4265-b129-228b9d4a5358
📒 Files selected for processing (3)
pkg/api/job_runs.gopkg/sippyserver/pr_new_tests_worker.gopkg/sippyserver/pr_new_tests_worker_test.go
2e02da7 to
b3a38b8
Compare
74b880e to
5657332
Compare
Queries against the heavily partitioned prow_job_run_tests table (~3,500 partitions) were scanning all partitions due to missing partition pruning keys. Two changes address this: 1. Load tests separately from the job run with explicit prow_job_run_release and prow_job_run_timestamp in the WHERE clause, enabling PostgreSQL to target a single partition. This applies to both the failed-tests path (onlyNewTests=false, ~432ms -> ~0.1ms) and the new-tests path (onlyNewTests=true, ~3,300ms -> ~0.2ms). 2. For the new-tests path, use NOT EXISTS instead of NOT IN for the test_ownerships anti-join and combine it with a merged-PR check in a single query. This eliminates the N+1 per-test IsNewTest queries, the NewTestFilter interface, pgNewTestFilter struct, and notNewTests cache — Postgres handles all filtering in one pass. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5657332 to
f0d895c
Compare
|
Scheduling required tests: |
|
@mstaeble: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Summary
Queries against the heavily partitioned
prow_job_run_teststable (~3,500 partitions) were scanning all partitions due to missing partition pruning keys. Two changes address this:prow_job_run_releaseandprow_job_run_timestampin the WHERE clause, enabling PostgreSQL to target a single partition instead of scanning ~3,500. Benchmarked against staging withenable_partitionwise_join = on:unknownTests=false): ~432ms → ~0.1ms per callunknownTests=true): ~3,300ms → ~0.2ms per callNOT EXISTSinstead ofNOT INfor thetest_ownershipsanti-join and combine it with a merged-PR check in a single SQL query. This eliminates the N+1 per-testIsNewTestqueries, theNewTestFilterinterface,pgNewTestFilterstruct, andnotNewTestscache — Postgres handles all filtering in one pass.Test plan
TestUnit_getNewTestsForJobRun,TestRiskScenarios)go build ./...go vetclean🤖 Generated with Claude Code
Summary by CodeRabbit