perf: fix O(N²) version column scan with deletion vectors#6375
Merged
BubbleCal merged 4 commits intolance-format:mainfrom Apr 2, 2026
Merged
Conversation
When scanning `_row_created_at_version` or `_row_last_updated_at_version` on fragments with deletion vectors, the previous implementation called `sequence.versions().skip(r.start).take(...)` for each range in the selection. Since `versions()` creates a fresh iterator from the start, `skip(r.start)` walks through all prior elements — O(rows) per range, leading to O(rows × ranges) total work. Replace with `version_values_for_selection()` that: - Fast-paths single-run fragments (common case) with `vec![version; count]` - Uses binary search over precomputed run offsets for O(log(runs)) per position in the multi-run case Benchmark (1M rows, 33% deleted): - Before: 53s - After: 0.02s
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
7181475 to
27c9ce3
Compare
BubbleCal
reviewed
Apr 2, 2026
Contributor
BubbleCal
left a comment
There was a problem hiding this comment.
Thanks for the great improvements!
rust/lance-table/src/utils/stream.rs
Outdated
| for pos in r.start..r.end { | ||
| let pos = pos as usize; | ||
| if pos >= total_len { | ||
| versions.push(1); // fallback |
Contributor
There was a problem hiding this comment.
i think we will get an error at https://github.com/lance-format/lance/pull/6375/changes#diff-e3ed3f2ff36ff45b28ec19c75b4b9fadcfd857e2ced681ceb22b07fdc4e705b4R360 if we don't have enough rows, but this would hide the error
| continue; | ||
| } | ||
| // Binary search for the run containing this position | ||
| let run_idx = match run_offsets.binary_search(&pos) { |
Contributor
There was a problem hiding this comment.
need one more test to cover this path
…n test Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
BubbleCal
approved these changes
Apr 2, 2026
Contributor
BubbleCal
left a comment
There was a problem hiding this comment.
Good to go once we have all greens
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
@BubbleCal could you approve the workflows again? Fixed the formatting and the windows test failure seemed unrelated. |
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
Scanning
_row_created_at_versionor_row_last_updated_at_versionis extremely slow on fragments with deletion vectors — 53 seconds for 1M rows (vs 0.03s for a regular data column on the same table).This makes the
delta()API (get_inserted_rows()/get_updated_rows()) unusable on any table that has had deletions.Root Cause
In
apply_row_id_and_deletes()(lance-table/src/utils/stream.rs), the version column is built by:versions()creates a fresh iterator from the start of the RLE sequence. For each range in the selection,skip(r.start)walks through all prior elements — O(rows) per range. With deletion vectors creating many small ranges, this becomes O(rows × ranges).Fix
Replace with
version_values_for_selection()that:vec![version; count]— O(1)Benchmark
1M rows, 33% deleted,
_row_created_at_versionscan:Minimal Reproduction