Skip to content

feat(dataset): stage index builds in staged transactions - #11382

Open
geruh wants to merge 9 commits into
lance-format:will/transaction-v2-action-constructorsfrom
geruh:staged-index-base
Open

geruh wants to merge 9 commits into
lance-format:will/transaction-v2-action-constructorsfrom
geruh:staged-index-base

Conversation

@geruh

@geruh geruh commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Note: This is stacked on #10722, #11203, and #11280. The branch includes those changes, so please review commit f45a030

Summary

This PR adds create_index and extend_index to StagedTransaction, allowing data and indexes to be committed together.

create_index builds a new index over the visible fragments. extend_index adds coverage for newly appended or otherwise uncovered fragments without rebuilding the existing index. Both can be used after tx.append(), with everything published in a single commit.

let mut tx = dataset.begin_transaction().await?;
tx.append(batches).await?;
tx.create_index(&["id"], IndexType::BTree, None, &ScalarIndexParams::default()).await?;
// or if the index already exists:
// tx.extend_index("id_idx").await?; <-- subject to change
let committed = tx.commit().await?;

Implementation

Index builds are split into separate segments for committed and local fragments.

Local segments use their transaction-local fragment IDs when building the index. At commit time, AddIndexSegment resolves those IDs and records the mappings in local_fragment_aliases. If another writer commits first, the transaction can retry with new fragment IDs without rebuilding the index files.

The mappings are derived from covered_fragments, so no protobuf changes are needed. A segment cannot mix committed and local fragment references because their stored IDs could overlap.

Current limitations

  • Local fragment indexing is supported for scalar indexes that can remap row addresses, including BTree, Bitmap, ZoneMap, BloomFilter, NGram, LabelList, and RTree.
  • Inverted, FM, MinHashLsh, and vector indexes can still be created over committed-only fragments.
  • extend_index supports scalar and inverted indexes but not vector, covering, or system indexes.
  • Index types that cannot safely rebase local fragments return NotSupported.
  • Index replacement isn't supported.

Testing

Added coverage for concurrent commits and retries, stable row IDs, index queries, protobuf round-trips, staged scans, and index maintenance. Also tested supported and unsupported index types, including compaction and index optimization after committing aliased segments.

Related to #7954, #10722, #10780, #11203, and #11280.

wjones127 and others added 6 commits November 17, 2026 17:46
Appends go through the existing insert writer and land as AddFragment
and AddDataFile on the reusable ApplyState. A scan pins publication to
the base version. Appends that were not scanned can rebase. The
uncommitted snapshot uses u64::MAX so commit and maintenance reject it.

Co-authored-by: Drew <[email protected]>
…mat#10780)

This PR adds `local_fragment_aliases` to IndexMetadata and reserves
feature flag `FLAG_LOCAL_FRAGMENT_ALIASES` so 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 lance-format#7954, lance-format#10386, and lance-format#10722.

### Testing
- `cargo test -p lance-table --lib`
- `cargo clippy --all-targets -- -D warnings`
- `cargo run --locked --manifest-path protos/codegen/Cargo.toml --
--check`
- `mkdocs build --strict`

---------

Co-authored-by: Drew <[email protected]>

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-format On-disk format: protos and format spec docs A-namespace Namespace impls format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). enhancement New feature or request labels Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 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: ❌ Blocked — 0 of 3 required approvals

Approvals none (0/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes none
Voting period elapsed — ended Thu 2026-11-26 04:31 UTC (Wed 20:31 PST)

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 23, 2026
@geruh
geruh changed the base branch from main to will/transaction-v2-action-constructors November 23, 2026 04:36
@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Nov 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 23, 2026
@geruh
geruh force-pushed the staged-index-base branch from f45a030 to 58c8205 Compare November 23, 2026 06:13
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 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 Nov 23, 2026
@geruh
geruh force-pushed the staged-index-base branch from 58c8205 to 71fc9bc Compare November 23, 2026 07:56
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 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 Nov 23, 2026
/// the MemWAL system index, a `covered_fragments` list that mixes
/// [`Ref::Committed`] and [`Ref::Local`], duplicate [`Ref::Local`] ids,
/// and [`Ref::Local`] carrying [`RowAddress::TOMBSTONE_FRAG`].
pub fn try_new_unchecked(mut parts: AddIndexSegmentParts) -> Result<Self> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review note:

We keep coverage either committed only or local only so we can derive local_fragment_aliases directly from covered_fragments without adding protobuf fields. alternatively we can add that field lmk what you think.

This also avoids collisions when committed and local fragments have the same stored ID.

/// the index does not exist, is a vector, covering, or system index, or if
/// staged fragments need indexing and the index type cannot rebase through
/// `local_fragment_aliases`.
pub async fn extend_index(&mut self, name: &str) -> Result<()> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review note:

I went with extend_index because we're only indexing fragments that the existing index doesn't cover yet, without rebuilding or merging existing segments.

Alternitely, we can go with the existing optimize_indices call but that would target indices that are outside of the scope or the transactions so I wanted to distinguish. It's worth noting that Spark users call refresh and it seems like both lance db and duckdb call optimize

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 26, 2026

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

Keeping committed and local fragments in separate segments makes sense because their stored IDs can collide. Please document that requirement on AddIndexSegment.covered_fragments so another writer can produce valid actions.

I found three technical blockers in 71fc9bc1 by source inspection:

  1. extend_index plans from stored bitmaps. After tagged fragment-reuse compaction, a BTree can already answer for the replacement fragment while its stored bitmap still names the original fragments. Conversely, a missing legacy bitmap makes the planner skip every committed fragment. Please use current coverage and handle unknown coverage explicitly. Test that extending a fully covered compacted BTree stages no step, and that an unknown bitmap cannot silently skip uncovered rows. Planner
  2. Two transactions can start on the same empty base, append different rows, and each create a BTree with the same name and definition. Both check the name during staging. At commit, the two segment claims have disjoint coverage because the conflict check excludes local fragments. Please preserve the create-only name check through commit and test that one create fails while independent extensions can still succeed. Conflict check
  3. A caller submitting AddIndexSegment directly can publish a vector segment with a local fragment alias such as 0 → 1. The vector reader rejects every nonempty alias map. Please reject this combination before publication and cover the direct transaction entry point. Action · Reader

@wjones127
wjones127 force-pushed the will/transaction-v2-action-constructors branch 2 times, most recently from de69e45 to 7acc64d Compare December 1, 2026 19:11
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Dec 1, 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 three issues in the latest review are addressed: extensions use current coverage, create-only names are checked during commit retries, and aliased vector segments are rejected before publication.

Please mark this PR with the breaking-change label: lance_table::format::IndexMetadata gained the required public local_fragment_aliases field, so Rust callers constructing it with struct literals must initialize that field.

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

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-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-namespace Namespace impls A-python Python bindings enhancement New feature or request format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants