Repository navigation
perf(filtered-read): backport upstream #8587, prune non-candidate fragment metadata - #115
Merged
Merged
Conversation
…mat#8587) After a scalar index returns its row-ID mask, `FilteredReadExec::get_or_create_plan_impl` still loads deletion vectors, row counts, and row-ID metadata for every fragment before applying that mask. An exact index miss therefore performs an O(fragment count) metadata pass even though no fragment can contribute a row. This is a follow-up to lance-format#7792. That PR removed the second all-fragment metadata load during stream construction; the first planning-time pass remained. Related to lance-format#4189, which tracks broader filtered-read planning costs. Use the index result's upper bound to decide whether a fragment can contribute before loading its full metadata: - skip every covered fragment for an exact empty allow-list; - use the fragment portion of address-style row IDs for direct pruning; - for non-empty stable row-ID masks, use each fragment's row-ID sequence to route candidates, then load deletion vectors and row counts only for candidate fragments; - carry the routed stable row-ID sequence and upper offset ranges into final planning, so exact and refined/at-most results do not map the same IDs twice; - cap retained stable-ID range payload at 16 MiB per plan and drain retained vectors fragment-by-fragment; over-budget fragments reuse the loaded row-ID sequence but recompute ranges during final planning; - keep uncovered fragments unless `only_indexed_fragments` is enabled; - conservatively keep block-list upper bounds and every fragment needed to calculate a pre-filter scan range. Candidate fragments still load and apply their deletion vectors, so stale deleted index hits remain excluded. Pruning uses the upper bound of refined index results to avoid false negatives. Lower is better for every metric below. | Scenario / metric | Baseline (`e958adfdf`) | This PR (`150e000f0`) | Benefit | | --- | ---: | ---: | ---: | | Exact-empty plan latency | 1,630.20 ms/query | 5.14 ms/query | 316.9x speedup | | Indexed zero-hit query latency | 2,067.66 ms/query | 84.73 ms/query | 24.4x speedup | | Indexed one-hit query latency | 2,081.91 ms/query | 163.69 ms/query | 12.7x speedup | | Exact-empty plan S3 reads | 2,600 reads/query | 0 reads/query | 2,600 reads/query eliminated | | Indexed zero-hit S3 reads | 2,603 reads/query | 3 reads/query | 867.7x fewer reads | | Indexed one-hit S3 reads | 2,606 reads/query | 7 reads/query | 372.3x fewer reads | The review follow-up also measures cache-hot dense stable-row-ID planning, where all 5,200 physical row IDs route to all 2,600 fragments: | Scenario / metric | Before follow-up (`824551d44`) | This PR (`150e000f0`) | Benefit | | --- | ---: | ---: | ---: | | Dense stable-ID plan latency | 9.17 ms/plan | 7.86 ms/plan | 1.17x speedup | The main-branch control was 7.13 ms/plan. The current implementation is 0.72 ms/plan (1.10x) above that control because it performs the stable-ID routing pass needed for pruning, but it no longer repeats the same mapping during final planning. All cache-hot measured plans performed 0 S3 reads. Environment and methodology: - AWS `m7i.4xlarge` in `us-east-1a`, reading S3 in the same region. - One dataset with 2,600 stable-row-ID fragments, 2 rows per fragment, one real deletion vector per fragment, 14 payload columns, and BTree indices on `org_id` and `repo_id`. - Separate main, pre-follow-up, and current PR binaries built with Rust 1.97.1, `release-with-debug`, `--no-default-features --features aws`; their SHA256 hashes were checked before measurement. - Three serialized trials per case; base/PR order alternated by trial. Each trial used a new process and fresh Lance `Session`; the table reports medians. - Dataset-open time and I/O were excluded. Query/planning I/O uses incremental `IOTracker` statistics after open. - The dense case used three processes per revision. Each process ran one excluded S3 warm-up plan followed by 21 measured plans; the table reports the median of the three process medians. Index-result serialization and exec construction were outside the timed region. - This measures the metadata path against real S3, not the Plan Executor persistent-disk cache. Measured bytes followed the same pattern: exact-empty planning dropped from 1,814,800 B/query to 0 B/query; the zero-hit query dropped from 1,882,874 B/query to 68,074 B/query; the one-hit query dropped from 1,965,927 B/query to 151,825 B/query. The regression coverage includes stable and address-style row IDs, exact-empty and sparse non-empty masks, refined upper bounds, partially indexed datasets, and `only_indexed_fragments` behavior. A deterministic dense stable-ID test counts `mask_to_offset_ranges` spans: four candidate fragments must produce exactly four mappings; the pre-follow-up implementation produced eight. A separate boundary test verifies that retained range payload cannot exceed the per-plan budget. For a non-empty stable row-ID mask, this change still visits each covered fragment's row-ID sequence to discover candidate fragments. The benchmark fixture stores those sequences inline, so it removes the S3 deletion-vector/row-count reads but not the O(fragment count) routing walk. Datasets with external row-ID metadata can still perform O(fragment count) row-ID metadata reads. Eliminating that remaining cost requires carrying physical candidate-fragment information from scalar-index execution or persisted row-ID routing metadata. - `cargo fmt --all` - `cargo test -p lance io::exec::filtered_read::tests -- --test-threads=1` (75 passed) - `cargo clippy --all --tests --benches -- -D warnings` - `RUSTFLAGS='-D warnings' cargo +nightly-2026-07-13 check -p lance --tests` - AWS S3 benchmark described above (cherry picked from commit f177fae)
zehiko
marked this pull request as ready for review
November 17, 2026 08:17
ilya-zlobintsev
approved these changes
Nov 17, 2026
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.
Backport of lance-format#8587 (
perf(filtered-read): prune non-candidate fragment metadata) to release-10.0.0, which already has lance-format#7792.Why
A filtered read loaded metadata for, and planned, every fragment of the table, even when the scalar index answer sat in one or two of them.
On a Metastore chunks table with 446 fragments that was most of the per-query CPU growth from 44 fragments:
plan_scan128 → 1,040 µs and fragment loading 91 → 706 µs per request.What
The upstream change, unmodified.
Three conflicts, all additive:
prune_ranges_by_page_values(from #112) andintersect_index_ranges(from lance-format#8587) sit next to each other, plus test imports.Diffing the added and removed lines against upstream f177fae shows only those test imports.
Testing
cargo test -p lance --lib io::exec::filtered_read: 77 passed.plan_scan1,040 → 47 andmask_to_offset_ranges453 → 17 µs per request.One behaviour change: a corrupt deletion or data file in a fragment the index rules out no longer fails the query.
Agent
This PR was written by Claude Code (an LLM), at the request of the author.
🤖 Generated with Claude Code