Skip to content

fix(fts): use the shared corpus scorer on tables with deleted rows - #11139

Merged
LuQQiu merged 5 commits into
lance-format:mainfrom
LuQQiu:lu/fts-corpus-plan-with-deletions
Nov 17, 2026
Merged

LuQQiu merged 5 commits into
lance-format:mainfrom
LuQQiu:lu/fts-corpus-plan-with-deletions

Conversation

@LuQQiu

@LuQQiu LuQQiu commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Related to #9058. Follow-up to #9243.

Problem

#9243 added a plan (MatchCorpus) that scores an exact Match or row-level Phrase query 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-column Match or row-level Phrase, default wand_factor, no fast_search, no data overlay, V2/V3 postings).

No execution code changes. The two arms already handle deletions:

Statistics it contributes Rows it can return
Indexed segments Values stored at index time. Rows deleted after indexing are still counted. Deleted rows are masked out.
Unindexed fragments Counted while scanning. The scan skips deleted rows, so only live rows are counted. Live rows only.

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 contains MatchCorpus, 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-mode optimize_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-level Phrase query. One indexed and one unindexed row that match the phrase are deleted; the plan contains MatchCorpus and PhraseQuery, 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-mode optimize_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

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]>
@github-actions github-actions Bot added the bug Something isn't working label Nov 16, 2026
@LuQQiu

LuQQiu commented Nov 16, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.

@LuQQiu
LuQQiu marked this pull request as ready for review November 16, 2026 22:29

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@LuQQiu

LuQQiu commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review found no issues

No high-confidence issues detected in this change.

@LuQQiu
LuQQiu merged commit a5e0dec into lance-format:main Nov 17, 2026
44 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants