Repository navigation
feat(format)!: add local_fragment_aliases to IndexMetadata - #10780
Conversation
|
Important Format specification voteThis 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
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 |
|
I went through all the current index writers to see what they actually store and reference for row identity, and now we are narrowing this feature to focus on mapping with fragment ids and potentially hopefully move everything to this and not use srid in indexes. In the table below, "Dataset row ID" means the writer stores a logical row ID when stable row IDs are enabled on the table, and a physical address otherwise. "Fragment map works?" just means whether a fragment ID map is enough on paper to handle a rebase, not that the runtime reader and maintenance paths are wired up yet.
None of these index algorithms inherently require global logical row IDs inside their files, though switching an index type over to physical addresses still touches its reader, prefilter, and maintenance paths. For this PR, keeping the format scoped to physical addresses already covers current |
|
UPDATE: according to the last sync we will focus on row addrs mapping and reject SRID, as all indexes are moving towards using fragment ids and row addrs. |
wjones127
left a comment
There was a problem hiding this comment.
Nice work. I have a few pieces of feedback. But this was a refreshingly small PR.
| - **Complete physical mapping:** Map keys are scoped to the segment. The map must | ||
| be nonempty and cover every stored physical fragment ID, including unchanged | ||
| IDs as explicit `id -> id` entries. Keys and values must be less than `2^32 - 1`, |
There was a problem hiding this comment.
question: do we need this the identity maps? I would think it would work just as well if the range the mapping were a subset of the fragment bitmap. What goes wrong if you don't have the complete mapping (missing the identity ones)?
There was a problem hiding this comment.
Yeah thats a fair question! I explored an array early on too in the first commit, but ended up going back to a map since I didn't want to assume we'd always have dense local IDs. My thought process was wouldn't this usually be all or nothing if we have a staged transaction local ids start either at 0 or the expected fragment id (was assuming 0 for simplicity), they'll either match the committed IDs and we don't need a map, or the commit assigns a different range and every ID needs translating.
I can see sparse mappings being useful if we eventually mix committed and local IDs in the same segment, but I'm not sure we have that case today. wdyt?
wjones127
left a comment
There was a problem hiding this comment.
Thanks for turning this around. Every point from my last review is addressed. Empty map now means no mapping, the map is sparse, the null/tombstone and visibility/ownership wording is gone, it's ordered before FRI and deletion, and bit 20 is reserved and rejected in code. The spec section is short and the FRI example is still the best part.
One thing I'd like settled before I lift my veto:
fragment_bitmapvs. aliases. The spec doesn't say whether a mapped segment'sfragment_bitmapholds stored (local) IDs or committed IDs. Coverage, prefilter, and maintenance all read that field, so the spec needs to say.
Smaller spec clarifications (non-blocking):
- Flag lifecycle: I'd make bit 20 non-sticky. It should also join the "both set or both clear" paired list.
- Scope: do aliases cover ZoneMap/BloomFilter zone references, not just row addresses?
- Naming and numbering of the proto field (
fragment_id_map, field 15).
The code change is small and safe: nonempty maps are rejected and the flag is masked out of supported_flags_when, with tests for both.
|
Thanks for the feedback @wjones127! I addressed the comments let me know if that works |
wjones127
left a comment
There was a problem hiding this comment.
Thanks for another quick turnaround. Every point from my last round is addressed: field 14, the rename to local_fragment_aliases across proto, flag and spec, the 2^32 - 1 rationale, the wider "fragment IDs referenced by the segment's files" scope, bit 20 in the paired list, the non-sticky lifecycle, and the stale "bits 16 and 17" sentence. My blocking question on fragment_bitmap is answered: it holds committed IDs (before FRI remapping) and is updated together with the aliases on rebase. Approving, which lifts my veto.
Non-blocking, but I'd like to see the first one before merge:
- Stable row IDs: a segment whose files store stable row IDs must not carry aliases, since a retry can reassign row IDs too. Suggested wording inline.
- State the bitmap/alias update as a "must" rule rather than a description.
- The proto comment and the non-transitivity wording have small suggestions inline.
- PR description: it still describes the earlier design: an optional
fragment_id_map, "Requires both reader and writer feature flags once a feature bit is assigned", and "The reader and writer feature flag bit is still unassigned." The title also says "fragment bindings". Since this becomes the commit message for a format change, could you update it tolocal_fragment_aliases, field 14, bit 20? lance-tools: now that any nonempty map makesIndexMetadata::try_fromfail,lance-toolsfalls back to the raw view inwrite_index, which prints every raw field exceptlocal_fragment_aliases. Could you add a line for it there (entry count, or the entries)? Fine as a follow-up with the reader PR.
f36e323 to
f1e8ac8
Compare
wjones127
left a comment
There was a problem hiding this comment.
Thanks for the follow-ups. Re-approving on the latest commit.
suggestion: the PR title and description still describe the earlier design (an optional fragment_id_map, "the feature flag bit is still unassigned", "fragment bindings"). Since this becomes the squash commit message for a format change, could you update them to local_fragment_aliases, field 14, bit 20 before merge?
Also left one non-blocking note on the "before FRI remapping" wording, which doesn't hold for bitmaps written under FRI v0.
Co-authored-by: Drew <[email protected]>
## 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 PR adds
local_fragment_aliasesto IndexMetadata and reserves feature flagFLAG_LOCAL_FRAGMENT_ALIASESso index files can keep their stored fragment IDs when a commit assigns different committed fragment IDs.The main use case is committing an append and its index together. If another writer commits first and changes the assigned fragment IDs, the retry can update local_fragment_aliases and fragment_bitmap together instead of rewriting the index files. For example, an index storing (17, 5) can alias 17 -> 42, and a rebase to fragment 43 updates local_fragment_aliases to {17: 43} and fragment_bitmap to {43}.
Segments that already store committed fragment IDs omit the map. When present, the map is resolved before the Fragment Reuse Index (FRI). Writers that reuse existing index files must preserve the map, and readers must reject any map they cannot interpret.
This PR adds the protobuf definition updates the spec in
index.md, and adds a read guard that rejects mapped segments until reader support lands. The reader and writer feature flag bit is still unassigned. Writing mapped indexes, applying the map on read, and wiring up index maintenance will follow in separate PRs.Related to #7954, #10386, and #10722.
Testing
cargo test -p lance-table --libcargo clippy --all-targets -- -D warningscargo run --locked --manifest-path protos/codegen/Cargo.toml -- --checkmkdocs build --strict