Repository navigation
fix(stable_row_id): segmented scalar index returns stale rows under stable row ids - #9785
Merged
Xuanwo merged 9 commits intoOct 23, 2026
Conversation
…w ids A segment's postings are only valid for rows still stored in the fragments it covers, but query-time masking used 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 value passed the union mask: after `optimize_indices(OptimizeOptions::append())`, `id = 0` through the index returned the updated row while a full scan returned nothing. `LogicalScalarIndex` now keeps each segment's fragment coverage and, for segments that return hits, restricts their row-id results to the live row ids currently stored in that coverage (the cached stable-row-id allow-list keyed by version and coverage) before combining them. Address-domain segments (zone map, bloom filter, FM-index) are unchanged: their stale hits are deleted addresses that the row-id translation already drops. `NullableRowAddrSet::into_parts` lets the restriction run in place.
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! |
Move the helper's imports to the top of the test module, build the input with record_batch!(), and run the BTree and ZoneMap cases as one rstest.
Since lance-format#9481 a newly built BTree returns row addresses, so the btree case of stale_posting_after_update_with_stable_row_ids no longer exercises the row-id mask and passes without it. Add a Bitmap case, which still returns row ids and fails without the mask, and assert each case's expected result domain so a future domain change cannot silently hollow out the test.
Xuanwo
force-pushed
the
fix/stable-row-id-segment-masking
branch
from
October 23, 2026 09:21
c1ccb12 to
d8b0f6e
Compare
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The constructor integration is fixed. Restricting each segment's hits before union addresses the stale-posting cause, and the Bitmap regression now exercises the row-ID path. No blocking findings remain.
Please mark this PR with the breaking-change label.
Xuanwo
approved these changes
Oct 23, 2026
Xuanwo
added a commit
that referenced
this pull request
Oct 23, 2026
…ow ids (#9872) ## 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 #9817 covers every search path and both merge paths. --------- Co-authored-by: Xuanwo <[email protected]>
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.
Problem
With
enable_stable_row_ids = true, a scalar index with more than one segment returns rows that no longer match the filter.BTreeindex onid.UPDATE ... SET id = 1000 WHERE id = 0. The row keeps its row idRbut moves to a new fragment; its old slot is marked deleted.optimize_indices(&OptimizeOptions::append()). The old segment A is kept; the new fragment gets segment B.WHERE id = 0through the index returns 1 row, a full scan returns 0.Root cause
id = 0 -> R.LogicalScalarIndexunions the per-segment results before that masking runs, so the segment boundary is lost.Ris live in a fragment segment B covers, so the union lets segment A's stale posting through.Fix
LogicalScalarIndex::try_newtakes the dataset and each segment with itsIndexMetadata, and under stable row ids keeps each segment'sfragment_bitmap.DatasetPreFilter::do_create_deletion_mask_row_id, cached per version and coverage, fetched only for segments with hits.ZoneMap,BloomFilter,FMIndex) are not masked: their stale hits are deleted addresses that the row-id translation already drops.NullableRowAddrSet::into_partsis added so the restriction runs in place.