Skip to content

Parquet: fuse dictionary-index decoding with the dictionary gather - #115819

Merged
alexey-milovidov merged 1 commit into
masterfrom
parquet-fused-dictionary-index
Aug 29, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
parquet-fused-dictionary-index

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Dictionary-encoded Parquet data pages were decoded in two passes: expand the RLE/bit-packed indexes into a temporary UInt32 column, then gather the dictionary values at those indexes into the output column (Dictionary::index). In hits.parquet, ~74% of all values sit in RLE runs of a repeated index (average run length 91 — the stats are quoted in a comment in the decoder), so most of that work was expanding runs into explicit indexes only to gather the very same dictionary value again and again — plus a full write + read pass over the temporary indexes column for everything else.

This fuses the two passes (PageDecoder::decodeAndIndex, overridden by BitPackedRLEDecoder):

  • an RLE run becomes a single dictionary lookup and a bulk fill of the value;
  • bit-packed runs are unpacked into a small stack buffer — with the bounds check hoisted out of the inner loop to once per batch, so the loop body is branch-free — and gathered from there;
  • Mode::Column dictionaries keep the old path (IColumn::index needs the indexes as a column anyway), as does anything else through the base-class fallback in the reader.

On ClickBench Q3 (SELECT SUM(AdvEngineID), COUNT(*), AVG(ResolutionWidth) FROM hits) over hits.parquet on 2 cores this is 21% faster (0.46 s → 0.36 s, best of 3, interleaved A/B of otherwise identical builds); in the profile, the dictionary gather that took 27% of the query's CPU disappears, closing about half of the gap to DuckDB on this query (0.25 s). Results are bit-identical on checksums over seven dictionary-encoded hits columns (including strings) and on nullable dictionary-encoded columns; the Parquet dictionary-filter, prewhere, filter-pushdown and preserve-order stateless tests all pass. The existing clickbench_parquet_short.xml performance test covers these query shapes.

Profiling context, for the record: after this change the remaining CPU of such queries is snappy decompression, the (now leaner) bit-unpacking, and the aggregation itself. Possible future refinements: SIMD bit-unpacking and batching the per-run insertRawUninitialized bookkeeping.

Changelog category (leave one):

  • Performance Improvement

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

Reading dictionary-encoded Parquet data got faster: the dictionary indexes are now decoded and resolved to values in one fused pass, turning runs of a repeated value into bulk fills instead of per-row gathers (~20% faster scans of dictionary-encoded numeric columns).


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

Version info

  • Merged into: 26.9.1.343 (included in 26.9 and later)

Dictionary-encoded data pages were decoded in two passes: expand the
RLE/bit-packed indexes into a temporary UInt32 column, then gather the
dictionary values at those indexes into the output column
(Dictionary::index). In hits.parquet, ~74% of all values sit in RLE
runs of a repeated index (average run length 91), so most of that work
was expanding runs into explicit indexes only to gather the very same
dictionary value again and again - plus a full write + read pass over
the temporary indexes column for everything else.

Fuse the two passes (PageDecoder::decodeAndIndex, overridden by
BitPackedRLEDecoder): an RLE run becomes a single dictionary lookup
and a bulk fill of the value, and bit-packed runs are unpacked into a
small stack buffer - with the bounds check hoisted out of the inner
loop to once per batch - and gathered from there. Mode::Column
dictionaries keep the old path (IColumn::index needs the indexes as a
column anyway), as does anything else through the base-class fallback.

On ClickBench query 3 (SELECT SUM(AdvEngineID), COUNT(*),
AVG(ResolutionWidth) FROM hits) over hits.parquet on 2 cores this is
21% faster (0.46 s -> 0.36 s); the dictionary gather that took 27% of
the query's CPU disappears from the profile. Results are bit-identical
on checksums over seven dictionary-encoded hits columns (including
strings) and on nullable dictionary-encoded columns.

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

clickhouse-gh Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3e02764]

Summary: ✅


AI Review

Summary

This PR fuses Parquet dictionary-index decoding with the dictionary gather for dictionary-encoded data pages, while keeping the existing fallback for dictionary modes that still require materialized index columns. I read the current diff and touched files in full, checked prior PR discussion and review threads, and did not find a correctness, safety, compatibility, test-coverage, or PR-metadata issue in the current head.

Final Verdict

✅ No findings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 87.00% 87.00% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 105/115 (91.30%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Aug 21, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3e02764ab with master 6e4e77ec8 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 704.50 MiB 701.48 MiB -3.02 MiB (-0.43%)

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 units

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

Median compile-time ratio to the baselines is ×0.93 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost -12.8 s (-8%) in total before that adjustment.

Job report

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

📊 Cloud Performance Report

⚠️ AI verdict: not_sure — no significant changes across 34 queries analysed

This change is entirely in the Parquet dictionary-decoding reader (fused decode-and-gather). The two flagged queries are TPCH Q7 and Q17, which run against native storage and never touch the Parquet reader, so neither delta can plausibly be attributed to this PR. Both were already marked not_sure because their baselines are unstable and, for Q17, the underlying measurements are very noisy. No actionable regression here; the deltas are run-to-run variance on an unrelated code path.

clickbench

🟢 No significant changes

tpch_adapted_1_official

⚠️ 2 inconclusive

Flagged queries (2 of 22)
Query Verdict Baseline median (ms) PR median (ms) Change q-value Hint
⚠️ 7 not_sure 67 79 +17.9% <0.0001 This PR only touches the Parquet dictionary-decode path; TPCH Q7 reads native storage and never exercises it, so the +17.9% delta is off-path baseline instability, not a PR effect.
⚠️ 17 not_sure 64 103 +60.9% <0.0001 Q17's baseline is unstable and the measurements are very noisy; the change is off-path from a Parquet-only PR, so the +60.9% reading is variance rather than a real regression.

Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on.

Debug info
  • StressHouse run: 564bf9e6-ab62-4d52-9b27-5c7907e120cc
  • MIRAI run: 60513ff8-be0e-4d4a-893b-58fc568014af
  • PR check IDs:
    • clickbench_7940_1787339712
    • clickbench_7954_1787339713
    • clickbench_7968_1787339712
    • tpch_adapted_1_official_8360_1787339754
    • tpch_adapted_1_official_8490_1787339800
    • tpch_adapted_1_official_8592_1787339840

@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.

Looks good.

@alexey-milovidov alexey-milovidov self-assigned this Aug 29, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 29, 2026
Merged via the queue into master with commit 78c9d47 Aug 29, 2026
353 of 354 checks passed
@alexey-milovidov
alexey-milovidov deleted the parquet-fused-dictionary-index branch August 29, 2026 14:42
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 29, 2026
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.

2 participants