Skip to content

feat(rowids): support btree indices on stable row ids - #10152

Open
BubbleCal wants to merge 15 commits into
yang/srid-stack-lookupfrom
yang/stable-row-id-btree
Open

BubbleCal wants to merge 15 commits into
yang/srid-stack-lookupfrom
yang/stable-row-id-btree

Conversation

@BubbleCal

@BubbleCal BubbleCal commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of #9474 / OSS-2358.

Allow an ordinary BTree index on the hidden _rowid field of a stable-row-ID dataset. Index creation, training, parameter recovery, maintenance and Python bindings use reserved field ID -3 without exposing a new user column. The ordered lookup layer below this PR serves covered fragments from the BTree and scans uncovered fragments.

dataset.create_scalar_index("_rowid", "BTREE")
dataset.optimize.optimize_indices()

Creation is opt-in. New writes remain queryable through coverage fallback; automatic write-time index deltas and Transaction V2 integration are separate work.

This is layer 5 of the split, stacked on #10421:
#10418 (maintenance) → #10419 (cache) → #10420 (BTree lookup) → #10421 (Dataset lookup) → #10152 (SRID index creation).
Bounded bulk capture and the benchmark harness are in the following layer. The maintenance enum change belongs to #10418.

The compatibility fixture is generated by Lance 13.0.0: twelve initial rows across multiple fragments, a legacy index on key, deletes and an update, leaving ten live rows. Its eighteen data/metadata files plus generator total about 12 KB. The test adds an _rowid index and verifies the existing index, live results and old snapshot.

Validation at 46dca8e74: 1,472 Rust tests and 25 Python Dataset integration tests passed. Full workspace Clippy, Rust formatting, Python build/lint and commit hooks passed. Coverage includes indexed/unindexed lookup, partial coverage, distributed build, compaction, empty tables, deletion cleanup, hidden-field parameter recovery and released-format reads.

The full platform CI run was started on this head before retargeting the PR to its stack base; its results remain in the checks tab. Other stacked PRs describe their own validation.

Performance was not remeasured during this split. Earlier S3 results are historical measurements at 93b5a7460, not claims for this head.

Review and merge order: #10418 → #10419 → #10420 → #10421 → #10152 → #10422.

@github-actions github-actions Bot added A-python Python bindings A-index Vector index, linalg, tokenizer A-docs Documentation enhancement New feature or request labels Oct 19, 2026
@BubbleCal
BubbleCal marked this pull request as ready for review October 23, 2026 10:33

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Oct 23, 2026
Exclude overlay-stale addresses when optimizing BTree segments with deletions. Compare reserved system field IDs without unsigned conversions during partial column rewrites.

Resolve captured row IDs in bounded batches and scan uncovered fragments once. Add regression coverage for coverage boundaries, duplicate and missing IDs, snapshots, and multi-fragment updates.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 23, 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 23, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 23, 2026
@wjones127
wjones127 self-requested a review October 27, 2026 19:06
Merge main at 9cfecdc, including the published ScalarIndex::lookup API. Preserve UInt64 routing and bounded page loading while streaming repeated-key matches. Adapt dataset lookup, hidden-field parameter recovery, and regression coverage.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 28, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

Record the extracted maintenance, cache, BTree lookup and Dataset lookup prerequisites. Move bounded capture resolution and its benchmark harness to the following layer.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 28, 2026
@BubbleCal BubbleCal changed the title feat(rowids): resolve stable row ids through btree indices feat(rowids): support btree indices on stable row ids Oct 28, 2026
@BubbleCal
BubbleCal changed the base branch from main to yang/srid-stack-lookup October 28, 2026 14:17

@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 Dataset lookup layer provides the lookup contract; this layer adds opt-in _rowid BTree creation through the existing scalar-index lifecycle. Partial coverage retains fallback lookup, and deletion handling, compaction and historical snapshots preserve row-ID semantics. I found no remaining blockers.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 28, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Oct 28, 2026
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]>

This branch has not been deployed

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

Labels

A-docs Documentation A-index Vector index, linalg, tokenizer A-python Python bindings enhancement New feature or request K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants