Skip to content

fix(fts): segmented full-text index returns stale rows under stable row ids - #9872

Merged
Xuanwo merged 8 commits into
lance-format:mainfrom
zhangyue19921010:fix/fts-stable-row-id-segment-masking
Oct 23, 2026
Merged

Xuanwo merged 8 commits into
lance-format:mainfrom
zhangyue19921010:fix/fts-stable-row-id-segment-masking

Conversation

@zhangyue19921010

Copy link
Copy Markdown
Collaborator

Problem

On a table with stable row ids, an update keeps a row's id but moves the row to a new fragment. After an append-only optimize_indices gives that fragment its own FTS segment, the old segment's postings for the row become visible again:

  • full-text search returns the row for text it no longer contains, and can return it twice;
  • merging the segments (optimize_indices or merge_existing_index_segments) carries the stale posting into the merged segment, where it can no longer be filtered out.

All segments share one prefilter built over the union of their fragment coverage. The moved row's id is live in a fragment the new segment covers, so the old segment's posting passes the filter. Merging filters old rows against the same union.

This is the full-text part of #9817; the BTREE part is fixed in #9785.

Fix

  • Search: when an index has more than one segment on a stable-row-id table, each segment only reports the live rows stored in the fragments it covers. Every FTS search path applies this per segment: match, phrase/boolean, cross-column, and combined_fields, including its BM25F document length. Tables without stable row ids and single-segment indexes are unchanged.
  • Merge: each source segment is filtered by its own coverage instead of the union, in both merge paths. When the filter drops nothing, the posting rebuild is skipped.
  • Test: one regression test based on the reproduction in bug: stale FTS and BTREE entries returned after an in-place update when the index has more than one segment #9817 covers every search path and both merge paths.

…ow ids

A segment's postings are only valid for rows still stored in the
fragments it covers, but every full-text search path masks hits with one
prefilter built over the union of all segment coverages. Under stable row
ids an updated row keeps its id while moving to a fragment another
segment covers, so the old segment's posting for the old token passed the
shared mask: after `optimize_indices(OptimizeOptions::append())`, a match
query for the old token returned the updated row while a filter scan
returned nothing.

The opener now restricts each segment to the live row ids currently
stored in the fragments it covers (`InvertedIndex::with_allowed_rows`,
built from the cached stable-row-id allow-list for that coverage), and
every search entry intersects that restriction into the query mask per
segment: the per-segment BM25 search, the compound search, the
cross-column search, and the combined-fields search. Address-based row
ids and single-segment indices are unchanged.
…gment merges

- Cross-column compound search: filter each source's staged candidates by
  the rows its segment may report, so a moved row is not matched against
  the old segment's postings.
- combined_fields: count a row's length only from segments that may report
  it, so a moved row's BM25F length leaves out its old content.
- Segment merges: filter each source segment by its own coverage instead of
  the union of all sources, in both optimize_indices and
  merge_existing_index_segments, so a merge does not carry a stale posting
  into the merged segment. Skip the posting rebuild when nothing is dropped.

The regression test follows the reproduction in lance-format#9817 and covers match,
phrase, cross-column, combined_fields and both merge paths.

Refs lance-format#9817

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 10, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 12, 2026
@zhangyue19921010

Copy link
Copy Markdown
Collaborator Author

Hi @wjones127 @BubbleCal Would u mind to take look ? This is a bug of incorrect data querying in the stable row id scenario. Thanks!

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. and removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 12, 2026
@wjones127

Copy link
Copy Markdown
Contributor

@zhangyue19921010 why did you close this?

@zhangyue19921010

Copy link
Copy Markdown
Collaborator Author

@zhangyue19921010 why did you close this?

Hi @wjones127 thanks for taking a look. To start with, I haven't been able to find a good way to address the additional cold-read cost. Also, I came across #8085 — I'm not sure whether it will naturally resolve this issue once it's ready. That said, if you could review it and we could work on solving it together, I'd really appreciate it.

@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 13, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 13, 2026
@wjones127
wjones127 self-requested a review October 16, 2026 18:35
@wjones127 wjones127 added the critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. label Oct 19, 2026
@lance-gatekeeper lance-gatekeeper Bot removed K-risk Latest Gatekeeper recommendation includes a non-blocking risk. K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 2026
@github-actions github-actions Bot added A-python Python bindings A-java Java bindings + JNI A-deps Dependency updates labels Oct 23, 2026
@Xuanwo
Xuanwo force-pushed the fix/fts-stable-row-id-segment-masking branch from 9dc5bb4 to 84ae40a Compare October 23, 2026 09:21
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 2026

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

⚠️ Gate recommendation: approve with a non-blocking risk.

The merge integration is fixed, and both stale-posting regression cases pass. Per-segment ownership addresses stale FTS postings in search and both merge paths.

Extra cold-query I/O and decoded-column memory remain the author-accepted non-blocking trade-off. Prewarming with sufficient cache can amortize that cost.

FTS still trains and updates with row IDs, so the broader row-address conversion in #8085 does not supersede this fix.

Please mark this PR with the breaking-change label.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk. labels Oct 23, 2026
@Xuanwo
Xuanwo merged commit 08b6af2 into lance-format:main Oct 23, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-deps Dependency updates A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-python Python bindings bug Something isn't working critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. K-approved Latest Gatekeeper recommendation permits acceptance. K-risk Latest Gatekeeper recommendation includes a non-blocking risk.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants