Skip to content

Parquet: check the bloom filter before reading the dictionary page - #120907

Merged
alexey-milovidov merged 9 commits into
masterfrom
parquet-bloom-filter-before-dictionary
Oct 7, 2026
Merged

alexey-milovidov merged 9 commits into
masterfrom
parquet-bloom-filter-before-dictionary

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 18, 2026 •

Copy link
Copy Markdown
Member

When a Parquet column chunk carries both a bloom filter and a dictionary page, the v3 reader read and decoded the dictionary page first and kept the bloom filter only as a runtime fallback. The dictionary page is by far the larger of the two — up to input_format_parquet_dictionary_filter_push_down bytes against one 32-byte bloom filter block per queried value — so for every row group the bloom filter alone could already rule out, the dictionary was read for nothing.

Reading a hits.parquet written by ClickHouse (which writes bloom filters by default) shows it. SELECT UserID FROM file(...) WHERE UserID = <constant> over a file of 16 row groups:

input_format_parquet_dictionary_filter_push_down bytes read random reads rows read
0 4,608 32 0
1048576 (default), before 8,017,209 48 0
1048576 (default), after 4,608 32 0

The 8 MB is the 16 UserID dictionary pages, read to reach a conclusion the bloom filters had already reached. That is what made query no. 5 of the clickbench_parquet_short performance test slower in both #106952 and #110567, on arm and on amd: DiskReadElapsedMicroseconds +34..75%, memory_usage +17..22%, OSCPUVirtualTimeMicroseconds +9..10%, client_time +1..2.5%.

The bloom filter is now evaluated in its own stage, before the dictionary pages are fetched. A bloom filter has no false negatives, so a row group it rules out is ruled out for good and no dictionary page is read. A row group it does not rule out goes on to the dictionary stage exactly as before, and the dictionary costs nothing extra there: either the row group is read anyway — which needs the dictionary page to decode it — or the dictionary rules it out exactly, which is the bloom filter's false positive. Pruning power is therefore unchanged, and files without bloom filters, which is what dictionary filtering was written for, take the same path as before.

BloomFilterHeader and BloomFilterBlocks share one stage's worth of the per-stage memory budget, so Dictionary, the index stages and ColumnData keep exactly the share they had when the bloom filter and the dictionary page were one stage, and input_format_parquet_memory_high_watermark means the same thing for the dictionary-pruning path as before.

Verified locally against a master build of the same tree, in the same rig:

  • the whole parquet stateless subset (188 tests) is unchanged — the only non-environmental difference was 04615_parquet_v3_dictionary_filter_hash_set_budget, which the budget split above restores;
  • on a file with no bloom filters, the dictionary filter prunes exactly what it pruned before (300M rows → 30M for a value in 30 of 300 row groups, → 0 for a value in none);
  • on a file with bloom filters, pruning is identical and the bytes read drop by 2.2–3.6x.

The new test 05229_parquet_v3_dictionary_filter_after_bloom fails on master (FAIL: 25872 > 576) and passes here.

Related: #106952
Related: #110567
Related: #120834

Changelog category (leave one):

  • Performance Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Parquet: check a column chunk's bloom filter before reading its dictionary page. A row group that the bloom filter rules out no longer reads the (much larger) dictionary page to reach the same conclusion, so input_format_parquet_dictionary_filter_push_down costs nothing on files that carry both, while pruning as much as before.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/120907]

Version info

  • Merged into: 26.10.1.1716-master (included in 26.10 and later)

When a column chunk carries both a bloom filter and a dictionary page, the
reader read and decoded the dictionary page first and kept the bloom filter only
as a runtime fallback. The dictionary page is by far the larger of the two - up
to `input_format_parquet_dictionary_filter_push_down` bytes against one 32-byte
bloom filter block per queried value - so for every row group the bloom filter
alone could already rule out, the dictionary was read for nothing.

Reading `hits.parquet` written by ClickHouse (which writes bloom filters by
default) shows it: `SELECT UserID FROM file(...) WHERE UserID = <constant>` over
a file of 16 row groups reads 4,608 bytes with
`input_format_parquet_dictionary_filter_push_down = 0` and 8,017,209 bytes at the
default - the 16 `UserID` dictionary pages - to arrive at the same answer. That
is what made query no. 5 of the `clickbench_parquet_short` performance test
slower in both #106952 and #110567, on `arm` and on `amd`:
`DiskReadElapsedMicroseconds` +34..75%, `memory_usage` +17..22%,
`OSCPUVirtualTimeMicroseconds` +9..10%.

The bloom filter is now evaluated in its own stage, before the dictionary pages
are fetched. It has no false negatives, so a row group it rules out is ruled out
for good and no dictionary page is read. A row group it does not rule out goes on
to the dictionary stage exactly as before, and the dictionary costs nothing extra
there: either the row group is read anyway - which needs the dictionary page to
decode it - or the dictionary rules it out exactly, which is the bloom filter's
false positive. Pruning power is therefore unchanged, and files without bloom
filters, which is what the feature was written for, take the same path as before.

After the change the same query reads 4,608 bytes at the default setting, the
same as with the filter turned off.

`BloomFilterHeader` and `BloomFilterBlocks` share one stage's worth of the
per-stage memory budget, so `Dictionary`, the index stages and `ColumnData` keep
exactly the share they had when the bloom filter and the dictionary were one
stage - `input_format_parquet_memory_high_watermark` means the same thing for the
dictionary-pruning path as before.

Co-Authored-By: Claude Opus 5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0db98b8]

Summary: ✅


AI Review

Summary

This PR splits the Parquet pruning path so BloomFilterBlocks run before Dictionary, and it carries the per-column bloom verdict forward so the reader skips dictionary pages whose own bloom filter has already proved every probed atom false. I reviewed the current PR-head diff, the touched scheduler / reader paths, the prior inline threads, and the added stateless tests. The two earlier review issues are fixed in the current code, the new tests cover both the single-column case and the mixed-column disjunction case, and I did not find any remaining correctness, memory-accounting, or performance-contract violations. PR-level CI is green, including performance-comparison and ClickBench jobs.

Final Verdict
  • Status: ✅ Approve
  • No additional action required.

LLVM Coverage Report

Measured on commit 0db98b8.

Metric Baseline Current Δ
Lines 88.20% 88.30% +0.10%
Functions 92.10% 92.10% +0.00%
Branches 79.70% 79.70% +0.00%

Changed lines: Changed C/C++ lines covered: 103/108 (95.37%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-performance Pull request with some performance improvements comp-parquet-reader-v3 Issues related to the native Parquet reader. labels Sep 18, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

✅ AI verdict: no_change — no significant changes across 32 queries analysed

This PR changes only the Parquet v3 reader. It adds a separate bloom-filter stage that runs before dictionary-page pruning, and it no longer reads a dictionary page early when that page is only needed for filtering. Neither ClickBench (MergeTree) nor TPC-H reads Parquet files, so these benchmarks don't exercise the changed code. Q30 (-16.7%) and Q31 (-15.5%) were held at no change because both PR medians are inside master's current range, and that call holds up: CPU time barely moved (2353 to 2339 ms and 2812 to 2795 ms), and the diff can't explain the shift. No query shows a performance effect that can be traced to this PR.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: bda1fc56-e921-4879-a2a1-1c9968bf34b0
  • MIRAI run: b38fe67a-3033-4292-97f4-ca7613b773e5
  • PR check IDs:
    • clickbench_108629_1791340543
    • clickbench_108635_1791340543
    • clickbench_108641_1791340543
    • tpch_adapted_1_official_108652_1791340543
    • tpch_adapted_1_official_108664_1791340543
    • tpch_adapted_1_official_108699_1791340543

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The only red check, promql_duplicate_series_if #0 (+15.6%, 3.2 ms → 3.7 ms), is unrelated to this PR: it runs numbers() plus a PromQL function and never reaches the Parquet reader. The query runs far below the 0.1 s minimum for performance tests, and the same test was flagged unstable in unrelated PRs #121816 and #115053. Fix: #122061

pull Bot pushed a commit to Spencerx/ClickHouse that referenced this pull request Sep 24, 2026
The queries ran in 3-17 ms, far below the 0.1 s minimum from
`tests/performance/scripts/README.md`, so fixed per-query overhead dominated
and the test produced spurious regressions and instability in unrelated PRs,
e.g. `promql_duplicate_series_if #0` +15.6% in
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120907&sha=4772aa1520e801ada8bde3d7fe7f922dbd4d603e&name_0=PR&name_1=Performance%20Comparison%20%28amd_release%2C%20master_head%2C%204%2F6%29
(ClickHouse#120907).

Drop the 1M-row query, which duplicated the 10M-row one and only measured
overhead, and scale the remaining two to about 0.2 s each.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0db98b82c with master 33d5cfbbc (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 7d4c81bc6; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

19 translation units recompiled, 156 s compile time in total, 19 of them have a recent master baseline.

Job report

alexey-milovidov and others added 2 commits October 4, 2026 17:59
… already ruled out

In `a = 1 OR b = 2`, `applyBloomFilters` can prove `a = 1` false while the row group
survives because `b = 2` is unresolved. The `Dictionary` stage still read `a`'s
dictionary page, which could only confirm the miss. `BloomFilterLookup` now records
whether it was probed and whether any probe reported a possible match. For a column
whose bloom filter reported a definite miss on every probe, `applyBloomFilters` clears
`use_dictionary_filter`, so its dictionary page is not read and the second pass uses
its bloom filter instead.

Added a test with a mixed-column disjunction that checks `a`'s dictionary page is not read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov and others added 2 commits October 5, 2026 19:32
…filtered column

The bloom filter is now checked before the dictionary page, but the
dictionary page was still registered with `likely_to_be_used = true`, so
`Prefetcher` could coalesce it into a nearby bloom-filter read and read
it even when the bloom filter rules the row group out. Register it as not
likely to be used for columns with `use_dictionary_filter`; the
`Dictionary` and `ColumnData` stages request it explicitly.

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

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=120907&sha=89cfb3974d415e2d2d19d1f8c2b327e90ab16ffd&name_0=PR&name_1=Integration%20tests%20%28arm_binary%2C%20distributed%20plan%2C%20targeted%29 (test_storage_nats/test_nats_jet_stream.py::test_nats_restore_failed_connection_without_losses_on_write, tracked in #116417) and provide a fix in a separate PR. If the fix is already in progress, link it here. This PR only changes the Parquet reader and does not touch NATS.

@groeneai

groeneai commented Oct 6, 2026

Copy link
Copy Markdown
Collaborator

This is the lost-messages failure tracked in #116417 (ClickHouse lost some messages: 93568), unrelated to this PR. The fix in progress is #119301 (re-applies #115343): its CI is green and it is mergeable, and on the arm_binary, distributed plan shards this test failed 0 of 1388 runs while #115343 was on master, versus 22 of 6388 since the revert.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Thanks, @groeneai. The NATS failure (#116417) is tracked and the fix is #119301, so nothing changes here. I merged the latest master into the branch to restart CI. The two new Parquet tests pass locally on the merged tree.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good.

@alexey-milovidov alexey-milovidov self-assigned this Oct 7, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 7, 2026
Merged via the queue into master with commit 0ca8150 Oct 7, 2026
150 checks passed
@alexey-milovidov
alexey-milovidov deleted the parquet-bloom-filter-before-dictionary branch October 7, 2026 09:33
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-parquet-reader-v3 Issues related to the native Parquet reader. pr-performance Pull request with some performance improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants