Repository navigation
Make Parquet dictionary-filter pruning cheaper: sorted hash vector, no per-value Field - #115744
Conversation
…o per-value Field Two changes to the exact dictionary filter of the native Parquet reader (`input_format_parquet_dictionary_filter_push_down`): 1. `parquetTryHashColumn` hashed integer columns through the generic per-value `Field` path: construct a `Field`, re-dispatch on its type, re-check the logical type - for every dictionary entry of every row group. Hash the data array directly instead, with the type check hoisted out of the loop (the digest is unchanged: widening to `Int64`/`UInt64` and narrowing to the physical type keeps the same low bits as a direct cast). Columns without a fast path (e.g. `IPv4`) fall through to the `Field` path unchanged. 2. `hashDictionaryValues` built a `HashSet` of all dictionary-value hashes per column chunk, probed by a handful of query constants. The set's power-of-two buffer (maximum fill factor 0.5) held up to ~4 cells per value on top of the hash vector it was built from, and its growth rule was the trickiest term of the pruning-memory reservation. Keep the vector itself, sort it in place, and binary-search the query constants: no extra allocation, a 3-5x smaller persistent footprint charged against `input_format_parquet_memory_high_watermark`, and an exact reservation instead of a modeled one. The extra default-value hash under `input_format_null_as_default` is kept outside the vector so the vector stays exactly the allocation the reservation covers. On a 4M-value dictionary microbenchmark (64 row groups, all values distinct, absent needle) this removes ~18% of the query's instructions; the pruning now also survives a ~35% tighter memory watermark (the behavior flip on the file of `04615_parquet_v3_dictionary_filter_hash_set_budget` moves from between 6.5 and 7.0 MB down to between 4.0 and 4.5 MB), which matters on small machines where the watermark is derived from the memory limit (~200 MiB on a 2 GiB machine). The smaller footprint also avoids multi-megabyte transient allocations per column chunk during pruning, which showed up as kernel page-fault time under a tight cgroup. `04615_parquet_v3_dictionary_filter_hash_set_budget` is retuned to pin the new footprint model from both sides: a watermark that affords the hash vectors must keep pruning, one just below must fall back to a full scan.
|
Workflow [PR], commit [65aafa0] Summary: ✅
AI ReviewSummaryThis PR replaces the Parquet dictionary-filter value set with a sorted hash vector, adds a direct integer-column hashing path, and retunes the related memory-budget and large- Final Verdict✅ No remaining review findings. The previously raised issues are fixed in the current revision. LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 68/72 (94.44%) · Uncovered code |
Co-Authored-By: Claude Fable 5 <[email protected]>
The watermark of the string-rounding budget test sat in the floored-vs-exact gap of the old footprint (which included the hash-table term this branch removed). Re-pin it inside the same gap of the new, smaller reservation, found by bisecting the behavior flip (~6.6 MB) on the patched build. Co-Authored-By: Claude Fable 5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units9 translation units recompiled, 35 s compile time in total, 9 of them have a recent master baseline. |
…in one pass
The exact dictionary filter of the native Parquet reader is deliberately
exempt from the bloom filter's set-size cap (`bloom_filter_max_set_size`,
100): `prepareBloomFilterCondition` keeps hashing over-cap `IN` sets so
that the exact filter can still prune them. `findAnyHash` can therefore
be called with thousands of probe hashes for one column chunk, and after
the switch from a `HashSet` to a sorted vector each of them was a
full-height binary search over the whole vector.
Intersect the two sequences instead: `KeyCondition::prepareBloomFilterData`
now sorts and deduplicates the probe hashes of every atom once (which
also stops a duplicate constant from being probed twice on every granule
or row group), and the dictionary lookup walks its sorted vector along
with them, so each probe continues where the previous one stopped. A
handful of constants still costs a binary search each; a large probe set
degrades to a linear merge instead of `probes.size()` full searches. An
out-of-order probe merely restarts the window, so the result does not
depend on the probes being sorted.
Measured with an absent needle (the worst case: every probe is searched)
against a sorted vector of 8-byte hashes, per `findAnyHash` call:
values probes binary search merge `HashSet` probe
16384 1000 0.010 ms 0.007 ms 0.001 ms
16384 100000 1.395 ms 0.723 ms 0.424 ms
131072 100000 2.838 ms 1.290 ms 0.632 ms
131072 1000000 20.338 ms 15.378 ms 5.769 ms
1000000 100000 4.079 ms 2.423 ms 2.391 ms
1000000 1000000 66.299 ms 13.376 ms 27.249 ms
So the large-`IN` path is 1.5-5x cheaper than searching for each probe,
and beyond ~1M probes it also beats the `HashSet` this change replaced,
whose build cost (an insert per dictionary value, ~10 ns each) it does
not pay either. For a handful of constants nothing changes.
Also pin the "the default value hash stays out of the vector" invariant
with a `chassert` in `hashDictionaryValues`: a watermark-based test
cannot detect an append there, because for a `FixedSize` dictionary the
reservation also covers the materialization terms, which leave enough
headroom for a doubled vector.
`04615_parquet_v3_dictionary_filter_hash_set_budget` gets the same
both-sides watermark check for the nullable file as for the non-null one,
and the new `05024_parquet_dictionary_filter_large_in_set` checks the
pruning decisions and the results of the intersection for over-cap `IN`
sets that miss every row group, hit one row group, or hit all of them.
…r a few lookups `hashDictionaryValues` sorted the hashes of every dictionary-filtered column chunk so that `DictionaryValueHashes::containsAny` could binary-search them (ClickHouse#115744). A chunk's value set lives for one row group filter evaluation and is usually probed once, by the 1-5 constants of one condition, so the O(n log n) sort dominated the cost of the dictionary filter. Keep the vector unsorted and let `containsAny` answer up to max(8, log2(n)) probes in total by a linear scan; the first call that would exceed that sorts the vector once, and the existing merge search is used from then on. A sort costs about log2(n) scans, so the scans never cost more than the sort they avoid, and a large probe set (an over-cap `IN` set) sorts on its first call exactly as before. Both paths compute membership in the same set, so pruning decisions are unchanged, and nothing new is allocated, so the pruning memory reservation still covers the vector. On 16 row groups of 100000 distinct UInt64 values (release build, 4 CPUs), one equality goes from 16 to 7 ms and from 43.5 to 2.9 ms of query CPU; ClickBench q20 on hits.parquet from 135.5 to 74.5 ms. The new test covers the scan, the switch to sorting and the sorted search, and the performance test gets a fixture with large dictionaries. Proposed by snelheidai in ClickHouse#123487 (analysis and patch). Closes: ClickHouse#123487 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Antalya 26.8: Backport of ClickHouse#115744 - Replace parquet dictionary filter value with sorted hash vector
The exact dictionary filter of the native Parquet reader (
input_format_parquet_dictionary_filter_push_down) evaluated each column chunk by hashing every dictionary value through the generic per-valueFieldpath and inserting all the hashes into a per-chunkHashSet, probed by a handful of query constants. This did two kinds of avoidable work:parquetTryHashColumnconstructed aFieldand re-dispatched on its type for every integer dictionary entry. It now hashes the data array directly, with the type check hoisted out of the loop; the digest is unchanged (widening toInt64/UInt64and narrowing to the physical type keeps the same low bits as a direct cast), and columns without a fast path (e.g.IPv4) fall through to theFieldpath unchanged.hashDictionaryValuesnow keeps the hash vector itself, sorts it in place, and binary-searches the query constants, instead of building aHashSetwhose power-of-two buffer (maximum fill factor 0.5) held up to ~4 cells per value on top of that same vector. No extra allocation, a 3-5x smaller persistent footprint charged againstinput_format_parquet_memory_high_watermark, and an exact reservation instead of a modeled one (theHashSetgrowth rule was the trickiest term of the pruning-memory accounting). The extra default-value hash underinput_format_null_as_defaultis kept outside the vector so the vector stays exactly the allocation the reservation covers.Measured on a dictionary-heavy microbenchmark (64 row groups, 4M distinct
UInt64values, absent needle, so the filter prunes everything): ~18% fewer instructions for the query. The pruning also survives a ~35% tighter memory watermark: the behavior flip on the file of04615_parquet_v3_dictionary_filter_hash_set_budgetmoves from between 6.5 and 7.0 MB down to between 4.0 and 4.5 MB. This matters on small machines, where the watermark is derived from the memory limit (about 200 MiB on a machine with 2 GiB of RAM, e.g.t3a.smallin ClickBench): the smaller and exact footprint lets more chunks be pruned instead of falling back to a full scan, and avoids multi-megabyte transient allocations per column chunk during pruning.04615_parquet_v3_dictionary_filter_hash_set_budgetis retuned to pin the new footprint model from both sides: a watermark that affords the hash vectors must keep pruning, one just below must fall back to a full scan.The probe side is an intersection, not a series of independent searches:
KeyCondition::prepareBloomFilterDatasorts and deduplicates each atom's probe hashes once, and the dictionary lookup walks its sorted vector along with them, so every probe continues where the previous one stopped. That matters becauseprepareBloomFilterConditiondeliberately keeps hashingINsets over the bloom filter's set-size cap so the exact dictionary filter can still prune them, so one column chunk can be probed with thousands of hashes. Measured perfindAnyHashcall with an absent needle (every probe searched), the merge is 1.5-5x cheaper than a binary search per probe, and once the probe set approaches the dictionary size it also beats theHashSetthis change replaces (13.4 ms vs 27.2 ms for 1M probes against 1M values), whose per-value insert cost and 4x memory it does not pay either.New test
05024_parquet_dictionary_filter_large_in_setcovers that path: over-capINsets that miss every row group, hit exactly one, hit all of them, and match only the last dictionary value, each compared against the same query with the dictionary filter disabled.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Parquet dictionary-based row group pruning (setting
input_format_parquet_dictionary_filter_push_down) got cheaper: integer dictionaries are hashed without per-valueFieldconversions, and the value set is kept as a sorted vector instead of a hash table, several times reducing the memory footprint of the pruning stage.Workflow [PR]
Sync PR [sync-upstream/pr/115744]