Repository navigation
Conversation
`merge_scalar_indices` listed only `IndexType::BTree` in
`has_segment_merge_primitive`, so a Bitmap index with more than one selected
segment fell through to `rebuild_scalar_segment` -- a full rescan and retrain
over every covered fragment. Bitmap declares
`TrainingCriteria::new(TrainingOrdering::Values)`, so that rescan is wrapped
in a blocking spilling `SortExec` against `FairSpillPool(LANCE_MEM_POOL_SIZE)`.
On a production boolean column that meant sorting ~955M rows through a 32 GiB
DataFusion pool to produce a ~1 MB index: 12-17s failures on an 8 GiB pool,
or 38+ minutes wedged on a zero-byte spill file on a 32 GiB one.
Wire Bitmap into the same N:1 segment-merge path BTree uses, as a k-way
sorted merge-join over the source segments' postings. Each segment
contributes its keys from the in-memory `index_map` and its bitmaps one key
at a time through `load_bitmap`. Both choices are load-bearing:
- `index_map` is a `BTreeMap`, so key order does not depend on the on-disk
row order. Bitmap lookup files are not reliably key-sorted -- `remap` and
the `merge_bitmap_indices` HashMap union wrote them from a `HashMap`, and
even `streaming_build_and_write` appends an old-only null row last -- so a
merge that read the files sequentially and assumed sorted input would
silently drop postings.
- `load_bitmap` is the accessor that applies fragment-reuse remapping.
Reading the lookup file's raw bytes would bypass it and emit row
addresses pointing at fragments compaction has already retired, which
under `defer_index_remap: true` is silent data loss.
Peak memory is one posting per segment for the current key plus the union
being emitted -- the bound `merge_shards` gives -- rather than the whole
merged index in heap the DataFusion pool cannot see, which is what the
deleted `merge_bitmap_indices` HashMap union held.
Per-segment `OldIndexDataFilter`s are applied to each source posting, so
compaction-retired fragments and stable-row-id rewrites are dropped exactly
as on the BTree path, and a filter that keeps nothing skips the segment's
reads entirely.
`Dataset::merge_existing_index_segments` now routes bitmap groups through the
same primitive, which also gives it the per-segment filtering it lacked.
Co-Authored-By: Claude Opus 5 <[email protected]>
…nsolidation Close three coverage gaps in the Bitmap segment-merge path: - a k-way merge whose NEW data stream contains nulls, exercising the finish_run null branch that folds every old segment's null_map in exactly once (with a per-segment filter applied to one null posting); - Boolean key columns, the motivating production column type (all previous tests used Utf8 keys); - a genuinely wide consolidation: 26 delta segments merged into one segment by a single optimize_indices call (previous e2e merged 3). Co-Authored-By: Claude Fable 5 <[email protected]>
Member
Author
|
@claude do a full code review, focus on correctness, edge cases, silent corruptions and data loss. |
This was referenced Aug 28, 2026
Member
Author
|
tested, seems to be a significant improvement, prepped a PR against v10 |
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
merge_scalar_indiceslisted only BTree inhas_segment_merge_primitive, so a Bitmap index with more than one selected segment fell through to a full rescan + retrain over every covered fragment. Bitmap trains onTrainingOrdering::Values, so that rescan runs a blocking spillingSortExecagainstFairSpillPool(LANCE_MEM_POOL_SIZE). On a production boolean column that meant sorting ~955M rows to produce a ~1MB index: 12–17s failures on an 8 GiB pool, and 38+ minutes wedged on a zero-byte spill file on a 32 GiB one.Fix
Wire Bitmap into the N:1 segment-merge path as a k-way sorted merge-join over each segment's
index_map, streaming one posting at a time through theload_bitmapaccessor (which applies fragment-reuse remapping), with each segment'sOldIndexDataFilterapplied before the union. Peak memory is one posting per segment plus the union being written. The old whole-index HashMap union (merge_bitmap_indices) is deleted.Benchmark
Rerun dataplatform consolidation harness, 500M-row Segment-Manifest-shaped dataset, 26 index segments, FRI at 26 versions/500M rows, prod env incl.
LANCE_FRAG_REUSE_REMAP_MODE=compact, cold cache, c7i.8xlarge local XFS:A commit-isolation ladder showed this commit alone accounts for the entire bitmap gain (baseline ≈ baseline+PR36+append-fix; adding this commit gives the full win; RSS 990 MB → 93 MB at 50M rows).
Tests
Shipped with the fix:
test_bitmap_merge_k_segments,test_bitmap_merge_k_segments_without_new_data,test_optimize_bitmap_multi_segment_merge_consolidates,test_optimize_bitmap_merge_remaps_deferred_compaction,test_optimize_bitmap_drops_stale_rows_across_segments_after_update.Added in the follow-up commit:
test_bitmap_merge_k_segments_with_new_nulls(nulls on the NEW data side of the k-way merge),test_bitmap_merge_k_segments_boolean_keys(Boolean key column, the production shape),test_optimize_bitmap_wide_consolidation(26 delta segments consolidated by oneoptimize_indicescall).cargo test -p lance-index --lib scalar::(330 passed),cargo test -p lance --lib index::(572 passed),cargo clippy -p lance-index -p lance --all-targetsclean.Upstream status
Not upstream: lancedb/lance main at
0a4e20e2a5cf09641109f466ea4846e62045f085(2026-08-28) still dispatches onlyIndexType::BTree | IndexType::NGraminhas_segment_merge_primitive, so multi-segment Bitmap consolidation still rebuilds via full rescan there (rerun-io release-9.0.0/release-10.0.0 likewise lack it).Suggested follow-up (not in this PR)
Replace the pre-existing
.unwrap()on posting deserialize (bitmap.rs ~465) with an error — consolidation now reads every posting of every source segment through it, and panic=abort deployments would die on one corrupt posting.🤖 Generated with Claude Code