Skip to content

fix(knowledge): read the projection-filled probe off the partial index instead of a sequential scan - #8139

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/projection-filled-probe-index
Sep 22, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/projection-filled-probe-index

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • The search's "is this projection filled yet" probe was SELECT EXISTS (SELECT 1 FROM <projection> WHERE acl IS NULL). PostgreSQL drops the order and limit inside an EXISTS, and while most rows are still unfilled the planner expects a sequential scan to meet one immediately, so it never picks the partial acl IS NULL index. When the unfilled rows sit past the filled ones, that sequential scan walks the whole projection on every miss of the one-minute memo
  • Because the probe runs under the search budget, ahead of the keyword ranking, it consumed the entire keyword leg on every member search of a large index and the leg returned nothing; the repeated full scans also kept the projection and its ranking index out of cache for everyone else
  • The probe now asks for the last unfilled row by id (ORDER BY id DESC LIMIT 1). That shape can only be served by the partial index, so the read is a handful of pages regardless of how many rows remain (the fill advances from the front of each range, so the last entry is also the one it reaches last)
  • The backfill's own end-of-chain probe (same EXISTS, joined to document) takes the same shape
  • Measured on a production-sized index: the sequential-scan form ran past the search budget; the index form completes in single-digit milliseconds

Type of Change

  • Bug fix

Testing

  • Unit test pins the probe's rendered shape and fails against the previous EXISTS form
  • bun run lint, check:audits (47 audits), docs-manifest:check, type-check pass

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.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Sep 22, 2026 4:36pm 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, with the performance fix consistently applied and covered by focused regression tests.

Summary

This PR replaces sequential-scan-prone EXISTS checks with ordered, single-row probes that can use the partial unfilled-row index.

  • Updates both the search-time projection readiness probe and the backfill completion probe.
  • Preserves the backfill probe’s document join so orphaned projection rows do not block completion.
  • Adds focused SQL-shape coverage for both probes, including the previously requested backfill assertions.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Search[Knowledge search or backfill] --> Probe[Ordered unfilled-row probe]
  Probe --> Index[Partial ACL-null index]
  Index --> Found{Unfilled row found?}
  Found -->|Yes| Pending[Projection remains pending]
  Found -->|No| Ready[Projection is filled]
Loading

Reviews (2) · Last reviewed commit: "test(knowledge): pin the backfill probe'..."

Comment thread apps/sim/lib/knowledge/search/projection-source-acl-backfill.ts

@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 3 files

Confidence score: 5/5

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

Re-trigger cubic

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

Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 17e415d into staging Sep 22, 2026
25 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/projection-filled-probe-index branch September 22, 2026 16:39

This branch was previously deployed

1 inactive deployment
Preview 47f9553a 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