Skip to content

fix(knowledge): index the connector tombstone check so a sync stops scanning the whole document table - #8122

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/connector-tombstone-index
Sep 22, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/connector-tombstone-index

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • add a partial index on document (connector_id) WHERE archived_at IS NULL AND (deleted_at IS NOT NULL OR content_hash IS NULL), the exact predicate of the connector sync's tombstone check
  • that check runs SELECT id … LIMIT 1 on every connector sync; the planner estimates thousands of matches and picks a sequential scan expecting to stop early, so a connector with no tombstoned documents reads the entire document table on every sync. Under I/O pressure that statement hits the 60 s statement timeout, the sync fails with SQLSTATE 57014, and ten such failures disable the connector
  • the index makes the check a point lookup regardless of table size or load
  • migration 0374 builds it concurrently with the usual commit breakpoint and replay-safe drop

Type of Change

  • Bug fix

Testing

  • bun run check:migrations origin/staging passes
  • the query's predicate implies the index predicate (each disjunct implies its counterpart), so the planner can use it; verified the current plan on a production-shaped table is a sequential scan

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 22, 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 22, 2026 2:36am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the migration, schema declaration, and generated metadata consistently define the intended partial index.

Summary

Adds a partial document.connector_id index matching the connector tombstone query so connector synchronization no longer scans the entire document table when no matching document exists.

  • Builds the index concurrently using the repository’s replay-safe migration pattern.
  • Declares the matching partial index in the Drizzle schema and generated snapshot.
  • Registers migration 0374 in the migration journal.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Connector sync tombstone check] --> B{Filter by connector_id}
  B --> C[Partial tombstone index]
  C --> D["archived_at IS NULL"]
  D --> E["deleted_at IS NOT NULL OR content_hash IS NULL"]
  E --> F[Fast existence lookup]
Loading

Reviews (2) · Last reviewed commit: "chore(db): format the generated migratio..."

@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.

All reported issues were addressed across 4 files

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

Fix all with cubic | Re-trigger cubic

Comment thread packages/db/schema.ts
@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 22, 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 merged commit 7a5fcee into staging Sep 22, 2026
34 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/connector-tombstone-index branch September 22, 2026 02:39

This branch was successfully deployed

1 active deployment
Preview bd2c77fe Deployed Sep 22, 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