Repository navigation
feat(index): merge LabelList segments with new rows during optimize - #11231
Conversation
fa568bb to
b490574
Compare
b490574 to
4cf5942
Compare
## Problem Every scalar index merge repeated the same field and declaration validation, row-domain guard, per-segment filters, destination store allocation, source opening/downcast, and `IndexMetadata` assembly. Bitmap also depended on btree for its empty new-data stream, and append's merge dispatch rebuilt the same filters per arm. ## Change Add `scalar/segment_merge.rs` to own the shared merge inputs and output: - empty groups, keyed field/path and same-declaration checks - per-type stable-row-id legacy guard, preserving Bitmap/BTree/LabelList/MinHash bottom-level mixed-domain errors; RTree/NGram keep the shared-domain guard - per-segment filters and coverage unions - typed source opening/downcast - UUID/store allocation and one metadata constructor - the empty value/address stream used by pure consolidation All scalar merge modules now use it; Bitmap no longer reaches into btree. `append.rs` constructs filters once for the simple merge primitives. MinHash keeps its historical admission rule: non-stable tables can merge disjoint v0 and v1 segments into v1, while stable tables still reject legacy input. No public API, persisted format, or Python wrapper changes. #11273, #11231 and #11280 are complementary and not dependencies; their behaviors are not pulled in here. Overlap is mechanical in the same scalar modules and append dispatch. Current main's #11290 only changes tagged FRI retention bookkeeping and #11391 changes commit configuration; neither changes a caller contract used by this change. ## Validation - `cargo fmt --all -- --check`: pass - `cargo clippy --all --tests --benches --profile ci -j 4 -- -D warnings`: pass (only existing lance-linalg build-script notices) - Runtime on head `d23cbafd5`, one test executable, 49 unique tests: - scalar MinHash module: 16 passed, including mixed v0-layout/v1 disjoint merge, commit, reopen and `fast_search` for both stable and non-stable datasets, plus the historical-layout legacy regression - `index::tests::merge`: 8 passed - append/optimize: BTree 9, Bitmap 7, NGram 1, BloomFilter 4, FTS 3, scalar stale-row 1 No released MinHash v0 fixture exists; the v0 layout is reconstructed from a current segment (`_rowid`, version 0) by the test helper. The test exercises real merge, commit, reopen and search rather than mocked metadata. Remaining coverage: the full workspace test matrix and a Python wheel were not run. The Python wrapper is unchanged, and the mixed historical layout is not constructible through it. Clean merge tree with current main `e90fe4b8e7c8c819bb51171a43fc94d01b40e2c7`: `bdbb1029cd3e7ab3a54ac3036d258cd4e6dcbcaa`.
4cf5942 to
0088d3f
Compare
Xuanwo
left a comment
There was a problem hiding this comment.
@ddupg I verified single-task optimize at 0088d3f33a after compaction with deferred remapping, deletes, and an append. It reused the old index and read only the appended data file. After reopening, both membership and negated membership queries matched a full scan.
There’s one blocker when integrating this with #11283. The new merge_segments wrote a posting for label 99 beneath a NULL Arrow list. The NULL bitmap masked it in query results. In either merge order, merge_segments still calls helpers removed by #11283 outside the marked conflict. In the second PR to land, please route new rows through unnest_labels(new_data, new_nulls.clone(), ROW_ADDR)?. A regression on the reopened index should check that a NULL parent contributes no child posting and that a null element in a valid list keeps its posting.
@Xuanwo Thanks for verifying and reviewing! Feel free to merge either PR first. Once one lands, I’ll rebase the other. |
|
Thanks @ddupg. #11283 landed first on |
0088d3f to
17e980b
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The rebase correctly applies #11283’s parent-validity expansion to new rows in merge_segments. Reopened stored-index regressions cover both List and LargeList, preserving null-element postings while excluding children of NULL lists. The direct merge preserves per-source filtering, overlays, and the legacy rebuild path while avoiding the intermediate write and merge pass, without changing the storage format.
Thanks, @Xuanwo! I’ve rebased #11231 onto |
Xuanwo
left a comment
There was a problem hiding this comment.
Thanks for the rebase. I verified 17e980b5 on top of b014d78b. All four stored-posting cases passed across List and LargeList, for training and merging new rows. A NULL list contributed only to the list-null bitmap, and a null element inside a valid list kept its posting. All 13 public label_list_optimize cases passed.
In a local deferred-remap, delete and append test with stable row IDs disabled, optimize read the appended data file once and neither compacted data file. After reopening, the stored postings matched the expected live rows, and both positive and negated indexed queries agreed with full scans.
Part of #10847. Follow-up to #10954.
#10954 added bounded optimize for LabelList and kept existing segments in the merge stage, even when a merge group had only one build task.
This PR lets a lone build task merge the selected old segments with new rows and write the final segment directly. That saves an intermediate index write and a separate merge pass. The merge applies each source segment's filter to both label postings and list-level NULLs. Incompatible legacy segments use the existing rebuild path.
Tests cover single-task and multi-task plans, partial deletions, and overlay updates. The single-task regression also checks that the task reads the new fragment's data files without rescanning the old fragments' data files.