Skip to content

feat(index): change btree scalar index to row-address domain - #9481

Merged
westonpace merged 31 commits into
mainfrom
feat/btree-to-row-addresses
Oct 14, 2026
Merged

westonpace merged 31 commits into
mainfrom
feat/btree-to-row-addresses

Conversation

@westonpace

@westonpace westonpace commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Trains and stores physical row addresses (_rowaddr) instead of row ids,
matching ZoneMap/BloomFilter, so a btree can coexist with a live
fragment-reuse index on a stable-row-id dataset. Previously the FRI/
stable-row-id/row-id-domain combination was rejected outright for btree
because an FRI applied to raw row ids would silently corrupt them.

  • Bump BTREE_INDEX_VERSION to 1
  • A pre-existing (row-id-domain) segment is still read correctly, and
    is never merged with address-domain data.
  • Remove btree from the hard-coded row-id-domain index lists in
    create.rs and format/index.rs.
  • Add/extend integration tests covering deferred-remap compaction with
    an FRI, FRI draining, and creating a btree under a live FRI.

In theory it would be possible to make this change without a version bump (which might be quite disruptive) if we stored both the ids and the addrs for compatibility but that seems too wasteful.

I know there are users building btree indexes outside of this crate (e.g. building through spark, etc.) This change will be disruptive for those users as they will need to change the column name and ensure they are reading row addrs and not row ids. I will bring this up in the community sync to attempt to get as much attention on the issue as possible.


Stack created with GitHub Stacks CLI • Give Feedback 💬

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer A-format On-disk format: protos and format spec docs 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 Sep 22, 2026
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch 2 times, most recently from b2992d0 to 394a7a6 Compare September 23, 2026 16:20
@westonpace
westonpace added this pull request to stack #9515 September 23, 2026 16:24
@westonpace
westonpace removed this pull request from stack #9515 September 23, 2026 16:28
@westonpace
westonpace changed the base branch from feat/defer-index-remap-stable-row-ids to feat/index-version-in-load September 23, 2026 16:29
@westonpace
westonpace added this pull request to stack #9519 September 23, 2026 16:29
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch from 394a7a6 to 86ff792 Compare September 23, 2026 17:07
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch from 86ff792 to e3024e3 Compare September 23, 2026 17:13
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch from e3024e3 to 2171145 Compare September 23, 2026 19:07
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch from 2171145 to f5be587 Compare October 5, 2026 17:00
Base automatically changed from feat/index-version-in-load to main October 5, 2026 18:37
@westonpace
westonpace force-pushed the feat/btree-to-row-addresses branch from f5be587 to 1766600 Compare October 5, 2026 21:55
@github-actions github-actions Bot added the A-python Python bindings label Oct 6, 2026
westonpace added a commit that referenced this pull request Oct 7, 2026
This reverts commit dcfcbcc.

The rename changed the literal on-disk schema field name for BTree's
second page column, not just an internal Rust constant. An old Lance
build merging new data into an index the current build already touched
reads that field back by name (not position) when reconstructing the
page to append to, so it fails with "Cannot write batch. The batch was
missing the column `ids`" once the stored name no longer matches what
it expects. Confirmed via the Compatibility Tests job on #9481,
where an old build's JsonIndex check_write (JSON index is backed by a
BTree target) crashed on exactly this.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions github-actions Bot added the A-namespace Namespace impls label Oct 7, 2026
@westonpace
westonpace marked this pull request as ready for review October 7, 2026 23:53

@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 commented Oct 7, 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, @BubbleCal, @jackye1995 (3/3)
Latest commit approved by @jackye1995
Vetoes none
Voting period elapsed — ended Mon 2026-10-12 23:53 UTC (16:53 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).

zhangyue19921010 added a commit to zhangyue19921010/lance that referenced this pull request Oct 23, 2026
Since lance-format#9481 a newly built BTree returns row addresses, so the btree case of
stale_posting_after_update_with_stable_row_ids no longer exercises the
row-id mask and passes without it. Add a Bitmap case, which still returns
row ids and fails without the mask, and assert each case's expected result
domain so a future domain change cannot silently hollow out the test.
wjones127 added a commit that referenced this pull request Oct 23, 2026
IndexJoinExec now consumes ScalarIndex::lookup as a stream and emits
output in batches of at most the session batch size, so a key matching
many table rows is not joined in one batch. Matches from row-address
indices (btree since #9481) are masked in the address domain and
translated to row ids under stable row ids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
wjones127 added a commit that referenced this pull request Oct 23, 2026
IndexJoinExec now consumes ScalarIndex::lookup as a stream and emits
output in batches of at most the session batch size, so a key matching
many table rows is not joined in one batch. Matches from row-address
indices (btree since #9481) are masked in the address domain and
translated to row ids under stable row ids.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
westonpace added a commit that referenced this pull request Oct 23, 2026
…ss domain (#9814)

## Summary

Stacked on #9481 (BTree → row-address domain). Applies the same
migration to the Bitmap and LabelList scalar indexes (LabelList's
underlying storage is literally a `BitmapIndex`, so the two moved
together):

- Bitmap and LabelList now store physical row addresses (`_rowaddr`) in
their postings instead of row ids, bumping their on-disk format versions
(Bitmap: 0 → 1; LabelList: 1 → 2, since its version 1 is already spoken
for as the list-null-metadata floor), tracked per-segment via
`IndexMetadata::index_version`.
- A segment is only written in the new address-domain format on a
dataset with stable row ids enabled; without stable row ids a row id and
a row address are the same value, so the pre-migration version is kept
and old builds see no forward-compatibility impact.
- Reading is fully backward compatible: both formats load correctly,
with domain tracked per-segment (`results_are_row_addresses`) and
threaded through merge/remap/update so a segment's own domain is
preserved rather than silently flipped. LabelList gets this for free
through the `BitmapIndex` it wraps.
- The BTree-only domain-mismatch guards in `merge_scalar_indices` (and
the cache codec/proto header) are extended to cover Bitmap and LabelList
the same way. LabelList gets its own dedicated merge arm (rather than
the generic fallback) since it has no N:1 merge primitive wired into
that path.
- Added Python compat tests
(`BitmapRowAddressDomainIndex`/`BitmapRowIdDomainIndex`,
`LabelListRowAddressDomainIndex`/`LabelListRowIdDomainIndex`) mirroring
the BTree ones, plus doc updates for both on-disk formats.
- Fixed several existing tests that had been using Bitmap as "the
remaining row-id-domain index" fixture (after BTree's own migration) —
mostly switched to NGram, with one small fixture gaining a text column
since no remaining row-id-domain scalar index type supports a plain
numeric column.
- Found and fixed two real bugs this surfaced: the directory namespace's
object-type (Bitmap) and base-objects (LabelList) indices each train
over a hand-built stream that still used the old `ROW_ID`-named column;
updated both to `ROW_ADDR` to match what training now expects (only the
column name changes, not the values). The now-dead `value_row_id_schema`
helper was removed once all three manifest indices moved to `ROW_ADDR`.
- A JSON-wrapped BTREE/Bitmap/LabelList target can't yet carry the
wrapped target's own version or domain through `JsonIndexDetails`, so
`build_scalar_index`/`merge_scalar_indices` refuse to create *or*
optimize that combination on a stable-row-id dataset (not required on a
dataset without stable row ids, where a row id and a row address
coincide). An **existing** such index on a stable-row-id dataset — from
before this guard existed — can still be read, but can no longer be
optimized/compacted by this build. `JsonIndexPlugin::load_index` was
also fixed to stop assuming every wrapped target is at its plugin's
current max version: it now always loads one of these three as the
pre-migration, row-id-domain floor version, since no genuinely
address-domain instance of them can exist through this wrapper (see the
review discussion on this PR).

## Test plan
- [x] `cargo test --workspace --lib` passes (0 failures, including
`lance`, `lance-index`, `lance-table`, `lance-namespace-impls`)
- [x] `cargo check --workspace --all-targets` (including the `python`
and `java/lance-jni` crates) builds clean
- [x] `cargo fmt --check` / `cargo clippy` clean
- [ ] Python compat test suite
(`python/python/tests/compat/test_scalar_indices.py`) — not run in this
environment (no Python/maturin toolchain available); added the new
classes by close mirroring of the already-passing BTree ones, recommend
running in CI

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

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Will Jones <[email protected]>
wjones127 added a commit that referenced this pull request Oct 26, 2026
)

## Summary

Adds `ScalarIndex::lookup`, which takes a batch of keys and streams
`(key_index, row)` record batches, one row per table row whose indexed
value equals a key. This is PR 1 of the indexed `merge_insert` plan in
#6444: the next PR joins merge sources against the index with it,
without reading target data.

```rust
let mut matches = index.lookup(keys, &metrics)?;
while let Some(batch) = matches.try_next().await? {
    // column 0 `key_index`: position in `keys`
    // column 1 `_rowaddr` or `_rowid`: the matching row, named after the index's result domain
}
```

- Exact equality only. A null key never matches, not even a null value.
Keys must have the index's value type.
- The row column is `_rowaddr` when `results_are_row_addresses()` (btree
since #9481, bitmap since #9814) and `_rowid` otherwise. Rows are not
filtered by deletions, and fragment-reuse remapping is already applied,
the same as `search`.
- Output streams in batches of at most 8192 matches, so a key matching
many rows, or repeated many times in `keys`, is never materialized at
once.
- The default implementation returns `NotSupported`.
- BTree: candidate pages come from the existing min/max page search, and
pages load through the same cached, chunked-prefetch path as `search`
(factored out into `evaluate_pages_stream`, which `evaluate_pages`
collects). Each page is hashed once and probed against a hashbrown table
of the keys, grouped by value. A page records only its matched rows and
their key group; they are expanded to one output row per matching key as
the stream is consumed, so a cold prefetch chunk holds at most one entry
per page row. Equality is decided by arrow's `make_comparator`, the same
scheme as DataFusion's generic IN-list filter.
- Bitmap: one bitmap load per distinct key, expanded as the stream is
consumed.
- `LogicalScalarIndex` merges its segments' streams. Under stable row
ids it restricts each row-id segment's matches to the live rows of its
own fragments, as `search` does. `JsonIndex` forwards `lookup` and
`results_are_row_addresses` to its target index. The second forward also
fixes `search` on a JSON-wrapped zone map, bloom filter or FM index
under stable row ids: its row addresses were read as row ids, so matches
past fragment 0 were lost.

## Evidence

- `test_lookup_matches_brute_force` (Int64/Utf8, cold/warm cache, both
row domains) checks BTree lookups against a brute-force scan, with
repeated, null and absent keys and value runs that span pages.
- `test_lookup_float_equality_matches_search` checks that lookup agrees
with `search(Equals)` for `0.0`, `-0.0` and NaN.
- `test_bitmap_lookup` covers the bitmap index, including empty and
all-null keys.
- `test_lookup_bounds_batches`, `test_bitmap_lookup_bounds_batches` and
`test_bitmap_lookup_bounds_repeated_keys` check the batch bound, for
pages or values matching many rows and keys repeated more than a batch
holds.
- `test_lookup_applies_remapping` and
`test_bitmap_lookup_applies_remapping` check that fragment-reuse
remapping is applied.
- `test_segmented_lookup` (BTree, Bitmap) covers lookups across segments
and a key-type error.
`test_lookup_drops_rows_moved_out_of_legacy_row_id_segments` checks, on
a legacy row-ID btree fixture, that lookup drops a row an update moved
out of a segment's fragments, the way search does.
`stale_posting_after_update_with_stable_row_ids` covers the
address-domain case, where the stale posting comes back only as the
deleted old row.
- `test_json_zonemap_index_with_stable_row_ids` covers the `search` fix;
it returns 1 of 3 rows without it.
- `test_json_lookup_forwards_to_target` (both target domains) and
`test_lookup_is_not_supported` (zone map) cover forwarding and the
default.
- New `btree_lookup_{1000,8192}` and `bitmap_lookup_{100,1000}`
benchmarks. Results and a main-vs-branch run for the `search` refactor
are in a comment below. A re-run after the streaming change is in a
later comment.

## Merge Risk

**Door:** Two-way. This adds a trait method with a default
implementation and changes no on-disk format.
**Blast Radius:** `perf` for BTree `search`, whose page loading was
refactored to share code with lookup. Back-to-back runs show no change
beyond run-to-run noise: cached cases are within −8% to +5%, and the
unchanged bitmap control varies as much. Also a `fix` for `search` on
JSON-wrapped address-domain indices (zone map, bloom filter, FM) under
stable row ids, which now return rows past fragment 0.

Part of #6444.

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

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
westonpace added a commit that referenced this pull request Oct 28, 2026
## Summary
- Follow-up to #9518 (merged). Addresses the non-blocking risk the
gatekeeper flagged there: `JsonIndexPlugin::load_index` passed
`target_plugin.version()` (the target plugin's current max format
version) instead of the version the target index was actually persisted
at, since `JsonIndexDetails` never recorded it.
- Adds an optional `target_index_version` field (field 4) to
`JsonIndexDetails`, populated from `CreatedIndex::index_version`
whenever the wrapper trains, remaps, or updates its target. `load_index`
now reads it, falling back to the target plugin's current version only
for details written before this field existed (matching the previous,
safe-for-now behavior for old data).
- Drops the now-stale note in the `target_data_type` docs saying these
details do not record the target's format version.
- This matters for the stacked [BTree format
change](#9481), which will use
the passed-in version to distinguish stored row IDs from row addresses.

## Test plan
- `cargo clippy -p lance-index -p lance --tests -- -D warnings` clean
- `cargo fmt --all -- --check` clean
- `cargo test -p lance-index --lib scalar::json::` — 27 passed

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

https://claude.ai/code/session_018BsnoP9ZPMX6vhJSygzdnN

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Oct 29, 2026
…m, rtree, minhash_lsh (#10299)

## Summary

Follow-on to #9481 (BTree → row-address domain) and #9814
(Bitmap/LabelList → row-address domain). Proposes the same migration for
the remaining row-id-domain index types so we can align on the storage
format before implementation begins. **No implementation changes are
included** — this is docs/src/format only.

Each type follows the same gating rule already established by
BTree/Bitmap/LabelList: a segment built on a dataset with stable row ids
enabled stores physical row addresses (`fragment_id << 32 | offset`)
instead of the dataset's logical row id; without stable row ids a row id
and a row address are the same value, so the pre-migration version is
kept. This allows us to avoid a breaking index change on those older
versions. Once we've established some runtime on the row-addr indexes we
can trigger the upgrade for non-stable-row-id datasets as well (at that
point we will hopefully have multiple releases of readers that can read
the new version).

- **Inverted (FTS)**: `INVERTED_INDEX_VERSION_V3` → `V4`. `_rowid` in
`docs.lance` and the delta-encoded posting-list identifiers become row
addresses.
- **NGram**: `NGRAM_INDEX_VERSION` 0 → 1. `posting_list` bitmap becomes
row addresses.
- **R-Tree**: `RTREE_INDEX_VERSION` 0 → 1. The leaf `id` column and
`nulls.lance` become row addresses.
- **MinHash LSH**: `minhash_lsh_index_version` 0 → 1. Adds a normative
"Version 1: Row-Address Domain" section describing the single change
from the existing Version 0 reference.
- **Vector**: `VECTOR_INDEX_VERSION` 1 → 2 (FLAT/PQ/SQ/HNSW) and
`IVF_RQ_INDEX_VERSION` 2 → 3 (RQ). The auxiliary file's `_rowid` column
becomes a row address.
- **JSON**: `JSON_INDEX_VERSION` 0 → 1. JSON is a wrapper with no files
of its own, so instead of adding a new proto field, the wrapper's own
segment version now records whether the wrapped target was built in the
row-address domain (wrapper and target are always written by the same
build, so this is sufficient). This closes the gap called out in #9814
that currently blocks creating or optimizing a JSON-wrapped
BTree/Bitmap/LabelList target in the row-address domain on a
stable-row-id dataset.

## Test plan

- Docs-only change; no code affected.
- [ ] Review and discussion on the proposed version numbers and storage
descriptions before implementation PRs are opened per index type.

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

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
Co-authored-by: Will Jones <[email protected]>
westonpace added a commit that referenced this pull request Nov 2, 2026
Stacked on #9481 (BTree) and #9814 (Bitmap/LabelList). Completes the
row-address-domain migration for the JSON scalar index: a JSON index
now records its wrapped target's own persisted version
(JsonIndexDetails::target_index_version) and is itself stamped with
format version 1 (JSON_ROW_ADDR_DOMAIN_VERSION) exactly when that
target stores physical row addresses, so IndexMetadata::results_are_row_addrs
and the optimize-time domain guards can see through the wrapper without
decoding the nested target details.

- lance-table/format/index.rs: extend index_details_are_row_addrs with
  a JSON case gated on the wrapper's own version.
- lance-index/scalar/json.rs: track target domain through
  create/update/remap, relabel to row-id domain on a dataset without
  stable row ids (mirroring BTree/Bitmap/LabelList), and fall back to
  the pre-migration version when loading details written before
  target_index_version existed.
- lance/index/{append,scalar}.rs: remove the now-unneeded guard that
  rejected a JSON-wrapped BTree/Bitmap/LabelList index on a
  stable-row-id dataset, and extend the merge/rebuild domain-safety
  checks to recognize a JSON-wrapped migrated target.
- Tests covering the new behavior end to end, plus a Python
  upgrade/downgrade compat test.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Nov 3, 2026
Stacked on #9481 (BTree) and #9814 (Bitmap/LabelList). Completes the
row-address-domain migration for the JSON scalar index: a JSON index
now records its wrapped target's own persisted version
(JsonIndexDetails::target_index_version) and is itself stamped with
format version 1 (JSON_ROW_ADDR_DOMAIN_VERSION) exactly when that
target stores physical row addresses, so IndexMetadata::results_are_row_addrs
and the optimize-time domain guards can see through the wrapper without
decoding the nested target details.

- lance-table/format/index.rs: extend index_details_are_row_addrs with
  a JSON case gated on the wrapper's own version.
- lance-index/scalar/json.rs: track target domain through
  create/update/remap, relabel to row-id domain on a dataset without
  stable row ids (mirroring BTree/Bitmap/LabelList), and fall back to
  the pre-migration version when loading details written before
  target_index_version existed.
- lance/index/{append,scalar}.rs: remove the now-unneeded guard that
  rejected a JSON-wrapped BTree/Bitmap/LabelList index on a
  stable-row-id dataset, and extend the merge/rebuild domain-safety
  checks to recognize a JSON-wrapped migrated target.
- Tests covering the new behavior end to end, plus a Python
  upgrade/downgrade compat test.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Nov 6, 2026
Similar to #9814 (Bitmap/LabelList → row-address domain), and #9481
(BTree). It applies the same migration to the JSON index. JSON is a
wrapper, so it takes its domain from the target index it wraps. This is
also built on #9721 which adds the target index version to the JSON
index details.

Prior to this change we only supported creating JSON indexes against
targets that were in their "legacy domain". For example, a JSON->BTREE
index would be row ids and a JSON->ZONE_MAP index would be row addrs.
This remains the behavior for JSON index version 0.

This PR adds a new JSON index version (1) which can only be used with
row address domain indcies. The new index version is really just
simplification and convenience as it makes it easy to tell we are in the
row address domain without consulting the index details and doing some
complicated type-dependent logic (we could otherwise determine this from
the target version and index type). However, it is also consistent with
the other indexes which have been bumping the index version as part of
the switch.

The actual index itself did not need to change (it's just a wrapper) but
some of the index management logic did (since JSON indexes could now
potentially be row address indexes).

---------

Co-authored-by: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Nov 12, 2026
…row-address domain (#9858)

## Summary

Stacked on #9814 (Bitmap/LabelList → row-address domain), which is
stacked on #9481 (BTree). This applies the same migration to the
**NGram**, **RTree**, and **MinHash LSH** indexes. These indexes now
store physical row addresses (`_rowaddr`) instead of row ids. FM was
already address-domain, so after this PR **Inverted (FTS)** is the only
scalar index still in the row-id domain.

### NGram and RTree (stable formats)
- Training and update now scan `_rowaddr`. The format version goes from
0 to 1 (`NGRAM_/RTREE_ROW_{ID,ADDR}_DOMAIN_VERSION`).
- The domain is tracked per segment from `IndexMetadata::index_version`
(`results_are_row_addresses`). It is preserved through merge, remap, and
update, so a row-id-domain segment is never silently relabelled.
- Without stable row ids, the index is still labelled with version 0.
Here a row id and a row address are the same value, so old builds see no
change. `build_scalar_index`'s per-type override is now a small
`row_id_domain_version` lookup; the RTree entry is behind the `geo`
feature.
- `IndexMetadata::results_are_row_addrs` now version-gates both types.
- Optimize/merge paths:
- The `append.rs` "fold stray legacy segment / rebuild instead of merge"
guards now cover both types. `has_legacy_row_id_domain` is derived from
`row_id_domain_version` (plus MinHash), so there is one less list of
migrated types to keep in sync.
- A new `shared_segment_domain` helper is used by the NGram and RTree
`merge_segments` paths. It refuses mixed-domain segments, and refuses
legacy segments on stable-row-id datasets.
- `merge_rtree_indices` independently rejects mixed-domain sources too,
since it's a public function direct callers could invoke without going
through that helper.
- The generic single-segment `update` arm in `merge_scalar_indices` now
passes the reference segment's own domain. It replaces the hardcoded
`false` and the LabelList-specific arm that duplicated this. ZoneMap,
BloomFilter, and FM ignore the old-data filter, and Inverted is still
row-id domain, so behaviour for other types is unchanged.
- `RTreeIndex::load` is public, so its signature is kept. It loads the
current (address-domain) format only, and its docs say so: a
pre-migration segment must be loaded through `RTreeIndexPlugin`'s
`load_index` with the manifest's `index_version`.

### MinHash LSH (experimental/unstable format)
Per AGENTS.md, this format gets no compatibility path for *writing*, but
reading a pre-migration segment is still supported:
- `MINHASH_LSH_INDEX_VERSION` goes from 0 to 1. The stored column is
renamed `_rowid` → `_rowaddr` for anything this build writes.
- A file version *newer* than the current one is rejected (a build that
doesn't understand it yet). A version *0* (pre-migration) file is still
read correctly, via a two-schema check and a row-id/row-addr column-name
lookup (`signature_id_col`) that works out which domain a given segment
is in without that case being passed down separately.
- `rebuild_from` (behind remap, update and merge) is the sole writer. It
always produces the current (address-domain) layout and copies each
source's identifiers as-is, and `created_index()` always reports
`MINHASH_LSH_INDEX_VERSION` to match. That is only correct for a v0
source when row ids equal row addresses, so the caller, which knows
whether the dataset uses stable row ids, decides:
- `lance`'s MinHash `merge_segments` rejects a v0 segment on a
stable-row-id dataset with a rebuild-required error. Without stable row
ids, a v0 merge is safe and allowed.
- In-repo `update`/`remap` never reach a v0 segment on a stable-row-id
dataset: `optimize_indices` folds it into a rebuild, and compaction
skips it (`supports_eager_remap` is false).
  - `merge_minhash_indices` documents this contract for direct callers.
- The search filters candidates by the row-id-domain prefilter inside
the index's top-k loop. So on a stable-row-id dataset,
`MinHashSearchExec` now gives each segment a synchronous live address →
row-id lookup (`live_row_addr_to_row_id_lookup`). The lookup skips
deleted slots, so an updated row's stale entry can't resolve to its
moved stable id.
- The lookup is passed through a new public
`MinHashLshIndex::search_signature_as_row_ids`. `search_signature` is
unchanged.
- MinHash still doesn't apply a fragment reuse index on load, so it
stays incompatible with an FRI on stable-row-id datasets.

### JSON-wrapped indexes
- `legacy_target_index_version` (and so `wraps_row_addr_domain_target`)
now also recognizes NGram and RTree as targets whose format moved from
row ids to row addresses, alongside BTree/Bitmap/LabelList. Without
this, a pre-migration JSON-wrapped-NGram/RTree segment was never folded
into an `optimize_indices` rebuild on a stable-row-id dataset, and a
stray row-id-domain segment surviving alongside a fresh address-domain
one made the commit fail.

### Tests and docs
- Tests that used NGram as "the remaining row-id-domain index" fixture
now use Inverted.
- New Rust tests:
- `test_compact_ngram_with_stable_row_ids` for NGram on a stable-row-id
dataset, with both eager and deferred compaction. The eager case checks
that the index is remapped in place and keeps full coverage. The
deferred case checks answers through the FRI and after draining it.
- The legacy-segment append rebuild test now runs for both BTree and
NGram.
- A MinHash search test on stable row ids, including an updated row's
deleted slot.
- A MinHash test that merging a legacy (row-id-domain) segment on a
stable-row-id dataset is rejected rather than silently losing matches.
- FRI compatibility cases for NGram, RTree, and MinHash (v0 and v1 for
each).
  - Version-gate cases in `lance-table`.
- Version ↔ domain mapping tests that go through
`RTreeIndexPlugin::load_index` and `NGramIndexPlugin::load_index` at v0
and v1. The RTree test also covers how merge handles the domain.
- A JSON-wrapped-NGram test reproducing the append + `optimize_indices`
failure above.
- A `translate_addr_mask_to_row_ids` unit test for the empty vs.
non-empty block-list branches.
- New Python compat test `NgramRowAddressDomainIndex`. The existing
`NgramIndex` test already covers the case without stable row ids.
- Format docs updated for ngram, rtree, and minhash_lsh.

### Known gaps
- **RTree on compaction with stable row ids.** RTree can't remap in
place (`can_remap() == false`), so a normal (non-deferred) compaction
drops its coverage of the rewritten fragments until `optimize_indices`
or a rebuild. Before this PR, the row-id domain survived compaction.
NGram, BTree, Bitmap, and LabelList remap in place and keep coverage.
#10969 tracks adding RTree remap support (likely reusing
`remap_rtree_data`).
- **RTree test coverage.** There is no RTree compat test and no RTree
query-under-FRI test, because both need geometry fixtures.

## Test plan
- [x] `cargo test -p lance-index --features geo --lib -- scalar::ngram
scalar::rtree scalar::minhash_lsh`
- [x] `cargo test -p lance-geo --lib` (including the plugin-backed
version/domain/merge test)
- [x] Targeted `cargo test -p lance --lib` run: MinHash, NGram
compaction (eager + deferred), FRI/stable-row-id, addr-domain
compaction, JSON-wrapped NGram, and legacy-segment tests (256 passed)
- [x] `cargo test -p lance-table --lib -- results_are_row_addrs`
- [x] `cargo clippy -p lance-geo -p lance-index -p lance --tests -- -D
warnings`, `cargo fmt --all --check`, `ruff check` / `ruff format
--check`
- [ ] Full `cargo test --workspace` (not run here because of disk
limits; relying on CI)
- [ ] Python compat suite (needs old-version venvs; relying on CI)

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

https://claude.ai/code/session_01Y3hhWhSPAggJTKAWR32ivc

---------

Co-authored-by: Claude <[email protected]>
westonpace added a commit that referenced this pull request Nov 13, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
westonpace added a commit that referenced this pull request Nov 13, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Xuanwo added a commit that referenced this pull request Nov 13, 2026
…ead (#10776)

## Why

The scalar index benchmarks should run to completion. Four bench targets
panicked in their first benchmark, because each one fed its trainer a
stream with column names the trainer does not read.

- `lance` `scalar_index`. The fixture trained the B-tree from `values`
and `row_ids`, but `train_btree_index` reads `value` and `_rowaddr`.
Training has looked up `value` by name since #4584, and #9481 moved the
row column from `_rowid` to `_rowaddr`.
- `lance-index` `btree` and `bitmap`. The shared generators in
`benches/common.rs` wrote `_rowid`. The B-tree trainer has read
`_rowaddr` since #9481, and the bitmap trainer has since #9814.
- `lance-index` `ngram`. The bench named its text column `doc`, but
`NGramIndexBuilder::train` has looked up `value` since #4584.

## What changed

- In `scalar_index.rs`, `test_data` takes the value and row column
names. The training stream passes `VALUE_COLUMN_NAME` and `ROW_ADDR`.
The dataset keeps `values` and `row_ids`, so the baseline benchmarks
scan the same data as before.
- In `common.rs`, the five generators write `ROW_ADDR` instead of
`_rowid`.
- In `btree.rs`, the ordered-search benchmark had its own copy of
`generate_int_unique_stream` with a `_rowaddr` column. It now calls the
shared generator, and the imports that only the copy used are gone.
- In `ngram.rs`, the text column is `VALUE_COLUMN_NAME`. The row column
stays `ROW_ADDR`, which main already used after #9858 moved NGram to the
row-address domain.

## Scope

- Only bench files change. The benchmarks, their queries, and their
assertions stay the same.
- The `zonemap`, `bloomfilter`, `inverted`, `geo`, and `minhash_lsh`
benches already write the columns their trainers read, so they do not
change.
- A missing row column still fails B-tree and bitmap training with the
vague error `Expected option to have value`. A schema check with a clear
message belongs in the trainers, in a separate change.

## Tradeoffs

- The `scalar_index` dataset cannot use the training names, because
Lance rejects a stored column named `_rowaddr`.
- A second generator for the `scalar_index` training stream would repeat
the row and batch counts that every assertion depends on.

## Blast radius

The change touches bench code only. Library code, the file format, and
tests do not change.

## Verification

The branch is merged with `main` at `01036bf80`. Every command below ran
in criterion test mode on that merged tree with `--profile ci --locked`,
and each benchmark reports `Success`, so this covers the fixture
generation and trainer calls rather than compilation alone.

- `cargo test --profile ci --locked -p lance-index --bench btree`: 84
`Success`, including `btree_ordered_first_k` and `tuple_planning`.
- `cargo test --profile ci --locked -p lance-index --bench bitmap`: 40
`Success`.
- `cargo test --profile ci --locked -p lance-index --bench ngram`: 2
`Success` (`ngram_train`, `ngram_search`).
- `cargo test --profile ci --locked -p lance --bench scalar_index`: 5
`Success`, including both baseline scans.
- `cargo fmt --all -- --check` and `cargo clippy --profile ci --all
--tests --benches --locked -- -D warnings` pass.

On the original base, before the fix, `--bench btree` and `--bench
bitmap` panicked with `Expected option to have value`, and `--bench
ngram` panicked with `Unable to get field named "value"`.

---------

Co-authored-by: Cursor <[email protected]>
Co-authored-by: Xuanwo <[email protected]>
westonpace added a commit that referenced this pull request Nov 23, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Nov 24, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Nov 30, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Nov 30, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Dec 1, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Dec 1, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Dec 2, 2026
Stacked on #9858 (NGram/RTree/MinHash LSH), stacked on #9814 (Bitmap/LabelList),
stacked on #9481 (BTree). This completes the scalar-index migration: Inverted
was the last builtin scalar index type still in the row-id domain, and now
stores physical row addresses (fragment_id << 32 | offset) in docs.lance's
identity column (still named `_rowid`) instead of row ids.

- New INVERTED_ROW_ADDR_DOMAIN_VERSION (4), orthogonal to the posting-list
  format axis (tracked separately via file metadata, not index_version).
- index_version()/results_are_row_addrs()/can_follow_stable_row_ids() gate on
  it; build_scalar_index relabels a fresh build back to the legacy version on
  a non-stable-row-id dataset, matching every other migrated type.
- append.rs/scalar/inverted.rs: old-data filters and legacy-domain-mismatch
  rebuild now use the segment's own domain instead of a hardcoded row-id
  assumption, fixing a real bug where a stale posting after an in-place
  update under stable row ids leaked through a merge.
- FTS's own deletion/filter/overlay masks (DatasetPreFilter, IndexVisibility)
  are checked directly against an address-domain index's own stored
  addresses, before any row-id translation -- they now translate the
  row-id-domain conventions every other mask follows into that same domain
  instead of silently comparing unrelated numeric spaces.
- create.rs no longer refuses creating an Inverted index under a live
  fragment reuse index: it applies to Inverted like every other scalar type
  now.
- Updated or replaced tests that assumed Inverted was "the last row-id-domain
  index" across append.rs, create.rs, frag_reuse_with_stable_row_ids.rs,
  dataset/optimize/tests, dataset/write/update.rs, and index/tests/lifecycle.rs,
  largely via the manual legacy-segment-relabel pattern already used for the
  prior migrations. Added an Inverted case to a few other-type-parametrized
  tests confirming it now behaves like every other address-domain index.
- New Python compat test InvertedRowAddressDomainIndex; format docs updated.

Known gap: a latent gap in compaction's eager-remap-vs-unreadable-index path
(planning.rs's `unreadable_coverage` hold-back only applies without stable
row ids) was exposed by this migration removing the last index type that
could dodge it, but predates this PR and affects every address-domain index
type, not just Inverted -- flagged separately for follow-up.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y3hhWk6pkpoQgZywMu49WT
westonpace added a commit that referenced this pull request Dec 2, 2026
#11018)

## Summary

Completes the scalar-index row-address migration (#9481 BTree → #9814
Bitmap/LabelList → #9858 NGram/RTree/MinHash LSH, all merged):
**Inverted (FTS)** was the last builtin scalar index type still in the
row-id domain. It now stores physical row addresses (`fragment_id << 32
| offset`) for each document instead of the dataset's logical row id.

### Format and domain tracking

- New `INVERTED_ROW_ADDR_DOMAIN_VERSION` (4), orthogonal to the
posting-list format axis (`INVERTED_INDEX_VERSION_V1/V2/V3`, tracked via
file metadata rather than `index_version`): a row-address-domain segment
can pair with any posting format.
- `index_version()`, `results_are_row_addrs()` and
`can_follow_stable_row_ids()` version-gate on it, matching the earlier
migrations.
- `build_scalar_index` relabels a fresh build's `index_version` back
down to the legacy posting-format version on a dataset *without* stable
row ids (where row id == row address, so an older reader still reads it
correctly) — the same relabeling every other migrated type does.
- **The document identity column in `docs.lance` is named for its
domain**: `_rowaddr` from version 4, `_rowid` in versions 1–3. This
follows MinHash LSH, the only other migrated type that had an identity
column literally named `_rowid` (see
`docs/src/format/index/scalar/minhash_lsh.md` and `minhash_lsh/mod.rs`,
which renames the same way and resolves the name from the file schema on
read). The remaining migrated types — BTree `ids`, Bitmap/LabelList
`bitmaps`, NGram `posting_list`, RTree `id` — use domain-neutral column
names and had nothing to rename, so no migrated scalar index now leaves
a column named `_rowid` holding addresses.

The name tracking the version is worth more than tidiness: a reader that
ignores `index_version` finds no such column rather than silently
reading one domain's values as the other's. Because `build_scalar_index`
relabels down for older readers, the name is chosen *before* the file is
written, from the version the segment will be committed with —
`TrainingRequest` gains a defaulted `set_stable_row_ids` hook so only
FTS implements it. Rewrites keep their source's version and therefore
its column: a loaded `DocSet` records the name it read and derived
builders inherit it, so no merge, remap or consolidation path has to
remember. Readers resolve the name from the file's own schema
(`docs_identity_column`), so one reader serves both.

### Changes the migration requires

These are hazards the migration *introduces* and this PR handles — not
fixes to pre-existing defects. **None of them can fail on the base
commit**, because before this PR there was no address-domain FTS segment
for them to go wrong on; the applicable test is "fails with the hunk
reverted on this branch", which is what the coverage below was measured
against.

- `append.rs` / `index/scalar/inverted.rs`: the old-data filters used
during a segment merge now use the segment's actual domain instead of a
hardcoded `false`. Reverting this fails
`stale_posting_after_in_place_update_with_stable_row_ids` and
`test_optimize_fts_consolidates_single_row_appends::stable_ids`.
- `append.rs`: `legacy_domain_mismatch` forces a full rebuild rather
than merging a legacy row-id-domain segment alongside a fresh
address-domain one. Pinned by
`test_optimize_append_rebuilds_stray_legacy_fts_segment_with_stable_row_ids`
(previously uncovered — reverting it changed nothing in the suite).
- FTS pushes its deletion/filter/overlay masks straight into the index's
own search as a live prefilter, checked against physical postings before
any row-id translation — unlike other scalar types, which translate an
index's address-domain results into row ids *before* any mask check
(`ScalarIndexExec`'s convention). Forcing only the deletion mask into
address domain was not enough: the externally supplied
`filtered_ids`/`external_mask` and the overlay-staleness block mask
follow the same row-id-domain convention and needed the same translation
(`io/exec/utils.rs`'s
`row_id_mask_to_row_addr_domain`/`translate_treemap_to_row_addr_domain`,
applied at every FTS prefilter boundary). Reverting it fails 46 tests.
- `create.rs` no longer refuses creating a *new* Inverted index while a
live fragment-reuse index exists: that guard assumed Inverted always
stored row ids.

### Addressed from review

- **Mixed identity domains across columns.** A multi-column FTS query
merges several *named indexes*' postings on the stored identifier alone,
so rebuilding one column's index after an upgrade left its sibling on
the older domain and an AND query silently returned nothing.
`fts_segments_are_address_domain` now resolves the one domain every
segment agrees on and errors naming both offenders; the callers already
pass every segment a query reads, so the same check covers the
cross-column and within-index cases.
- **Row-address segment coverage.** Opening a multi-segment FTS index
under stable row ids failed outright (`segment coverage of row-address
hits has no live row ids`): `open_fts_segment` asked for a stable-row-id
allow-list unconditionally. `SegmentCoverage::allowed_row_mask` now
serves both restrictions, allowing each covered fragment whole for
address-domain hits.
- **Tied-result pagination.** Top-k selection ranks ties by the stored
identifier, which is now an address, while the plan above sorts by
`_rowid`; paging a tie skipped and repeated rows. Selection cannot be
re-keyed — `combined_maxscore` discovers candidates in ascending
stored-id order and its pruning depends on that — so the order is
reconciled after selection: searches retain extra candidates, and a tie
at the cutoff larger than that margin is completed exactly (the escape
hatch the WAND tie certificate already had). Applied to combined fields,
both compound paths, Match and Phrase.
- Spec text stated normatively (reader/writer rules rather than library
behaviour); `translate_treemap_to_row_addr_domain` reports a
whole-fragment entry instead of silently passing it through
untranslated; the repeated relabel-to-row-id-domain test snippet
extracted as `utils::test::as_legacy_row_id_segment`, documenting that
its segment still holds addresses while claiming row ids; comment/nit
fixes.

### Tests

- Updated or replaced tests whose premise was "Inverted is the last
row-id-domain scalar index type" across `append.rs`, `create.rs`,
`frag_reuse_with_stable_row_ids.rs`, `dataset/optimize/tests*`,
`dataset/write/update.rs`, `dataset/mem_wal/index/tests.rs` and
`index/tests/lifecycle.rs`.
- `index/tests/lifecycle.rs`'s
`test_compaction_survives_an_unsupported_index` renamed to
`test_compaction_drops_coverage_of_an_unsupported_index_it_rewrites`:
its premise no longer holds for *any* scalar index type.
- New: mixed-domain rejection (cross-column and within-index),
`docs.lance` identity column asserted for both domains and across a
merge, tie pagination within and beyond the re-rank margin and across
four query shapes, `translate_treemap_to_row_addr_domain` unit tests,
and a Python compat test `InvertedRowAddressDomainIndex` mirroring
`NgramRowAddressDomainIndex`.

### Known gaps

- **Compaction's eager-remap vs. unreadable-index gap.**
`plan_groups_with_budget`'s `unreadable_coverage` hold-back only runs
without stable row ids; under stable row ids it relies on
`supports_eager_remap`, a type-level capability check that does not
account for a *specific* index instance being unreadable. Predates this
PR and affects every address-domain scalar type — it was only ever
hidden because Inverted was the last type that could dodge it in tests.
Flagged as a follow-up.
- Tie ordering is reconciled above the collectors, in each exec.
Teaching the collectors to retain ties at the k-th score in one pass
would remove both the retained margin and the exact-completion replay.
- `build_prefilter` / `build_prefilter_restricted_to_fragments` still
have `_in_domain` siblings. Collapsing them needs the overlay-block
translation made lazy first, since the merged function would otherwise
be `async` while three vector `execute()` bodies are sync.

## Test plan

- [x] Rebased onto `main` (was 11 commits behind; picked up `cd45844c9`,
which fixes the `HnswQueryParams` compile error that was failing
clippy/builds/MSRV)
- [x] `cargo test -p lance --lib` — 11459 passed, 1 failed
(`test_only_proven_address_indices_are_compatible::case_10_rtree_address_domain`,
which also fails on `origin/main`; unrelated to this PR)
- [x] `cargo test -p lance-index --lib` — 4185 passed
- [x] `cargo clippy -p lance -p lance-index --lib --tests` and `cargo
fmt` clean
- [x] Full CI green (41/41 excluding the format-spec vote) as of
`01da7a07e`
- [ ] CI for the identity-column rename (`99d810578`, `87935eb6e`) —
still running
- [ ] Python compat suite — relies on CI. Schema-driven reading should
let an existing version-4 fixture written before the rename still open,
but that is reasoning rather than evidence; worth watching that job
specifically.

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

---------

Co-authored-by: Claude Opus 5 <[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 A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-namespace Namespace impls A-python Python bindings breaking-change enhancement New feature or request 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.

6 participants