fix(manager-core): F-P-010 add idx_triggers_kind_enabled

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) <noreply@anthropic.com>
This commit is contained in:
MechaCat02
2026-06-07 20:44:37 +02:00
parent e9f1b835f8
commit 3c5978190e

View File

@@ -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;