Skip to content

fix(index): fence older writers from row-address indices - #10352

Merged
westonpace merged 4 commits into
mainfrom
gatekeeper/fix-10351-1
Oct 29, 2026
Merged

westonpace merged 4 commits into
mainfrom
gatekeeper/fix-10351-1

Conversation

@lance-gatefixer

@lance-gatefixer lance-gatefixer Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Older writers skip version 1 B-tree segments but still extend their fragment coverage as if the stored identifiers were stable row IDs. An update to another column can then suppress fallback scans for moved rows and silently lose matches.

Add the writer-only FLAG_ROW_ADDR_INDICES capability (bit 18) for stable-row-ID tables with row-address indices. Derive it from the final raw index metadata on commits and manifest writes, including restore and clone, preserve it through flag recomputation, and remove it when the last affected index is dropped. Reader feature flags remain unchanged. The shared contract also protects Bitmap and LabelList segments that moved to row addresses.

The regression failed on the original implementation for address-based B-tree, Bitmap, and LabelList segments. Coverage includes legacy versions, a future unsupported B-tree version, tables without stable row IDs, and persisted flags across update, clone, restore, and index removal. Commit tests also verify that the row-address fence and index object-metadata protection coexist through flag recomputation and index removal. Cross-version tests require older inserts and affected updates to fail without changing the dataset, while retaining reader fallback and ordinary writes on tables without stable row IDs.

Validation:

  • cargo test -p lance-table --lib — 872 passed.
  • cargo test -p lance test_row_addr_index_writer_fence_survives_dataset_operations --lib
  • cargo fmt --all
  • cargo clippy --all --tests --benches -- -D warnings
  • Scalar-index compatibility suite with released versions, including 0.39.0, 12.0.0, 13.0.0, 14.0.0, and 15.0.0b4 — 126 passed, 2 skipped.
  • uv run make lint

The fence applies to newly written manifests; it does not modify historical snapshots or repair index coverage already corrupted by an older writer. Such an index must be rebuilt.

Fixes #10351

@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 repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added the bug Something isn't working label Oct 26, 2026
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
@github-actions github-actions Bot added the A-python Python bindings label Oct 26, 2026
@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 the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 26, 2026
Preserve upstream reader capability checks for 15.0.0b2 alongside the old-writer regression assertions.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 27, 2026
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 27, 2026
@wjones127
wjones127 self-requested a review October 27, 2026 19:05
Preserve both index writer fences and test their coexistence through commits, flag recomputation, and index removal.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 28, 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 writer-only manifest fence still addresses the older-writer coverage corruption in #10351. It coexists correctly with the upstream object-metadata protection through commits, flag recomputation, and index removal, while preserving reader compatibility. No blocking findings.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 28, 2026
@wjones127 wjones127 added critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. priority: high Issues that are high priority (for LanceDb, the organization) labels Oct 29, 2026

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

Unfortunate that this was missed earlier but good to have!

@westonpace
westonpace merged commit 85e117e into main Oct 29, 2026
46 checks passed
@westonpace
westonpace deleted the gatekeeper/fix-10351-1 branch October 29, 2026 19:01
Ali2Arslan added a commit to Ali2Arslan/lance that referenced this pull request Oct 29, 2026
lance-format#10352 added writer feature flag bit 18 as FLAG_ROW_ADDR_INDICES for
stable-row-ID tables that carry row-address indices, including any
BTree segment at version 1 or above.

- Drop the separate FLAG_BTREE_KEY_LAYOUT constant and document
  FLAG_ROW_ADDR_INDICES in the feature flags table.
- Scope the BTree key_layout reader and writer flag rules to manifests
  that set FLAG_STABLE_ROW_IDS, where v12.0.0 and v13.0.0 updates
  extend fragment_bitmap to rewritten fragments unless fenced.
- Document how v10.0.0 through v14.0.0 handle a key_layout segment on
  tables with and without FLAG_STABLE_ROW_IDS.

Co-authored-by: Cursor <[email protected]>
Ali2Arslan added a commit to Ali2Arslan/lance that referenced this pull request Oct 29, 2026
FLAG_ROW_ADDR_INDICES (bit 18, added in lance-format#10352) cannot certify that a
BTree key_layout segment was not carried through an unflagged manifest:
writers that support FLAG_ROW_ADDR_INDICES but not key layouts (such as
v15.0.0-beta.7) recompute bit 18 from index_version >= 1 on restore,
clone, and commits without checking the source manifest's flags or
dropping a damaged key_layout segment after a v10.0.0/v11.0.0 restore
and v12.0.0/v13.0.0 update.

Keep the independent writer feature flag FLAG_BTREE_KEY_LAYOUT at bit 19
(2^19) and bind the key_layout reader and writer discard rules to it.

Co-authored-by: Cursor <[email protected]>
Xuanwo added a commit that referenced this pull request Nov 2, 2026
`15.0.0b7` includes #10352's row-address writer fence, so compatibility tests must not require that release to reject writes it already supports.

Gate the old-writer rejection by the release that introduced the capability. Preserve exact post-write checks for supported writers by deriving a fresh key for each repeated write, and update the maintenance regression to derive its expected key from the fixture.
zhangyue19921010 added a commit to zhangyue19921010/lance that referenced this pull request Nov 2, 2026
Partial backport of lance-format#10578 to release/v14.0.

## Problem

The compat matrix appended the newest pre-release on fury.io, which is now
15.0.0b8, a build newer than the 14.0 code under test. A 15.0 beta that
creates a BTREE index on a stable-row-id table sets the writer flag
`FLAG_ROW_ADDR_INDICES`, which 14.0 treats as unknown and refuses to write,
so `test_BTreeRowAddressDomainIndex_upgrade_downgrade[15.0.0b8]` fails on
every PR to this branch.

## Fix

Parametrize compat tests over stable releases only, as main does since
lance-format#10578: drop the pre-release slot and filter PyPI releases with
`Version.is_prerelease`. The rest of lance-format#10578 depends on 15.0-only index
changes (lance-format#9814, lance-format#10352) and is not taken; pinned minimum versions are
unchanged.
Xuanwo pushed a commit that referenced this pull request Nov 2, 2026
Partial backport of #10578 to release/v14.0.

## Problem

The compat matrix appended the newest pre-release on fury.io, which is now
15.0.0b8, a build newer than the 14.0 code under test. A 15.0 beta that
creates a BTREE index on a stable-row-id table sets the writer flag
`FLAG_ROW_ADDR_INDICES`, which 14.0 treats as unknown and refuses to write,
so `test_BTreeRowAddressDomainIndex_upgrade_downgrade[15.0.0b8]` fails on
every PR to this branch.

## Fix

Parametrize compat tests over stable releases only, as main does since
#10578: drop the pre-release slot and filter PyPI releases with
`Version.is_prerelease`. The rest of #10578 depends on 15.0-only index
changes (#9814, #10352) and is not taken; pinned minimum versions are
unchanged.
BubbleCal pushed a commit that referenced this pull request Nov 12, 2026
…ental) (#10949)

Add the persisted contract of the `listelement` scalar index, which
indexes fields inside the elements of a `list<struct>` column and
answers `any_element` filters (#10901). It is marked experimental.
Design discussion: #10948. Issue: #10900.

- **Details:** `ListElementIndexDetails` has these fields:
- `keys`: direct children of the element struct, at least one, no
repeats.
- `key_types`: Lance logical types. A reader declines the index when a
key field is gone or its type changed.
- `key_encoding`: an enum. `ARROW_ROW_V1` is the only defined value, and
UNSPECIFIED must not be used.
- `target_details` and `target_index_version`: the details and version
of the inner BTREE.

  All segments of one index share keys, types and encoding.
- **Files:** none of its own. The files are a standard BTREE over
`Binary`, given as PyArrow schemas, with one row per list element:
  - A null element is an all-null key tuple.
  - A null list is a single null key.
  - An empty list has no rows.

  The posting is the row address.
- **Key encoding:** Arrow row format, every key ascending, nulls first.
The admitted key types are the same as the `arrow_row` v1 set in #10358.
The byte layout is spelled out for fixed-width and variable-width types,
with a worked example, `("car", 0.5)`, that an implementation must
reproduce.
- **Queries:**
- **What the index can answer:** `=`, `IN` or `IS NULL` on the first
key, then equalities on further keys in order, then one range on the
next key.
- **Exact or rechecked:** the answer is exact when the index covers
every condition. Otherwise it's a superset that the scan rechecks with
`any_element`.
  - **NULL rows:** they are found for `NOT`.
- **Row addresses:** the index stores row addresses, so it joins the
row-address and eager-remap lists. On stable-row-ID tables the #10352
writer fence applies.

Library edits are limited to the generated protobuf source. The
implementation follows in a separate PR.

**Experimental:**
- **Forward compatible:** readers that don't know the type ignore the
index and scan.
- **Backward compatible:** nothing existing changes.
- **Droppable:** dropping the index never rewrites data.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
BubbleCal pushed a commit that referenced this pull request Nov 12, 2026
… elements (#10950)

## Summary

Adds `listelement`, an experimental built-in scalar index over fields
inside the elements of a `list<struct>` column. It answers `any_element`
filters (#10901) from the index, with every condition on the same
element:

```python
dataset.create_scalar_index(
    "detections",
    IndexConfig(index_type="listelement", parameters={"keys": ["label", "confidence"]}),
)
dataset.to_table(filter="any_element(detections, 'label = ''car'' AND confidence > 0.9')")
```

This is the second part of #10900. The format is specified in #10949,
and the design discussion is #10948.

**Depends on #10949.** This PR carries the identical
`protos/index.proto` change and generated source so that it compiles.
Those changes drop out when this branch is rebased after #10949 merges.

## Design

- **Training:** one entry per element.
- The key is the element's `keys` fields as a tuple, encoded with
Arrow's row format (ascending, nulls first), so the bytes sort like the
tuples.
    - The posting is the row address.
- Entries are sorted with spilling, and an ordinary BTREE is trained
over the `Binary` keys. The index wraps the BTREE the way the JSON index
wraps its target.
- **Search:** `visit_scalar_function` claims `any_element(<indexed
column>, '<literal>')`. The predicate is planned exactly as
`any_element` plans it, then with the tuple planner
(`plan_tuple_predicate`) over the keys.
- **Seeks:** an `=`, `IN` or `IS NULL` prefix, then one range on the
next key, becomes byte-range seeks in the BTREE.
- **Superset and recheck:** conditions the keys can't express, such as a
field that isn't a key, make the answer a superset. The scan then
rechecks it with `any_element`.
- **No first key, no index:** without a condition on the first key, the
index declines.
- **NULLs:** NULL lists, and elements on which the predicate is NULL,
are tracked, so `NOT` is exact.
- **Maintenance:** update encodes the new fragments the same way, then
defers to the BTREE. Remap defers to the BTREE.
- **Row addresses:** in `lance-table`, the index joins the row-address
and eager-remap lists. On stable-row-ID tables, the #10352 writer fence
applies and compaction remaps the index.
- **`lance-datafusion` API:** it exports `ANY_ELEMENT`,
`any_element_predicate` and `plan_element_predicate`, so the index plans
the same expression the scan evaluates. `lance-index` now depends on
`lance-datafusion` as a normal dependency; there's no cycle.

## Fix included

On a stable-row-ID table, `optimize_indices` dropped old entries of a
row-address index outside fragment 0. The generic update arm in
`merge_scalar_indices` only treated the JSON index as storing row
addresses, so it filtered row addresses against row IDs. That arm now
also covers this index. JSON behavior is unchanged.

## Tests

- **Index unit tests** (13):
- same-element trap, every range operator, `IN`, label-only prefix,
recheck;
    - NULL rows for `NOT`;
    - shapes the index declines;
- details round trip, and invalid parameters (no keys, unknown key,
repeated key, nested key type, unknown parameter, non-struct list);
- segment key mismatch, an all-null column, and the spec's encoding
bytes.
- **`lance-table`:** row-address and eager-remap classification.
- **Dataset tests:** #10901's fixture is extended rather than
duplicated.
- Every filter case, plus the edge-row and invalid-predicate tests, runs
with and without the index, checking the plan and whether it rechecks.
- New: declining when the first key isn't constrained; `fast_search`
plus `optimize_indices`; delete plus compaction remap, with and without
stable row IDs.

## Docs

The read and write guide covers creating the index and which filters it
answers, and the scalar indexing guide has a row for it. Both mark it
experimental.

## Not in this PR

- **Training memory:** there's no explicit budget. Like the JSON index,
training uses the default spill pool. At 100M elements the prototype
needed `LANCE_MEM_POOL_SIZE=8GiB`.
- **Merging segments** for distributed builds.
- **Fragment reuse index:** batch row-ID remapping isn't supported. Like
JSON, the index is reported incompatible on stable-row-ID tables that
use a fragment reuse index.

Closes #10900.

This conflicts with #10947 in the dataset scanner tests and the guide.
Whichever merges second will rebase.

Lint: `cargo fmt --all`, and `cargo clippy --no-deps -p lance-datafusion
-p lance-index -p lance-table -p lance --tests --benches --features
lance-datafusion/substrait -- -D warnings`. With dependencies included,
clippy on arm64 currently fails in `lance-encoding` (`unreachable_code`
from #10905), which this PR doesn't touch.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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]>
Xuanwo pushed a commit that referenced this pull request Nov 20, 2026
## Why

This PR is the format vote for the composite key track in #10250. It
specifies how a BTree index stores encoded keys, for two or more columns
or for one column with an explicit direction and null placement, so that
later PRs can build the codec, training, and search against a voted
contract.

## What changed

- `BTreeIndexDetails` gains an optional `key_layout`. It sets the key
encoding and the key ordering, each a `oneof` with one message per kind,
and gives each key its direction and null placement. The `arrow_row`
message carries its version.
- Index version 2 is a superset of version 1. A version 2 segment
without `key_layout` has the version 1 layout, and a reader picks the
page layout from whether `key_layout` is present, not from the number of
fields.
- The BTree spec gains an experimental Key Layout section. It covers
one-key and composite layouts, the Binary page layout, the `arrow_row`
version 1 bytes with 52 examples from the Arrow ordering fixtures, the
`lexicographic` ordering, the reader rules, and the writer rules. A
short compatibility section gives the reason for each fence: the index
version fences released readers, and the flag fences the v12.0.0 and
v13.0.0 writers that would otherwise extend `fragment_bitmap`.
- The writer rules state as musts when a writer sets bit 22, that it
drops a segment with a `key_layout` from a manifest without the bit, and
how it maintains a segment it cannot use. Compaction may rewrite the
fragments such a segment covers. The same commit removes them from its
`fragment_bitmap`, as an update does, also when compaction defers the
remap to a fragment reuse index, and readers scan them. By default, a
writer builds a single-column index without a `key_layout`. One-key
layouts stay allowed.
- Writer feature flag bit 22, `FLAG_BTREE_KEY_LAYOUT`, is reserved and
unsupported, and `lance-tools` names it `btree_key_layout`. Its doc
comment says what the bit means and links to the writer rules. Bits 19,
20, and 21 went to `FLAG_INLINE_DELETIONS`,
`FLAG_LOCAL_FRAGMENT_ALIASES` (#10780), and `FLAG_DELETION_FILE_PATHS`
(#10914) on `main`. The bit 22 fence re-check passed 173 checks: 104
table and chain checks matched the expected outcomes, and all 69 rows
shared with the bit 20 runs matched cell for cell. It gives the table
below.
- `main` checks in generated protobuf code, so
`rust/lance-index/src/pb/lance.table.rs` is regenerated for
`key_layout`.
- Encoding Stability now pins `arrow_row` version 1 to `arrow-row`
59.3.3, the version `main` builds with, and the `arrow_ordering.rs`
fixtures pass on it.

## Scope

- Spec, proto, the regenerated protobuf code, and the reserved flag with
its `lance-tools` name. No table writer emits a `key_layout` or derives
bit 22 yet, and no BTree query path interprets `key_layout`. Generated
protobuf code can decode the field, the feature-flag gate rejects bit 22
as unsupported, and `lance-tools` renders its name.
- Bit 22 covers only segments with a `key_layout`. #10352 added
`FLAG_ROW_ADDR_INDICES` at bit 18 for stable row ID tables with a BTree
at index version 1 or above, but `FLAG_ROW_ADDR_INDICES` cannot replace
`FLAG_BTREE_KEY_LAYOUT`: writers that support `FLAG_ROW_ADDR_INDICES`
without `key_layout` support (such as 15.0.0b7) recompute bit 18 from
`index_version >= 1` on restore, clone, and commits without checking the
source manifest's flags or dropping a damaged `key_layout` segment after
a 10.0.0 or 11.0.0 restore clears bit 18 and a 12.0.0 or 13.0.0 update
extends `fragment_bitmap`. Keeping `FLAG_BTREE_KEY_LAYOUT` as an
independent bit that pre-`key_layout` writers cannot set ensures a
damaged segment never becomes usable again.
- Covering columns on an index with a `key_layout` are left to a later
vote.

## Blast Radius

Every BTree written today has empty details, so it decodes as before. No
writer sets bit 22 yet. Index version 2 is free, because #10150 kept
stable row ID BTrees on version 1 and #10152 does not change the index
version.

## Verification

- A script implements `arrow_row` version 1 from the spec text alone. It
reproduces all 113 fixtures in `rust/lance/tests/arrow_ordering.rs` and
all 52 examples on the page. On 3,000 random tuples, byte order equals
the `lexicographic` order. Three planted errors each fail it.
- Fence probe. The head Rust API writes a table with a composite index
at index version 2 and sets `FLAG_BTREE_KEY_LAYOUT`, once with stable
row IDs and once without. Each pylance release runs each write first on
its own copy, then queries `a = 1` and `b = 1`.
- A one-key `key_layout` meets the same fences, from reading 10.0.0
through 14.0.0. Every release drops a BTree segment above its maximum
index version from the index list that reads and query planning use,
before any code counts `fields`. The commits of 10.0.0 and 11.0.0 also
use that filtered list, which is why they drop the index. The commits of
12.0.0 through 14.0.0 keep the segment, and an update counts its
`fields`, but `FLAG_BTREE_KEY_LAYOUT` refuses those commits. Once a
10.0.0 or 11.0.0 restore clears the bit, the reader rule makes the
segment unusable whatever its key count, even if a writer that supports
`FLAG_ROW_ADDR_INDICES` (`2^18`) later sets bit 18 again.
- `cargo run --locked --manifest-path protos/codegen/Cargo.toml --
--check`, `cargo test -p lance-table --lib feature_flags`, `cargo test
-p lance-tools format_feature_flags`, `cargo test -p lance --test
arrow_ordering`, `cargo fmt --all -- --check`, workspace clippy,
`ci/check_proto_comments.py`, `ci/check_module_size.py`, and `make
build` in `docs/` pass, and every link and anchor on the changed pages
resolves.

The index version fences readers. In 10.0.0 through 14.0.0, `a = 1` and
`b = 1` return the same rows as a full scan after every write, and no
plan uses the composite index. Bit 22 fences writers from 12.0.0 on.
"Stable" and "plain" name the table kind where the two differ.

| Release | Insert | Update, delete, create index, add column | Restore,
shallow clone, create branch | `optimize_indices()` | `compact_files()`
|
| --- | --- | --- | --- | --- | --- |
| 14.0.0 | refused | refused | refused | refused | stable refused, plain
commits nothing |
| 13.0.0, 12.0.0 | refused | refused | refused | stable commits nothing,
plain refused | stable refused, plain commits nothing |
| 11.0.0, 10.0.0 | refused | drops the index, clears bit 22 | keeps the
index, clears bit 22 | stable commits nothing, plain drops the index and
clears bit 22 | drops the index, clears bit 22 |
| head, stable only | refused | refused | refused | refused | refused |

After an 11.0.0 restore, shallow clone, or branch clears bit 22, a
13.0.0 update moves the composite index's `fragment_bitmap` from `[0, 1,
2, 3]` to `[0, 1, 2, 3, 5]`, and a 15.0.0b7 restore sets bit 18
(`FLAG_ROW_ADDR_INDICES`) again while leaving bit 22
(`FLAG_BTREE_KEY_LAYOUT`) clear. That result is why an index with a
`key_layout` from a manifest without `FLAG_BTREE_KEY_LAYOUT` is
unusable.

---------

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

Labels

A-python Python bindings bug Something isn't working critical-fix Bugs that cause crashes, security vulnerabilities, or incorrect data. K-approved Latest Gatekeeper recommendation permits acceptance. priority: high Issues that are high priority (for LanceDb, the organization)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: an update from 12.x or 13.x makes a 14.x B-tree miss rows on stable-row-id tables

2 participants