Skip to content

Commit 97558cd

Browse files
committed
improvement(db): disable embedding FTS fastupdate and index delete-action foreign keys
Inserts into embedding could stall for seconds merging the shared GIN pending list in the foreground, while holding the document row lock. Turn fastupdate off (the 0364 pattern) and drain the existing list once. User and workspace deletion ran sequential scans for four referential actions inside the deleting transaction, holding row locks other writers queued behind. Add concurrent indexes backing document.uploaded_by, user_table_rows.created_by, user_table_definitions.created_by and execution_large_values.workspace_id.
1 parent 3bfd224 commit 97558cd

4 files changed

Lines changed: 30359 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- migration-safe: Metadata-only storage option; existing and new workers retain the same index and search semantics.
2+
ALTER INDEX "public"."emb_content_fts_idx" SET (fastupdate = off);--> statement-breakpoint
3+
-- Release the DDL lock before maintenance and index builds. Everything below is safe to replay after a partial migration.
4+
COMMIT;--> statement-breakpoint
5+
-- Disabling fastupdate does not flush existing pending entries. Drain them once without rebuilding the index.
6+
SET statement_timeout = '5min';--> statement-breakpoint
7+
SELECT pg_catalog.gin_clean_pending_list('"public"."emb_content_fts_idx"'::regclass);--> statement-breakpoint
8+
SET statement_timeout = 0;--> statement-breakpoint
9+
-- Indexes backing user and workspace delete actions, which otherwise scan these tables inside the deleting transaction.
10+
SET lock_timeout = 0;--> statement-breakpoint
11+
-- migration-safe: replay replaces only this new index to recover an interrupted concurrent build; existing indexes remain available.
12+
DROP INDEX CONCURRENTLY IF EXISTS "doc_uploaded_by_idx";--> statement-breakpoint
13+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "doc_uploaded_by_idx" ON "document" USING btree ("uploaded_by") WHERE "document"."uploaded_by" IS NOT NULL;--> statement-breakpoint
14+
-- migration-safe: replay replaces only this new index to recover an interrupted concurrent build; existing indexes remain available.
15+
DROP INDEX CONCURRENTLY IF EXISTS "execution_large_values_workspace_id_idx";--> statement-breakpoint
16+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "execution_large_values_workspace_id_idx" ON "execution_large_values" USING btree ("workspace_id");--> statement-breakpoint
17+
-- migration-safe: replay replaces only this new index to recover an interrupted concurrent build; existing indexes remain available.
18+
DROP INDEX CONCURRENTLY IF EXISTS "user_table_def_created_by_idx";--> statement-breakpoint
19+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "user_table_def_created_by_idx" ON "user_table_definitions" USING btree ("created_by");--> statement-breakpoint
20+
-- migration-safe: replay replaces only this new index to recover an interrupted concurrent build; existing indexes remain available.
21+
DROP INDEX CONCURRENTLY IF EXISTS "user_table_rows_created_by_idx";--> statement-breakpoint
22+
CREATE INDEX CONCURRENTLY IF NOT EXISTS "user_table_rows_created_by_idx" ON "user_table_rows" USING btree ("created_by") WHERE "user_table_rows"."created_by" IS NOT NULL;--> statement-breakpoint
23+
SET lock_timeout = '5s';

0 commit comments

Comments
 (0)