Repository navigation
fix(fts): use the shared corpus scorer on tables with deleted rows - #11139
Merged
LuQQiu merged 5 commits intoNov 17, 2026
Merged
Conversation
The shared-corpus plan was skipped when any fragment had a deletion file. Remove that condition: indexed statistics keep their index-time values, the unindexed scan stays deletion-aware, and deleted rows are never returned. Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
@claude review |
LuQQiu
marked this pull request as ready for review
November 16, 2026 22:29
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
jackye1995
approved these changes
Nov 16, 2026
Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
Contributor
Author
|
@claude review |
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.
Related to #9058. Follow-up to #9243.
Problem
#9243 added a plan (
MatchCorpus) that scores an exactMatchor row-levelPhrasequery against one set of corpus statistics: the committed index statistics plus every unindexed row. Both the indexed arm and the unindexed arm use it, so scores no longer depend on the query filter or on how much of the table is indexed.That plan was limited to append-only tables. The planner skipped it as soon as any fragment in the dataset had a deletion file. One deleted or updated row anywhere in the table sent every such query back to the older plan and the behaviour described in #9058. Deletion files stay until compaction rewrites the fragment, so a table that receives updates rarely qualified.
Change
Remove that one condition from
plan_corpus_query. A deletion file no longer decides which plan runs. Every other eligibility rule is unchanged (primary FTS, exact single-columnMatchor row-levelPhrase, defaultwand_factor, nofast_search, no data overlay, V2/V3 postings).No execution code changes. The two arms already handle deletions:
Scoring on a table with deletions
Example: 1000 rows are indexed, 100 of them are later deleted, and 50 rows are appended without indexing. The shared scorer uses a document count of 1050 (1000 from the index, 50 from the scan); the exact live count is 950. Document frequency and average length are built the same way.
This is the approximation the indexed arm of the older plan already uses, so no score gets less accurate with this PR. What changes is that both arms now use the same numbers on these tables too. An update counts twice until the index is rebuilt: the old version in the index statistics and the new version in the scan.
Making the indexed statistics exclude deleted rows needs a pass over the posting list of every query term. That stays with #9058.
Tests
In
rust/lance/src/dataset/tests/dataset_index.rs, next to the existing #9058 cases and reusing their helpers:test_fts_9058_deletions_corpus_scores: one row is deleted in an indexed fragment and one in an unindexed fragment. The plan containsMatchCorpus, the deleted rows are not returned, and rows and scores match the raw-text BM25 oracle computed over "indexed rows as of index time plus live unindexed rows". Cases: no filter, prefilter, filter; with and without stable row ids; with and without a limit. Checked before and after an append-modeoptimize_indices: the existing segments keep their statistics and the new segment is built from live rows, so the expected scores are the same at both stages.test_fts_9058_phrase_deletions_corpus_scores: the same check for a row-levelPhrasequery. One indexed and one unindexed row that match the phrase are deleted; the plan containsMatchCorpusandPhraseQuery, neither deleted row is returned, and scores match the raw-text phrase oracle over the same corpus definition. Cases: no filter, prefilter, a filter that selects only unindexed rows, an explicit fragment selection; with and without stable row ids; before and after an append-modeoptimize_indices.test_fts_9058_fully_deleted_fragment: a fully deleted indexed fragment and a fully deleted unindexed fragment return no rows and do not fail, before and after index optimization.test_fts_9058_deleted_candidates_stay_excluded: existing test, assertions unchanged, comment updated.All of the above run in CI.
🤖 Generated with Claude Code