Site event log: severity / event_type filters sort every matching row (slowest query on a full 1 GB log) #123
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by the #49
[xc-3]run (docs/plans/2026-11-10-wp4-residual-scope-results.md§3.3,ResidualBench eventlog).On a full 1 GB / 30-day
site_eventstable (2.36 M rows), equality filters onseverityorevent_typeare the slowest event-log queries:Every other shape is ≤ 14 ms warm, including the time-window pages and the instance filter.
The cause is visible in
EXPLAIN QUERY PLAN. With noANALYZEstatistics, SQLite picks the single-columnidx_events_severity/idx_events_type, reads every matching row in the table, and then sorts them (USE TEMP B-TREE FOR ORDER BY) to return 500. So the cost grows with table size, not page size.This is not a failure: everything is under 0.5 s warm. Possible fixes:
(severity, timestamp)/(event_type, timestamp)indexes. These change the row model the storage-cap estimate is calibrated on, soSiteEventsSchemaCalibrationTests, the cap-semantics calibration and register row 93 would need re-calibrating in the same change.ANALYZE/PRAGMA optimizeso the planner prefersidx_events_timestampwith a filter.INDEXED BYhint when a time window is present.Fixed in
424db155with composite indexes, as decided:idx_events_type_timestamp (event_type, timestamp)andidx_events_severity_timestamp (severity, timestamp)replace the single-column indexes.SiteEventLogSchema.Applydrops the old two in place on first boot; site-a's file on the rig migrated cleanly. Indexes are not in LocalDb's replicated-table digest, so this does not affect pair sync.ResidualBench eventlogre-run (full 1 GB, 30 d, page 500):Plans now
SEARCH … USING INDEX idx_events_severity_timestamp (severity=? AND timestamp>?)with only a last-term (tie) sort; pinned bySchemaIndexTests.Cost (accepted): 454 → 530 B/row on disk. The 1 GB cap holds 2.03 M rows instead of 2.36 M, and 30 days fit only below 0.78 events/s per site (was 0.91). The CDC-on writer drains 8,760 events/s (was 10,535); the purge tick is unchanged (10.7 s).
Recalibration (register row 93): still four secondary indexes; the sampler now counts
timestampthree times.EstimateSiteEventsSize_TracksTheRealFootprinterrors are +8.7 % / +12.8 % / −0.5 % (were +8.4 / +12.8 / −0.8), inside the −5…+25 % band with constants unchanged.SiteEventsSchemaCalibrationTestsre-pinned; memo §3.2 records it.