Skip to content

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

Merged
waleedlatif1 merged 1 commit into
stagingfrom
improvement/drop-unused-slot-indexes
Sep 26, 2026
Merged

waleedlatif1 merged 1 commit into
stagingfrom
improvement/drop-unused-slot-indexes

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

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)

@vercel

vercel Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Sep 26, 2026 9:43pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Database schema and migration to drop indexes.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR drops four date-slot indexes that do not serve the current date-filter predicates and four single-column indexes covered by retained composites. It keeps the numeric and boolean tag-slot indexes.

Reviews (5) · Last reviewed commit: "improvement(db): drop unusable date slot..."

Comment thread packages/db/migrations/0386_drop_unused_tag_slot_indexes.sql Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
waleedlatif1 force-pushed the improvement/drop-unused-slot-indexes branch from 8e04445 to fff6736 Compare September 26, 2026 20:13
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@greptile-apps

This comment has been minimized.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1
waleedlatif1 force-pushed the improvement/drop-unused-slot-indexes branch from a447be1 to a5815cb Compare September 26, 2026 21:41
@waleedlatif1 waleedlatif1 changed the title improvement(db): drop unused tag slot and redundant prefix indexes improvement(db): drop unusable date slot and redundant prefix indexes Sep 26, 2026
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Sep 26, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

You've manually re-run cubic several times on this PR. Each manual re-review checks the full PR again and counts toward your usage quota. To preserve your usage limits, we recommend letting cubic automatically review new commits.
Tip: cubic can generate docs of your entire codebase and keep them up to date. Try it here.

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 65af161 into staging Sep 26, 2026
32 of 33 checks passed

This branch was successfully deployed

1 active deployment
Preview — a5815cb3 Deployed Sep 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant