Repository navigation
fix(fts): skip rows COPY rejects with ignore_errors - #123
Merged
Merged
Conversation
COPY indexes its rows in FTSIndex::finalize, after the whole file is read, but a row rejected for a duplicate primary key is deleted earlier, through NodeTable::delete_. FTSIndex::delete_ then looked for a document that was never indexed and threw "FTS index is inconsistent", failing the whole COPY. delete_ now skips a row past the index's indexed prefix when the docs table has no document for it, and finalize skips rows whose lookup fails instead of indexing the previous row's values under the deleted offset, which added a phantom document and skewed BM25 scores. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adsharma
reviewed
Oct 14, 2026
| ---- ok | ||
| -STATEMENT CALL QUERY_FTS_INDEX('Doc', 'idx', 'banana') RETURN node.id, score; | ||
| ---- 1 | ||
| 2|0.353634 |
Contributor
There was a problem hiding this comment.
@zahariash the exact score match may be a bit brittle and require frequent updates due to code/data changes.
Author
There was a problem hiding this comment.
Fixed in 38c08a2: the pinned score is gone. The test now builds one index before the COPY (maintained through it, so it would pick up the phantom document) and one after (which can't), and checks both score the document the same. Still fails with 2|False without the fix.
Author
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.
This work was produced with the help of language models.
Fixes #118.
COPY ... (ignore_errors=true)into a table with an FTS index mishandled a row rejected for a duplicate primary key.COPYindexes its rows inFTSIndex::finalize, but the rejected row was deleted before that, so the index looked for a document it had never seen and theCOPYfailed. A rejected row without text instead became a phantom document with the previous row's text, skewing BM25 scores.Fix.
delete_skips a row at or past the indexed prefix (checkpointed rows plus this transaction's inserts) when the docs table has no document for it, so an indexed row is still deleted.finalizecheckslookup()and skips deleted rows instead of indexing the previous row's vectors. This also makes rows a crash left outside the index deletable again, until a later insert moves the prefix past them; they stay unsearchable, tracked by LadybugDB/ladybug#1241.Tests.
copy_ignore_errors.testcopies a duplicate with text and checks the other row is indexed and deletable, then one without text and checks the score equals a rebuilt index's, and one where the rejected row is the last in the file, followed by an insert and deletes. The new cases fail on main and pass here. FTS extension tests: no new failures.