fix(index): use exact scalar indices for filtered count_rows#6489
Open
myandpr wants to merge 2 commits intolance-format:mainfrom
Open
fix(index): use exact scalar indices for filtered count_rows#6489myandpr wants to merge 2 commits intolance-format:mainfrom
myandpr wants to merge 2 commits intolance-format:mainfrom
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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.
Fixes #2682.
Summary
Dataset::count_rows(Some(filter))Problem
Dataset::count_rows(Some(filter))always went through the scan-based count path, even when the filter could be satisfied exactly by a scalar index. That meant we still materialized row ids and counted them through the scanner.There was also a correctness gap once a logical scalar index had multiple physical segments. Coverage checks could treat the logical index as fully covering the dataset, while query execution still loaded only one segment. In that state, an exact result could be treated as complete even though it only came from part of the logical index.
Approach
This change adds a dedicated exact-count path for filtered
count_rowsand only uses it when the filter planner produces an exact scalar-index search with full fragment coverage and no refine step. Exact allow-list and block-list results are counted directly, with deletion masks handled explicitly.To keep coverage checks and execution aligned, scalar-index loading now aggregates all segments for the same logical index name into a
LogicalScalarIndexand unions their search results.Tests
cargo test -p lance test_fast_count_rows -- --nocapturecargo test -p lance test_logical_scalar_index_search_unions_all_segments -- --nocapturecargo test -p lance test_plans -- --nocapture