Skip to content

perf(aci): Narrow latest group detector query#115027

Merged
scttcper merged 2 commits intomasterfrom
scttcper/detector-latest-group
May 7, 2026
Merged

perf(aci): Narrow latest group detector query#115027
scttcper merged 2 commits intomasterfrom
scttcper/detector-latest-group

Conversation

@scttcper
Copy link
Copy Markdown
Member

@scttcper scttcper commented May 6, 2026

Fetch the latest DetectorGroup ids first, then load only those groups instead of joining every candidate group before DISTINCT ON.

This avoids building and sorting a wide joined Group/Project rowset that mostly gets discarded.

A before/after EXPLAIN on the slow detector list page showed execution time drop from 32,400ms to 1,075ms. The wide Group/Project join went from ~99k rows to 20 and the disk sort spill went away.

fixes SENTRY-5NPP

The detector serializer was joining every candidate DetectorGroup row to Group and Project before DISTINCT ON picked the newest group. For noisy detectors that meant dragging around a huge joined rowset just to keep one group per detector.

Fetch the latest group ids first, then serialize only those groups. Keeps the latestGroup response the same while avoiding the wide joined sort.

Co-Authored-By: Codex GPT-5 <noreply@openai.com>
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 6, 2026
@scttcper scttcper changed the title perf(workflows): Narrow latest group detector query perf(aci): Narrow latest group detector query May 6, 2026
@scttcper scttcper marked this pull request as ready for review May 6, 2026 21:52
@scttcper scttcper requested a review from a team as a code owner May 6, 2026 21:52
Comment thread tests/sentry/workflow_engine/endpoints/serializers/test_detector_serializer.py Outdated
@scttcper scttcper merged commit 62913a8 into master May 7, 2026
57 of 60 checks passed
@scttcper scttcper deleted the scttcper/detector-latest-group branch May 7, 2026 15:13
constantinius pushed a commit that referenced this pull request May 8, 2026
Fetch the latest DetectorGroup ids first, then load only those groups
instead of joining every candidate group before DISTINCT ON.

This avoids building and sorting a wide joined Group/Project rowset that
mostly gets discarded.

A before/after EXPLAIN on the slow detector list page showed execution
time drop from 32,400ms to 1,075ms. The wide Group/Project join went
from ~99k rows to 20 and the disk sort spill went away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants