Bug 2017561 - Use IN clauses instead of OR-chains in alert summary#9535
Open
florinbilt wants to merge 3 commits into
Open
Bug 2017561 - Use IN clauses instead of OR-chains in alert summary#9535florinbilt wants to merge 3 commits into
florinbilt wants to merge 3 commits into
Conversation
Contributor
|
Thanks for the detailed tests and the diff validation! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactor _build_tc_metadata_map and _build_duplicated_summaries_map in PerformanceAlertSummaryViewSet to use SQL IN clauses instead of chunked OR-chains. No behavior change —
payload is byte-for-byte identical (verified by JSON diff across 10 summary IDs of varying sizes).
Problem
For alert summaries with thousands of alerts, /api/performance/alertsummary/?id= was issuing up to 9 chunked queries against performance_datum, each with a 500-way OR over
(repository_id, signature_id, push_id) tuples — ~69 KB of SQL per query. On a real summary with 2103 alerts (id 43868), this alone accounted for ~5s of DB time.
Solution
Collapse the lookup into a single query that filters via three IN clauses (repository_id__in, signature_id__in, push_id__in) and discard the small amount of cartesian
over-fetch in Python. The same treatment is applied to _build_duplicated_summaries_map.
Benchmarks — DB time
Staging Postgres, 10 representative summary IDs, 7 runs each, mock-tc to isolate DB performance, median reported.
Query count is now constant (13) regardless of summary size; previously it scaled with alert count due to OR-chain chunking.
Benchmarks — real endpoint
GET /api/performance/alertsummary/?id=X. cold = first request with Redis cleared; warm = median of 3 subsequent requests.
The DB savings are present everywhere; their visibility at endpoint level depends on the alert mix: