From 3c5978190e068a01d36984dd8407517c441f8a7b Mon Sep 17 00:00:00 2001 From: MechaCat02 Date: Sun, 7 Jun 2026 20:44:37 +0200 Subject: [PATCH] fix(manager-core): F-P-010 add idx_triggers_kind_enabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit list_active_queue_consumers fires every 100ms from the dispatcher queue arm and predicates on `WHERE t.kind='queue' AND t.enabled=TRUE` with no app_id filter — but the only available index `idx_triggers_app_kind_enabled` is keyed on `(app_id, kind)` and so requires an app_id predicate to be useful. Without one, the planner falls back to a sequential scan every tick. Add migration 0036 with a partial index on `kind` (WHERE enabled = TRUE) so the hot dispatcher query becomes an index-only lookup. AUDIT.md anchor: F-P-010. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../migrations/0036_index_triggers_kind_enabled.sql | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 crates/manager-core/migrations/0036_index_triggers_kind_enabled.sql diff --git a/crates/manager-core/migrations/0036_index_triggers_kind_enabled.sql b/crates/manager-core/migrations/0036_index_triggers_kind_enabled.sql new file mode 100644 index 0000000..8093350 --- /dev/null +++ b/crates/manager-core/migrations/0036_index_triggers_kind_enabled.sql @@ -0,0 +1,12 @@ +-- F-P-010 (audit 2026-06-07): list_active_queue_consumers runs every +-- 100 ms via the dispatcher's queue arm. Predicate is +-- `WHERE t.kind = 'queue' AND t.enabled = TRUE` with no `app_id` +-- filter. The available index `idx_triggers_app_kind_enabled +-- (app_id, kind) WHERE enabled = TRUE` requires an app_id predicate to +-- be useful — without one the planner falls back to a sequential scan +-- of the triggers table every tick. Add an index keyed purely on +-- `kind` (partial, where enabled) so the same hot query becomes an +-- index-only lookup. +CREATE INDEX IF NOT EXISTS idx_triggers_kind_enabled + ON triggers (kind) + WHERE enabled = TRUE;