diff --git a/backend/migrations/20260405150554_cleanup_delete_indexes.down.sql b/backend/migrations/20260405150554_cleanup_delete_indexes.down.sql new file mode 100644 index 0000000000..9f3c14d3a7 --- /dev/null +++ b/backend/migrations/20260405150554_cleanup_delete_indexes.down.sql @@ -0,0 +1,2 @@ +DROP INDEX IF EXISTS concurrency_key_ended_at_only_idx; +DROP INDEX IF EXISTS autoscaling_event_applied_at_idx; diff --git a/backend/migrations/20260405150554_cleanup_delete_indexes.up.sql b/backend/migrations/20260405150554_cleanup_delete_indexes.up.sql new file mode 100644 index 0000000000..4d638c30b0 --- /dev/null +++ b/backend/migrations/20260405150554_cleanup_delete_indexes.up.sql @@ -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);