Skip to content

fix(index): share one load among concurrent bitmap cache misses - #11042

Merged
Xuanwo merged 1 commit into
lance-format:mainfrom
xuanyu-z:bitmap-single-load
Nov 18, 2026
Merged

Xuanwo merged 1 commit into
lance-format:mainfrom
xuanyu-z:bitmap-single-load

Conversation

@xuanyu-z

@xuanyu-z xuanyu-z commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Concurrent searches for a value whose bitmap is not yet cached each read the bitmap from the index file, and each kept its own copy alongside the cached one. The bitmap index now loads through the cache's get_or_insert_with_key_hit, so concurrent misses on one value share a single read, and every caller gets the cached bitmap. Cache hit and miss metrics keep their existing meaning for successful lookups; a failed load still records a part load but returns before hit or miss is recorded.

Tests

  • test_bitmap_concurrent_misses_load_once: eight concurrent searches for one uncached value record one part load, one miss and seven hits. Without the change it records eight loads.

Concurrent searches for a value whose bitmap is not cached each read it and kept their own copy. They now share one load through the cache's get_or_insert, and the caller gets the cached bitmap.

@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 pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer bug Something isn't working labels Nov 13, 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: approve.

No blocking issues found.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 13, 2026
@Xuanwo
Xuanwo merged commit c236c7c into lance-format:main Nov 18, 2026
46 of 47 checks passed
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]>
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 bug Something isn't working K-approved Latest Gatekeeper recommendation permits acceptance.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants