Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The per-segment restriction addresses the stale scalar answers in #10987, including rewritten NULL values and translated fragment coverage.
Xuanwo
approved these changes
Nov 20, 2026
Xuanwo
added a commit
that referenced
this pull request
Dec 1, 2026
…alarIndexExpr (#11176) Closes #11155 ## Summary ### Root Cause 1. **`ScalarIndexExpr::optimize`** left contiguous `Or` trees unbalanced and did not deduplicate repeated disjuncts or exact duplicate conjuncts. 2. **`ScalarIndexExpr::evaluate_with_options`** evaluated `And` / `Or` via unbounded recursive `try_join!`, re-loading and re-searching identical repeated leaves (e.g., `grp = 'hot_grp'` / `'cold_grp'` across 256 `OR` branches), keeping hundreds of full-dataset `RowAddrTreeMap` masks live concurrently, and evaluating wide predicates unconditionally alongside narrow/empty conjuncts. 3. **`ScopedScalarIndexLoader`** did not bound physical-address leaf hits to `fragment_scope` when a shared index segment matched out-of-scope fragments, and **`fragments_covered_by_index_query`** walked duplicate index references repeatedly. ### Changes - **Borrowed-RHS 3VL algebra (`lance-select`)**: - Added `BitAnd<&Self>` and `BitOr<&Self>` on `NullableRowAddrMask` (`BitAndAssign<&Self>` / `BitOrAssign<&Self>` on `NullableRowAddrSet`), mutating `self` in place without cloning `rhs` while preserving SQL Kleene three-valued logic. - Added `BitAnd<&Self>` and `BitOr<&Self>` on `NullableIndexExprResult`, retaining `#11012` `MaskDomain` invariants and `#11552` single-mask fast paths when `self.exact && rhs.exact`. - **Expression optimization (`lance-index`)**: - Updated `ScalarIndexExpr::optimize` with iterative contiguous `Or` flattening, first-seen-order disjunct deduplication, and balanced `rebuild_or_tree` (`O(log2 N)` depth). - Made `collect_and_leaves` and `needs_recheck` iterative and deduplicated exact duplicate conjuncts in `optimize_and_leaves`. - **Evaluation engine (`rust/lance-index/src/scalar/eval.rs`)**: - Pre-evaluation iterative duplicate-only leaf CSE pass allocating `CseSlot` (`OnceCell` for native and reconciled `RowAddress` results) only for leaves appearing `>= 2` times under `(column, index_name, index_type, needs_recheck, track_nulls, query)`; unique leaves (`count == 1`) bypass caching so bitmaps drop immediately after folding. - Expression-wide unique leaf search budget (`MAX_LEAF_SEARCH_CONCURRENCY = 32`) enforced via a per-evaluation semaphore acquired strictly when a unique leaf search starts (`eval_search`): parent `Not` / `And` / `Or` nodes awaiting children and duplicate CSE callers awaiting an in-flight `OnceCell` consume zero slots. - Selective-first `And` ordering (`ConjunctPriority`), `track_nulls`-aware short-circuiting, and 3-phase `And` evaluation: (1) zero-I/O drain of ready CSE leaves, (2) lone initial selective probe, and (3) bounded tail overlap (`MAX_AND_CONCURRENCY = 8`, `MAX_NESTED_AND_CONCURRENCY = 4` under `Or`), plus `MAX_OR_CONCURRENCY = 8` incremental `Or` folding. - Preserved native `MaskDomain::RowAddress` / `MaskDomain::RowId` on leaves (`#11012`), reconciling mixed domains lazily via `ScalarIndexLoader::row_id_result_to_row_addrs` with per-slot memoization and cooperative polling (`drive_with_in_flight`). - **Fragment-scoped index loading & coverage (`lance`)**: - Retained `#11045` per-segment coverage in `open_scalar_index_segments` / `LogicalScalarIndex` and wrapped subset-scoped physical-address indices in `FragmentScopedScalarIndex` so `selected` and `nulls` are restricted via `retain_fragments` while preserving native domains and `Exact` / `AtMost` / `AtLeast` bounds. - Deduplicated `(column, index_name)` pairs iteratively in `ScalarIndexExec::fragments_covered_by_index_query`. ## Benchmark (`lance#11155` repeated-leaf comparison vs rebased `main` `1b778e120`) Fixture: 2,000,000 rows across 40 fragments (50,000 rows/frag) with `item_id` BTree, `grp` Bitmap, and `ts` BTree; 256-branch composite `OR` `(grp = 'hot_grp'|'cold_grp' AND item_id = ... AND ts >= ... AND ts <= ...)`. Measured against rebased parent `1b778e120` (includes `#11042` bitmap read coalescing, `#11045`, `#11012`, and `#11552`), `--profile release-with-debug`, median of 5 fresh child processes (all modes returned exact `[("item_0_0", 0)]`): | Mode | Scope | Variant | Median (ms) | RSS delta (MB) | `parts_loaded` | `index_comparisons` | | --- | --- | --- | ---: | ---: | ---: | ---: | | `enable_stable_row_ids=false` | `fragments=[frag0]` | `main` (`1b778e120`) | 415.77 | +328.28 | 214 | 3,138,944 | | `enable_stable_row_ids=false` | `fragments=[frag0]` | **This PR** | **117.71** (-71.7%) | **+83.85** (-74.5%) | **213** | **1,098,881** | | `enable_stable_row_ids=false` | Full dataset (40 frags) | `main` (`1b778e120`) | 403.38 | +330.80 | 214 | 3,138,944 | | `enable_stable_row_ids=false` | Full dataset (40 frags) | **This PR** | **184.32** (-54.3%) | **+89.83** (-72.8%) | 214 | 3,138,690 | | `enable_stable_row_ids=true` | `fragments=[frag0]` | `main` (`1b778e120`) | 386.27 | +324.24 | 214 | 3,138,944 | | `enable_stable_row_ids=true` | `fragments=[frag0]` | **This PR** | **114.09** (-70.5%) | **+81.53** (-74.9%) | **213** | **1,098,881** | | `enable_stable_row_ids=true` | Full dataset (40 frags) | `main` (`1b778e120`) | 412.16 | +303.69 | 214 | 3,138,944 | | `enable_stable_row_ids=true` | Full dataset (40 frags) | **This PR** | **175.48** (-57.4%) | **+89.30** (-70.6%) | 214 | 3,138,690 | --------- Co-authored-by: Xuanwo <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #10987
LogicalScalarIndexnow restricts every segment of a multi-segment scalar index to the fragments it covers before it combines their answers. Address-domain segments are restricted by fragment, and so are row-id segments on a table without stable row ids, where a row id is the row's address; row-id segments under stable row ids keep the live-row restriction. Coverage comes fromresolve_query_segment_coverages, so a segment translated through a tagged fragment reuse history answers for the destinations the reader derives. Lookups read the row column thatlookup_schemanames (_rowaddror_rowid), and the fragment restriction walks each segment's hits rather than its coverage, becauseMapIndexExecsearches once per input batch.With more than one segment,
LogicalScalarIndex::try_newnow needs segment metadata from the dataset's own listing for every index, not only for row-id segments under stable row ids. FTS and MinHash search open their segments outsideLogicalScalarIndexand are unchanged here, so on tables without stable row ids they keep the same gap (#6283 for FTS).