Repository navigation
fix(index): include covering fields in index dependency checks - #10345
Merged
Xuanwo merged 5 commits intoOct 30, 2026
Merged
Conversation
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.
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.
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.
…-20261029 # Conflicts: # rust/lance/src/io/commit/conflict_resolver.rs
Contributor
There was a problem hiding this comment.
✅ 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.
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Todayfieldsrepeats every carried column, so that is correct. Once flag1 << 13letsfieldshold 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
IndexMetadata::dependency_fieldsreturnsfields, then each covering field thatfieldsdoes not list, once. It borrowsfieldswhen nothing is missing.index_maintenance.rs, the unknown-coverage rewrite check from fix: reject unsafe legacy index coverage #10256, thealter_columnscast 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_fragmentsandprune_stale_segment_coveragepass both lists toindexed_field_ids.field_affects_index.Scope
validate_covering_fieldsrejects afieldslist that omits a carried column when a manifest is decoded and when an index is created. For every index it accepts,dependency_fieldsborrowsfields.index::remap_indexreturnsDropfor one, andremap_column_indexrefuses one. Both refusals predate this PR. They test only whethercovering_fieldsis empty, which means the same under both covering-field contracts, so flag1 << 13does not change them.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_fieldsborrowsfields, so results are identical. The added cost is one scan ofcovering_fields, which is empty for almost every index.Verification
FLAG_INDEPENDENT_COVERING_FIELDSis unsupported. So the doctest ondependency_fieldsbuilds it in memory, and so do the tests. The cast test puts it in the session index cache.test_covering_dependency, inindex_maintenance.rs,conflict_resolver.rs, andmerge_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_dependencyadds a carried struct and a carried child at the subtree checks.test_alter_columns_cast_fails_with_covering_indexcasts each column. With a site reverted to readfields, its keys-only case fails and its suffix case still passes.remap_drops_fragments_a_newer_overlay_made_staleruns both remap paths throughremove_overlay_stale_frags. Both read stored metadata through decode, so it uses the suffix shape. The helper's keys-only case is inindex_maintenance.rs.lance-tablecovering_dependencycases, all 792lance-tablelib tests, thedependency_fieldsdoctest, the 13lancecases, all 150io::commit::conflict_resolvertests, and the 5schema_changes_reject_reserved_column_namescases from fix: reject unsafe legacy index coverage #10256 pass.cargo fmt --all -- --checkandcargo clippy --all --tests --benches -- -D warningsare clean.ci/check_module_size.pypasses with warnings.index.rsgrows by 5 lines andmanifest_build.rsby 4.conflict_resolver.rsgrows by 183,remapping.rsby 164, andschema_evolution.rsby 67, nearly all tests. The rebase and remap tests call private functions, and the cast test sits with the cast guard's other tests.