Skip to content

Resize after the sources of a split Parquet file - #131140

Merged
tiandiwonder merged 5 commits into
ClickHouse:masterfrom
groeneai:parquet-split-file-resize
Nov 13, 2026
Merged

tiandiwonder merged 5 commits into
ClickHouse:masterfrom
groeneai:parquet-split-file-resize

Conversation

@groeneai

@groeneai groeneai commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Performance Improvement

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

When a single local Parquet file is read by several streams, the rows read by each stream are now spread over several threads after the read, so a filter that keeps rows from only a few row groups no longer leaves most threads idle. ClickBench Q39 on a single hits.parquet is 1.7x faster at 16 and 32 threads.

Description

Related: #125738, #130740. Follow-up requested in #125738 (comment); analysis, patch and the grouping by @ snelheidai (#125738 (comment), #125738 (comment)).

A split file has as many sources as threads, and ReadFromFile::initializePipeline added a Resize only when there were fewer sources than threads. So the rows of each bucket stayed on the chain of the source that read it. With CounterID = 62 only 3 of 226 row groups of hits.parquet pass, and @ snelheidai measured one of 32 threads aggregating 467,687 of 722,688 rows for Q39. This PR adds a Resize after the sources of a split file, in groups of 8 streams (capped by min_outstreams_per_resize_after_split, so 0 disables the grouping). One Resize over all streams made short queries switch threads far more often: Q1 at 32 threads had 3,284 context switches per query, against 693 on master and 1,269 with groups of 8.

Measured on x86 (release, one binary switching the variants, 20-30 paired rounds, ratio to master): Q39 0.60 at 16 threads, 0.56-0.60 at 32, 0.62 at 96; Q36 0.80-0.84, Q37 0.77-0.83, Q40 0.85-0.86. Q1/Q7 at 32 threads: 1.00-1.08 in a fresh process, 1.12/1.04 for 200 runs in one process (one Resize: 1.06-1.22, and 1.64/1.36). Q27 is 3-8% slower. Geomean over all 43 queries at 16 threads 0.975. Results are identical for 8 checking queries at 16-96 threads. #125275 replaces this condition with a sticky Resize. aarch64 not measured.

Tests: 05394_parquet_single_file_parallel_read checks the Resize at 4 and 16 threads and with the grouping disabled, 02725_parquet_preserve_order.reference gains it, and parquet_single_file_unequal_row_groups.xml gets a query that only reads the first two row groups (0.30x of master locally).


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

Version info

  • Merged into: 26.11.1.2157-master (included in 26.11 and later)

groeneai and others added 3 commits November 11, 2026 17:47
… threads

`ReadFromFile::initializePipeline` added a `Resize` only when there were
fewer sources than threads. A split single file has as many sources as
threads, so the rows read from a bucket stayed on the chain of transforms
of the source that read it. When the rows passing a filter sit in a few
row groups (e.g. `CounterID = 62` in ClickBench), a few threads did all
the aggregation while the others idled.

Analysis and patch by @ snelheidai in
ClickHouse#125738 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`05394_parquet_single_file_parallel_read` checks that the pipeline of a
split file has a `Resize` after its sources. The performance test gets a
query whose filter keeps only the first two row groups (1.5M and 0.5M
rows), so without the `Resize` at most two streams do the per-row work.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the split-file Resize comment to the property it relies on.

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

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

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (3 nits).

# Sev Finding Verdict Evidence / action
1 💡 output_ports > 1 is redundant for a split file (a split always has at least 2 sources) AGREE harmless, kept as in the original patch
2 💡 PR text overstated how much of the cost #125275 avoids AGREE, fixed in the description none

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-10:20261112-215100

@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [dcc2f1c]

Summary: ✅


AI Review

Summary

Reviewed #131140 at dcc2f1c0c4000c0dc6950789d4f0a4e2708930f8, including all prior discussion. The PR adds grouped Resize processors after split local Parquet reads to distribute downstream work, with functional and performance coverage. The linked paired benchmarks support the improvement and document the short-query tradeoff. No actionable findings remain, and no new inline comments were posted.

Final Verdict

✅ Approve.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. EXPLAIN PIPELINE of a split file has no Resize on master (05394's new query returns nothing); ClickBench Q39 on one hits.parquet is slower on master in every paired round.
b Root cause explained? A split file has resize_to sources and ReadFromFile::initializePipeline resized only when output_ports < resize_to, so each bucket's rows stayed on the chain of the source that read it; with a selective filter a few threads did all the post-read work.
c Fix matches root cause? Yes: the split pipeline gets the same Resize the many-file branch already uses; nothing is gated or guarded.
d Test intent preserved / new tests added? 05394 asserts the Resize (new query, no existing query changed); 02725's reference shows it; the performance test gets a query reading only the first two row groups.
e Both directions demonstrated? 02725 and 05394 fail on a master-equivalent debug server and pass on the fix; Q39 0.53-0.68 and the new perf query 0.30 fix/base.
f Fix is general across code paths? The many-file branch and a 1-source split are unchanged; ReadFromObjectStorageStep has no single-object split on master; URL/HDFS/Azure do not split.
g Fix generalizes across inputs (params/datatypes/wrappers)? Only splittable reads change (one seekable uncompressed Parquet file, no preserve-order, not count-only/statistics/TopN/lazy); results identical on master and fix for 10 ClickBench queries, sum(cityHash64(*)) over all columns, at 16 and 96 threads.
h Backward compatible? (maintainer-approved exception only) Yes: no setting or format change; only the EXPLAIN PIPELINE shape of split reads changes.
i Invariants and contracts preserved? A Resize does not change the set of rows; the query condition cache write and the file-changed check stay in the sources; order-preserving reads are never split.

Session id: cron:clickhouse-impl-slot-7:20261112-214600

@clickhouse-gh clickhouse-gh Bot added the pr-performance Pull request with some performance improvements label Nov 12, 2026
@clickhouse-gh clickhouse-gh Bot added can be tested Allows running workflows for external contributors comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing dcc2f1c0c with master 365bb22b2 (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

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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.61, programs/clickhouse-keeper ×0.62 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 5.5 s 11.3 s +7.9 s (+234%)
programs/clickhouse _ZN6detail10static_forITk7is_enumN2DB23AttributeUnderlyingTypeEZNS1_29callOnDictionaryAttributeType… 3.3 s 7.2 s +5.1 s (+254%)
Compile time of recompiled translation units

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

Job report

One `Resize` over all streams lets any thread take a source's chunks, so
short queries switch threads several times as often. ClickBench on one
`hits.parquet`, x86 release, one binary switching the variants, paired
rounds, ratio to master (95% CI):

- Q1 at 32 threads, x200 in one process: one `Resize 32 -> 32` 1.64
  [1.56, 1.73] (3284 context switches per query, master 693), groups of
  8 1.12 [1.06, 1.18] (1269). Q7: 1.36 vs 1.04.
- Q1/Q7 at 32 threads, fresh process: 1.12/1.11 vs 1.01/1.01.
- Gains kept at 16/32/96 threads: Q39 0.60/0.56-0.60/0.62 (one Resize:
  0.60/0.57-0.60/0.61), Q36 0.83/0.80-0.84/0.83, Q40 0.86/0.85/0.85.
- Results identical for 8 checking queries at 16, 32 and 96 threads.

The group size is capped by `min_outstreams_per_resize_after_split`, so
0 still disables the split; its default (24) alone would not split the
`Resize` below 48 streams. Below 16 streams it stays one `Resize`.

Suggested and measured first by snelheidai:
ClickHouse#125738 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tiandiwonder tiandiwonder self-assigned this Nov 13, 2026
Comment thread src/Storages/StorageFile.cpp Resolved
Comment thread src/Storages/StorageFile.cpp Resolved
Review: ClickHouse#131140 (comment)

The default of `min_outstreams_per_resize_after_split` (24) splits a `Resize`
only from 48 streams, so honouring it would leave one `Resize 16 → 16` or
`Resize 32 → 32` after the sources of a split file, which costs short queries
(ClickBench Q1 1.64x of master at 32 threads in one process, vs 1.12x with
groups of 8). No behaviour change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@tiandiwonder
tiandiwonder added this pull request to the merge queue Nov 13, 2026
Merged via the queue into ClickHouse:master with commit 0a251a7 Nov 13, 2026
204 checks passed
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 13, 2026
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-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). 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