perf: add indexes for cleanup deletes on concurrency_key and autoscaling_event (#8726)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ruben Fiszel
2026-04-05 11:10:30 -04:00
committed by GitHub
parent 31df861ee2
commit eae46a21a9
2 changed files with 9 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
DROP INDEX IF EXISTS concurrency_key_ended_at_only_idx;
DROP INDEX IF EXISTS autoscaling_event_applied_at_idx;

View File

@@ -0,0 +1,7 @@
-- Add indexes on the time column alone to speed up the periodic cleanup DELETEs in monitor.rs:
-- DELETE FROM concurrency_key WHERE ended_at <= now() - ($1::bigint::text || ' s')::interval
-- DELETE FROM autoscaling_event WHERE applied_at <= now() - ($1::bigint::text || ' s')::interval
-- The existing composite indexes (key, ended_at DESC) and (worker_group, applied_at) cannot be
-- used efficiently when filtering only on the time column, so Postgres falls back to a seq scan.
CREATE INDEX IF NOT EXISTS concurrency_key_ended_at_only_idx ON concurrency_key (ended_at);
CREATE INDEX IF NOT EXISTS autoscaling_event_applied_at_idx ON autoscaling_event (applied_at);