Repository navigation
perf(index): deduplicate identical leaves and bound concurrency in ScalarIndexExpr - #11176
Conversation
12b3b99 to
6a0e612
Compare
Xuanwo
left a comment
There was a problem hiding this comment.
AI-assisted review of 6a0e6128
The comment on MAX_NESTED_AND_CONCURRENCY in eval.rs promises at most 32 simultaneous leaf searches. Each nested node has its own limit. The CI wheel produced a nested plan for an ordinary predicate, and a separate test of the extracted scheduler with controlled mock leaves recorded 40 pending searches.
Please enforce the budget across one expression where a unique leaf search starts. Parent nodes awaiting children and duplicate callers awaiting a cached result should consume no slots. Preserve the selective first probe and allow independent searches to overlap. A deterministic nested regression should count pending unique searches and check the documented maximum.
The trial merge with main conflicts in expression.rs, result.rs, and scalar_index.rs. When rebasing, please retain per-segment coverage, native row-address and row-ID domains, and exact-mask handling from #11045, #11012, and #11552. Please rerun the correctness cases and a focused repeated-leaf comparison against the rebased parent so the measurement includes the read coalescing from #11042.
6a0e612 to
2904832
Compare
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The budget now spans the whole expression and addresses the nested-concurrency concern, while retaining selective probing and overlapping tail searches. The rebase preserves NULL/NOT behavior, native mask domains, per-segment coverage, and conservative result bounds. Leaf reuse still reduces search and mask work with the read coalescing from #11042 already present.
Verified the shared leaf-search budget on 2904832. The hosted nested-expression regression fills all 32 slots without exceeding the limit and covers duplicate waiters and cancellation.
|
Thanks @Xuanwo for the review! Addressed in
|
Use the bounded scalar evaluator for typed prefilters while keeping a single mask for exact results. Preserve filter depth checks, segment coverage, and deletion-aware stable row ID translation.
❌ 2 Tests Failed:
View the top 2 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Keep hits from selected segments when negation can turn them into block-list exclusions. Apply fragment scope to allow lists before resolving stable row IDs.
Closes #11155
Summary
Root Cause
ScalarIndexExpr::optimizeleft contiguousOrtrees unbalanced and did not deduplicate repeated disjuncts or exact duplicate conjuncts.ScalarIndexExpr::evaluate_with_optionsevaluatedAnd/Orvia unbounded recursivetry_join!, re-loading and re-searching identical repeated leaves (e.g.,grp = 'hot_grp'/'cold_grp'across 256ORbranches), keeping hundreds of full-datasetRowAddrTreeMapmasks live concurrently, and evaluating wide predicates unconditionally alongside narrow/empty conjuncts.ScopedScalarIndexLoaderdid not bound physical-address leaf hits tofragment_scopewhen a shared index segment matched out-of-scope fragments, andfragments_covered_by_index_querywalked duplicate index references repeatedly.Changes
lance-select):BitAnd<&Self>andBitOr<&Self>onNullableRowAddrMask(BitAndAssign<&Self>/BitOrAssign<&Self>onNullableRowAddrSet), mutatingselfin place without cloningrhswhile preserving SQL Kleene three-valued logic.BitAnd<&Self>andBitOr<&Self>onNullableIndexExprResult, retaining#11012MaskDomaininvariants and#11552single-mask fast paths whenself.exact && rhs.exact.lance-index):ScalarIndexExpr::optimizewith iterative contiguousOrflattening, first-seen-order disjunct deduplication, and balancedrebuild_or_tree(O(log2 N)depth).collect_and_leavesandneeds_recheckiterative and deduplicated exact duplicate conjuncts inoptimize_and_leaves.rust/lance-index/src/scalar/eval.rs):CseSlot(OnceCellfor native and reconciledRowAddressresults) only for leaves appearing>= 2times under(column, index_name, index_type, needs_recheck, track_nulls, query); unique leaves (count == 1) bypass caching so bitmaps drop immediately after folding.MAX_LEAF_SEARCH_CONCURRENCY = 32) enforced via a per-evaluation semaphore acquired strictly when a unique leaf search starts (eval_search): parentNot/And/Ornodes awaiting children and duplicate CSE callers awaiting an in-flightOnceCellconsume zero slots.Andordering (ConjunctPriority),track_nulls-aware short-circuiting, and 3-phaseAndevaluation: (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 = 4underOr), plusMAX_OR_CONCURRENCY = 8incrementalOrfolding.MaskDomain::RowAddress/MaskDomain::RowIdon leaves (#11012), reconciling mixed domains lazily viaScalarIndexLoader::row_id_result_to_row_addrswith per-slot memoization and cooperative polling (drive_with_in_flight).lance):#11045per-segment coverage inopen_scalar_index_segments/LogicalScalarIndexand wrapped subset-scoped physical-address indices inFragmentScopedScalarIndexsoselectedandnullsare restricted viaretain_fragmentswhile preserving native domains andExact/AtMost/AtLeastbounds.(column, index_name)pairs iteratively inScalarIndexExec::fragments_covered_by_index_query.Benchmark (
lance#11155repeated-leaf comparison vs rebasedmain1b778e120)Fixture: 2,000,000 rows across 40 fragments (50,000 rows/frag) with
item_idBTree,grpBitmap, andtsBTree; 256-branch compositeOR(grp = 'hot_grp'|'cold_grp' AND item_id = ... AND ts >= ... AND ts <= ...). Measured against rebased parent1b778e120(includes#11042bitmap read coalescing,#11045,#11012, and#11552),--profile release-with-debug, median of 5 fresh child processes (all modes returned exact[("item_0_0", 0)]):parts_loadedindex_comparisonsenable_stable_row_ids=falsefragments=[frag0]main(1b778e120)enable_stable_row_ids=falsefragments=[frag0]enable_stable_row_ids=falsemain(1b778e120)enable_stable_row_ids=falseenable_stable_row_ids=truefragments=[frag0]main(1b778e120)enable_stable_row_ids=truefragments=[frag0]enable_stable_row_ids=truemain(1b778e120)enable_stable_row_ids=true