Skip to content

perf(fts)!: keep the whole FTS execution path in the row-address domain - #11489

Open
westonpace wants to merge 3 commits into
mainfrom
claude/fts-tie-ordering-11456
Open

westonpace wants to merge 3 commits into
mainfrom
claude/fts-tie-ordering-11456

Conversation

@westonpace

@westonpace westonpace commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

#11018 has merged, so this now targets main and all three commits are for review:
the row-address execution path, the review fixes on top of it, and the identity-domain
groundwork.

Resolves the follow-up recorded in lance-format/lance#11456 (comment): FTS tie ordering forced candidate materialization.

The problem

Top-k selection ranks on the identifier the postings store — a row address since #11018 — while the plan above sorted on (score DESC, _rowid ASC). Within a tie group the two orders disagree whenever a row's address differs from its id, so each page's selection kept the lowest-address members while the sort promoted different ones and paging skipped and repeated rows. #11018 reconciled that after selection: searches retained FTS_TIE_RERANK_BUDGET extra candidates, re-ranked them on row id, and escalated to the whole match set when the cutoff tie was larger than the margin. The contract was old; the cost was new.

The fix

Make the identifier the plan carries the one selection ranks on, rather than reconciling two orders afterwards. The FTS execution path is now row-address domain end to end:

  • FTS_SCHEMA's identity column is _rowaddr. Nothing between the postings and the take above the plan translates.
  • fts_score_sort_exprs, the Or-path dedup and the element-hit dedup key on _rowaddr; so does the hybrid arm merge.
  • The flat siblings project _rowaddr (plan_uncovered_rows_scan takes an explicit UncoveredRowIdentity), so the two sides of a mixed plan rank on the same identifier.
  • TakeExec reads by address, which it already preferred (get_row_addrs short-circuits the row-id-index lookup).
  • A _rowid the caller projected is derived once, above the plan's own ordering and fetch, by a new AddRowIdExec — the inverse of AddRowAddrExec. The row id is an output column, never a sort key.

A bounded search's result is then a prefix of the order the plan emits in, so no tie group is held anywhere and no search is replayed.

Deleted: FTS_TIE_RERANK_BUDGET, widen_limit_for_tie_rerank, cutoff_tie_unresolved, exhaustive_limit, finalize_row_ids_and_scores, translate_row_ids_and_scores, fts_row_addr_to_row_id, the whole-dataset RowAddrToRowId build, the exact-completion replays in five exec paths, and the re-ranks in both finalize_row_ids_and_scores and scored_documents_batch. Also the now-unreachable build_prefilter_restricted_to_fragments / DatasetPreFilter::new_restricted_to_fragments.

Legacy segments are refused, not ranked

A segment persisted before INVERTED_ROW_ADDR_DOMAIN_VERSION stores row ids, which this path cannot rank or page on once row ids and addresses diverge. On a stable-row-id dataset such a segment is now refused by name (require_fts_address_domain, replacing fts_segments_are_address_domain) with the index to rebuild and how. The state is transient — it only arises between turning stable row ids on and the index's next rebuild or merge, which optimize_indices' legacy_domain_mismatch already forces — and the same check still catches segments that disagree with each other, which is the only thing standing between a multi-column query and two numbering systems at once.

Without stable row ids nothing changes: a row id is a row address there, so a segment relabelled down for older readers still answers.

Tie order is now deterministic at every merge

Found while fixing the above, and necessary for the pagination guarantee to hold at all. ScoredDoc and ScoredPartitionDoc compare the score alone, so a tie's order fell to heap and arrival order — and segments and partitions are searched concurrently, so which of two equal-scoring documents a bounded search kept was not stable run to run. Each merge now keys on the full (score DESC, identity ASC) order:

  • search_prepared_segments / search_segments (cross-segment) through a local RankedDoc wrapper.
  • push_scored_key (cross-partition, where the key is the address).
  • ScoredPartitionDoc's Ord (cross-partition, before addresses are resolved) tiebreaks on (partition ordinal, doc id), which ascends with the address for an index built the only way InvertedIndexBuilder builds one — its partitions are filled in scan order.

combined_maxscore already keyed on (score, Reverse(row_id)) and needed no change.

Two domain mismatches fall out

Both were producing wrong BM25F statistics on an overlay under stable row ids, and both are fixed by the move rather than worked around:

  • The scanner built FlatStatsCoverage::stale_rows from the overlay's own result domain (stable ids), while both consumers key by address — bm25_row_stats_for_terms looks each row up in docs to subtract its pre-overlay statistics, and the flat side allows the same set through a stats mask. open_combined_fields_scan carried a compensating translation for the index side only, so the flat side allowed nothing. Now addresses, and the compensating translation is gone.
  • The flat combined_fields stats and emit masks were built in the row-id domain to match the scan's _rowid; they are address-domain now (create_restricted_deletion_mask_in_row_addr_domain, build_prefilter_restricted_to_fragments_in_domain).

What this does not promise

A tie order that survives compaction for a reader that does not pin a dataset version: a row's address moves when it is rewritten. Per the decision recorded in the issue, the contract is same-version determinism and pages that neither skip nor repeat — which is what ties actually need, and all that is available anyway, since any delete shifts docCount/avgdl/docFreq and so moves the scores themselves. test_fts_combined_fields_tied_scores_are_deterministic's premise is unaffected: its fixture leaves enable_stable_row_ids at the default, where a row id is a row address.

Tests

  • The three tie-pagination tests now assert the contract rather than a particular id sequence: assert_tied_pages_visit_each_row_once walks one-row pages over the whole result, requires every page to visit a row the earlier pages did not, and requires the pages to agree with the unpaginated order of the same query. Their fixtures keep what made them meaningful — stable row ids, more than one fragment, and an update that moves row id 0's address behind every other row's, so row ids and addresses deliberately disagree.
  • test_fts_combined_fields_tied_pagination_completes_large_ties now pages through every matching row (132, not the first three): a tie that straddles the cutoff is only visible at the page boundary it crosses.
  • New test_fts_row_id_domain_segment_is_rejected_under_stable_row_ids covers the single-column rejection; test_fts_mixed_domain_across_columns_is_rejected keeps the cross-column half.
  • Plan snapshots, identity-column fixtures and expectations updated across dataset_scanner_plans, dataset_fts_plan_state, dataset_fts_combined_fields/reconstruction, dataset_index/composition, the io::exec::fts tests and the lance-index flat-search fixtures.

Test plan

  • cargo test -p lance --lib — 11562 passed, 0 failed
  • cargo test -p lance-index --lib — 4185 passed, 0 failed
  • cargo clippy -p lance -p lance-index --lib --tests clean
  • cargo fmt --all --check clean
  • Full CI, including the Python compat suite — relies on CI. The on-disk format is untouched by this PR (the _rowaddr/_rowid rename is to the in-memory execution schema, not docs.lance), so the version-4 fixtures feat(index)!: change Inverted (FTS) scalar index to row-address domain #11018 added should be unaffected; that is reasoning rather than evidence, so worth watching.

Left for the follow-up

The parent issue's actual ask — writing the domain contract at each distributed boundary (PreFilterSource::ScalarIndexQuery, FilteredRowIds, external_mask, the overlay block mask, the emitted row identities) — is deliberately not in this PR. It is now much easier to state: the FTS path emits row addresses and never translates its results. The remaining translation is at the input boundary, where build_prefilter_in_domain converts the row-id-domain masks that prefilter_mask_future produces; moving that upstream is the open review thread the issue cites, and it touches vector search too.

🤖 Generated with Claude Code

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer performance breaking-change labels Nov 25, 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.

I found two merge blockers in d1a1d67c relative to its parent ef58136a7.

  1. A fixed snapshot can return the same row on consecutive pages. I ran the candidate collector with one equal-score document in each of two partitions, with the smaller row address in partition 0. When partition 1 arrives first, k=1 retains [1] because push_scored_partition_doc only replaces a full heap entry for a strictly higher score. With the same arrival order, k=2 returns [0, 1]. Both one-row pages can therefore return partition 1. Please apply the same (score DESC, current row address ASC) order before each top-k cutoff. Partition/document coordinates can diverge from current addresses after remapping, and the indexed-plus-flat merge also truncates on score alone. A scanner test with controlled reverse completion should compare the pages against an independently sorted full result, including remapped and partially indexed data.

  2. An upgrade can make an existing FTS index unqueryable. From the release and candidate sources, v14.0.3 can create a stable-row-ID table and write a single row-ID-domain FTS segment. The parent can query it, but require_fts_address_domain rejects it on this head. Default optimization can return early for one fully covered segment. Please preserve this read path and cover it with a two-fragment, single-segment fixture written by v14.0.3 that the candidate opens and queries without rebuilding.

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 25, 2026
@westonpace
westonpace force-pushed the claude/inverted-index-row-address-ece48a branch 2 times, most recently from 462ed39 to 6f8ea34 Compare November 30, 2026 15:18
westonpace added a commit that referenced this pull request Nov 30, 2026
…r uses

Review of #11489 found three places where the identity an FTS cutoff or mask
used was not the one its consumer ranks or filters by.

**External masks.** `Scanner::with_row_id_prefilter` takes its mask in the
dataset's logical row-id space, but the flat FTS branches now emit row
addresses and passed it through unchanged, so a stable-row-id search filtered
addresses against row ids and dropped allowed rows. The mask is translated at
each flat boundary now -- the same translation `build_prefilter_in_domain`
already does for the indexed sibling's copy -- including the overlay
stale-take path, which previously forced a `_rowid` into the take purely to
filter on.

`RowAddrMaskFilterExec` takes its identity column explicitly instead of
inferring it from which columns the batch carries: a batch can hold both, and
under stable row ids they are different numbers for the same row. The identity
is also carried across `with_new_children`, which otherwise reset it to the
default during optimization.

**The cross-partition cutoff.** A candidate is a `(partition, doc id)`
coordinate while it is scored, and that coordinate is not the row address the
plan sorts and pages on -- consolidating partitions, the parallel build
pipeline and any remap all leave a partition's addresses out of doc-id order.
Each partition's candidates are resolved to their addresses before any of them
is cut, and the cutoff keys on `(score DESC, address ASC)`. The resolution
keeps the byte-bounded concurrency the single global resolution used; each read
now covers one partition's `limit` candidates rather than the merged `limit`,
so no individual read grew. `resolve_resident_modern_candidates` and
`resolve_deferred_modern_candidates` fold into that one step.

**The mixed-plan merge.** The indexed-plus-flat union sorted on score alone, so
its fetch kept whichever member of a tie arrived first from concurrently read
children. It uses the same key both children cut on.

Co-Authored-By: Claude Opus 5 <[email protected]>
@westonpace
westonpace force-pushed the claude/fts-tie-ordering-11456 branch from d1a1d67 to cf91551 Compare November 30, 2026 15:45
@github-actions github-actions Bot added the A-python Python bindings label Nov 30, 2026
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 30, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Nov 30, 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 30, 2026
@westonpace
westonpace force-pushed the claude/inverted-index-row-address-ece48a branch 2 times, most recently from 4012a23 to 00ac034 Compare December 1, 2026 20:14
westonpace added a commit that referenced this pull request Dec 1, 2026
…r uses

Review of #11489 found three places where the identity an FTS cutoff or mask
used was not the one its consumer ranks or filters by.

**External masks.** `Scanner::with_row_id_prefilter` takes its mask in the
dataset's logical row-id space, but the flat FTS branches now emit row
addresses and passed it through unchanged, so a stable-row-id search filtered
addresses against row ids and dropped allowed rows. The mask is translated at
each flat boundary now -- the same translation `build_prefilter_in_domain`
already does for the indexed sibling's copy -- including the overlay
stale-take path, which previously forced a `_rowid` into the take purely to
filter on.

`RowAddrMaskFilterExec` takes its identity column explicitly instead of
inferring it from which columns the batch carries: a batch can hold both, and
under stable row ids they are different numbers for the same row. The identity
is also carried across `with_new_children`, which otherwise reset it to the
default during optimization.

**The cross-partition cutoff.** A candidate is a `(partition, doc id)`
coordinate while it is scored, and that coordinate is not the row address the
plan sorts and pages on -- consolidating partitions, the parallel build
pipeline and any remap all leave a partition's addresses out of doc-id order.
Each partition's candidates are resolved to their addresses before any of them
is cut, and the cutoff keys on `(score DESC, address ASC)`. The resolution
keeps the byte-bounded concurrency the single global resolution used; each read
now covers one partition's `limit` candidates rather than the merged `limit`,
so no individual read grew. `resolve_resident_modern_candidates` and
`resolve_deferred_modern_candidates` fold into that one step.

**The mixed-plan merge.** The indexed-plus-flat union sorted on score alone, so
its fetch kept whichever member of a tie arrived first from concurrently read
children. It uses the same key both children cut on.

Co-Authored-By: Claude Opus 5 <[email protected]>
@westonpace
westonpace force-pushed the claude/fts-tie-ordering-11456 branch from 3ee2f39 to a4e0a56 Compare December 1, 2026 23:37
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Dec 1, 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 Dec 1, 2026
@westonpace
westonpace force-pushed the claude/inverted-index-row-address-ece48a branch from 00ac034 to 4c18d98 Compare December 2, 2026 19:09
Base automatically changed from claude/inverted-index-row-address-ece48a to main December 2, 2026 19:58
@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Dec 2, 2026
westonpace and others added 3 commits December 2, 2026 12:24
Top-k selection ranks on the identifier the postings store -- a row
address since #11018 -- while the plan above sorted on `_rowid`. Paging a
tie then skipped and repeated rows, so the execs held the tie group whole
and re-ranked it, escalating to the full match set when the cutoff tie was
larger than the retained margin.

Make the identifier the plan carries the one selection ranks on: FTS nodes
emit `_rowaddr`, every sort and dedup keys on it, `TakeExec` reads by it,
and a `_rowid` the caller projected is derived once above the fetch. A
bounded search's result is then a prefix of the order the plan emits in,
so no tie group is held and no search is replayed.

Deleted: `FTS_TIE_RERANK_BUDGET`, `widen_limit_for_tie_rerank`,
`cutoff_tie_unresolved`, `exhaustive_limit`, `finalize_row_ids_and_scores`,
`translate_row_ids_and_scores`, `fts_row_addr_to_row_id` and the
exact-completion replays in five exec paths.

A row-id-domain segment cannot answer on a stable-row-id dataset any more
and is refused by name (`require_fts_address_domain`) rather than ranked
against addresses. The state is transient: it only arises between turning
stable row ids on and the index's next rebuild, which `optimize_indices`
already forces.

Ties are now ordered deterministically at every merge. `ScoredDoc` and
`ScoredPartitionDoc` compare the score alone, so a tie fell to heap and
arrival order -- and segments and partitions are searched concurrently, so
which of two equal-scoring documents a bounded search kept was not stable
run to run. Each merge now keys on the full order.

Two domain mismatches fall out of the move, both of which were producing
wrong BM25F statistics on an overlay under stable row ids: the scanner
built `FlatStatsCoverage::stale_rows` in the overlay's own result domain
while both consumers key by address, and the flat `combined_fields` stats
masks were built in the row-id domain. Both are addresses now, and
`open_combined_fields_scan`'s compensating translation is gone.

Co-Authored-By: Claude Opus 5 <[email protected]>
…r uses

Review of #11489 found three places where the identity an FTS cutoff or mask
used was not the one its consumer ranks or filters by.

**External masks.** `Scanner::with_row_id_prefilter` takes its mask in the
dataset's logical row-id space, but the flat FTS branches now emit row
addresses and passed it through unchanged, so a stable-row-id search filtered
addresses against row ids and dropped allowed rows. The mask is translated at
each flat boundary now -- the same translation `build_prefilter_in_domain`
already does for the indexed sibling's copy -- including the overlay
stale-take path, which previously forced a `_rowid` into the take purely to
filter on.

`RowAddrMaskFilterExec` takes its identity column explicitly instead of
inferring it from which columns the batch carries: a batch can hold both, and
under stable row ids they are different numbers for the same row. The identity
is also carried across `with_new_children`, which otherwise reset it to the
default during optimization.

**The cross-partition cutoff.** A candidate is a `(partition, doc id)`
coordinate while it is scored, and that coordinate is not the row address the
plan sorts and pages on -- consolidating partitions, the parallel build
pipeline and any remap all leave a partition's addresses out of doc-id order.
Each partition's candidates are resolved to their addresses before any of them
is cut, and the cutoff keys on `(score DESC, address ASC)`. The resolution
keeps the byte-bounded concurrency the single global resolution used; each read
now covers one partition's `limit` candidates rather than the merged `limit`,
so no individual read grew. `resolve_resident_modern_candidates` and
`resolve_deferred_modern_candidates` fold into that one step.

**The mixed-plan merge.** The indexed-plus-flat union sorted on score alone, so
its fetch kept whichever member of a tie arrived first from concurrently read
children. It uses the same key both children cut on.

Co-Authored-By: Claude Opus 5 <[email protected]>
Groundwork for reading an index whose segments predate the row-address
domain. The identity column was a constant in `FTS_SCHEMA`; it becomes
`FtsIdentityDomain`, one decision per plan, taken from the segments the query
reads and threaded through every node.

A plan's segments always agree on it -- a mixed index is refused when it is
read -- so there is exactly one domain per query, never a mixed plan.

The flat path takes its domain from the rows it was handed rather than from a
parameter: the scan that produced them already chose, and the indexed sibling
it is unioned with must agree. `fts_identity_domain_of` and
`fts_identity_column_of` read it off a schema or a batch.

Every call site passes `RowAddr` for now, which is what
`require_fts_address_domain` already guarantees: a row-id-domain segment is
still refused on a stable-row-id dataset. Teaching the planner to resolve the
domain and carry `RowId` through is the next step; this commit only gives that
value somewhere to live.

No behaviour change.

Co-Authored-By: Claude Opus 5 <[email protected]>
@westonpace
westonpace force-pushed the claude/fts-tie-ordering-11456 branch from a4e0a56 to 5ca8dad Compare December 2, 2026 20:38
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Dec 2, 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: request changes.

The two remaining blockers from Xuanwo’s review still apply on this head: stable-ID datasets reject released logical-ID FTS indices, and partition-local top-k selection discards tied candidates before resolving their current addresses. The latter still permits fixed-version pages to skip or repeat rows; rebuilding an index cannot repair historical snapshots.

Preserve the frozen logical-ID reader and select each query’s execution domain from its segments. For modern pagination, land the order-aware collector in #7846 first, then rebase so every candidate cutoff uses the final address order.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Dec 2, 2026
@codecov

codecov Bot commented Dec 2, 2026

Copy link
Copy Markdown

⚠️ JUnit XML file not found

The CLI was unable to find any JUnit XML files to upload.
For more help, visit our troubleshooting guide.

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-index Vector index, linalg, tokenizer A-python Python bindings breaking-change K-changes Latest Gatekeeper recommendation requests changes. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants