feat: add segmented BTree index merge_segments support#6889
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
ffc7cb8 to
9fce59f
Compare
|
Hi @Xuanwo This pr is ready for review. please take a look. thanks! |
Resolve conflicts in index.rs and scalar.rs where main's segmented Bitmap index work runs parallel to this branch's segmented BTree work: - scalar.rs: register both `mod bitmap` and `mod btree` - index.rs: keep both segment detectors and route merge_existing_index_segments to bitmap vs btree (vector / inverted / bitmap / btree) Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| .num_indices_to_merge | ||
| .unwrap_or(1) | ||
| .min(old_indices.len()), | ||
| _ => { |
There was a problem hiding this comment.
This makes a publicly reachable state fail during optimize. Multi-segment non-BTree scalar indexes can be committed today, but this guard rejects them instead of defining whether they should be unsupported at commit time or rebuilt during optimize.
There was a problem hiding this comment.
Nice Catch~
Removed the guard — optimize now handles multi-segment non-BTree gracefully instead of failing. merge_scalar_indices decides per case:
- Append delta (no segment selected) → build a new segment over the unindexed fragments, keep the old ones.
- Type supports N:1 merge, ≥1 selected → k-way merge into one segment.
- Type not supports N:1 merge, exactly 1 selected → single-segment update.
- Type not supports N:1 merge, ≥2 selected → rebuild a fresh segment over the covered fragments.
|
Hi @Xuanwo Thanks a lot for your help and review. Comments are all addressed. and CI passed. PTAL~ |
Xuanwo
left a comment
There was a problem hiding this comment.
Thank you for working on this!
Closes: #6979
Also refactored scalar index optimize logic in
append.rs:Unified
merge_scalar_indices— consolidates all scalar-index merge logic frommerge_indices_with_unindexed_fragsinto one function with explicit segment selection and a single capability-based decision tree.Added
BTreeIndex::merge_segments— a k-way segment merge primitive, enabling multi-segment consolidation without re-reading the dataset.num_indices_to_mergeis now honored uniformly for all scalar types — previously scalar indices ignored it and always merged into one segment. Nowappend(=0) builds a delta only for the unindexed fragments,merge_Nmerges the latest N segments, anddefault/merge_1merges the newest delta — matching the inverted/vector semantics.Multi-segment handling is capability-based, never a hard error —
merge_scalar_indicespicks per case:update().Compatibility Testing
Context
Main branch ignores
num_indices_to_mergefor scalar indices — every mode merges the single old segment + new data → 1 segment. A multi-segment scalar index is a state that cannot exist on main.Test Results (single-segment starting state — the only state main can produce)
Behavior is identical across all scalar types here (capability only matters once ≥2 segments exist):
PR-only new behavior: multi-segment scenarios (unreachable on main)
After accumulating N segments via repeated append-mode optimizes (applies to all scalar types):
Query correctness: All combinations verified — no data loss or incorrect results. Added tests for the delta-append, single-segment
update, and multi-segment rebuild paths.