improvement(db): drop unusable date slot and redundant prefix indexes
Merged
WA
1mo ago+29339+29339+01234567890123456789012345678901234567890123456789-14-14-01234567890123456789
Summary
- Drops 8 indexes on hot write tables in one
DROP INDEX CONCURRENTLYmigration (0386), following the 0239 pattern:COMMITbreakpoint,lock_timeout 0, idempotent replay {emb,doc}_date1_idx/date2_idx: tag filters comparecol::date, which a plain timestamp btree can never match, so these are written on every chunk insert and document update and never serve a query- Four left-prefix duplicates of an existing non-partial superset, which keeps serving equality lookups and FK cascades on the leading column:
emb_kb_id_idx: covered byemb_kb_enabled_idx/emb_kb_model_idxemb_doc_id_idx: covered byemb_doc_chunk_idx/emb_doc_enabled_idxusage_log_workspace_id_idx: covered byusage_log_workspace_created_at_idxcopilot_runs_execution_id_idx: covered bycopilot_runs_execution_started_at_idx
- Kept on purpose:
- Every
numberandbooleantag-slot index. The vector leg's short-result rescue probe checks tag filters with anEXISTSoverembeddingthat relies on them, and without them a selective number/boolean filter turns that probe into a table-wide scan - The small
copilot_runschat/workspace indexes
- Every
Type of Change
- Improvement
Testing
- Knowledge search A/B (real
retrieveKnowledgeSearch, 58 shapes, 732k-chunk multi-tenant fixture, EXPLAIN ANALYZE BUFFERS per statement): with the prefix and date drops, every shape keeps its plan and latency within noise, and results are identical. Plans move to the covering composites. The same run showed that dropping the number/boolean slot indexes regresses filtered vector search, so those are kept - Every app query and FK cascade that used a dropped prefix index (including the live document → embedding cascade and batched
document_id = ANY(...)) stays an index scan on the covering composite with the same leading column asIndex Cond - Fresh DB: migrate plus replay succeed, the 8 indexes are gone, and the kept slot indexes remain.
drizzle-kit generatereports no drift, andcheck:migrations origin/stagingpasses - Knowledge search suites (kb-block-search, filtered-search, workspace-kb-document-access, search-index-policy) pass identically before and after
Checklist
- Code follows project style guidelines
- Self-reviewed my changes
- Tests added/updated and passing
- No new warnings introduced
- I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)