Registry Mirror
Skip to content

Conversation

@charleshuang119

@charleshuang119 charleshuang119 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

ZONEMAP and BLOOMFILTER scalar indices return silently incomplete results (often empty) for filters on datasets created with enable_stable_row_ids=True. Any value whose matching rows live in fragments other than fragment 0 is partially or completely dropped. The same query is correct with a BTREE/BITMAP index or with use_scalar_index=False. This is a correctness bug (false negatives).

Fixes #7434.

Root cause

Address-domain indices (zone map, bloom filter) are trained over _rowaddr and their search returns physical row addresses (fragment_id << 32 | offset). On a stable-row-id dataset a row's stable id differs from its physical address in every fragment except fragment 0. The filtered-scan path resolves index matches through the fragment's stable-row-id sequence, so an address-domain result fails to intersect and matching rows outside fragment 0 are silently dropped. BTREE/BITMAP are trained with _rowid, so they are unaffected.

Fix

Normalize address-domain results to the row-id domain at the dataset/query layer, before they are combined or handed to the scan.

  • Add ScalarIndex::results_are_row_addresses() (default false), overridden to true for ZoneMapIndex and BloomFilterIndex.
  • Add ScalarIndexLoader::row_addr_result_to_row_ids() (default identity). Dataset implements it: for stable-row-id datasets it maps each physical address to its stable row id via the per-fragment RowIdSequence (zipping live physical offsets with the sequence, skipping deleted rows); otherwise it returns the result unchanged.
  • In ScalarIndexExpr::evaluate_nullable, translate a leaf's result when the index is address-domain, so all downstream AND/OR/NOT combination and scan consumption stay in the row-id domain. This also handles queries that mix address-domain and row-id-domain indices.

This keeps zone map / bloom filter acceleration working under stable row ids (no fallback to a full scan) and fixes the same latent bug in the bloom filter index.

Tests

  • test_address_domain_index_with_stable_row_ids[ZONEMAP|BLOOMFILTER] — reproduces the issue's 5-fragment non-adjacent layout and asserts the index result equals a full scan.
  • test_zonemap_with_stable_row_ids_after_compaction — covers deletions + compaction (physical address != stable id for surviving rows).
  • Existing test_scalar_index.py (155) and the Rust zonemap/bloom unit tests pass; cargo fmt, clippy -D warnings, and ruff format are clean.

@github-actions github-actions Bot added bug Something isn't working A-python Python bindings A-index Vector index, linalg, tokenizer and removed bug Something isn't working labels Jul 1, 2026

@westonpace westonpace 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.

Marking request changes until we get the extra test case in place. Assuming that test passes I think this can be approved (just request re-review or ping me).

Claude had two other bits of review that seem like nice-to-haves if you want:

rust/lance/src/io/exec/scalar_index.rs:97 — Full-fragment branch duplicates bulk conversion that already exists (CONFIRMED, cleanup)
for id in sequence.iter() { row_ids.insert(id); } should be row_ids |= RowAddrTreeMap::from(sequence.as_ref()) — the same pattern used in retain_fragments a few hundred lines below. The manual loop is a future maintenance hazard if new RowIdSequence segment types are added.

rust/lance/src/io/exec/scalar_index.rs:115 — Two independent async calls per fragment are awaited serially in the Partial branch (CONFIRMED, efficiency)
get_deletion_vector().await? and physical_rows().await? are independent but sequential. futures::try_join! makes them concurrent, halving per-fragment round-trips on object-store-backed datasets.

translate_addr_set_to_row_ids(dataset, set).await?,
)),
NullableRowAddrMask::BlockList(_) => Err(Error::internal(
"cannot translate a block-list address mask to the row-id domain",

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.

Claude seemed to think we could hit this arm in a NOT query but I'm not sure that is the case. If I understand the code correctly we would evaluate the index first, then translate, then apply the NOT. Can you add this test case to verify (main...claude/lance-pr-7565-review-1r8xwx)?

I do think we could still hit this arm if the index search itself returned a block list. However, that isn't the case today so we are ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I added the NOT-query regression test from your compare branch:

  • test_address_domain_index_not_query_with_stable_row_ids
    • covers both ZONEMAP and BLOOMFILTER
    • verifies x != 42 on a stable-row-id dataset matches the non-indexed scan

I also applied the two cleanup suggestions in scalar_index.rs:

  • reuse RowAddrTreeMap::from(sequence.as_ref()) in the full-fragment branch
  • use futures::try_join! for deletion vector / physical row count in the partial branch

@codecov

codecov Bot commented Jul 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.95041% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
rust/lance/src/io/exec/scalar_index.rs 85.43% 9 Missing and 6 partials ⚠️
rust/lance-index/src/scalar/expression.rs 66.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

…under stable row ids

Zone map and bloom filter scalar indices report matches as physical row
addresses (fragment_id << 32 | offset). On a dataset that uses stable row
ids the address and row-id domains diverge, so the filtered scan resolved
these results through the fragment's stable-row-id sequence and silently
dropped every match outside fragment 0 (often returning nothing).

Mark address-domain indices via a new ScalarIndex::results_are_row_addresses
and, in evaluate, translate their results to the row-id domain at the
dataset layer (using per-fragment row-id sequences, skipping deleted rows)
before they are combined with other results or handed to the scan. Non
stable-row-id datasets keep the existing behavior.

Closes lance-format#7434
@charleshuang119
charleshuang119 force-pushed the fix/zonemap-bloom-stable-row-id-7434 branch from 0524116 to 4fe7e69 Compare July 3, 2026 07:36
@westonpace
westonpace merged commit 41e6e74 into lance-format:main Jul 8, 2026
30 checks passed
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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZoneMap scalar index returns incomplete results on datasets with stable row IDs

2 participants