Repository navigation
perf(fts)!: keep the whole FTS execution path in the row-address domain - #11489
westonpace wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
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.
Xuanwo
left a comment
There was a problem hiding this comment.
I found two merge blockers in d1a1d67c relative to its parent ef58136a7.
-
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=1retains[1]becausepush_scored_partition_doconly replaces a full heap entry for a strictly higher score. With the same arrival order,k=2returns[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. -
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_domainrejects 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.
462ed39 to
6f8ea34
Compare
…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]>
d1a1d67 to
cf91551
Compare
4012a23 to
00ac034
Compare
…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]>
3ee2f39 to
a4e0a56
Compare
00ac034 to
4c18d98
Compare
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]>
a4e0a56 to
5ca8dad
Compare
There was a problem hiding this comment.
❌ 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.
|
Summary
#11018 has merged, so this now targets
mainand 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 retainedFTS_TIE_RERANK_BUDGETextra 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._rowaddr(plan_uncovered_rows_scantakes an explicitUncoveredRowIdentity), so the two sides of a mixed plan rank on the same identifier.TakeExecreads by address, which it already preferred (get_row_addrsshort-circuits the row-id-index lookup)._rowidthe caller projected is derived once, above the plan's own ordering and fetch, by a newAddRowIdExec— the inverse ofAddRowAddrExec. 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-datasetRowAddrToRowIdbuild, the exact-completion replays in five exec paths, and the re-ranks in bothfinalize_row_ids_and_scoresandscored_documents_batch. Also the now-unreachablebuild_prefilter_restricted_to_fragments/DatasetPreFilter::new_restricted_to_fragments.Legacy segments are refused, not ranked
A segment persisted before
INVERTED_ROW_ADDR_DOMAIN_VERSIONstores 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, replacingfts_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, whichoptimize_indices'legacy_domain_mismatchalready 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.
ScoredDocandScoredPartitionDoccompare 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 localRankedDocwrapper.push_scored_key(cross-partition, where the key is the address).ScoredPartitionDoc'sOrd(cross-partition, before addresses are resolved) tiebreaks on(partition ordinal, doc id), which ascends with the address for an index built the only wayInvertedIndexBuilderbuilds one — its partitions are filled in scan order.combined_maxscorealready 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:
FlatStatsCoverage::stale_rowsfrom the overlay's own result domain (stable ids), while both consumers key by address —bm25_row_stats_for_termslooks each row up indocsto subtract its pre-overlay statistics, and the flat side allows the same set through a stats mask.open_combined_fields_scancarried a compensating translation for the index side only, so the flat side allowed nothing. Now addresses, and the compensating translation is gone.combined_fieldsstats 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/docFreqand so moves the scores themselves.test_fts_combined_fields_tied_scores_are_deterministic's premise is unaffected: its fixture leavesenable_stable_row_idsat the default, where a row id is a row address.Tests
assert_tied_pages_visit_each_row_oncewalks 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_tiesnow 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.test_fts_row_id_domain_segment_is_rejected_under_stable_row_idscovers the single-column rejection;test_fts_mixed_domain_across_columns_is_rejectedkeeps the cross-column half.dataset_scanner_plans,dataset_fts_plan_state,dataset_fts_combined_fields/reconstruction,dataset_index/composition, theio::exec::ftstests and thelance-indexflat-search fixtures.Test plan
cargo test -p lance --lib— 11562 passed, 0 failedcargo test -p lance-index --lib— 4185 passed, 0 failedcargo clippy -p lance -p lance-index --lib --testscleancargo fmt --all --checkclean_rowaddr/_rowidrename is to the in-memory execution schema, notdocs.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, wherebuild_prefilter_in_domainconverts the row-id-domain masks thatprefilter_mask_futureproduces; moving that upstream is the open review thread the issue cites, and it touches vector search too.🤖 Generated with Claude Code