Skip to content

Parquet dictionary filter compares integer dictionary values with query constants directly - #124951

Open
groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:parquet-dictionary-filter-physical-constants
Open

groeneai wants to merge 4 commits into
ClickHouse:masterfrom
groeneai:parquet-dictionary-filter-physical-constants

Conversation

@groeneai

@groeneai groeneai commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #124669
Related: #123579

Changelog category (leave one):

  • Performance Improvement

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

Row group pruning by dictionaries in the Parquet reader is faster for = and IN conditions on integer columns, such as ClickBench q20 (WHERE UserID = ...): the dictionary values are compared with the query constants directly instead of being copied and hashed, also when several conditions on the column check the same dictionary.

Description

Proposed by @ snelheidai in #124669 (analysis and patch); the numbers below are my own.

For =/IN, the dictionary filter copied and hashed every value of a column chunk's dictionary and, above max(8, log2(n)) probes, sorted the hashes. An INT32/INT64 dictionary stores the decoded integers, so the constants can be compared with them directly.

Change. prepareBloomFilterCondition records the physical value of each hashed integer constant (at most 256 per column). DictionaryLookup compares the stored values with them, each constant at most once per dictionary however many conditions probe it: one vectorized pass each for the first 32, then one binary-search pass over the rest. Other types, encodings and more constants keep the hashed value set.

Measured (ThinLTO release, clickhouse local on 4 CPUs, 12-20 alternating pairs; outputs and ParquetReadPages identical):

hits.parquet Before After
q20, UserID = c 64 ms 56 ms
UserID IN (20 constants) 148 ms 83 ms
3 INs of 32, 32, 33 176.5 ms 131 ms
8 INs of 31 281 ms 233 ms
IN of 257 (hashed set) 144 ms 145 ms

100 files: q20 0.79x, 20 constants 0.47x. Synthetic dictionaries of 256-65536 values: nothing slower; of 16: within 3%.

Validation. New test 05345_parquet_v3_dictionary_filter_physical_constants compares counts and rows_read with the filter on and off for every integer width and sign, extreme values, Nullable with input_format_null_as_default, and conditions holding different found constants. 04615 also prunes by the comparison under a memory budget the hashed set does not fit. 04614/04615 (301 constants) and 05317 (a String column) keep testing the hashed set. The perf test gains queries that reach the filter.

🤖 Generated with Claude Code


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

groeneai and others added 2 commits October 9, 2026 15:18
…ry constants directly

For `=` and `IN` on an INT32/INT64 column whose dictionary page stores the decoded
integers, the v3 reader's dictionary filter no longer copies and hashes every dictionary
value: it compares the stored values with the physical values of the query constants,
recorded with their hashes when the condition is prepared (at most 256 per column). Each
constant is compared with a dictionary at most once, however many conditions on the column
probe it: one vectorized pass each for the first 32, then one pass with a branchless binary
search over all the remaining ones. More constants, other types and other dictionary
encodings keep the hashed value set.

Proposed by snelheidai in ClickHouse#124669 (analysis
and patch). The patch's per-lookup pass budget is replaced by comparing each constant at
most once per dictionary, which avoids building the hashed value set after the budget was
spent when several conditions on one column probe the same dictionary.

Tests: new 05345 (every integer width and sign, extreme values, Nullable output and
`input_format_null_as_default`, which condition holds a found constant); 04614, 04615 and
05317 keep testing the hashed path; 04615 also checks the direct comparison under a memory
budget the hashed value set does not fit; the performance test gains queries that reach the
dictionary filter.

Closes: ClickHouse#124669
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop design narration and motivation from the comments added by the dictionary filter change; keep the invariants (null handling, the cast parquetTryHashColumn applies, hash collisions).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-issue PR origin: picked up an external GitHub issue labels Oct 9, 2026
@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 3 rounds, 4 findings) plus my own review (6 findings), at dd78cf0.

# Sev Finding Verdict Evidence / action
1 ⚠️ The null-handling rule of the dictionary filter is written twice (hashDictionaryValues, findPhysicalConstants) AGREE, fixed one helper, hashDictionaryNulls, used by both paths
2 ⚠️ The 256-constant cap counts repeated constants across conditions AGREE, fixed distinct constants are counted; 04615 line with two overlapping sets of 151 (201 distinct)
3 ⚠️ ... and counts the rows of a tuple set, e.g. (category, n) IN ((5, 0), ..., (5, 300)) AGREE, fixed binary-search dedup while recording, no raw-size cutoff; 04615 tuple line (32768 rows read before, 16384 after)
4 ⚠️ 05345 cannot tell the direct comparison from the hashed fallback AGREE in part, fixed 04615 lines under a budget the hashed set does not fit (1, 41, 2 x 151 constants, the tuple set)
5 ⚠️ ... including per integer type DISAGREE a wrong type mapping gives wrong answers on 05345's sign-bit/extreme lines; a decline is a cost property measured by the perf test
6 💡 parquetTryPhysicalInteger mirrors tryHashInt DISAGREE every recorded constant is re-checked against its hash, which also validates the typed-column hashes of IN sets
7 💡 Commit message overstates 05345's input_format_null_as_default coverage AGREE, fixed reworded
8 💡 04615's "prunes row group 0 despite its default-extended value set" line is now decided by the direct comparison AGREE, fixed it goes back to the hashed set (301 constants)
9 💡 The direct path re-derives the null rule per lookup noted, not blocking only for a nullable chunk read as non-nullable under input_format_null_as_default; about a microsecond per condition
10 💡 04615's tuple line says "same watermark" but runs at 5000000, not 4000000 noted, not blocking the value is needed: at 4000000 neither build prunes for this two-column query

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding. Findings on hunks unchanged by the fix round are auto-dropped.

Session id: cron:clickhouse-review-slot-10:20261009-155000

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes, as a timing A/B: clickhouse local over ClickBench hits.parquet, alternating base/fix processes on 4 pinned CPUs; e.g. UserID IN (20 constants) 148 ms vs 83 ms, ratio 0.568 [0.554, 0.582] over 20 pairs. Outputs and ParquetReadPages identical in every run.
b Root cause explained? For =/IN the dictionary filter answers in hash space: it copies every dictionary value into a new column, hashes each, and sorts the hashes once a chunk gets more than max(8, log2(n)) probes. For an INT32/INT64 dictionary the stored bytes already are the decoded integers, so the copy, the hashes and the sort are overhead.
c Fix matches root cause? Yes: the constants' physical values are recorded once at prepare time and compared with the stored values directly; each constant is compared with a dictionary at most once, so several conditions on one column never repeat work or fall back to the hashed set.
d Test intent preserved / new tests added? New 05345_parquet_v3_dictionary_filter_physical_constants (on/off agreement and rows_read for every integer width, sign and extreme value, Nullable, input_format_null_as_default, per-condition attribution). 04614, 04615 and 05317 keep testing the hashed set (301 constants, a String column). Perf test gains queries that reach the dictionary filter.
e Both directions demonstrated? Perf: base vs fix A/B (table in the description). Correctness: 05345 passes on master and on the fix; each mutation of the comparison, the binary search, the per-constant bookkeeping and the null handling reddens the lines it covers; disabling the hashed set changes only the two 300-constant lines.
f Fix is general across code paths? = (hash_one), IN sets incl. Nullable set columns, tuple sets (hash_many), every decoded integer type of INT32/INT64; FixedSize dictionaries from trivial and non-trivial converters. Strings, decimals, dates, IPv4, Enum and other dictionary modes keep the hashed path unchanged.
g Fix generalizes across inputs (params/datatypes/wrappers)? Int8..Int64, UInt8..UInt64, sign bit and both extremes of each type, Nullable with input_format_null_as_default (05345) and without it (04340), 1, 12, 32, 33, 100, 256, 257, 300 constants and several INs on one column; synthetic dictionaries of 16 to 65536 values.
h Backward compatible? (maintainer-approved exception only) Yes: no setting, no format change; pruning decisions equal the hashed path's (which could only add false positives on XXH64 collisions).
i Invariants and contracts preserved? A found/absent answer is recorded only after the comparison on this column chunk's dictionary; the memo lives in the per-chunk DictionaryLookup and the recorded constants are immutable after prepare. Every gate failure (type, size, nulls) returns before the memo is touched and falls back to the unchanged hashed path, its memory reservation and the bloom filter fallback.

Session id: cron:clickhouse-impl-slot-6:20261009-114600

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b56741f]

Summary: ❌

job_name test_name status info comment
Build (arm_tidy, 4/4) FAIL
Build ClickHouse FAIL cidb
Build (amd_debug) DROPPED
Build (amd_asan_ubsan) DROPPED
Build (amd_tsan) DROPPED
Build (amd_msan) DROPPED
Build (amd_binary) DROPPED
Build (arm_asan_ubsan) DROPPED
Build (arm_binary) DROPPED
Build (amd_release) DROPPED
Build (arm_release) DROPPED

AI Review

Summary

The PR speeds up Parquet dictionary pruning for integer equality and IN predicates by comparing decoded dictionary values directly with query constants and caching each constant's presence per dictionary. No actionable correctness, safety, compatibility, or performance findings were identified. The reported before/after measurements and focused regression coverage support the change.

Missing context / blind spots
  • ⚠️ Runtime tests were not rerun locally because this checkout has no ClickHouse binary or configured build. The latest Praktika run skipped runtime jobs following the arm_tidy build failure. Successful runs of 04614, 04615, 05317_parquet_dictionary_filter_several_conditions_on_one_column, and 05345_parquet_v3_dictionary_filter_physical_constants on the current head would close this independent validation gap; the PR documents earlier successful regression runs.
Final Verdict

Status: ✅ Approve based on the current code, regression coverage, and reported performance evidence. No new inline findings.

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

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

This PR only changes the Parquet v3 reader's row-group dictionary filter: integer dictionaries are now compared directly against query constants instead of hashing every dictionary value. Neither clickbench nor tpch_adapted_1_official reads Parquet files, so no change is expected and no query is flagged. The one suppressed row, clickbench Q31 (-13.1%, 297 ms to 258 ms), is consistent with that. Master shifted on 2026-10-09, and the PR's median sits inside master's current range of 241 to 357 ms. The effect of this change would show in the parquet_dictionary_filter performance test rather than in these benchmarks.

clickbench

🟢 No significant changes

tpch_adapted_1_official

🟢 No significant changes

Debug info
  • StressHouse run: f1b01003-db32-4b3f-9b54-1b4ce242aeb6
  • MIRAI run: d37d756b-72d0-417e-bef5-b1dea600ae5f
  • PR check IDs:
    • clickbench_646078_1791597340
    • clickbench_646084_1791597341
    • clickbench_646090_1791597341
    • tpch_adapted_1_official_646101_1791597340
    • tpch_adapted_1_official_646112_1791597340
    • tpch_adapted_1_official_646149_1791597340

@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit d85e9d3412d038bec249a47b8fdb38cbb1e82e99 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

@groeneai

groeneai commented Oct 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 9122fe9

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 1/2) / 05316_secret_arguments_declared_by_engines not from this PR: under DatabaseReplicated the test's last query_log check counts the CREATE DICTIONARY row twice (0 2 instead of 0 1; the password stays hidden). 180 PRs show it since 2026-10-02 #124928 (external, merged 17:58Z). This run was dispatched at 16:25Z, before that merge, so I will merge master here to pick it up
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05317_local_read_throttler_filesystem_cache flaky, not from this PR (a different test than this PR's 05317_parquet_dictionary_filter_several_conditions_on_one_column): the ProfileEvents check reads 0 1 instead of 1 1 because under parallel replicas another replica did the read. 98/98 reruns pass; 14 PRs show it since 2026-10-06 #124920 (mine, open)
Mergeable Check, PR praktika rollups of the two stateless rows above (Failed: 2) #124928 (external, merged), #124920 (mine, open)

Session id: cron:our-pr-ci-monitor:20261009-230008

…filter-physical-constants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…filter-physical-constants

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@al13n321
al13n321 removed their request for review October 29, 2026 16:44

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-parquet-reader-v3 Issues related to the native Parquet reader. groeneai-origin-issue PR origin: picked up an external GitHub issue pr-performance Pull request with some performance improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parquet dictionary filter: INT32/INT64 dictionaries are copied into a new column before hashing; hashing them in place makes ClickBench q20 6% faster

2 participants