fix: create index conflict with concurrent rewrite columns updates#6493
Open
zehiko wants to merge 1 commit intolance-format:mainfrom
Open
fix: create index conflict with concurrent rewrite columns updates#6493zehiko wants to merge 1 commit intolance-format:mainfrom
zehiko wants to merge 1 commit intolance-format:mainfrom
Conversation
…ed fields
When a MergeInsert updates fewer columns than the dataset schema, Lance
takes the RewriteColumns path — rewriting column data files in-place
within the same fragment (same fragment ID, same row IDs, different
column values). If optimize_indices concurrently builds a new index from
the pre-update data and commits it, the conflict resolver in
check_create_index_txn unconditionally allows it ("row ids are still
valid"). The resulting index has stale values for the rewritten columns.
Since the fragment ID didn't change, effective_fragment_bitmap does not
filter it out, and the stale index data is authoritative. Indexed scans
then return incorrect results while full scans return correct data.
The fix: when CreateIndex encounters a concurrent Update with
RewriteColumns mode, check whether the modified fields overlap with the
new index's fields AND whether the rewritten fragments are in the
index's fragment_bitmap (treating None as "covers everything" for
safety). If so, return a retryable conflict, forcing optimize_indices
to re-read the updated data.
RewriteRows (full-column upsert) and Delete operations remain
unconditionally allowed — they remove the old fragment entirely, so
effective_fragment_bitmap naturally filters out stale entries.
Contributor
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
This was referenced Apr 16, 2026
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.
What is this about?
While running concurrently index optimization along with Dataset updates we've observed incorrect query results. As we dug deeper I believe we've identified the root cause - index corruption when
optimize_indices(CreateIndex) races with a partial-columnMergeInsert(Update withRewriteColumnsmode).I obviously don't have deep knowledge of Lance internals, so I'm happy to learn that actually our usage of APIs was problematic or that this bug fix is not really the right way to go about it.
Investigation
I've built independent (to our own code base) small reproducer and managed to figure out that the key thing to reproduce was making sure that updates to the dataset are partial-column updates i.e. we try to update with the
RecordBatchthat has less columns then ourDataset. While doing such updates concurrently withoptimize_indicescalls, we've landed at situation where the index was corrupted (or more precisely - stale).Repro example is basically something like:
Root cause details
When a
MergeInsertupdates fewer columns than the dataset schema, Lance takes theRewriteColumnspath — rewriting column data files in-place within the same fragment (samefragment ID, same row IDs, different column values). If
optimize_indicesconcurrently builds a new index from the pre-update data and commits it,check_create_index_txnunconditionally allows it with the comment "row ids are still valid." The resulting index has stale values for the rewritten columns.Since the fragment ID didn't change,
effective_fragment_bitmapdoes not filter it out, and the stale index data is authoritative. Indexed scans return incorrect results while full scans return correct data.Fix
When
CreateIndexencounters a concurrentUpdatewithRewriteColumnsmode:fragment_bitmap(treatingNoneas "covers everything")optimize_indicesto re-read the updated dataRewriteRows(full-column upsert) andDeleteremain unconditionally allowed — they remove the old fragment entirely, soeffective_fragment_bitmapnaturally filtersstale entries.
Testing done