Skip to content

Commit 8746c4a

Browse files
fix(db): index large-value workflow_id FKs so workflow deletes don't seq-scan
1 parent c0e7ea9 commit 8746c4a

4 files changed

Lines changed: 18344 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- Both tables carry `workflow_id ... ON DELETE SET NULL` (migration 0212) with no index leading
2+
-- on that column. Postgres implements SET NULL as an AFTER ROW referential trigger running
3+
-- `UPDATE ... SET workflow_id = NULL WHERE workflow_id = $1` once per deleted parent row, so
4+
-- every `DELETE FROM workflow` sequentially scans both tables per workflow — enough to blow the
5+
-- statement timeout once the soft-delete retention job starts hard-deleting archived workflows.
6+
-- Both indexes exist to make that trigger index-driven.
7+
--
8+
-- Replay-safety: this file is only CONCURRENTLY index builds below an embedded COMMIT, so a
9+
-- failure replays the whole file — both statements are idempotent.
10+
COMMIT;--> statement-breakpoint
11+
SET lock_timeout = 0;--> statement-breakpoint
12+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "execution_large_value_references_workflow_id_idx" ON "execution_large_value_references" USING btree ("workflow_id");--> statement-breakpoint
13+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "execution_large_values_workflow_id_idx" ON "execution_large_values" USING btree ("workflow_id");--> statement-breakpoint
14+
SET lock_timeout = '5s';

0 commit comments

Comments
 (0)