Skip to content

fix(index): include covering fields in index dependency checks - #10345

Merged
Xuanwo merged 5 commits into
lance-format:mainfrom
Ali2Arslan:fix/covering-dependency-checks
Oct 30, 2026
Merged

Xuanwo merged 5 commits into
lance-format:mainfrom
Ali2Arslan:fix/covering-dependency-checks

Conversation

@Ali2Arslan

@Ali2Arslan Ali2Arslan commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Part of #10250, which tracks upstreaming composite scalar indexes and ordered index scans. This is C1 there.

Why

Index maintenance decides whether a change makes an index stale by reading IndexMetadata.fields. Today fields repeats every carried column, so that is correct. Once flag 1 << 13 lets fields hold only keyed columns, these checks would miss an update, overlay, rewrite, cast, or drop of a carried column, and the index would keep serving old values.

Closes #10098.

What changed

  • New IndexMetadata::dependency_fields returns fields, then each covering field that fields does not list, once. It borrows fields when nothing is missing.
  • These dependency checks read it. They are the overlay staleness collectors, the commit-time checks in index_maintenance.rs, the unknown-coverage rewrite check from fix: reject unsafe legacy index coverage #10256, the alter_columns cast guard, and the conflict resolver's checks against a cast, a data replacement in either commit order, and a deferred compaction that folds in an overlay. The two remap overlay checks, which were the same loop twice, now call one new function, staleness::remove_overlay_stale_frags. fresh_fragments and prune_stale_segment_coverage pass both lists to indexed_field_ids.
  • The merge arm's in-place rewrite check on a tagged table reads it too. The keyed field is in both lists, so no index with one changes behavior. No existing test reaches this check.
  • Each check keeps its matching rule. The subtree checks from fix(index): match nested fields by subtree in index maintenance #10108 still go through field_affects_index.

Scope

  • No index that a released writer can commit changes behavior. validate_covering_fields rejects a fields list that omits a carried column when a manifest is decoded and when an index is created. For every index it accepts, dependency_fields borrows fields.
  • Remap still skips covered indices. index::remap_index returns Drop for one, and remap_column_index refuses one. Both refusals predate this PR. They test only whether covering_fields is empty, which means the same under both covering-field contracts, so flag 1 << 13 does not change them.
  • fix(index): conflict CreateIndex with a DataReplacement of a packed parent #10341 edits the same CreateIndex-over-DataReplacement conflict check, so the second of the two to land must read dependency_fields() there and keep the packed-parent match from fix(index): conflict CreateIndex with a DataReplacement of a packed parent #10341.

Blast Radius

Every commit runs these checks on every index. For indices that exist today dependency_fields borrows fields, so results are identical. The added cost is one scan of covering_fields, which is empty for almost every index.

Verification

  • Decode and create reject the keys-only shape while FLAG_INDEPENDENT_COVERING_FIELDS is unsupported. So the doctest on dependency_fields builds it in memory, and so do the tests. The cast test puts it in the session index cache.
  • Each test_covering_dependency, in index_maintenance.rs, conflict_resolver.rs, and merge_coverage.rs, runs every check against a keyed, a carried, and an unrelated change, for the suffix and the keys-only shape. test_nested_covering_dependency adds a carried struct and a carried child at the subtree checks. test_alter_columns_cast_fails_with_covering_index casts each column. With a site reverted to read fields, its keys-only case fails and its suffix case still passes.
  • remap_drops_fragments_a_newer_overlay_made_stale runs both remap paths through remove_overlay_stale_frags. Both read stored metadata through decode, so it uses the suffix shape. The helper's keys-only case is in index_maintenance.rs.
  • At this head, the 16 lance-table covering_dependency cases, all 792 lance-table lib tests, the dependency_fields doctest, the 13 lance cases, all 150 io::commit::conflict_resolver tests, and the 5 schema_changes_reject_reserved_column_names cases from fix: reject unsafe legacy index coverage #10256 pass.
  • cargo fmt --all -- --check and cargo clippy --all --tests --benches -- -D warnings are clean. ci/check_module_size.py passes with warnings. index.rs grows by 5 lines and manifest_build.rs by 4. conflict_resolver.rs grows by 183, remapping.rs by 164, and schema_evolution.rs by 67, nearly all tests. The rebase and remap tests call private functions, and the cast test sits with the cast guard's other tests.

Index maintenance reads `IndexMetadata.fields` to decide whether a change
makes an index stale. Once `fields` can hold only keyed columns, those
checks would miss a change to a carried column, and the index would keep
serving old values.

Add `IndexMetadata::dependency_fields`, which returns `fields` plus each
covering field that `fields` omits, and read it in the overlay staleness
collectors, the checks in `index_maintenance.rs` and `index.rs`, the
conflict resolver, the `alter_columns` cast guard, and remap.

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 26, 2026
The check that refuses an in-place rewrite for an index with unknown
fragment coverage matched the rewritten fields against
`IndexMetadata.fields` alone. A Rust caller can commit a user index
without a fragment bitmap, so a keys-only covering index would let a
rewrite of its carried column through and keep serving old values.

Read `dependency_fields()` there, and add the check to both
covering-dependency test matrices.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 26, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 26, 2026
Xuanwo added a commit that referenced this pull request Oct 29, 2026
## Why

Scalar and FTS query paths independently reconstructed a segment's
current fragment coverage and live-row mask from index metadata. That
made provenance, translated coverage, deletion handling, and row-domain
choices easy to drift.

## What changed

- Add an internal `SegmentCoverage` that resolves query coverage once
through `FriQueryPlan` (or the query listing when no tagged translation
is needed) and obtains live stable row IDs through `DatasetPreFilter`.
- Reuse it for scalar segment unions/lookups and FTS segment opens.
- Keep address-domain hits, non-stable-row-ID tables, and single-segment
indexes on the existing no-filter path.
- Refuse missing or unavailable FRI coverage instead of treating it as
empty. No persistent format or cross-index trait is added.

## Boundaries

- Maintenance and append filtering remain unchanged; #10418 owns the
adjacent old-data and address-deletion semantics.
- Consolidating field-rewrite withdrawal is left separate because it
overlaps #10345's dependency-field changes and is not a small
behavior-preserving change.
- #10001 also moves the same scalar-local coverage implementation for
its hybrid-prefilter work; this PR centralizes FRI-derived coverage and
shares it with FTS, so review/merge order should be coordinated. Do not
stack either branch.

## Verification

Validated at `54e33ff04d43f28f446d7a01e274fad0cb65a43d` with the
repository toolchain `1.98.1` after removing an ambient
`RUSTUP_TOOLCHAIN=1.99.1` override:

- `cargo fmt --all -- --check`
- `cargo clippy --all --tests --benches -- -D warnings`
- 2 segment-coverage unit tests
- 27 scalar-logical tests
- 2 FTS stable-row-ID stale-posting cases
- 274 FRI/tagged-history tests

The full workspace test suite was not run.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 30, 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 dependency union preserves current metadata behavior, including unknown fragment coverage, and the rebase retains the packed-parent conflict handling from #10341. All 46 targeted dependency, rewrite, cast, remap, and replacement-race tests passed on this revision.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 30, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the latest main integration and confirmed the dependency-field union preserves the packed-parent conflict handling from #10341. No blocking findings; the applicable current-head checks and Gatekeeper pass.

@Xuanwo
Xuanwo merged commit dcbbb1c into lance-format:main Oct 30, 2026
41 checks passed
Xuanwo added a commit that referenced this pull request Nov 13, 2026
Part of #10250, which tracks upstreaming composite scalar indexes and
ordered index scans. This is C2 there. It builds on #10345 (C1), which
made every index dependency check read both `fields` and
`covering_fields`.

## Why

#9159 specified feature flag `1 << 13`,
`FLAG_INDEPENDENT_COVERING_FIELDS`, and kept it masked out. Under that
flag, `IndexMetadata.fields` lists only an index's keys and
`covering_fields` lists its carried columns on its own, so an index can
carry one of its keys. This PR turns the flag on. The format spec says a
reader must pick the layout from the manifest flags before it reads any
entry, so manifest decode and encode now take the manifest's layout.

## What changed

- `CoveringContract` names the two layouts.
`IndexMetadata::from_manifest_proto` and `to_manifest_proto` decode and
encode one manifest entry under the manifest's layout. The manifest
reader and writer, the cached decode in `Dataset::load_manifest`, and
the clone path use them.
- In memory, an entry's shape names its layout. Carried fields that form
a shorter tail of `fields` are the suffix layout, and any other covered
entry is keys-only. `keyed_fields`, `IndexSegment::keyed_field`,
`validate_covering_fields`, and the MemWAL fresh tier read the shape.
`declares_same_fields` compares two entries by keyed and carried fields,
and every check on two segments of one index uses it.
- `build_manifest` sets bit 13 next to bit 7 while some index needs the
keys-only layout, and the writer then stores every suffix entry as its
keys. `apply_feature_flags` and a shallow clone keep the bit.
- Transaction files store every index entry in the suffix layout, keys
then carried fields. A release without bit 13 can then read a
transaction that names a keys-only entry, such as the one that drops it.
`IndexMetadata::from_transaction_proto` decodes each entry and refuses
one outside the suffix layout, as releases do.

## Scope

- This PR changes no persisted proto and no format doc. Transaction
entries keep the suffix layout that the proto already describes, so
nothing under `protos/` or `docs/src/format/` moves, and the PR needs no
format vote.
- Compaction still skips remapping a covered index, and a column remap
still refuses it, as #10345 left it. Both checks read only whether
`covering_fields` is empty, and no index type carries the carried values
through a remap, so bit 13 does not change them.
- Once bit 13 is set, it stays set while an entry it stored keys-only
remains, even after the keys-only index that set it is dropped. The spec
requires this: "Every manifest built from one that sets it keeps the bit
set, unless a writer converts every entry back to the legacy contract in
one atomic change of its own." Dropping the last covered index is that
conversion, so bits 7 and 13 clear together.

## Blast Radius

Tables without covered indices, and tables whose covered indices all use
the suffix layout, write the same manifests and transactions as before,
and releases without bit 13 still open them. A table that gains a
keys-only index sets bit 13, and every release through 15.0.0-beta.10
refuses it until the index is dropped. Releases from 13.0.0 mark bit 13
unsupported, and older ones do not know it. A transaction read from
storage returns a keys-only entry with its carried fields appended to
`fields`.

## Verification

Author-reported results below were measured on this branch's
pre-integration history, before it was merged with current `main`.

- `cargo test -p lance-table --lib` (1,002 tests) and its 17 doctests
pass. They cover the transaction round trip of the tail-shaped entry
keyed on `[7, 11]` that carries `[11]`, and `declares_same_fields` on
both layouts.
- `test_create_index_entry_outside_the_suffix_layout_is_refused` decodes
three transaction entries outside the suffix layout: `[7]` carrying
`[11]`, `[11]` carrying `[11]`, and `[7, 11]` carrying `[7]`. Each fails
from `new_indices` and from `removed_indices` with an error that names
`fields` and `covering_fields`, while the same bytes decode as a
manifest entry under bit 13. All three cases fail on `8d7e03e6f`, and
reverting either decode line fails them again.
- The 35 `lance` tests whose names contain `covering` pass, and so does
`test_row_addr_index_writer_fence_survives_dataset_operations` from
#10352. One covering case commits a stable row ID table whose covered
B-tree also stores row addresses, so bits 7, 13, and 18 hold through the
commit and an unrelated delete, and all three clear when the index is
dropped.
- Before the merge with `main`, at `f53fcf348`, 1,410 `lance` tests
passed, including 989 MemWAL tests and the conflict-resolver suite.
Reverting the MemWAL key reads, the transaction encoder, the segment key
rule, or any comparison site fails its new cases, and an always-true
comparison fails the negative cases.
- At `0c2419ead`, `cargo test -p lance --lib` passes 8,764 tests with 9
ignored, including the 1,078 whose names contain `mem_wal`. In three of
those tests, MemWAL writers on a covered B-tree and a covered full-text
index open, write, flush, and filter the same rows in either layout, and
a writer still flushes after another session turns bit 13 on. Each one
checks that the generation carries the covered index, and at `290bf8968`
all five of their cases failed that check when the flush wrote no index.
- At `b7a2babec`, manifest commit and load were measured with 100 B-tree
indices: commit 3.73 → 3.76 ms median (+0.84%) and load 0.698 → 0.707 ms
median (+1.26%), 63 samples per side over three interleaved rounds.
- The scalar-index compat file passes (97 passed, 2 skipped), including
the row address index cases from #10352, and 13.0.0 reads the commit and
drop transactions of a dropped keys-only index. `test_commit_index.py`
passes (7 tests). Clippy, rustfmt, the Python lint, and the Java
`spotless:check` pass.

Integrated onto `main` at `2320b5a6a` (merge `353bba6a2`, tree
`18ac2f84f`):

- `cargo check --workspace --tests --benches --profile ci` passes.
- `cargo test -p lance-table --profile ci`: 1,066 lib tests and 22
doctests pass.
- `cargo test -p lance --lib --profile ci`: 10,338 pass with 9 ignored.
The `covering` selector matches 34 passing tests, `mem_wal` 1,078
passing (2 ignored), and
`remap|lifecycle|merge|shallow_clone|declares_same_fields|conflict_resolver`
1,501. `cargo test -p lance --doc --profile ci`: 142 pass.
- `python/tests/compat/test_scalar_indices.py --run-compat`: 112 passed,
3 skipped (all three are the harness's intentional "downgrade
unsupported" skips), including the new suffix and keys-only cases
against pylance 13.0.0. `python/tests/test_commit_index.py`: 7 passed.
`uv run make lint` passes.
- `cargo fmt --all --check`; `cargo clippy --profile ci --all --tests
--benches -- -D warnings`; Java `spotless:check`, `compile`, and the
targeted index tests (3 in `TransactionTest`, 2 in `DatasetTest`) all
pass.

## Follow-ups

- The carried columns format change, C3 in #10250, will state the rule
this PR follows: every `IndexMetadata` in a serialized transaction uses
the suffix layout, whether stored in a transaction file or inline in a
manifest, and a reader refuses any other shape.
- A merge of segments in both layouts copies the first input's
declaration. The merged entry's layout, and so whether bit 13 stays set,
depends on input order.
- The derived `IndexMetadata` equality and `Operation` equality still
compare raw `fields`. Nothing uses them to match two segments of one
index today.
- Comments in `index/scalar.rs` and `dataset/write/seeds.rs` still say
that a covered index lists its carried columns in `fields`.

---------

Co-authored-by: Cursor <[email protected]>
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.

feature: use fields and covering_fields in index dependency checks before flag 1<<13

2 participants