BIT-29730's incident-first fast path for GET recent-errors still ran ROW_NUMBER() OVER (PARTITION BY incident_id ...) across ALL occurrences of every selected incident before filtering rn = 1. MariaDB can't turn a PARTITION BY window function into a loose index scan, so it materializes and sorts each partition in full. At fleet-audit scale (status=open,investigating,resolved,ignored&limit=2000), several "mega-incidents" with 48k-148k occurrences each landed in the selected page, and sorting those partitions hung the query for 70s+ (confirmed via KILL QUERY / SHOW FULL PROCESSLIST showing Creating sort index).
Fix
Replace the ROW_NUMBER() CTE with a LIMIT 1 correlated subquery per selected incident. EXPLAIN confirms this walks er_incident_occurrences_incident_time_idx (incident_id, occurred_at DESC) and stops at the first row per incident instead of scanning the rest of its history.
Verification
Verified against MariaDB (docker compose) seeded with the production shape from the bug report (3235 resolved / 20 open incidents, 5 mega-incidents at 48k-148k occurrences each, ~425k occurrence rows total): status=open,investigating,resolved,ignored&limit=2000 dropped from 2.1s to 0.44s with identical result rows, and status=resolved&limit=10 stayed at ~0.3s, untouched by the mega-incidents.
npx vitest run (47/47) and npx tsc --noEmit both pass.
Deploy note
No new migration — reuses the er_incidents_state_seen_idx index added in BIT-29730/BIT-30039. Once this deploys and is confirmed <1s at limit=2000, BIT-30039's remaining item (restoring the multi-status filter in paperclip_fleet_error_reporting_audit_once.py, reverting the BIT-25722 workaround) can proceed.
Fixes BIT-30040.
## Problem
BIT-29730's incident-first fast path for `GET recent-errors` still ran `ROW_NUMBER() OVER (PARTITION BY incident_id ...)` across ALL occurrences of every selected incident before filtering `rn = 1`. MariaDB can't turn a `PARTITION BY` window function into a loose index scan, so it materializes and sorts each partition in full. At fleet-audit scale (`status=open,investigating,resolved,ignored&limit=2000`), several "mega-incidents" with 48k-148k occurrences each landed in the selected page, and sorting those partitions hung the query for 70s+ (confirmed via `KILL QUERY` / `SHOW FULL PROCESSLIST` showing `Creating sort index`).
## Fix
Replace the `ROW_NUMBER()` CTE with a `LIMIT 1` correlated subquery per selected incident. `EXPLAIN` confirms this walks `er_incident_occurrences_incident_time_idx (incident_id, occurred_at DESC)` and stops at the first row per incident instead of scanning the rest of its history.
## Verification
Verified against MariaDB (docker compose) seeded with the production shape from the bug report (3235 resolved / 20 open incidents, 5 mega-incidents at 48k-148k occurrences each, ~425k occurrence rows total): `status=open,investigating,resolved,ignored&limit=2000` dropped from 2.1s to 0.44s with identical result rows, and `status=resolved&limit=10` stayed at ~0.3s, untouched by the mega-incidents.
`npx vitest run` (47/47) and `npx tsc --noEmit` both pass.
## Deploy note
No new migration — reuses the `er_incidents_state_seen_idx` index added in BIT-29730/BIT-30039. Once this deploys and is confirmed `<1s` at `limit=2000`, BIT-30039's remaining item (restoring the multi-status filter in `paperclip_fleet_error_reporting_audit_once.py`, reverting the BIT-25722 workaround) can proceed.
spark
self-assigned this 2026-09-07 09:10:43 +01:00
BIT-29730's incident-first fast path still ran ROW_NUMBER() OVER
(PARTITION BY incident_id ...) across ALL occurrences of every
selected incident before filtering rn = 1. MariaDB can't turn a
PARTITION BY window function into a loose index scan, so it
materializes and sorts each partition in full. At fleet-audit scale
(status=open,investigating,resolved,ignored&limit=2000) several
"mega-incidents" with 48k-148k occurrences each landed in the
selected page, and sorting those partitions hung the query for 70s+.
Replace the ROW_NUMBER CTE with a `LIMIT 1` correlated subquery per
selected incident. EXPLAIN confirms this walks
er_incident_occurrences_incident_time_idx (incident_id, occurred_at
DESC) and stops at the first row per incident instead of scanning the
rest of its history.
Verified against MariaDB (docker compose) seeded with the production
shape from the bug report (3235 resolved / 20 open incidents, 5
mega-incidents at 48k-148k occurrences each, ~425k occurrence rows
total): status=open,investigating,resolved,ignored&limit=2000 dropped
from 2.1s to 0.44s with identical result rows, and
status=resolved&limit=10 stayed at ~0.3s untouched by the
mega-incidents.
spark
merged commit 3da9e47873 into master2026-09-07 09:12:29 +01:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes BIT-30040.
Problem
BIT-29730's incident-first fast path for
GET recent-errorsstill ranROW_NUMBER() OVER (PARTITION BY incident_id ...)across ALL occurrences of every selected incident before filteringrn = 1. MariaDB can't turn aPARTITION BYwindow function into a loose index scan, so it materializes and sorts each partition in full. At fleet-audit scale (status=open,investigating,resolved,ignored&limit=2000), several "mega-incidents" with 48k-148k occurrences each landed in the selected page, and sorting those partitions hung the query for 70s+ (confirmed viaKILL QUERY/SHOW FULL PROCESSLISTshowingCreating sort index).Fix
Replace the
ROW_NUMBER()CTE with aLIMIT 1correlated subquery per selected incident.EXPLAINconfirms this walkser_incident_occurrences_incident_time_idx (incident_id, occurred_at DESC)and stops at the first row per incident instead of scanning the rest of its history.Verification
Verified against MariaDB (docker compose) seeded with the production shape from the bug report (3235 resolved / 20 open incidents, 5 mega-incidents at 48k-148k occurrences each, ~425k occurrence rows total):
status=open,investigating,resolved,ignored&limit=2000dropped from 2.1s to 0.44s with identical result rows, andstatus=resolved&limit=10stayed at ~0.3s, untouched by the mega-incidents.npx vitest run(47/47) andnpx tsc --noEmitboth pass.Deploy note
No new migration — reuses the
er_incidents_state_seen_idxindex added in BIT-29730/BIT-30039. Once this deploys and is confirmed<1satlimit=2000, BIT-30039's remaining item (restoring the multi-status filter inpaperclip_fleet_error_reporting_audit_once.py, reverting the BIT-25722 workaround) can proceed.