Skip to content

fix(index): keep overlays masked when updating a non-indexed column#7926

Open
wjones127 wants to merge 2 commits into
lance-format:mainfrom
wjones127:fix/update-nonindexed-overlay-unmask
Open

fix(index): keep overlays masked when updating a non-indexed column#7926
wjones127 wants to merge 2 commits into
lance-format:mainfrom
wjones127:fix/update-nonindexed-overlay-unmask

Conversation

@wjones127

Copy link
Copy Markdown
Contributor

Problem

A RewriteRows update (under stable row ids) that sets only a non-indexed column moves the matched rows to a new fragment. Because the update didn't touch the scalar index's field, register_pure_rewrite_rows_update_frags_in_indices extends that index's coverage onto the new fragment and reuses its existing entries — assuming the moved rows' indexed value is unchanged.

That assumption breaks when a moved row carried a data overlay on the indexed field. The update reads the row through overlay resolution, so it materializes the overlay's current value into the new fragment, but:

  • the reused index entry still holds the stale pre-overlay value, and
  • marking the new fragment as covered removes the flat-path re-evaluation that overlay masking relied on to serve the correct value.

The overlaid row then vanishes from index-path queries. Minimal repro: BTree on age, overlay age 10 → 999 on a live row, then UPDATE SET id=100 WHERE id=1 (touching only the non-indexed id). Afterwards age = 10 wrongly returns the row and age = 999 returns nothing — the row is lost from the index path (a range scan returns 99 where 100 are expected).

This is a distinct root cause from the OptimizeIndices un-masking (#7924): no version-gate flip and no merge involved — the trigger is the coverage-extension reusing stale entries.

Fix

In register_pure_rewrite_rows_update_frags_in_indices, before extending an index's coverage to the moved-rows fragments, skip any index whose fields are touched by an overlay committed after the index was built on any of the moved rows' original fragments (reusing collect_overlay_stale_frags). Those new fragments are then left unindexed and fall to the flat path against current values.

Tests

Adds test_update_nonindexed_column_preserves_overlay_masking (fails before, passes after). The existing update/transaction suites — including test_update_affects_index_fragment_bitmap, which covers the non-overlay coverage-extension optimization — still pass, so the optimization is unchanged when no overlay is present.

🤖 Generated with Claude Code

A rewrite-rows update (under stable row ids) that sets only a non-indexed
column moves the matched rows to a new fragment. Because the update did not
touch the scalar index's field, `register_pure_rewrite_rows_update_frags_in_indices`
extends that index's coverage onto the new fragment and reuses its existing
entries, on the assumption that the moved rows' indexed value is unchanged.

That assumption breaks when a moved row carried a data overlay on the indexed
field: the update materializes the overlay's current value into the new
fragment, but the reused index entry still holds the stale pre-overlay value,
and marking the new fragment covered removes the flat-path re-evaluation that
overlay masking relied on. The overlaid row then vanishes from index-path
queries (a range scan returns 99 rows where 100 are expected).

Skip extending coverage for an index whose fields are touched by an overlay
committed after the index was built on any of the moved rows' original
fragments, so those new fragments fall to the flat path against current values.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: 7daaf429-1b79-4a8a-a70e-e19ea5365047

📥 Commits

Reviewing files that changed from the base of the PR and between f1c4674 and 58d5b2a.

📒 Files selected for processing (1)
  • rust/lance/src/dataset/transaction.rs

📝 Walkthrough

Walkthrough

This change prevents pure row rewrites from reusing index coverage when source fragment overlays may expose stale values. A new integration test verifies scalar index masking after updating a non-indexed column on an overlaid row.

Changes

Overlay index masking

Layer / File(s) Summary
Rewrite manifest context
rust/lance/src/dataset/transaction.rs
Stable-row-id RewriteRows handling collects overlaid source fragments and passes them to index registration.
Overlay-aware bitmap gating
rust/lance/src/dataset/transaction.rs, rust/lance/src/dataset/tests/dataset_overlay_index_masking.rs
Index bitmap extension now checks source coverage and overlay staleness; an integration test validates stale and overlaid scalar index results after rewriting a row.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant UpdateBuilder
  participant build_manifest
  participant collect_overlay_stale_frags
  participant ScalarIndex
  UpdateBuilder->>build_manifest: RewriteRows update
  build_manifest->>collect_overlay_stale_frags: Check original overlaid fragments
  collect_overlay_stale_frags-->>build_manifest: Stale fragment set
  build_manifest->>ScalarIndex: Extend bitmap only when safe
Loading

Possibly related issues

Possibly related PRs

Suggested labels: A-index

Suggested reviewers: xuanwo, jackye1995, touch-of-grey

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main fix: preserving overlay masking when updating only a non-indexed column.
Description check ✅ Passed The description clearly matches the changeset and explains the bug, fix, and regression test in detail.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Jul 23, 2026
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/dataset/transaction.rs 90.00% 2 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@wjones127
wjones127 marked this pull request as ready for review July 23, 2026 16:40

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@rust/lance/src/dataset/transaction.rs`:
- Around line 2695-2730: Refactor the fragment_bitmap handling in the
index-update loop to avoid the is_none-then-unwrap pattern. Bind
index.fragment_bitmap once with let ... else or if let, continue when absent,
and reuse that binding for both the coverage check and subsequent fragment
insertions, removing the as_ref().unwrap() and as_mut().unwrap() calls while
preserving the existing skip behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: QUIET

Plan: Pro Plus

Run ID: dee9e8bb-0c14-4918-8483-eb13ee195a40

📥 Commits

Reviewing files that changed from the base of the PR and between 9726f88 and f1c4674.

📒 Files selected for processing (2)
  • rust/lance/src/dataset/tests/dataset_overlay_index_masking.rs
  • rust/lance/src/dataset/transaction.rs

Comment thread rust/lance/src/dataset/transaction.rs Outdated
Addresses CodeRabbit review: replace the check-then-unwrap pattern
(`is_none()` followed by `as_ref().unwrap()`/`as_mut().unwrap()`) with a
`let ... else` binding and an `if let`, per the crate's coding guidelines.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wjones127
wjones127 requested a review from westonpace July 23, 2026 17:52
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.

1 participant