Repository navigation
Dynamically size bloom filter in parquet writer - #119230
alexey-milovidov merged 36 commits into
Conversation
Instead of using a hash set of hashes which is heavy weight in both runtime and memory, use bloom filter folding to arrive at approximately the same result. File size and filter quality should on average only deviate slighly (~by the fpp of the filter) from the previous solution, writing is much faster and the worst case memory consumption lower than before and free of degenerate cases like ClickHouse#105295. Closes ClickHouse#105295 bck bck bck bck bck
alexey-milovidov
left a comment
There was a problem hiding this comment.
The idea looks nice. We will need at least some tests.
|
Workflow [PR], commit [da2e406] Summary: ✅
AI ReviewSummaryThis PR replaces hash-set-based distinct-count estimation in the Parquet writer with an oversized split-block bloom filter that is folded down after writing, switches sparse nested sizing to the actual hashed leaf-value count, and adds focused regression coverage for folded, sparse, and over-cap filters. After reading the current diff and the full thread history, I do not see any unresolved correctness, compatibility, or performance-contract violations in the current code. Final Verdict
LLVM Coverage ReportMeasured on commit da2e406.
Changed lines: Changed C/C++ lines covered: 78/79 (98.73%) · Uncovered code |
|
Sure thing @alexey-milovidov I can look into some tests. I think the existing functional tests reproduce the false-negative failure case (with bloom filters active by default on parquet)? So I assume we'd want some unit tests that make sure the folding/sizing math works out? |
`finishBloomFilter` folds the written filter down, so two of the column chunks in `03263_parquet_write_bloom_filter` now get a 128-byte filter instead of a 256-byte one; the reference is updated accordingly (the `miss` probes still prune every row group). The new test `05194_parquet_write_bloom_filter_folding` covers the two properties folding must preserve: a chunk with few distinct values still gets a small filter without deduplicating hashes in a hash set first, and folding never drops a value, so a row group holding a matching value is never pruned - checked for the default 10.5 bits per value and for a dense filter with 4 bits per value. Also hoist the `salt` table out of the per-value loop and fix two typos in the comment of `finishBloomFilter`. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🕵 Merged
Verified locally: I also answered the open question about the 128 MiB limit in the review thread: it can't be raised (arrow's reader requires it), but it is now applied to the number of values rather than the number of distinct values. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes16169 object files changed (+4.87 MiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units10 translation units recompiled, 35 s compile time in total, 10 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
|
📊 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
|
…exercise the folded filter The test `05194_parquet_write_bloom_filter_folding` failed in every stateless CI job of ClickHouse#119230: * it spawned 150 `clickhouse-client` processes, one per probe, and timed out after 600 s in the flaky check with sanitizers - now all probes of a file run in a single client invocation, ~3.6 s in total; * its `ParquetMetadata` query used two `ARRAY JOIN` clauses and dotted tuple access, which the old analyzer does not support - now it uses nested `arrayJoin` and `tupleElement` calls; * as the AI review pointed out, the soundness probes queried the all-distinct column `u`, whose filter is never folded, so the "folding never drops a value" contract was not exercised. The probes now query a column `c` with only 4 distinct values per row group, and the test first asserts from `ParquetMetadata` that the filter of `c` is at least 16x smaller than the one of `u` in every row group before using the hits as coverage. Every value of `c` lives in exactly one row group, so the probe must return 500 matching rows, and it must read exactly that row group. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119230&sha=27971ad63b171d78e363f22732578fbde37b313a&name_0=PR&name_1=Stateless%20tests%20%28amd_asan_ubsan%2C%20flaky%20check%29 Co-Authored-By: Claude Fable 5.1 <[email protected]>
…folding` The flaky check ran the test in 380-450 s and failed it with `Test runs too long (> 180s)`: each of the 300 probe queries over the Parquet file takes about a second on a loaded CI machine, while the two `INSERT`s and the two `ParquetMetadata` queries take a few seconds in total. The filter sizes of all 100 row groups are still verified; only the probes are reduced to every 10th row group (30 queries), and the false-positive tolerance of the summaries is tightened from 2 to 1 probe accordingly. CI report: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=119230&sha=7c94b933834bfc6cc294d26d977fac135117197c&name_0=PR&name_1=Stateless%20tests%20(amd_binary%2C%20flaky%20check) PR: ClickHouse#119230 Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Merged
|
…riter `05218_parquet_write_bloom_filter_over_cap` was removed together with the clamp it asserted, which left the reader-side cap (at most 4 Mi blocks, 128 MiB of filter) without functional coverage. The new `05238_parquet_write_bloom_filter_over_cap` pins the current contract: a column chunk whose initial filter would exceed the cap gets no bloom filter at all, whether it holds eight distinct values or only distinct ones, while a leaf under the cap with the same values still gets a folded filter. It also probes the file with only bloom filter pruning enabled and checks that the reads succeed and scan the whole file. Co-Authored-By: Claude Fable 5.1 <[email protected]>
|
🕵 Pushed 49c790e: merged Reds on 3c12980, none from this PR:
|
|
🕵 Merged The only reds on The remaining AI "Request changes" item (live accounting for the under-cap unfolded filter) is still waiting on @rschu1ze. He asked for the memory callback to be removed, and my reply is in the thread. All 16 of his threads have replies and are waiting on his re-review. |
|
🕵 Status for
@groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=119230&sha=e1fbbea156b849d3aba25cc740738750d02f835a&name_0=PR&name_1=Stress%20test%20%28amd_asan_ubsan%29 and provide a fix in a separate PR. If the fix is already in progress, link it here. Review state is unchanged. All 17 open threads end with my replies, and they are waiting for @rschu1ze to review again. The AI review still asks for live accounting of the under-cap unfolded filter. That would bring back the memory-usage callback that @rschu1ze asked us to remove, so I am leaving that decision to him. |
|
This is a fuzzed copy of the Your #118445 fixes it (its The count in your comment spans several STIDs of this message. 2508-3319 itself has 6 hits in 20 days, none on master, and 5 of them are this same fixture (the sixth has an empty
|
|
🕵 Thanks @groeneai. So the Nothing else has changed for |
…atedBytes` - `tests/performance/parquet_write_bloom_filter.xml`: the table population timed out in the performance comparison, so insert one third of the rows and use `ENGINE = Memory` instead of `MergeTree`. - `ColumnChunkWriteState::allocatedBytes`: remove the extra accounting of the folded bloom filter, as requested by the reviewer. https://s3.amazonaws.com/clickhouse-test-reports/PRs/119230/e1fbbea156b849d3aba25cc740738750d02f835a/pr/performance_comparison_arm_release_master_head_6_6/report.html PR: ClickHouse#119230 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/PRs/119230/df43335dba7c67766697ea9e04eae4ca30c05d6d/pr/result_stress_test_amd_debug.json ( The other red, |
|
The fix is in progress: #123238. In this run's stress log, two It is not the drifted-tracker case of #117995: |
|
🕵 Thanks @groeneai for tracking the |
|
Hi, original author of apache/arrow-rs#9628 here 👋🏻 Did I understand correctly that this change resulted in some pretty substantial improvements in general Parquet write performance? |
|
@adriangb, thank you! Yes, the performance tests show massive improvements: https://performance.ci.clickhouse.com/runs/pr-119230-da2e406d0334149b0c860f994765e8fc876f447d |
Pretty much the same solution as used by arrow (e.g. in apache/arrow-rs#9628) adapted for the current codebase.
Instead of using a hash set of hashes which is heavy weight in both runtime and memory, use bloom filter folding to arrive at approximately the same result. File size and filter quality (false positive rate) should on average only deviate slighly (~by the fpp of the filter when testing the hits dataset as in https://clickhouse.com/blog/clickhouse-release-25-02) from the previous solution, writing is much faster and the worst case memory consumption lower than before and free of degenerate cases like #105295.
It might be a good idea to move the setting from bits/value to something like "maximum false positive probability" since deduplication as well as this solution both make that setting rather hard to interpret (and the current comment on it maps to fpp anyways). That would simplify the code and reasoning a bit.
Closes: #105295
Edit:
In fact, looking at the "benchmark" results again, for the hits test data the results from this actually beat current
masterin every dimension. Writing runs slightly faster (~10%), the resulting files are the same size (this one is slightly smaller actually):But the filter seems visibly better:
master's output file queries as:1 row in set. Elapsed: 0.121 sec. Processed 1.13 million rows, 2.41 MB (9.30 million rows/s., 19.90 MB/s.)
Peak memory usage: 96.52 MiB.
while this branch quieries half as many rows:
I think this makes sense (although the exact order of the improvement is impossible to predict). Initially, the logic here filters out more quasi duplicates because it deduplicates on a subset of the bits in the hash (the set that eventually matters for the bloom filter) vs. all bits for the hash-set based solution. The folding then on average produces the about the same size of filter but for each chunk written varies based on the actual collisions in the data. So degenerate cases analogous to the one in #105295 where a lot of collisions happen in the bloom filter (but not the hashes outright) result in a smaller filter here and there, while cases on the other end of the spectrum where the fill rate is higher from fewer collisions result in a larger filter (statistically speaking) which is more accurate.
Tests:
05194_parquet_write_bloom_filter_foldingcovers that a column chunk with 4 distinct values still gets a small filter (asserted fromParquetMetadata: at least 16x smaller than the filter of an all-distinct column in every row group) and that folding never drops a value: every probe against the folded column finds its 500 matching rows and reads exactly the one row group holding them, for the default 10.5 bits per value and for a dense filter with 4 bits per value. The filter sizes in03263_parquet_write_bloom_filterare updated for the two column chunks that now fold down.05213_parquet_write_bloom_filter_sparse_nestedchecks that the null and empty-array placeholders of a nested leaf do not count towards the initial filter size. A column chunk that would need a filter above the 128 MiB reader cap gets none, as before;05238_parquet_write_bloom_filter_over_cappins that (no filter for two over-cap column chunks, a folded one for a leaf under the cap with the same values, and reads of the file still succeed). The performance testparquet_write_bloom_filterruns the export of #105295 (generic and hash set adversarial data).Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Speed up writing Parquet bloom filters: instead of deduplicating the value hashes in a hash set to determine the filter size, the writer now builds a filter sized for the number of values and folds it down to the size implied by
output_format_parquet_bloom_filter_bits_per_value. This removes the worst case slowdown on data that is adversarial for the hash set, and lowers the worst case memory usage.Workflow [PR]
Sync PR [sync-upstream/pr/119230]
Version info
26.10.1.1233-master(included in26.10and later)