Repository navigation
fix(index): merge segments across a compaction without emptying the index - #9421
Conversation
3a6f0ac to
f188671
Compare
f188671 to
ecb6070
Compare
2df321e to
2cd0c51
Compare
There was a problem hiding this comment.
❌ Gate recommendation: request changes.
The retained-history recovery must update the physical row-address space used while merging, not only segment coverage. Carry the recovered remapper into each affected scalar source merge, or rebuild those sources from current fragments, and verify the trimmed-history path with live query results; otherwise a merged index can claim full current coverage while containing no matching rows.
… mapping Coverage may only move with the row addresses. open_scalar_index takes its remapper from the dataset's own reuse index, so 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 suppresses the scan fallback its rows need. Coverage shrinks instead, and the three ways that loses rows are reported.
2cd0c51 to
107c161
Compare
There was a problem hiding this comment.
The false-coverage failure is fixed: unmappable compacted fragments now remain outside index coverage, and a committed empty-coverage merge still returns all rows through flat-scan fallback. The trade-off is that a merge after reuse history has been trimmed can publish partial or empty coverage, so affected queries may scan those fragments until the index is rebuilt; the warning and coverage metadata expose that recovery path.
westonpace
left a comment
There was a problem hiding this comment.
I'm approving because this is fixing legitimate bugs but I'm pretty worried about the rtree and vector special cases. I'll accept a vector special case (we special case just about everything else there too) but we should change rtree to be consistent with the other scalar indexes. Or is there some reason it needs a special path?
At the very least we should probably file a follow-up to get rid of these special cases.
| // Vector merging reads physical files directly and RTree performs its own | ||
| // historical staleness pruning. Scalar merge helpers load their sources | ||
| // through the FRI row-address remapper, so they must filter and report | ||
| // coverage in that same current fragment space. | ||
| let has_remapped_source_coverage = if !all_vector && !all_rtree { | ||
| let index_name = source_segments[0].name.clone(); | ||
| remap_merged_segment_coverage(self, &index_name, &mut source_segments).await? | ||
| } else { | ||
| false | ||
| }; |
There was a problem hiding this comment.
This special casing confuses me. Why are vector indexes or rtree indexes treated differently with respect to remapping?
I thought the fragment bitmap / coverage logic was uniform. I don't really like that we have to have these special cases.
Also Claude seems to think the rtree path is broken but not tested because the geo feature isn't on. It suggests the following
Write a geo-feature test that stages an RTree segment, compacts with defer_index_remap, merges, and asserts the empty result
There was a problem hiding this comment.
Thanks for taking a look, those 2 do have a bit different in handling FRI when merging segments, making vector work will be a larger change so merge vector segments will stay inefficient before we make the change, will open an issue on that. For rtree, I updated the reason why its excluded in this PR with more details, but I'm creating a separate PR as a quick follow up to get it supported so that will leave vector as the only special case.
On the rtree testing, there is missing test for deferred remapping, not really geo is missing. Will include the proper testing in the rtree followup as well
Keeps main's segment-parameter validation ahead of the coverage remap, so a mismatched set is refused before any reuse-index work. An RTree merge without the `geo` feature is refused before the coverage pruning rather than after it, and the comment on the remap exemptions states what each one rests on.
There was a problem hiding this comment.
The deferred-compaction failure remains fixed after the mainline merge: scalar segment coverage now tracks the row addresses the merged index can serve. When reuse history is missing or trimmed, coverage can instead become partial or empty, leaving affected queries to scan those fragments until the index is rebuilt. RTree still uses separate staleness pruning and can also lose coverage after deferred compaction; this is a performance risk, not a reason to claim rows the index cannot serve.
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm (`plan_staged_segments`, from the consumers PR) and threads that plan through every scalar `merge_segments`, the per-segment filters and the opens. `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
… translation plan The distributed build flow (`execute_uncommitted` per fragment, then `merge_existing_index_segments`, then `commit_existing_index_segments`) failed on a tagged table, in three places: every staged open went through the snapshot plan, which only lists committed segments; the tagged coverage and filter builders read "not registered" as "covers nothing" and would have filtered every row of a staged segment out of the merge; and the merged coverage went through the v0 handle, which a tagged table does not have, so it shrank to nothing. The merge now plans the staged set as one group with the reader's own algorithm: `plan_staged_segments` runs the steps `fri_query_plan` runs per committed group (`may_need_translation`, `segment_plans`, `translation_fingerprint`), so a staged segment translates exactly as it would once committed, with its stored bitmap as provenance and the other staged segments as its siblings. That plan is threaded through every scalar `merge_segments`, the per-segment filters and the opens (the `*_with_plan` entry points from the consumers PR). `tagged_segment_coverage` takes the plan: a staged segment's coverage comes from it, and a segment that is neither staged nor listed in the manifest is an error, never empty coverage. Coverage follows the destination model. The per-type merges already emit the effective union in the live domain, and a provenance bitmap left on a merged segment is pruned to nothing at commit, so `remap_merged_segment_coverage` writes each staged segment's planned live coverage into its bitmap before the merge and reports the coverage as remapped. A group that covers no rewrite destination completely claims nothing: those rows stay on the scan path and a warning says so. The v0 handle is never consulted on a tagged table. The NGram merge reads spill files and translates only through the v0 remapper, so a staged NGram segment whose plan translates is refused (NotSupported) instead of being merged with stale addresses; the FM merge rebuilds over the derived coverage. Tests (`index/create/tests/staged_tagged.rs`): btree and bitmap staged segments merged and committed across a stable partition claim exactly the destinations the group covers and answer point queries like the scan; a lone contributor over half a partition claims nothing and scans; segments over fragments no rewrite touched merge as identity; the #9421 deferred compaction flow on a tagged table; and the NGram refusal. Co-Authored-By: Claude Fable 5.1 <[email protected]>
…le indexed data matches (#9524) Extends the merged-segment coverage remap from #9421 to RTree, and only lets coverage follow rows through a compaction where the indexed data is unchanged. ## Problem `merge_existing_index_segments` excluded RTree from the remap, so its staleness pass dropped every fragment a deferred compaction had retired. RTree segments staged before a compaction then merged into an index covering nothing, and their rows fell back to a flat scan. For every scalar family, the remap also carried coverage forward when something else had changed the indexed column along the way, for example an overlay that a compaction then folded in. The merge also stamped the index as current, so an overlay on a covered fragment that no compaction touched stopped masking the index's old value. In both cases the index answered stale values. **Example:** BTree segments on `age` are staged, an overlay updates one row's `age`, and a compaction folds that overlay into a new fragment. The merge claims the new fragment, and on `main` a query for the new `age` returns nothing. ## Fix - RTree now goes through the remap. Its staleness pass exempts only the fragments the remap added. - Coverage moves to a compaction's output only if the segments cover the whole rewrite group. - Each covered fragment is followed through the compactions that rewrote it. Its indexed data must match the version its index entries describe: - where each indexed field is stored (base, path, file version and column), with a packed struct holding an indexed child counting as that child's storage; - its overlays on the indexed fields, judged by the query-time rule; - its deleted rows. Rewriting another column, even in the same file, does not count. - Only fragments shown fresh keep their coverage. A fragment that fails the check is left out, together with everything a compaction later produced from it, and its rows are scanned. If a manifest needed for the check was cleaned up, the affected fragments are left out the same way. That includes a segment's own build version, which costs only that segment's fragments; RTree's second pass also drops such a segment rather than failing the merge. Tagged tables keep their own replay path. ## Tests The merge tests are in `dataset/tests/merge_coverage.rs`. Coverage is dropped for: - partial group coverage - overlays before, after or between compactions - data replacement - in-place updates, including a packed struct whose child is indexed - a cleaned-up commit manifest, or a segment's cleaned-up build version (the other group stays covered) - a restore that removes an overlay or revives a row Coverage is kept for: - whole-group remaps (the merged index holds every row it claims) - other groups in the same compaction, beside a stale one - a fragment no compaction touched, beside an overlaid one - a rewrite of another column in the same file - a group retired without a reuse mapping - RTree on a tagged history A seeded workload stages segments in two batches, with only non-compacting writes in between so the second batch lands at a later version. It runs appends, deletes, in-place updates, overlays, folding and plain deferred compactions, added columns and config commits before, between and after the merge. Point and range lookups are then compared against a scan. `main` returns stale values on this workload. Each check in the staleness logic was disabled in turn, and each change made tests fail. `cargo test -p lance --lib --features geo` passes. clippy is clean with and without `geo`. ## Follow-ups These are left out to keep the change small: - **One pass for RTree.** Its staleness pass and the remap's check overlap and could become one. - **Fewer history reads per merge.** Each merge lists every version and opens some manifests twice. - **Overlapping staged segments.** A segment staged on a fragment's compaction output alongside one staged on the fragment itself indexes those rows twice. Scalar lookups stay correct, but a full-text index counts the documents twice in its BM25 statistics. The merge should refuse a source together with its descendant. - **Record the proof in the reuse index** (#9543), so a cleanup no longer costs coverage. --------- Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Jack Ye <[email protected]>
Supersedes #9271; merging this closes #9270.
Merging segments across a compaction
merge_existing_index_segmentscombines staged segments into one. When acompaction 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_indextakes its remapper from the dataset's reuse index. Where thatmapping 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:
their rows leave the index. Partly retired counts, since the surviving half
would otherwise make the coverage look healthy.
every link; a trim that dropped an earlier one leaves the remap on an
intermediate fragment the dataset no longer has.
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, whichpasses the reuse index to the builder.
RTree does load through the remapper, so it belongs under this rule, but the
all_rtreebranch 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
geofeature is refused before the coverage workrather than after it.