Repository navigation
Prune parquet row groups using fully dictionary-encoded columns - #23851
DarkWanderer wants to merge 7 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #23851 +/- ##
========================================
Coverage 82.49% 82.50%
========================================
Files 1140 1141 +1
Lines 438529 439018 +489
Branches 438529 439018 +489
========================================
+ Hits 361783 362200 +417
- Misses 54874 54933 +59
- Partials 21872 21885 +13 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks @DarkWanderer -- do you have any benchmarks / examples showing this in action / showing how it is faster? The idea in theory sounds reasonable but it would be good to verify it in practice |
|
Thanks for feedback @alamb Here is a benchmark on synthetic dataset mimicking the shape of observability traces data. The specific property that highlights the performance gain is - TraceIDs are pseudo-random (so stats-based pruning doesn't help), but are clustered in time. I imagine it would be applicable to any "needle in haystack" scan where the search key is clustered along sorting key. Wall-clock timeCriterion,
Dictionary pruning is ~comparable to bloom filter in wall clock, but importantly, doesn't require extra writes; also, it can be used together with bloom filtering, compounding the win. More importantly, it allows better performance for "in" and "not in" scenarios which degrade bloom performance or cannot be handled at all respectively. Bytes readThis measures the efficiency gain from more precise page pruning. This win is not fully highlighted by using local SSD - but in S3-backed object-store context, I expect that reduction to have a much more pronounced effect.
Grain of salt: this dataset mimics a very specific domain I was optimizing for, I am not sure how well the wins translate to general use cases. |
|
Thank you for this @DarkWanderer I am sorry I haven't had a chance to review this -- it sounds great. But I am totally swamped at the moment (and for the forseeable future 😢 ) |
# Which issue does this PR close? - Closes #9010. - Supersedes #9011 (closed as stale) # Rationale for this change This change provides low-level API necessary for enabling dictionary-based pruning in DataFusion: apache/datafusion#23851 # What changes are included in this PR? - `parquet::file::metadata::dictionary::decode_dictionary_page`: decodes a BYTE_ARRAY dictionary page (Thrift header parse, decompress, PLAIN decode) into a `Utf8`/`Binary` Arrow array. - `ParquetMetaDataReader::read_column_dictionary` (sync) and `read_column_dictionary_async` (async) to fetch and decode a given row group/column's dictionary page from a `ParquetMetaData`, returning `Ok(None)` if the chunk has no dictionary page. - `ParquetRecordBatchStreamBuilder::get_row_group_column_dictionary` convenience method mirroring `get_row_group_column_bloom_filter`. # Are these changes tested? Yes: a round-trip unit test for a dictionary-encoded string column, a non-BYTE_ARRAY rejection test, and sync + async reader tests that decode a real dictionary page written through `ArrowWriter`. # Are there any user-facing changes? Yes, three new public APIs (see above). No changes to existing API. --------- Co-authored-by: Claude Sonnet 5 <[email protected]> Co-authored-by: Ed Seidl <[email protected]>
840df44 to
f3ae87f
Compare
|
run benchmarks |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark tpcdsResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark tpchResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark clickbench_partitionedResults will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark tpchCPU Details (lscpu)Details
Resource Usagetpch — base (merge-base)
tpch — branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark tpcdsCPU Details (lscpu)Details
Resource Usagetpcds — base (merge-base)
tpcds — branch
File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing dictionary-filter (07acfb1) to 6a9a129 (merge-base) diff Run configurationrun benchmark clickbench_partitionedCPU Details (lscpu)Details
Resource Usageclickbench_partitioned — base (merge-base)
clickbench_partitioned — branch
File an issue against this benchmark runner |
|
There seems to be no impact on the standard benchmarks. It might be worth thinking about how we're going to measure the perf improvement. |
|
Thank you @DarkWanderer -- this is neat this is a pretty massive PR. I think we'll need help to evaluate it (like maybe a clear, CONCISE, write up / description / design of what the proposal is, what types of queries it will help with, etc) I especially worry (without looking at the code) that this will just be more code to maintain and like Adrian observes not provide widely applicable real-world improvemetns |
|
Sure. The optimization specifically does the following:
This is geared toward needle-in-haystack queries in data hosted on S3, with the following idea:
The benchmark run did not show improvement because the option is opt-in - because in some cases it produces small regression due to dictionary check overhead. I leave it up to you to judge usefulness of this option @alamb @adriangb P.S. One more piece of context - this work comes out of my previous attempts to utilize DataFusion as a query engine for Tempo. While generally DataFusion was orders of magnitude faster, a few scenarios on observability data - owing specifically to dictionary-based pruning - still had Tempo in the lead. I'm sure there is a better way of implementing this technique than my simplistic attempt |
|
Marked as draft after 14 days without activity: merge conflicts. Please address these items and mark Ready for review when ready. |
|
@DarkWanderer @alamb I wonder if this couldn’t fit better inside of arrow-rs? Or as some sort of option to tell arrow-rs how to do the reads? Or would it make sense to do this only as part of the row filter machinery (maybe it is already, I haven’t checked the code)? This certainly seems like the right idea in principle, but we need to make sure it works in practice.
could you elaborate a bit? maybe we can help resolve this.
fwiw we also have a benchmark mode to simulate s3 like latencies. we can run those if you think it might be an improvement. surely some of the standard benchmarks have needle in haystack type queries? |
Add the `datafusion.execution.parquet.dictionary_filter_on_read` option (off by default). When enabled, the dictionary page of a fully dictionary-encoded BYTE_ARRAY column chunk is read as the exact set of the row group's distinct values, so IN/=/NOT IN/!= predicates prune it exactly. Add the `row_groups_pruned_dictionary` metric and the proto field for the option, plus criterion benchmarks and sqllogictest coverage. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19JVxvTCWQKRoQnYpSR
…sion dictionary_filter_on_read DictionaryStatistics::insert now checks the chunk is fully dictionary-encoded itself, and the opener only reads pages passing eligible_dictionary_page (offset range, size bound), so soundness no longer relies on callers. The opener prunes each row group as its dictionary read completes (4 reads in flight per file) so decoded values are released early; reader, read and decode failures are optional and counted in predicate_evaluation_errors. Row groups with nothing to read or already fully matched by statistics are skipped, and still counted as matched in row_groups_pruned_dictionary. Scans planned via ParquetFormat use the current session dictionary_filter_on_read instead of the value captured at table creation; config docs, configs.md, information_schema.slt and slt comments say so. The end-to-end bench gains a throttled object-store variant (BENCH_GET_LATENCY_MS) and a query with no dictionary candidate. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19JVxvTCWQKRoQnYpSR
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19JVxvTCWQKRoQnYpSR
Upstream's enable_exact_reverse_scan took tag 42 in ParquetOptions. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19LZ2VUzwtQDbkQDb4XT
…ueries Remove the two criterion benchmarks that generated their own data. Add a clickbench_needle bench.sh target: point lookups on hits_partitioned of string values stored in few row groups, which min/max statistics cannot prune, plus a control value present in most row groups. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19LZ2VUzwtQDbkQDb4XT
A `!=` or `NOT IN` predicate prunes a row group only when every value in it is excluded. When the column chunk's min/max statistics already show a value outside the excluded set, its dictionary cannot prune the row group, so the read is skipped. This removes the extra object store GETs for filters such as ClickBench's `<> ''`. Inexact bounds are treated as truncated: a minimum as a prefix of the true minimum, a maximum as shorter than the true maximum. Readers report bounds from writers that predate the exactness flags as inexact. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19LDPpsfabaCZBZHoDu
Turns on dictionary-based row group pruning by default so that benchmark runs against this branch compare it with main without extra settings. Tests that relied on the old default now set the option explicitly, and the expected EXPLAIN ANALYZE output of a join probe scan reflects the dictionary stage running. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_012oZ19LDPpsfabaCZBZHoDu
07acfb1 to
a88687f
Compare
|
@adriangb this change is specifically in row group filter machinery, so I don't see a way to put it into While testing, I found that my change in Below is Claude-generated benchmark report with the locally applied patch. OverviewEach query runs with `datafusion.execution.parquet.dictionary_filter_on_read` off, then on, in fresh `dfbench` processes on the same VM. Times are medians of the timed iterations; the first iteration of each process is dropped. Change is on / off − 1, so negative is faster. Every query returns the same number of rows in both modes.
Totals
Per queryTPC-H: local +0.2% overall, no query moves by 10% or more; simulated S3 +6.8%: Q19 +60%, Q11 +36%, five more +11% to +18%Local (4 timed samples per query and mode)
Simulated S3 (9 timed samples per query and mode)
TPC-DS: local +0.6% overall, short queries vary up to ±25% either way; simulated S3 +2.8%: Q41 +148%, Q26 +74%, Q37 +70%, 27 more +10% to +51%, 17 queries −10% to −27%Local (4 timed samples per query and mode)
Simulated S3 (9 timed samples per query and mode)
IMDB (Join Order Benchmark): local +1.3% overall, six queries +10% to +14%; simulated S3 +4.9%: Q5 +44%, Q15 +36%, 38 more +10% to +30%, six queries −11% to −21%Local (4 timed samples per query and mode)
Simulated S3 (3 timed samples per query and mode)
ClickBench: local −0.9% overall, no query moves by 10% or more; simulated S3 −0.8%: three queries +12% to +18%, three −11% to −19%Local (4 timed samples per query and mode)
Simulated S3 (3 timed samples per query and mode)
ClickBench with filter pushdown: local −0.7% overall, no query moves by 10% or more; simulated S3 −0.9%: Q41 +44%, four queries −12% to −34%Local (4 timed samples per query and mode)
Simulated S3 (3 timed samples per query and mode)
ClickBench needle queries: local −56.5% overall: Q0 37x and Q1 28x faster, Q2 −38%; simulated S3 −51.1%: Q0 7.1x and Q1 6.5x faster, Q2 −40%Q0 to Q2 look up values that few row groups hold. Q3 looks up a phrase that every row group holds, which dictionaries cannot prune. Local (12 timed samples per query and mode)
Simulated S3 (9 timed samples per query and mode)
ClickBench needle queries with filter pushdown: local −4.7% overall: Q0 3.6x and Q1 4.7x faster; simulated S3 −8.8%: Q0 −41%, Q1 −36%, Q2 −17%Same queries as above, with Local (12 timed samples per query and mode)
Simulated S3 (9 timed samples per query and mode)
|
|
I think in general, the idea of "processing on parquet encoded data" is a good idea, but most of the encodings in Parquet is pretty hard to operate on I think @HippoBaro's work to support reading into parquet into more efficient arrow formats (e.g RunEndArrays) is a good avenue to pursue (though we need to review 20k PR somehow 🤔 ) |
|
Thanks @alamb! Small clarification: my current work is on the writer side: preserving Arrow’s encoding characteristics ()including REE) through to Parquet without expanding intermediate representations. There are similar opportunities on the reader side that I’d like to explore next. I agree with the broad direction: Arrow is designed for in-memory processing and Parquet for storage. These objectives often compete with each other. I’d rather focus on making that transition efficient and encoding-preserving than build general execution over Parquet encodings directly, though retaining opportunities for early pruning is important. |
Which issue does this PR close?
N/A
Rationale for this change
Dictionary pages are essentially free, exact indexes for
IN/NOT INqueries. Bloom filters can prove a target value is absent from a row group (useful for pruning=/IN), but they are probabilistic (non-zero false-positive rate) and cannot prove aNOT IN/!=exclusion, since that would require confirming every distinct value in the row group is excluded -- information a bloom filter doesn't retain. A fully dictionary-encoded column chunk does retain the complete set of distinct values, so it can prune exactly in both directions:IN/=when the dictionary is disjoint from the target set, andNOT IN/!=when the dictionary is a subset of the excluded set. This approach stacks with bloom filters: dictionary pruning subsumes bloom-filter pruning where it applies, and is exact (no false positives) where bloom filters are only probabilistic.What changes are included in this PR?
datafusion.execution.parquet.dictionary_filter_on_readconfig option (default
false).DictionaryStatistics(dictionary_filter.rs): an exactPruningStatisticsimpl backed by decoded dictionary values.Insertion is gated on
is_fully_dictionary_encoded, which requires achunk's page encoding stats to be exactly
PLAIN_DICTIONARY/RLE_DICTIONARY(a writer that fell back toPLAINpartway through no longer has a complete dictionary), and oneligible_dictionary_page, which rejects chunks whose dictionary pagebyte range is inconsistent or larger than 128 MiB.
RowGroupAccessPlanFilter::prune_by_dictionaryand aLoadDictionariesstage in the Parquet opener's state machine, afterthe bloom-filter stage. Dictionary pages are fetched with bounded
concurrency and each row group is pruned as soon as its dictionaries
arrive. Row groups already proven fully matched by statistics are
skipped.
row_groups_pruned_dictionarymetric,.sltcoverage(
parquet_dictionary_pruning.slt, plus the metric added to existingEXPLAIN ANALYZEgolden files), and two criterion benchmarks: apruning-cost microbenchmark in
datasource-parquetand an end-to-endquery benchmark in
corewith an optional per-request latency tomodel object storage.
Session vs. table option precedence
Other Parquet read options (
bloom_filter_on_read,enable_page_index,...) are captured at
CREATE EXTERNAL TABLEtime, so a laterSET datafusion.execution.parquet.<option>has no effect on existingtables. For
dictionary_filter_on_readthis PR deliberately deviates:when a scan is planned through
ParquetFormat, the current sessionvalue overrides the table-level option, so
SET/RESETtoggles thefeature on existing tables. Scans already planned keep the value they
were planned with. The tradeoff is that an explicit
OPTIONS('format.dictionary_filter_on_read' 'true')on the table isignored when the session value is
false. The alternativetable || sessionsemantics (used bypushdown_filters) wasconsidered; it honours explicit table opt-in but makes it impossible to
disable the feature per session. Happy to switch if reviewers prefer
consistency with the other options.
arrow-rs dependency
The dictionary-page read API this relies on
(
ParquetRecordBatchStreamBuilder::get_column_chunk_dictionary,apache/arrow-rs#10420, closes apache/arrow-rs#9010) shipped in arrow-rs
60.1.0, which
mainalready uses. No[patch.crates-io]is needed.Are these changes tested?
Yes: unit tests in
dictionary_filter.rsmirroringbloom_filter.rs(absent value,
INlist absent, present value,!=sole value,NOT INlist, a PLAIN-fallback chunk correctly not pruned, and thedictionary-page eligibility guard), an integration test for the
session-override semantics (
string_in_list_pruning.rs), new.sltcoverage showing
row_groups_pruned_dictionaryinEXPLAIN ANALYZE,and the two criterion benchmarks.
Are there any user-facing changes?
Yes: a new opt-in config option
dictionary_filter_on_read(defaultfalse, no behavior change unless enabled) and a newrow_groups_pruned_dictionarymetric inEXPLAIN ANALYZE.🤖 Generated with Claude Code
https://claude.ai/code/session_012oZ19JVxvTCWQKRoQnYpSR