Skip to content

fix(index): drop old fragment ids from stale indices on deferred overlay compaction - #10109

Merged
wjones127 merged 1 commit into
lance-format:mainfrom
ump45nose:fix/deferred-overlay-compaction-stale-index
Oct 17, 2026
Merged

wjones127 merged 1 commit into
lance-format:mainfrom
ump45nose:fix/deferred-overlay-compaction-stale-index

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Closes #10091.

On a table without stable row ids, a compaction with defer_index_remap: true that folds a data overlay on an indexed field left the index covering the compacted rows with their pre-overlay values. prune_overlay_stale_fields_from_indices only removed the group's new fragment ids from a stale index's bitmap, but on the deferred path the bitmap still holds the old ids (the fragment reuse index translates them at load time), so nothing was removed and val = <old value> kept matching.

This removes both the old and the new fragment ids of the group from stale indices, which is the second option the issue gives (per #10090). On the eager path the old ids are already gone, so that path behaves as before. Tagged FRI tables still refuse this compaction, so they aren't affected.

Testing: test_overlay_compaction_reconciles_stale_index now runs with both eager and deferred remap; the deferred case fails on main (the index still covers the compacted fragment) and passes here. test_prune_overlay_stale_fields_from_indices gained a stale index that still covers the old fragment id. cargo test -p lance-table --lib passes, as do the overlay, dataset::optimize and dataset::index::frag_reuse tests in lance. cargo fmt --all is clean and cargo clippy -p lance -p lance-table --lib --tests -- -D warnings passes; I didn't run the full-workspace clippy.

This touches the same function as #10108 (which changes how stale fields are matched, not which fragment ids are removed), so whichever lands second needs a small rebase.

I used an AI coding assistant to help write this change and the tests; I reviewed the diff and ran the checks above.

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added the bug Something isn't working label Oct 17, 2026

@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.

The change restores scan fallback for stale index entries after deferred overlay compaction. No merge-blocking issues found.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 17, 2026
@wjones127
wjones127 merged commit ac70561 into lance-format:main Oct 17, 2026
Xuanwo added a commit that referenced this pull request Nov 10, 2026
… segment predates (#10538)

## Summary

With a v0 fragment reuse index (FRI), every index segment's cache
entries are keyed by the whole FRI history, so any change to it (a
deferred-remap compaction or a trim) cold-starts every segment of every
index.

This keys each segment only by the versions that can still change its
decoded rows: those it was **not** built after. A segment built (or
remapped) after a version's rewrite holds none of that version's source
addresses, so decoding with or without the version gives the same rows.

- **Built after the whole history:** the plain per-index key, as with no
FRI.
- **Otherwise:** a hash of the digests of the versions it predates, so
trimming older versions leaves its key unchanged.
- **No fragment bitmap:** the whole-history key, as before. A rewrite
group split by the segment's coverage counts as a version it predates.

Disjoint coverage alone is **not** treated as unaffected: deferred
overlay compaction (#10109) withdraws coverage from a stale index while
its data keeps the rows, which the remapper still translates.

## What it improves

- **Compaction:** no change; every existing segment predates the new
version.
- **Trim:** segments built or remapped after the trimmed versions stay
warm. Older segments still reload.

## Changes

- `index/frag_reuse_v0_cache.rs`: `v0_segment_cache_id`, plus
per-version digests (blake3 of the protobuf encoding) cached once per
history.
- `ResolvedRemapping::V0` carries the segment's `cache_id`;
`fri_cache_id` returns it, so the scalar and IVF open paths use it.
- `dataset/index/frag_reuse.rs`: `index_postdates_rewrite` split out of
`is_index_remap_caught_up` (trim unchanged).
- Unchanged: tagged (v1) histories, legacy vector file formats, the
FRI's own cache key.

## Test plan

- [x] `test_overlay_compaction_reconciles_stale_index` (deferred case):
a fresh reader warms the latest snapshot, then an indexed query on the
pre-compaction snapshot must still match. Fails if disjoint coverage is
treated as unaffected, or if v0 segments use the plain key.
- [x] `v0_history_keeps_remapped_segments_warm_through_trim`: segments
reload once after the compaction and are then warm (the vector segment
through the generic open); the remapped segment stays warm through the
trim; scalar and nearest-neighbor queries stay correct. Fails if keys
change on every open.
- [x] `v0_segment_cache_id_tracks_versions_on_the_path`: one case per
branch.
- [x] `cargo nextest run -p lance --lib` filtered to `frag_reuse`,
`v0_`, `overlay`, `prewarm`, `legacy`, `defer`, `remap_caught_up` (1,107
tests).
- [x] `cargo clippy -p lance --tests -- -D warnings`, `RUSTDOCFLAGS="-D
warnings" cargo doc -p lance --no-deps`.

---------

Co-authored-by: Xuanwo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: deferred compaction folding an overlay leaves index serving pre-overlay values

2 participants