improvement(db): drop unusable date slot and redundant prefix indexes

Merged
WA
1mo ago
+29339-14

Summary

  • Drops 8 indexes on hot write tables in one DROP INDEX CONCURRENTLY migration (0386), following the 0239 pattern: COMMIT breakpoint, lock_timeout 0, idempotent replay
  • {emb,doc}_date1_idx / date2_idx: tag filters compare col::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 by emb_kb_enabled_idx / emb_kb_model_idx
    • emb_doc_id_idx: covered by emb_doc_chunk_idx / emb_doc_enabled_idx
    • usage_log_workspace_id_idx: covered by usage_log_workspace_created_at_idx
    • copilot_runs_execution_id_idx: covered by copilot_runs_execution_started_at_idx
  • Kept on purpose:
    • Every number and boolean tag-slot index. The vector leg's short-result rescue probe checks tag filters with an EXISTS over embedding that relies on them, and without them a selective number/boolean filter turns that probe into a table-wide scan
    • The small copilot_runs chat/workspace indexes

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 as Index Cond
  • Fresh DB: migrate plus replay succeed, the 8 indexes are gone, and the kept slot indexes remain. drizzle-kit generate reports no drift, and check:migrations origin/staging passes
  • 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)