Repository navigation
fix: apply fragment bitmap allow-list to index search results - #6563
Merged
westonpace merged 4 commits intoApr 19, 2026
Merged
westonpace merged 4 commits into
westonpace merged 4 commits into
Conversation
Restrict index search results to only fragments listed in the index's fragment_bitmap. This prevents stale index entries from leaking through when a fragment's data changes (e.g. via DataReplacement or partial merge_insert) but the index is not rewritten. The allow-list is applied in two places: - DatasetPreFilter (for vector and FTS index queries) - MapIndexExec (for scalar index queries used by merge_insert) Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Instead of applying the allow-list separately in DatasetPreFilter and MapIndexExec, move it into create_deletion_mask so all callers get the protection automatically. When the dataset has fragments outside the index's fragment bitmap, the mask now restricts results to only the indexed fragments. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Split create_deletion_mask into two variants: - create_deletion_mask: original behavior, no fragment restriction - create_restricted_deletion_mask: also applies allow-list The allow-list should only be applied when the fragments parameter represents a real index fragment bitmap, not a conservative fallback range (which happens when fragment_bitmap is None). Fixes remap_ivf_pq_index test failure caused by the fallback range 0..max_fragment_id being empty for single-fragment datasets. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
westonpace
marked this pull request as ready for review
April 17, 2026 22:22
wjones127
approved these changes
Apr 17, 2026
wjones127
left a comment
Contributor
There was a problem hiding this comment.
This looks good! Thanks for putting this up.
1 task done
westonpace
pushed a commit
that referenced
this pull request
Apr 20, 2026
## Summary Fix `unresolved link to create_deletion_mask` rustdoc error introduced in #6563. `[create_deletion_mask]` → `[Self::create_deletion_mask]` in the doc comment for `create_restricted_deletion_mask`. ## Test plan - [x] `RUSTDOCFLAGS="-D warnings" cargo doc -p lance --no-deps` passes
jackye1995
pushed a commit
that referenced
this pull request
May 2, 2026
#6664) The fragment-bitmap allow-list filter dominates the cost of merge_insert and vector-search prefilter on tables that have received writes since their index was built. The filter ANDs an AllowList of full fragments with the deletion BlockList. RowAddrMask::bitand expands AllowList & BlockList into AllowList - BlockList, and the per-fragment (Full - Partial) branch in RowAddrTreeMap::sub_assign materializes RoaringBitmap::full() for every fragment with deletions. Build the equivalent BlockList directly (deletions union rows in fragments outside the index bitmap) using only Full markers and a HashMap clone. Existing #6563 stale-index tests cover correctness. --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
westonpace
pushed a commit
that referenced
this pull request
May 4, 2026
#6664) The fragment-bitmap allow-list filter dominates the cost of merge_insert and vector-search prefilter on tables that have received writes since their index was built. The filter ANDs an AllowList of full fragments with the deletion BlockList. RowAddrMask::bitand expands AllowList & BlockList into AllowList - BlockList, and the per-fragment (Full - Partial) branch in RowAddrTreeMap::sub_assign materializes RoaringBitmap::full() for every fragment with deletions. Build the equivalent BlockList directly (deletions union rows in fragments outside the index bitmap) using only Full markers and a HashMap clone. Existing #6563 stale-index tests cover correctness. --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This was referenced May 27, 2026
Xuanwo
pushed a commit
that referenced
this pull request
May 28, 2026
…6965) ## Summary Closes #6877. `do_create_deletion_mask_row_id` previously iterated every fragment in the dataset, so the resulting allow-list included stable row ids whose **current** physical home was outside the index's `fragment_bitmap`. On stable-row-id datasets this bypassed the allow-list added in #6563: `MapIndexExec` requests `create_restricted_deletion_mask`, but the stable-row-id branch at `prefilter.rs:270` ignored the restriction. ### Effect on merge_insert After a `merge_insert UpdateAll` rewrites a row into a new fragment, a second merge_insert against the same key saw that row twice — once via the BTREE (which holds the row's stable row id and resolves to its new fragment through `TakeExec`) and once via the unindexed-fragments scan that also covered the new fragment. Both branches emitted the same `_rowid`, tripping the source-dedup HashSet: ``` Invalid user input: Ambiguous merge inserts are prohibited: multiple source rows match the same target row on (id = "A"). ``` ### Effect on FTS A `full_text_search` after a `merge_insert` returned each moved row twice, because the inverted index's hits went through the same prefilter and the post-filter scan picked up the new fragment. The new regression test `test_issue_6877_fts_no_duplicates_stable_row_ids` empirically fails with "30 unique out of 40 total" before this fix. ## Fix - `prefilter.rs`: thread `restrict_to: Option<RoaringBitmap>` through `do_create_deletion_mask_row_id`. When set, only iterate fragments in the bitmap. The resulting allow-list now means "stable row ids whose current home is inside the restriction" — semantically equivalent to the non-stable-row-id branch. - `prefilter.rs:270`: pass `Some(fragments)` when `restrict_to_fragments=true`, `None` otherwise. - `caches.rs`: add `restrict_hash: Option<u64>` to `RowAddrMaskKey` so two consumers asking for different fragment subsets don't poison each other's cached mask. ## Mechanism, validated Instrumentation on the unfixed code shows the BTREE returning stable row id `4` for the matched row, the deletion-mask allow-list containing `4` (because the new unindexed fragment was iterated globally), `mask & 4 = {4}` passing the filter, both branches emitting `_rowid=4`, dedup HashSet tripping. After the fix, `mask & 4 = {}` correctly excludes the BTREE side and only the unindexed-fragment scan delivers the row. ## Test plan - [x] **Reproduces pre-fix**: stashed the prefilter + cache changes, re-ran the two new regression tests — both FAIL with the documented errors. - [x] **Fixed post-fix**: restored the stash, both tests pass. - [x] `cargo test -p lance --lib prefilter` — 18/18 pass (17 existing + 1 new). - [x] `cargo test -p lance --lib merge_insert` — 145/145 pass (143 existing + 2 new). - [x] `cargo fmt --all` - [x] `cargo clippy --all --tests --benches -- -D warnings` New regression tests: - `test_restricted_deletion_mask_stable_row_id_honors_bitmap` — pins the prefilter contract: full / restricted-subset / empty-bitmap cases. - `test_issue_6877_repeated_merge_insert_stable_row_ids` — mirrors the issue's exact repro: two sequential merge_insert UpdateAll against the same key on a stable-row-id dataset with a BTREE scalar index. - `test_issue_6877_fts_no_duplicates_stable_row_ids` — companion FTS regression: an inverted index + merge_insert sequence that previously returned duplicate hits. ## Notes - The hash on `RowAddrMaskKey` uses `DefaultHasher` over the bitmap's sorted u32s. The cache is process-local in-memory, so cross-version stability isn't required.
Xuanwo
pushed a commit
to lancedb/lancedb
that referenced
this pull request
Aug 6, 2026
## Summary - add a Python regression test for two partial-schema merge inserts against the same BTree-indexed rows - verify repeated updates retain one copy of every row and the final update values ## Root cause Lance 4.0, used by LanceDB 0.30.2, removed a rewritten fragment from the index bitmap while stale BTree entries for that fragment remained searchable. The next merge found each target through both the stale index and the unindexed-fragment scan, producing the ambiguous-match error. Lance fixed the root cause in lance-format/lance#6563 by applying the fragment-bitmap allow-list to index results, and the Lance release pinned by current LanceDB includes that fix. This test preserves the corrected behavior through the Python API. ## Validation - `cd python && uv run --extra tests pytest python/tests/test_table.py -k merge_insert -q` (9 passed) - `cd python && uv run --extra tests --extra dev ruff format --check python/tests/test_table.py` - `cd python && uv run --extra tests --extra dev ruff check python/tests/test_table.py` Repository-wide Ruff also reports 20 pre-existing violations in untouched CI and plugin scripts. Fixes #3280 <!-- lance-gatekeeper-fix:v1 agent=ee6b9565f9780712026076930566f116 generation=1 --> Co-authored-by: Gatefixer <313497061+lancedb-gatefixer[bot]@users.noreply.github.com>
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.
Summary
fragment_bitmap, filtering out stale entries from fragments whose data changed but whose index was not rewrittenDatasetPreFilter(vector/FTS queries) andMapIndexExec(scalar index queries used by merge_insert)DataReplacementand partial-schemamerge_insert(BTree, FTS, and vector indices)Test plan
test_data_replacement_populates_invalidated_bitmap— DataReplacement removes fragment from bitmaptest_fts_stale_entries_after_data_replacement— stale FTS entries blocked after DataReplacementtest_vector_index_after_data_replacement— stale vector index entries blocked after DataReplacementtest_partial_merge_insert_stale_index_ambiguous— repeated partial merge_insert doesn't cause ambiguous errorstest_partial_merge_insert_stale_index_fragment_not_exist— stale btree entries don't cause fragment-not-found errorstest_partial_merge_insert_stale_index_batch_size_mismatch— stale btree entries don't cause batch size mismatchtest_partial_merge_insert_stale_vector_index_duplicates— no duplicate rows from stale vector indextest_partial_merge_insert_stale_fts_index_duplicates— no duplicate rows from stale FTS indextest_compaction_after_invalidated_fragment— compaction succeeds after fragment invalidation🤖 Generated with Claude Code