Conversation
…egment FM-Index merge_segments always rebuilds from source text, even for a single source segment whose fragment coverage is unchanged. Distributed builds that fold intermediates 1:1 into final segments therefore build every segment twice. Return the source segment as-is when there is exactly one and its coverage is still fully live. Multi-source merges and segments with retired fragments keep the rebuild behavior.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
xuanyu-z
approved these changes
Jul 2, 2026
Xuanwo
approved these changes
Jul 2, 2026
jackye1995
pushed a commit
that referenced
this pull request
Sep 23, 2026
…ndex (#9421) Supersedes #9271; merging this closes #9270. ## Merging segments across a compaction `merge_existing_index_segments` combines staged segments into one. When a compaction has retired the fragments those segments were built over, their coverage has to be resolved against the current manifest before the merge can mean anything. Resolving each segment on its own cannot do that. A segment covering one fragment of a three-fragment rewrite group is a straddle, and the remapper drops straddles rather than claim a fragment holding rows the segment never indexed — so every segment of the group resolves to nothing and the merge produces an empty index. This affected five of eight scalar families. The merge owns the whole group, so it remaps the *union* of its segments, which is complete where each segment alone is not. FM segments are rebuilt rather than passed through, because a passthrough returns coverage in the new fragment space with row addresses still in the old one. ## Coverage may only move with the row addresses `open_scalar_index` takes its remapper from the dataset's reuse index. Where that mapping is missing, the addresses stay in the old fragment space and the coverage must not advance to the new one. An index claiming coverage it cannot serve is worse than one covering less: a short claim falls back to a flat scan, a false claim suppresses that fallback and returns nothing. So coverage shrinks where no mapping applies, and the three ways that loses rows are reported: - **No applicable mapping over retired fragments.** They are intersected away and their rows leave the index. Partly retired counts, since the surviving half would otherwise make the coverage look healthy. - **A rewrite chain only partly mapped.** Fragments compacted more than once need every link; a trim that dropped an earlier one leaves the remap on an intermediate fragment the dataset no longer has. - **A straddling union.** The segments together cover only part of a rewrite group. The remapper reports the group it heals, but not that here it costs the entire merged index rather than the straddling rows. None is an error. A shrunk coverage is correct when the rows were deleted, and at that point nothing distinguishes that from a mapping that was trimmed. A merge whose coverage shrank rebuilds rather than fails, which `test_fmindex_merge_single_segment_rebuilds_when_coverage_shrinks` (#7569) holds. ## Index families the remap does not cover Vector cannot remap here: its merge hands the segments to the distributed file merger with an object store and a directory, reaching no dataset and so no reuse index. Vector indexes are remapped through `optimize_vector_indices_v2`, which passes the reuse index to the builder. RTree does load through the remapper, so it belongs under this rule, but the `all_rtree` branch writes the same coverage field from its own staleness pruning — which drops fragments whose indexed files changed, a different question from which fragments a rewrite replaced. Bringing RTree under the remap means settling how the two compose, and no test yet drives an RTree index through a deferred compaction. Both families shrink coverage rather than over-claim, so the uncovered case costs a flat scan rather than a wrong answer. An RTree merge without the `geo` feature is refused before the coverage work rather than after it. --------- Co-authored-by: Gatefixer <312823363+lance-gatefixer[bot]@users.noreply.github.com>
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_existing_index_segmentsfor FM-Index always rebuilds the segment from source text — correct for multi-source merges (there is no cheap way to combine two BWT structures), but wasted work when merging a single segment whose fragment coverage is unchanged.This makes distributed FM-Index builds pay for everything twice: workers build per-fragment-subset segments via
execute_uncommitted, and when intermediates fold 1:1 into final segments, the merge step discards each one and rebuilds identical content over the same fragments.Fix
After computing the merged coverage (union of source bitmaps ∩ live fragments), if there is exactly one source segment and its coverage is still fully live, return it as-is. The caller already re-stamps
dataset_version/fields, and the segment (fromexecute_uncommitted) carries itsindex_detailsandfiles, so commit-side validation is unaffected.Multi-source merges, empty coverage, and single segments with retired fragments (concurrent compaction) keep the existing rebuild behavior — the new
test_fmindex_merge_single_segment_rebuilds_when_coverage_shrinkstest guards that boundary.