Skip to content

Parquet: dictionary-based row group filtering - #106952

Merged
alexey-milovidov merged 32 commits into
masterfrom
parquet-dictionary-filter-push-down
Jul 13, 2026
Merged

alexey-milovidov merged 32 commits into
masterfrom
parquet-dictionary-filter-push-down

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

Implement dictionary-based row group filtering for the Parquet v3 reader.

When all data pages of a column chunk are dictionary-encoded, the dictionary page holds the complete set of values present in that column chunk. For equality and IN conditions, ClickHouse can therefore skip a whole row group when none of the requested values appear in its dictionary — even when no bloom filter is present, and exactly (no false positives beyond hash collisions).

The new DictionaryLookup plugs into the existing KeyCondition bloom-filter machinery: it hashes the dictionary values with the same hasher used for the query constants (parquetTryHashColumn) and reports whether any requested hash is present. This reuses checkInHyperrectangle, so it composes with min/max statistics just like the bloom filter, and takes precedence over the bloom filter when both apply.

Eligibility requires PageEncodingStats proving every data page is dictionary-encoded; otherwise the dictionary might not hold all values and pruning would be unsound. To make ClickHouse-written files usable by this optimization, the writer now also emits PageEncodingStats.

The optimization is controlled by the new setting input_format_parquet_dictionary_filter_push_down (the maximum dictionary page size in bytes for which it is applied, default 1 MiB; 0 disables it).

Microbenchmarks: ~2x faster wall-clock (76x fewer rows read) when it prunes, negligible overhead for low/medium-cardinality dictionaries that do not prune, and a small bounded worst case for high-cardinality dictionaries that cannot prune.

Changelog category (leave one):

  • Performance Improvement

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

The Parquet v3 reader can now skip whole row groups using the dictionary page (in addition to min/max statistics and bloom filters) for equality and IN conditions, when a column chunk is fully dictionary-encoded. Controlled by the new setting input_format_parquet_dictionary_filter_push_down.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.7.1.872 (included in 26.7 and later)

alexey-milovidov and others added 2 commits June 10, 2026 11:15
Add row-group pruning for the Parquet v3 reader based on the dictionary
page. When all data pages of a column chunk are dictionary-encoded, the
dictionary holds the complete set of values present in the chunk, so for
equality/`IN` conditions we can skip whole row groups whose dictionary
does not contain any of the requested values.

The new `DictionaryLookup` plugs into the existing `KeyCondition` bloom
filter machinery: it hashes the dictionary values with the same hasher
used for the query constants (`parquetTryHashColumn`) and reports whether
any requested hash is present. This reuses `checkInHyperrectangle`, so it
composes with min/max statistics exactly like the bloom filter does, and
takes precedence over the bloom filter when both are available.

Eligibility (`columnChunkCanUseDictionaryFilter`) requires `encoding_stats`
proving every data page is dictionary-encoded; otherwise the dictionary
might not hold all values and pruning would be unsound. To make
ClickHouse-written files usable by this optimization, the writer now emits
`PageEncodingStats`.

Controlled by the new setting `input_format_parquet_dictionary_filter_push_down`
(maximum dictionary page size in bytes for which the optimization applies,
default 1 MiB; 0 disables it).

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

Copy link
Copy Markdown
Member Author

Enable the setting by default and also add its randomization to clickhouse-test.

@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [1beba64]

Summary: ✅


AI Review

Summary

This PR adds dictionary-page-based row-group pruning to the Parquet v3 reader, wires the new setting through format settings and docs, emits PageEncodingStats from the writer so ClickHouse-written files can use the optimization, and adds focused regression coverage for the soundness issues that came up during review. I re-checked the current code against the prior discussion and did not find any remaining correctness, compatibility, or test gaps in the changed surface.

Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Jun 11, 2026
Comment thread src/Core/FormatFactorySettings.h Resolved
@murphy-4o murphy-4o self-assigned this Jun 11, 2026
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

no significant changes detected. K_source=5 K_base=30 flagged=0/65

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: 428e18b9-7bc4-419d-a902-6e7e19b26d13
  • MIRAI run: 5ee02188-4d9a-4298-9b58-50473fc2d5d4
  • PR check IDs:
    • clickbench_373195_1783902807
    • clickbench_373201_1783902807
    • clickbench_373205_1783902807
    • tpch_adapted_1_official_373213_1783902807
    • tpch_adapted_1_official_373224_1783902807

alexey-milovidov and others added 3 commits June 13, 2026 03:35
…ock_size

The test asserts exact `rows_read` per query, relying on the file having three
10000-row row groups whose `category` value sets are disjoint, so the dictionary
filter prunes whole row groups. That layout only holds when the insert writes the
rows in a single block: with the randomized `max_block_size` the writer splits
the data into differently-sized row groups (e.g. 13149 / 13148 / 3703), the
per-row-group value sets stop being disjoint, and the expected row counts change.

Pin `max_block_size` on the insert (mirroring `03263_parquet_write_bloom_filter`)
so the row group boundaries are deterministic. The dictionary filter itself is
correct; only the test's assumptions were settings-dependent.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The Parquet v3 dictionary-based row group filter looked up query constants only
among the dictionary values, which hold the non-null values of a column chunk.
Under `input_format_null_as_default`, null values read into a non-nullable column
decode as the type's default value, which is not in the dictionary. So a row group
whose nulls matched the queried default was wrongly skipped: e.g. an optional column
read as non-nullable `UInt64` with `WHERE x = 0` returned 0 instead of the count of
null rows.

Mirror the conservative rule the min/max path already applies in
`adjustRangeFromIndexIfNeeded`: when `null_as_default` is in effect and the chunk may
contain nulls, add the default value's hash to the set looked up by `DictionaryLookup`
(or, if the default can't be hashed, disable filtering for that chunk).

Add `05017_parquet_v3_dictionary_filter_null_as_default` covering the regression.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…h_down

Exercise the disabled path (0), a small limit, and the default limit of the new
Parquet v3 dictionary-based row group filter in randomized stateless runs. Tests
that depend on a fixed pruning behaviour set the setting explicitly (per query or
per session), which wins thanks to `--allow_repeated_settings`.

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

Copy link
Copy Markdown
Member Author

Pushed three commits:

  • 281c6269187 — make 04326 robust to randomized max_block_size. The test asserted exact rows_read assuming three clean 10000-row row groups with disjoint category sets, but the randomized max_block_size makes the writer split the data into differently-sized row groups (e.g. 13149 / 13148 / 3703), so the value sets overlap and the optimization correctly prunes fewer rows. Pinned max_block_size on the insert (mirroring 03263_parquet_write_bloom_filter) so the row group boundaries are deterministic. The optimization itself is correct.
  • ca5516bb165 — fix a soundness bug with input_format_null_as_default (reported in review): nulls read into a non-nullable column decode as the type default, which isn't in the dictionary, so a row group whose nulls matched the queried default was wrongly skipped. Now adds the default value's hash, mirroring the min/max path. Added 05017_parquet_v3_dictionary_filter_null_as_default.
  • 58ca4346dc9 — randomize input_format_parquet_dictionary_filter_push_down in clickhouse-test (reported in review).

The remaining red CI is unrelated: the AST fuzzer PLACEHOLDER action (STID 1611-343c) is open issue #105501, and the Server died in the targeted/flaky-check jobs is not a crash — the server logs show a clean shutdown with no fault, and the runner was under memory pressure (a known runner-wide total-memory flake).

Comment thread tests/clickhouse-test Resolved
alexey-milovidov and others added 2 commits June 14, 2026 03:57
The style check `test_numbers_check` flagged `Gap (4337, 5017) > 100`:
the regression test had been numbered 05017, far above the highest
existing test number on master (04337). Renumber it to 04338 so the
functional test numbering stays contiguous.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master (was ~1485 commits behind) — clean merge, no conflicts; verified Reader.cpp, Write.cpp, and ParquetV3BlockInputFormat.cpp still compile against the merged headers (the only overlap with this PR's files was the additive Pretty NBSP settings, and KeyCondition::BloomFilter is unchanged).

The sole CI failure was the style check test_numbers_check: Gap (4337, 5017) > 100. The input_format_null_as_default regression test had been numbered 05017, far above master's highest test number (04337), so I renumbered it to 04338 (55f9b96fd92). The numbering gap check now passes against the committed tree.

alexey-milovidov and others added 3 commits June 16, 2026 05:35
`prepareBloomFilterCondition` reuses `PrimitiveColumnInfo::use_bloom_filter`
as a generic "we hashed the query constants for this column" flag, setting it
for dictionary filtering even when `input_format_parquet_bloom_filter_push_down`
is `0`. The per-row-group bloom prefetch in `initializePrefetches` only checked
that flag and the metadata offset, so a row group that is not dictionary-filter
eligible but has a bloom filter would still use the bloom filter, ignoring the
user disabling `input_format_parquet_bloom_filter_push_down`.

Require the setting in that condition so the bloom filter is only used when the
user enabled it; dictionary filtering remains controlled by its own setting.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The dictionary page holds only the non-null values of a column chunk. When a
nullable Parquet column is read into a non-nullable output column with
`input_format_null_as_default=0`, decoding a null raises
`CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN`. The dictionary filter, looking up only
the non-null values, would consider a predicate like `WHERE x = 0` impossible
and skip the whole row group, suppressing that error and changing the query
result.

The min/max path is already conservative here: `adjustRangeFromIndexIfNeeded`
extends the range to include NULL so the row group is not pruned. Mirror that in
`hashDictionaryValues`: when the chunk may contain nulls and they would raise a
conversion error, return `std::nullopt` to disable dictionary filtering for the
chunk (we can't rule out a match). The `input_format_null_as_default` branch
that adds the default value's hash is preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Covers the two soundness fixes for dictionary-based row group filtering in the
Parquet v3 reader:

  1. Reading nulls into a non-nullable column with `input_format_null_as_default=0`
     must raise `CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN`; the dictionary filter must
     not skip the row group and suppress the error.
  2. `input_format_parquet_bloom_filter_push_down=0` must disable bloom filtering
     even when the dictionary filter reused the per-column hash-eligibility flag: a
     bloom-filter-only row group must not be pruned when the user disabled it.

Verified against the pre-fix binary (commit 55f9b96): it fails exactly these two
assertions and passes the rest, so the test detects both regressions.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Pushed three commits addressing the two review comments on the merged head (55f9b96 → c6ae860):

  • 5403ab9 — don't use the bloom filter when input_format_parquet_bloom_filter_push_down=0. prepareBloomFilterCondition reuses PrimitiveColumnInfo::use_bloom_filter as a generic "we hashed the query constants" flag (set for dictionary filtering too), so the per-row-group bloom prefetch in initializePrefetches could use a bloom filter on a non-dictionary-eligible row group even with the setting off. Now gated on the setting. This only affected rows_read / honoring the setting, not results (bloom filters have no false negatives).
  • e349af9 — don't suppress the null-conversion error. When a nullable column is read into a non-nullable output with input_format_null_as_default=0, decoding a null raises CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN. The dictionary (non-null values only) would consider WHERE x = 0 impossible and skip the row group, suppressing the error. hashDictionaryValues now returns std::nullopt in that case, mirroring the conservative null handling in adjustRangeFromIndexIfNeeded.
  • c6ae860 — regression test 04340_parquet_v3_dictionary_filter_soundness. Verified against the pre-fix binary (55f9b96, build_arm_release): it fails exactly these two assertions and passes the rest, so it detects both regressions.

Reader.cpp compiles clean with both fixes (built the dbms object locally). Both review threads resolved.

@murphy-4o murphy-4o removed their assignment Jun 16, 2026
alexey-milovidov and others added 2 commits June 17, 2026 22:21
The test's second row group ('hi_1000'..'hi_1999', 1000 distinct short
strings) was meant to be bloom-only, but with the default
`output_format_parquet_max_dictionary_size = 1048576` its ~11 KiB dictionary
stays under the limit, so the writer keeps it dictionary-encoded. That makes
it dictionary-filter eligible, so the `dict on, bloom off` query for
`absent_value` was pruned by the dictionary too and read 0 rows instead of
the expected 1000 — a deterministic failure across configs (amd_debug,
amd_tsan, arm_binary, asan_ubsan distributed plan, llvm_coverage).

Pin a tiny `output_format_parquet_max_dictionary_size = 1024` on the write so
the high-cardinality row group falls back to PLAIN (bloom-only) while the
low-cardinality row group 0 stays dictionary-encoded. Verified with pyarrow:
row group 0 keeps `RLE_DICTIONARY` + dictionary page, row group 1 becomes
pure `PLAIN` with no dictionary page. Reference values are unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…filter-push-down

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@alexey-milovidov

Copy link
Copy Markdown
Member Author

Merged master (a9c99b3ef3e, branch was 1919 commits behind, merge-base 06-14 ~5 days).

The merge is clean and orthogonal: master touched the Parquet V3 reader only in page-decode validation functions (decodeDictionaryPageImpl, initializeDataPage, decodeAndCheckPageHeader, decompressPageIfCompressed — negative num_values/row-count rejection, DataPageV2 level-length OOB fix, Arrow SIMD), which do not overlap this PR's dictionary-filtering functions (hashDictionaryValues, DictionaryLookup, eligibility) or the writer (Write.cpp PageEncodingStats, untouched by master). Verified the merged tree combines both change-sets and that the SettingsChangesHistory entry stays in the 26.6 block with no duplication.

CI triage on the previous head (01d1ed52ae3): all failures were unrelated, master-wide flakes — none touch Parquet:

  • Unexpected exception in refresh scheduling (STID 2508-34af / 2508-3e7b, RefreshTask.cpp) in Stress test (amd_asan_ubsan / arm_tsan) — tracked flake #106737; 19/36/37 failures/day on master over 06-17..06-19 across dozens of PRs.
  • Logical error: Trying to get name of not a column: A (STID 2310-395b, evaluateConstantExpression/TableFunctionNumbers) in AST fuzzer — recurs on master (PR=0) daily since 06-06.
  • BuzzHouse (arm_asan_ubsan) — the fuzzer's own bookkeeping query SELECT count() FROM system.constraints ... INTO OUTFILE failed with QUERY_CACHE_USED_WITH_SYSTEM_TABLE (Code 719), a harness issue in FuzzConfig::tableCountSystemRows, not a server problem.

The soundness test 04340_parquet_v3_dictionary_filter_soundness (and 04326/04338) passed on 01d1ed52ae3, confirming the 06-17 fixture fix. AI Review verdict on that head was ✅ Approve with no remaining blocking findings; CI is re-running on the merged head.

alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
…nary_filter_push_down`

The setting was added by #106952 (merged into this branch on 07-13) and
reverted on master by #110354, but the merge kept the history entry
because it is adjacent to this PR's own `snappy_mode` entry. The orphan
entry made every query with a `compatibility` setting fail with
`UNKNOWN_SETTING`, which is what broke the Fast test on
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=bee84f139ca122148eaa99904c0a6dca3733cbd3&name_0=PR&name_1=Fast%20test

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
…ory entry

The setting was introduced on master by #106952 and was picked up by the
2026-07-14 morning merge of master into this branch. Master then reverted
#106952 in #110354, and the subsequent merge of master into this branch
removed the setting declaration but left the `SettingsChangesHistory.cpp`
entry behind, orphaning it: applying any `compatibility` value older than
26.7 threw `UNKNOWN_SETTING`, which broke all 19 compatibility-related
tests in Fast test.

Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=97254&sha=53cf0bf945b6661cccd0398f696f2882d42cf695&name_0=PR&name_1=Fast%20test
PR: #97254
alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
… from settings changes history

The setting was added by #106952 and reverted on master by #110354
("Broke private CI"), but the last merge of master into this branch kept
its `SettingsChangesHistory.cpp` entry, because the removal landed on
master concurrently and the merge resolved the adjacent region in favor
of keeping the line. Since the setting no longer exists, applying any
`compatibility` value below 26.7 threw `UNKNOWN_SETTING`, which failed
19 Fast test cases and cancelled the rest of the CI run:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106215&sha=73c5d060466431c91b10b914d0ae6001760fa8ab&name_0=PR&name_1=Fast%20test

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
…rquet_dictionary_filter_push_down`

The setting was added by #106952 and reverted on master by #110354, which
deleted both the setting and its `SettingsChangesHistory.cpp` entry. Because
this PR adds its own two entries (`network_compression_method`,
`network_zstd_compression_level`) immediately above that line, the
2026-07-14 merge of master kept the branch-side block and resurrected the
deleted entry. A history entry referencing a nonexistent setting makes every
`SET compatibility = ...` throw `UNKNOWN_SETTING`, which failed 19
compatibility-related tests in Fast test:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108786&sha=e07f5bdc1a0969d07670a9ebb0d560cda6b6daab&name_0=PR&name_1=Fast%20test

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
…y from settings history

The setting was added by #106952 and reverted on master by #110354, which
removed both the setting declaration and its history entry. The merge of
master into this branch kept the stale history line (it sits adjacent to
this PR's own `ignore_on_cluster_for_replicated_handler_queries` entry, so
the hunk auto-merged without a conflict). The orphan made every
`SET compatibility` older than 26.5 throw `UNKNOWN_SETTING`, failing 19
compatibility tests in Fast test:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106231&sha=22033553d4f041305264ea4248e4fd24fcdc9ee8&name_0=PR&name_1=Fast%20test
alexey-milovidov added a commit that referenced this pull request Jul 15, 2026
…ting

The `input_format_parquet_dictionary_filter_push_down` setting arrived on
this branch via a master merge (added by #106952), but master then reverted
that PR in #110354. The next master merge into this branch resolved cleanly
in text, yet silently kept the deleted history line in
`SettingsChangesHistory.cpp`, because this branch inserts its own new-settings
entries directly above it in the same `26.7` block. The setting declaration
itself was removed, so every `SET compatibility = ...` threw
`UNKNOWN_SETTING: Unknown setting 'input_format_parquet_dictionary_filter_push_down'`
from `applyCompatibilitySetting`, failing 19 tests in `Fast test`:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105249&sha=ff346faaaa81ae9d7072fc1714a5396d3870b73f&name_0=PR&name_1=Fast%20test

All 19 tests pass locally after removing the entry.

Co-Authored-By: Claude Fable 5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Jul 16, 2026
…ory entry

The 2026-07-15 merge of master kept the settings-changes-history entry for
`input_format_parquet_dictionary_filter_push_down` although the setting
itself was removed on master by the revert of #106952 (#110354): the entry
was adjacent to this branch's own `query_cache_use_only_when_data_was_not_changed`
line, so the three-way merge kept both sides without a textual conflict.

An orphan history entry makes `SettingsImpl::applyCompatibilitySetting` throw
`UNKNOWN_SETTING` for any `SET compatibility` older than 26.7, which failed
19 compatibility tests in Fast test:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108721&sha=bddca1b12a2ec30a986afcfc73d0cbb53f51780c&name_0=PR&name_1=Fast%20test
#108721
alexey-milovidov added a commit that referenced this pull request Jul 16, 2026
…onary-filter setting

A prior master merge picked up `input_format_parquet_dictionary_filter_push_down`
from #106952 while it was briefly on master; #110354 reverted that feature on
master, but because the net diff for that region looked unchanged relative to
older merge-bases, later merges kept the orphaned history entry with no
corresponding `DECLARE` anywhere in `src/`. Any `compatibility` setting older
than 26.7 then threw `UNKNOWN_SETTING` walking the history, failing every
compatibility-related Fast test (`02324_compatibility_setting`,
`03916_check_settings_constraints_erases_with_compatibility`, etc).
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Address review: replace `std::unordered_set<UInt64>` with our own
`HashSet<UInt64>` for the set of dictionary value hashes probed by
`DictionaryLookup`. The values are already well-distributed 64-bit hashes,
so this avoids node-based allocation and is faster to build and probe.

The API maps directly: `reserve` + `insert` to build, `contains` to probe.
`HashSet` is movable, so it still fits inside the `std::optional` return
value of `hashDictionaryValues` and the `DictionaryLookup::value_hashes`
member. A `0` hash - which can be produced, e.g. the `null_as_default`
default-value hash - is stored and looked up correctly via `HashSet`'s
dedicated zero-key cell.

ClickHouse#106952 (comment)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…_max_set_size

The dictionary filter reuses the bloom filter's prepared query-constant hashes,
so it inherited `hash_many`'s `bloom_filter_max_set_size` (default 100) cutoff:
an `IN` list with more than 100 elements set neither `use_bloom_filter` nor
`use_dictionary_filter`, silently disabling dictionary pruning for exactly the
large-constant-list workload the feature targets.

That cutoff is a bloom-filter heuristic - a large set is unlikely to be ruled
out by a probabilistic filter, and reading one filter block per hash is
wasteful. The dictionary lookup is exact and reads no extra data per value, so
the cutoff should not apply to it. `prepareBloomFilterCondition` now records
whether a column can use the dictionary page in any surviving row group, and
`hash_many` skips the cap for such columns; the cap still applies to columns
that can use nothing but the bloom filter. Results are unchanged - this only
enables more pruning.

Added `04494_parquet_v3_dictionary_filter_large_in_set`: a 150-element `IN`
list (above the 100-element cap) prunes a whole row group.

Addresses the AI review "Request changes" finding on
ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
`columnChunkCanUseDictionaryFilter` reads `page_type` and `encoding`
directly from the Thrift-decoded `encoding_stats`. Like `PageHeader`, a
malformed file can carry out-of-range enum values there, so the direct
comparisons took the same `-fsanitize=enum` undefined-behavior path that
`decodeAndCheckPageHeader` already guards against: with dictionary
filtering enabled, a corrupted `encoding_stats` entry could trip UBSan
before we even decided whether the row group is prunable.

Validate each `PageEncodingStats` `page_type` and `encoding` with
`checkThriftEnum` (which reads the underlying integer via `memcpy`, so no
out-of-range enumerator is ever loaded), and reject a negative page
`count`, so malformed metadata fails as `INCORRECT_DATA` instead of
taking the UB path. A `count` of zero keeps its previous meaning of an
empty page whose encoding is irrelevant.

Addresses the AI review "Request changes" finding on
ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…est output

The flaky check re-runs each test that a PR modifies many times under
randomized settings. `03036_test_parquet_bloom_filter_push_down` failed there
because its reference asserts `.statistics.bytes_read`, which is not
deterministic under randomized read settings (read buffer size, `mmap` vs
`pread`, direct I/O, prefetch) even though `rows_read` - the value these tests
actually assert - matched. In the failing run the query read the expected 536
rows but 4174 bytes instead of the reference 4997.

These tests already disable the randomized
`input_format_parquet_dictionary_filter_push_down` and strip
`.statistics.elapsed`; extend the same `jq` filter to also drop
`.statistics.bytes_read` in the three shell tests that print Parquet read
statistics (`03036_test_parquet_bloom_filter_push_down`,
`03036_test_parquet_bloom_filter_push_down_ipv6`,
`03261_test_merge_parquet_bloom_filter_minmax_stats`) and regenerate their
references. The tests keep asserting `rows_read`, the metric that reflects
row-group pruning.

CI report (flaky check): https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106952&sha=13720e505f5bb3538b08b638c08277d645afa8c1&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20flaky%20check%29
PR: ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…a requirement

Addresses the AI review "Request changes" verdict on PR ClickHouse#106952.

Finding 2 (missing docs): the new `input_format_parquet_dictionary_filter_push_down`
setting was declared in `FormatFactorySettings.h` but absent from both user-facing
settings tables. Add it (after `input_format_parquet_bloom_filter_push_down`) to
`docs/en/interfaces/formats/Parquet/Parquet.md` and to the in-source `DOCS_MD`
table in `ParquetV3BlockInputFormat.cpp`, documenting that `0` disables it, the
value is the maximum dictionary-page size in bytes, and it applies only when all
data pages of a column chunk are dictionary-encoded (it also takes precedence over
the bloom filter).

Finding 1 (behavior gap): document, at the eligibility check in
`columnChunkCanUseDictionaryFilter`, why dictionary filtering deliberately requires
a declared `dictionary_page_offset` and stays disabled for the "undeclared
dictionary page" legacy shape (writer omits `dictionary_page_offset` and points
`data_page_offset` at the dictionary page). Computing the dictionary page's byte
range in that shape needs the offset index, which is not available at the pruning
stage, and such files also typically lack the `encoding_stats` this check requires;
the only cost is a missed optimization, never a wrong result.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The setting `input_format_parquet_dictionary_filter_push_down` is documented
(PR body, `FormatFactorySettings.h`, `SettingsChangesHistory.cpp`, `Parquet.md`,
and the in-source settings table in `ParquetV3BlockInputFormat.cpp`) as the
maximum dictionary page size for which dictionary-based row group pruning is
applied. The eligibility check in `columnChunkCanUseDictionaryFilter` used
`>=`, which made the boundary exclusive and silently disabled pruning for a
dictionary page whose size is exactly the configured limit. Change the
predicate to `>` so the documented "maximum" is inclusive.

Addresses the AI code review finding on ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The previous commit let a column skip the `bloom_filter_max_set_size` cutoff
when any surviving row group could use its dictionary page, so that large `IN`
lists still get exact dictionary pruning. But it did this by setting the
per-column `use_bloom_filter` flag, which `initializePrefetches` also uses to
turn the (probabilistic) bloom filter back on for every non-dictionary row
group of that column.

On a mixed file - some row groups dictionary-encoded, others `PLAIN` with a
bloom filter - a `WHERE x IN (...)` with more than `bloom_filter_max_set_size`
constants would then read one bloom filter block per value on the bloom-only
row groups, which is exactly the expensive path the cutoff was meant to
suppress. The dictionary-encoded row groups need the hashes for exact pruning,
but the bloom-only ones should keep falling back to a full scan for such a
large set.

Separate the two concepts: `hash_many` now marks a column
`bloom_filter_set_too_large` when the set exceeds the cap, still hashes it for
the dictionary filter (which receives the hashes through the query-condition
RPN, not through `bloom_filter_hashes`), but does not register the hashes for
bloom-filter prefetching. `initializePrefetches` keeps the bloom filter
disabled for such a column. Dictionary pruning on the dictionary-encoded row
groups is unaffected; results are unchanged in every case - this only avoids
reading bloom filter blocks that the old heuristic already avoided.

There is no deterministic regression test: the only observable difference is
whether bloom filter blocks are read on the fall-back row groups (reflected in
non-deterministic `bytes_read`, which the tests here already strip), or a
deliberate choice to prune less on those row groups, which would require a
fragile mixed dictionary/`PLAIN`/bloom file to construct.

Addresses the AI review "Request changes" finding on
ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The previous commit kept a larger-than-cap `IN` set out of the bloom filter
(so it is used only by the exact dictionary filter) by marking the whole
column `bloom_filter_set_too_large`, which `initializePrefetches` then used to
disable the bloom filter for every non-dictionary row group of that column.

But `KeyCondition::prepareBloomFilterData` hashes each predicate atom
separately, so a column can carry both a small hashable atom and an over-cap
`IN`, e.g. `x = 'a' OR (x IN (<large set>) AND b = 2)`. The column-wide flag
then disabled the bloom filter for the small `x = 'a'` atom too: on a `PLAIN`
row group that has a bloom filter (min/max having already ruled out `b = 2`),
the cheap one-hash bloom probe for `x = 'a'` was skipped and the row group
fell back to a full scan.

Track the distinction per atom using the data we already have.
`bloom_filter_hashes` is the union of the query-constant hashes registered for
bloom-filter prefetching, and over-cap sets are already left out of it (they
still reach the exact dictionary filter through the query-condition RPN). So:

  * `initializePrefetches` enables the bloom filter for a column whenever
    `bloom_filter_hashes` is non-empty, i.e. as long as some atom is under the
    cap - not only when no atom is over it;
  * `BloomFilterLookup::findAnyHash` treats a value whose block was not
    prefetched (an over-cap hash) as possibly present. A bloom filter can only
    ever rule a value out, so this is always sound and simply falls back to the
    other pruning (min/max, or the dictionary filter on dictionary-encoded row
    groups).

The per-column `bloom_filter_set_too_large` flag is no longer needed and is
removed. Results are unchanged in every case; this only restores the bloom
pruning of the smaller atoms.

Added `04495_parquet_v3_dictionary_filter_large_in_keeps_bloom`: a mixed
`PLAIN`+bloom / dictionary-encoded file with a small equality and an over-cap
`IN` on the same column; the `PLAIN`+bloom row group is still pruned by the
small atom's bloom probe (this is the fragile mixed file the previous commit
mentioned as hard to construct - pinning the writer settings makes the row
groups and `rows_read` deterministic).

Addresses the AI review "Request changes" finding on
ClickHouse#106952

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…ry-filter-push-down

Parquet: dictionary-based row group filtering
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…nary_filter_push_down`

The setting was added by ClickHouse#106952 (merged into this branch on 07-13) and
reverted on master by ClickHouse#110354, but the merge kept the history entry
because it is adjacent to this PR's own `snappy_mode` entry. The orphan
entry made every query with a `compatibility` setting fail with
`UNKNOWN_SETTING`, which is what broke the Fast test on
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=100752&sha=bee84f139ca122148eaa99904c0a6dca3733cbd3&name_0=PR&name_1=Fast%20test

Co-Authored-By: Claude Fable 5 <[email protected]>
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
The merge of master at dcdabc1 kept the branch side of
src/Core/SettingsChangesHistory.cpp wholesale, retaining the history entry
for `input_format_parquet_dictionary_filter_push_down` although master had
removed both the entry and the setting itself when ClickHouse#106952 was reverted
by ClickHouse#110354. The orphan entry made `Settings::applyCompatibilitySetting`
throw `UNKNOWN_SETTING` for any query with a non-empty `compatibility`
setting, failing all 19 compatibility-family tests in Fast test:
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108944&sha=dcdabc13df899dbef3fdb4c5cccbbd9fadaf1803&name_0=PR&name_1=Fast%20test

Verified locally: `clickhouse local --compatibility=24.6` no longer throws,
`compatibility='26.6'` correctly rolls `mysql_datatypes_support_level` back
to `decimal,datetime64,date2Date32`, and `02325_compatibility_setting_2`
passes against its reference.

Co-Authored-By: Claude Fable 5 <[email protected]>
pull Bot pushed a commit to Mu-L/ClickHouse that referenced this pull request Sep 20, 2026
…rquet

`input_format_parquet_dictionary_filter_push_down` (ClickHouse#106952, re-landed in
ClickHouse#110567) lets the `Parquet` reader skip a whole row group for an equality or
`IN` condition when the column chunk is fully dictionary-encoded and its
dictionary page holds none of the values that are searched for. Nothing in
`tests/performance` covered it.

The fixture puts the reader in the situation the feature was written for, the
one a real `hits.parquet` is in: a low-cardinality string column whose values
are spread over the whole file, so min/max statistics prune nothing (every row
group's range spans every value searched for), and no bloom filters, which is
what most Parquet writers produce. The dictionary page is then the only
per-row-group structure that can rule a value out.

Measured locally on the fixture the test builds, at `max_threads = 1`, with
`input_format_parquet_dictionary_filter_push_down` off and on:

    query                                            off       on   rows read
    count(), value in 30 of 300 row groups        0.401s   0.040s   300M -> 30M
    count(), value in no row group                0.393s   0.004s   300M -> 0
    count(), IN over both of them                 1.107s   0.118s   300M -> 30M
    sum() of another column, same condition       0.060s   0.013s
    count(), value in every row group             0.421s   0.426s   300M -> 300M

The last query is the counterweight: nothing can be skipped there, so the
dictionary pages are read and hashed for nothing and the query must not become
slower.

Co-Authored-By: Claude Opus 5 <[email protected]>
alexey-milovidov added a commit to valerypetrov/ClickHouse that referenced this pull request Oct 7, 2026
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 ClickHouse#106952 and ClickHouse#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]>

This branch was successfully deployed

1 active deployment
staging - docs — 1beba647 Deployed Jul 12, 2026 by mintlify[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

5 participants