Skip to content

refactor(index): share scalar segment merge scaffolding - #11402

Merged
Xuanwo merged 3 commits into
mainfrom
xuanwo/deduplicate-index-merge-scaffolding
Nov 24, 2026
Merged

Xuanwo merged 3 commits into
mainfrom
xuanwo/deduplicate-index-merge-scaffolding

Conversation

@Xuanwo

@Xuanwo Xuanwo commented Nov 23, 2026

Copy link
Copy Markdown
Member

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.

Move the inputs and output shape every scalar segment merge repeats into
one module: field and declaration checks, the row-domain guard,
per-segment filters, source opening, index store allocation, and
metadata assembly. Bitmap no longer builds its empty stream through
btree, and the append merge path builds filters once for all simple
merge primitives.
Only a stable-row-id table must reject a pre-migration v0 segment:
without stable row ids its stored ids are addresses, so a v0 and a v1
segment with disjoint coverage merge into one v1 segment. Restore that
admission rule so explicit staged merges and distributed optimize keep
working.

Keep the stable-row-id rejection in the per-type guard for Bitmap, BTree,
LabelList and MinHash, so their bottom-level mixed-domain checks retain
the existing error class. Drop the synthetic Bitmap relabeling test and
extend the MinHash legacy test through merge, commit, reopen and
fast_search for both source fragments.

Simplify open_sources through open_source, and remove ensure_details now
that the only caller dispatches by details first.
The explicit index name now belongs to the committed v0 segment, so the
disjoint current v1 builder must opt into replacing that name before its
uncommitted segment can be merged.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Gate recommendation: approve.

No blocking issues found in the shared merge scaffolding or append dispatch.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 23, 2026
@Xuanwo
Xuanwo merged commit 58d32b6 into main Nov 24, 2026
42 checks passed
@Xuanwo
Xuanwo deleted the xuanwo/deduplicate-index-merge-scaffolding branch November 24, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants