Skip to content

docs(format): specify btree indices on stable row ids - #10150

Merged
BubbleCal merged 3 commits into
mainfrom
yang/spec-srid-btree-index
Oct 23, 2026
Merged

BubbleCal merged 3 commits into
mainfrom
yang/spec-srid-btree-index

Conversation

@BubbleCal

Copy link
Copy Markdown
Contributor

Define how an ordinary address-domain BTree indexes the logical _rowid column through reserved field ID -3, whether its values are inline or spilled. Document snapshot visibility and partial-coverage lookup, and clarify that opening a table does not require constructing a complete in-memory row-ID map.

This reuses the existing BTree version 1 layout and changes no protobuf fields, wire numbers, or encodings. Runtime implementation is separate; this does not provide TV2 write-time maintenance or enable production SRID/FRI support.

Validation:

  • uv run mkdocs build passed. The partial local site reports links to separately assembled catalog/integration content in untouched pages.
  • Protobuf comment-style check and pre-commit hooks passed.
  • protoc descriptors, including imports and excluding source comments, are byte-identical to 98079a55e.
  • Both added documentation links resolve to rendered anchors; git diff --check passed.

Part of #9474.

@BubbleCal BubbleCal added the format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). label Oct 19, 2026

@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 A-format On-disk format: protos and format spec docs label Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ✅ Vote passed — 3 PMC approvals, voting period elapsed

Approvals @wjones127, @Xuanwo, @westonpace (3/3)
Latest commit approved by @Xuanwo
Vetoes none
Voting period elapsed — ended Thu 2026-10-22 16:10 UTC (09:10 PDT)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label Oct 19, 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.

Reusing the ordinary address-domain BTree is consistent with the existing snapshot, coverage, and deletion contracts. Runtime implementation and write-time maintenance remain separately scoped under #9474.

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

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

I think we can shorten part of this, but otherwise this looks good to me.

Readers that do not support this BTree format version must treat the segment as
unsupported and use the ordinary uncovered-data path, subject to the table's other
feature flags. An existing version-0 segment keeps its original interpretation.

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.

suggestion: perhaps make this into a list of clear requirements:

Suggested change
An ordinary BTree may index the logical `_rowid` column of a table, given the following rules:
* Stable Row IDs **must** be enabled on the table.
* `IndexMetadata.fields` **must** be a single field ID `-3`.
* `_rowid` **must** be represented as a non-nullable `UInt64` field.
* The index **must** use the address-domain format and be at least version 1.

Much of this is obvious things that follow from this, so it can be removed. For example,

No new index type, file, encoding, field ID, or address representation is introduced.

Others are just restatement of general rules about indexes, which I think we can also skip. For example,

The index has an ordinary logical index name and segment UUIDs. Multiple segments
may contribute to one logical index.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Oct 21, 2026
Comment on lines -298 to -307
**Example Scenario:**

1. Initial state (version V): Fragment 1 contains rows with IDs `[1, 2, 3]` at offsets `[0, 1, 2]`.
2. An update operation modifies the row with `_rowid = 2`:
- A new fragment 2 is created with a row for `_rowid = 2` at offset `0`.
- In fragment 1, the original physical row at offset `1` is marked deleted in the deletion vector.
3. Row ID index in version V+1:
- `1 → (1, 0)` ✓ Valid
- `2 → (2, 0)` ✓ Valid (updated row in fragment 2)
- `3 → (1, 2)` ✓ Valid

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.

Why did we remove this example?

@BubbleCal
BubbleCal merged commit 77b7fd4 into main Oct 23, 2026
@BubbleCal
BubbleCal deleted the yang/spec-srid-btree-index branch October 23, 2026 07:41
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-format On-disk format: protos and format spec docs documentation Improvements or additions to documentation format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants