WIP cleanup: split branch stash into 8 focused commits #2
@@ -0,0 +1,26 @@
|
||||
-- Targeted indexes for hot queries whose current indexes don't match the
|
||||
-- filter. Each one was chosen after reading the actual sqlx call sites; we
|
||||
-- didn't add "just in case" indexes on tables whose only access pattern is
|
||||
-- a PK lookup.
|
||||
|
||||
-- Outbox drainer: `WHERE status = 'queued' ORDER BY created_at LIMIT $1`
|
||||
-- (crates/cm-db/src/repo/outbox.rs). The existing outbox_workspace_idx is
|
||||
-- `(workspace_id, created_at DESC)` — no help for the workspace-agnostic
|
||||
-- drainer that pops the oldest queued row. Partial index keeps it tiny.
|
||||
CREATE INDEX IF NOT EXISTS outbox_queued_idx
|
||||
ON outbox (created_at)
|
||||
WHERE status = 'queued';
|
||||
|
||||
-- Audit log rate limiting: `WHERE workspace_id = $1 AND event_type = $2
|
||||
-- AND created_at > now() - interval '1 hour'` fires on every door tool
|
||||
-- call (cm-api/src/mcp_door.rs) and every A2A invocation. Descending
|
||||
-- created_at because count()s scan the recent tail.
|
||||
CREATE INDEX IF NOT EXISTS audit_log_workspace_event_idx
|
||||
ON audit_log (workspace_id, event_type, created_at DESC);
|
||||
|
||||
-- Node rules eval loop: `SELECT ... FROM node_rules WHERE enabled`
|
||||
-- (crates/cm-db/src/repo/node_rules.rs:90) runs periodically. Partial
|
||||
-- index avoids indexing disabled rules.
|
||||
CREATE INDEX IF NOT EXISTS node_rules_enabled_idx
|
||||
ON node_rules (workspace_id)
|
||||
WHERE enabled;
|
||||
Reference in New Issue
Block a user