From d03b9643e902f4926249d178b8bed0a15b1822b8 Mon Sep 17 00:00:00 2001 From: Simon Diesenreiter Date: Sat, 14 Nov 2026 11:28:25 +0100 Subject: [PATCH] Index chunk.claim_id and chunk.document_id enrich.embed looks up claims without a chunk on every batch. The existing unique index is on COALESCE expressions, which that lookup can't use, so after the history backfill each run took hours and starved the other enrichers on the same queue. Co-Authored-By: Claude Opus 5.5 --- backend/migrations/0005_chunk_indexes.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 backend/migrations/0005_chunk_indexes.sql diff --git a/backend/migrations/0005_chunk_indexes.sql b/backend/migrations/0005_chunk_indexes.sql new file mode 100644 index 0000000..670ad1f --- /dev/null +++ b/backend/migrations/0005_chunk_indexes.sql @@ -0,0 +1,6 @@ +-- enrich.embed looks up claims and documents without a chunk on every batch. chunk_uniq is an expression index +-- (COALESCE(...)), which those lookups can't use, so each batch scanned the whole table: after the history +-- backfill (over a million claims) a run took hours and blocked the other enrichers. Built CONCURRENTLY by hand on +-- 2026-11-14; IF NOT EXISTS makes this a no-op there. +CREATE INDEX IF NOT EXISTS chunk_claim_idx ON chunk (claim_id) WHERE claim_id IS NOT NULL; +CREATE INDEX IF NOT EXISTS chunk_document_idx ON chunk (document_id) WHERE document_id IS NOT NULL;