Skip to content

perf(scan): prune pages based on dictionary values before materialization - #10991

Open
ilya-zlobintsev wants to merge 4 commits into
lance-format:mainfrom
rerun-io:dictionary-pruning-main
Open

ilya-zlobintsev wants to merge 4 commits into
lance-format:mainfrom
rerun-io:dictionary-pruning-main

Conversation

@ilya-zlobintsev

Copy link
Copy Markdown
Contributor

Closes #10310.

For dictionary-encoded pages, filters are now checked against the dictionary itself, and pages that are known to not match the filter are pruned and not materialized. Previously they would be materialized into an array with mostly-duplicate values, only to then compare each row again. This provides significant performance improvements for unindexed filtered reads on such pages, and I expect that a lot of data in different workloads is low cardinality and falls into dictionary encoding.

The same pruning is also applied for constant and all-null pages. All other page types, pages with overlays, pre-2.1 fragments, nested or dictionary-typed columns, etc are excluded.

Using the example python script from the linked issue, these are the numbers:

Lance 14.0.2

wrote 10000000 rows
read 50000 rows in 23.7 ms

With this PR:

wrote 10000000 rows
read 50000 rows in 5.5 ms

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

lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 12, 2026
ilya-zlobintsev and others added 3 commits November 12, 2026 12:41
Add `CoreFieldDecoderStrategy::rows_that_may_match`, which checks a column's
dictionary, constant and all-null pages against a `ValuePredicate` without
decoding their rows. Page metadata is loaded through the shared cache, so a
later read of the same pages reuses it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Plumb `rows_that_may_match` through `ProjectedFileReader`,
`GenericFileReader` and `FragmentReader`. Fields replaced by overlays are not
checked, because page values don't include the overlaid values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ng them

Split the fragment filter into per-column conjuncts and check them against
page values before reading, dropping the row ranges of pages that can't
contain a match (e.g. pages whose dictionary has none of the ids in
`id IN (...)`).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

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

This PR makes me a little nervous though I can see the appeal. I've tried very hard to avoid compute calculations into the file itself, preferring those to be handled by indexes.

Primarily I am concerned it becomes a slippery slope and the file format ends up with far too many heavy dependencies and complexity.

However, this PR strikes a pretty compelling middle ground. The lance-encoding crate remains blissfully unaware of things like "expressions". Instead it seems we are mainly saying "look, I can sometimes give you a preview of the data, in Arrow format, before I've decoded, and you the caller can tell me if you want to proceed or not".

I think this is an acceptable compromise. My main request is that we write some of this (what this PR does and what I've just said) up in the spec files or top-level comment files. Can you add something to this section (https://lance.org/format/file/#functional-decomposition) basically stating that we expect query engines to be responsible for anything beyond encoding and decoding (e.g. filtering and projection) but we may provide hooks for those engines to interact in the encoding and decoding process early to save work?

@github-actions github-actions Bot added A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). labels Nov 13, 2026
@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ❌ Blocked — vetoed by @westonpace

Approvals none (0/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes @westonpace
Voting period elapsed — ended Wed 2026-11-18 13:57 UTC (05:57 PST)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label 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.

The added documentation makes query-engine ownership of filtering and optional decoder hints explicit. Pruning remains conservative for nulls and unsupported pages, and surviving rows still receive the original filter. No blocking issues found.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 13, 2026
@ilya-zlobintsev

Copy link
Copy Markdown
Contributor Author

Can you add something to this section (https://lance.org/format/file/#functional-decomposition) basically stating that we expect query engines to be responsible for anything beyond encoding and decoding (e.g. filtering and projection) but we may provide hooks for those engines to interact in the encoding and decoding process early to save work?

Done, feel free to rephrase or expand the wording if you think there's a better way to describe it.

@lance-gatekeeper lance-gatekeeper Bot added K-approved Latest Gatekeeper recommendation permits acceptance. and removed K-approved Latest Gatekeeper recommendation permits acceptance. labels Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-encoding Encoding, IO, file reader/writer A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf: prune filtered reads of dictionary-encoded pages based on the dictionary

2 participants