Skip to content

fix(index): match nested fields by subtree in index maintenance - #10108

Merged
wjones127 merged 2 commits into
lance-format:mainfrom
ump45nose:fix/nested-field-index-maintenance
Oct 23, 2026
Merged

wjones127 merged 2 commits into
lance-format:mainfrom
ump45nose:fix/nested-field-index-maintenance

Conversation

@ump45nose

Copy link
Copy Markdown
Contributor

Closes #10092.

Three index maintenance paths decided whether an index depends on a field by exact field id: the overlay check in remap_index / remap_index_tagged, prune_overlay_stale_fields_from_indices, and the untagged branch of withdraw_in_place_rewrites. A change reported against a struct s then left coverage on an index over s.x (and a change to s.y left an index over s alone), so the index could keep serving the old values.

These paths now use field_affects_index, the same subtree rule fresh_fragments and the overlay staleness checks already use:

  • the remap overlay checks call overlay_affects_index;
  • prune_overlay_stale_fields_from_indices takes the schema and matches overlaid fields by subtree;
  • the untagged branch of withdraw_in_place_rewrites drops the rewritten fragment from every index that depends on a rewritten field. The tagged branch is unchanged.

IndexMetadata.fields already holds the covering fields, so this matches the fields ∪ covering_fields subtree rule from #10090. Like the issue says, I haven't confirmed that a current writer reports only the parent id; this just makes the three paths agree with the rest.

Testing: added test_prune_overlay_stale_fields_matches_nested_fields and test_untagged_in_place_rewrite_withdraws_nested_fields (parent change vs. child index, child change vs. parent index, unrelated field). cargo test -p lance-table --lib passes, as do the dataset::optimize::remapping (49) and overlay (206) tests in lance. cargo fmt --all is clean, cargo clippy -p lance --lib -- -D warnings is clean, and cargo clippy -p lance-table --tests shows nothing in the touched code (with -D warnings it stops on existing dead-code warnings in lance-io's throttle module). I didn't run the full-workspace clippy.

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

remap_index's overlay check, prune_overlay_stale_fields_from_indices and
the untagged branch of withdraw_in_place_rewrites decided whether an index
depends on a field by exact field id. A change reported against a struct
then missed an index on one of its children (and the other way around),
leaving the index serving stale values. Use field_affects_index on these
paths, as fresh_fragments and the overlay staleness checks already do.

Closes lance-format#10092.

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

Packed-struct writes can report only the parent field ID, so the shared subtree rule addresses a real stale-index failure. The changed paths preserve the existing version gate and keep unrelated fields covered. No blocking issues found.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 17, 2026
wjones127 pushed a commit that referenced this pull request Oct 17, 2026
…lay compaction (#10109)

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.

Co-authored-by: ump45nose <[email protected]>
@ump45nose
ump45nose force-pushed the fix/nested-field-index-maintenance branch from b9a2e48 to 1fdc8f4 Compare October 19, 2026 13:41
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 19, 2026
The overlay in this case records geometry's nested field ids, while the
committed RTree index records geometry itself. With subtree matching,
folding the overlay now drops the first compaction's output from the
committed index, and compaction does not mix indexed and unindexed
fragments, so the second compaction left two fragments. Overlay a source
of each first-round group so both outputs leave the index and the second
compaction still merges them.
@ump45nose

Copy link
Copy Markdown
Contributor Author

After the rebase, test_rtree_merge_drops_coverage_an_overlay_reaches::case_3_before_two_compactions (added in #9946) failed. Its overlay records geometry's nested field ids (3, 4) while the committed RTree index records geometry (1), so with subtree matching, folding the overlay now drops the first compaction's output from the index, which is the stale coverage this PR is meant to catch. Compaction doesn't mix indexed and unindexed fragments, so the second compaction left two fragments. b92a6f9 overlays a source in each first-round group so the second compaction still merges them; the rest of the test is unchanged.

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

I'll merge this is as is, but I think there's a follow up to handle covering_fields (see #10090).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: index maintenance matches nested fields by exact id on some paths

2 participants