Repository navigation
fix(core): avoid correlated sqlite-vec orphan cleanup - #1612
Merged
Merged
Conversation
Signed-off-by: mikemikimike <[email protected]>
The contributor's reconciliation test checks which rows the cleanup keeps, and it passes on the old correlated DELETE too, since both statements delete the same rows. Add a regression test that captures the executed DELETE and asserts its EXPLAIN QUERY PLAN has no correlated subquery. It fails on main and passes with the join. Also add a comment on why the subquery joins by rowid, and a CHANGELOG entry crediting @mikemikimike for #1581. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01BF4TkgAJpVrgwzrhemkdig Signed-off-by: phernandez <[email protected]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #1584 by @mikemikimike, landed through an in-repo branch so CI runs (fork PRs get no CI). Their commit is cherry-picked with authorship and sign-off intact; it will be rebase-merged to keep it.
Fixes #1581
Why
SQLiteVecIndex.delete_orphansdeleted stale vectors with a subquery that readsearch_vector_embeddings.source_hashfrom the outer DELETE. That makes it a correlated subquery, so SQLite re-ran it once per vec0 row. The work is quadratic in vault size and holds the write lock long enough that concurrent writers fail withdatabase is locked.What changed
search_vector_embeddingsby rowid and comparessource_hashthere. It deletes the same rows. Their test extends the reconciliation case (stale hash, other model, other index, other project, true orphan).EXPLAIN QUERY PLANhas noCORRELATEDstep. It fails on main and passes with the fix. Also a comment on the join and a CHANGELOG entry.Verified against current main (partitioned vec0)
The #1558 work added a
project_idpartition key to the vec0 table. The old SQL was unchanged on main, and the fix still applies. Benchmark on the partitioned schema, 5,000 rows, 64 dimensions:CORRELATED LIST SUBQUERYLIST SUBQUERY, chunks byidx_search_vector_chunks_project_entity, vectors by rowid point lookupjust fast-checkpassesjust fast-testpasses on the sqlite-vec, semantic, and vector-sync repository tests🤖 Generated with Claude Code
https://claude.ai/code/session_01BF4TkgAJpVrgwzrhemkdig