Skip to content

Shuffle input rows in 05407_distributed_plan_exchange_compression_default - #127186

Merged
davenger merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05407-shuffle-input-rows
Oct 21, 2026
Merged

davenger merged 1 commit into
ClickHouse:masterfrom
groeneai:groeneai/05407-shuffle-input-rows

Conversation

@groeneai

@groeneai groeneai commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #126743
Related: #123537

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

Test-only change, no changelog entry required.

Description

05407_distributed_plan_exchange_compression_default fails since #123537 merged: 05407_default, 05407_empty_lz4 and
05407_zstd_exchange_level print 1 0 instead of 1 1 in the compressed column (5 failures in about 2 hours, 2 of them on master:
amd_debug,
arm_binary ParallelReplicas).

Compression is applied, but the oracle sent < serialized no longer holds. Without NDV statistics for k (a randomized
auto_statistics_types without uniq*, or use_statistics = 0) the aggregation now shuffles partial states, and a randomized
group_by_two_level_threshold = 1 or group_by_two_level_threshold_bytes = 1 makes them two-level. The exchange then sends about 1000
packets of about 110 bytes. The per-packet framing, written for every codec, costs more than LZ4 saves: LZ4 sends 133 KB for 112 KB
serialized, while NONE sends 156 KB.

The fix sets distributed_plan_force_shuffle_aggregation = 1, as 478d701 did for 05218. The exchange then carries the input
rows (about 4 MB in 14 packets) whatever the aggregation settings, which is the payload this query had before #123537. The reference
is unchanged.

Validation: with fixed settings, the unpatched test failed 10/10 (CI's diff) and the patched one passed 50/50, both for
group_by_two_level_threshold{,_bytes} = 1 + auto_statistics_types = 'tdigest' and for group_by_two_level_threshold_bytes = 1 +
use_statistics = 0. With full randomization it passed 250/250. Before #123537 the unpatched test passed under the same settings. With
distributed_plan_exchange_compression_method = 'NONE' on the default run, the patched test fails as it should.


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

Version info

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

…ault

The test checks that the streaming exchange compresses, i.e. that it writes
fewer bytes to the sockets than the Native blocks it serializes. Since ClickHouse#123537
a distributed aggregation without NDV statistics shuffles partial aggregation
states. With a randomized `group_by_two_level_threshold = 1` or
`group_by_two_level_threshold_bytes = 1` the partial aggregation is two-level,
so the states cross the exchange as ~1000 packets of ~110 bytes, and the
per-packet framing, written for every codec, outweighs what the codec saves:
LZ4 sends 133 KB for 112 KB serialized (NONE sends 156 KB).

Force the shuffle of the input rows, as 478d701 did for the sibling
05218: the exchange then carries ~4 MB in 14 packets whatever the aggregation
settings, and LZ4 sends 11% of it.

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 cold review (1 finding).

# Sev Finding Verdict Evidence / action
1 💡 The description counted all 5 CI failures as master failures; 3 of them are unrelated PRs AGREE, fixed in the PR description none in code

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

Session id: cron:clickhouse-review-slot-8:20261021-133100

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. tests/clickhouse-test 05407_distributed_plan_exchange_compression_default --test-runs 10 --settings "--group_by_two_level_threshold 1 --group_by_two_level_threshold_bytes 1" --merge-tree-settings "--auto_statistics_types tdigest" fails 10/10 with CI's diff; so does --settings "--group_by_two_level_threshold_bytes 1 --use_statistics 0" --no-random-merge-tree-settings.
b Root cause explained? Without NDV statistics the aggregation shuffles partial states (since #123537); two-level partial aggregation splits them into about 1000 packets of about 110 bytes, and the codec-independent per-packet framing then exceeds the LZ4/ZSTD saving, so sent < serialized is false although compression is applied (LZ4 133 KB vs NONE 156 KB for 112 KB).
c Fix matches root cause? Yes. distributed_plan_force_shuffle_aggregation = 1 makes the exchange carry the input rows (14 packets, about 4 MB), the payload this query had before #123537 (byte-identical counts measured on a pre-#123537 binary). Same remedy as 478d701 for 05218. No widened bound, no blanket tag.
d Test intent preserved / new tests added? Yes. The codec is chosen once per query, so the asserted codec selection (default, empty, exchange ZSTD level, compatibility, rejected codecs) is unchanged; the reference is unchanged. Adding distributed_plan_exchange_compression_method = 'NONE' to the default run makes the patched test fail. Test-only change.
e Both directions demonstrated? Yes. Both fixed-settings arms: 10/10 FAIL unpatched, 50/50 OK patched, same binary. Defaults 10/10 OK; full randomization 250/250 OK.
f Fix is general across code paths? The only other test reading these counters, 05218, already forces the shuffle for its GROUP BY runs (0 failures since #123537). No product defect: LZ4 sends less than NONE on the same payload.
g Fix generalizes across inputs (params/datatypes/wrappers)? N/A (test-only). 250 randomized runs included 79 two-level draws, tdigest-only statistics and use_statistics = 0.
h Backward compatible? (maintainer-approved exception only) N/A (test-only; no setting or format change).
i Invariants and contracts preserved? The NONE and compatibility rows still send more than they serialize (framing is always added), and every run still goes through the exchange (14 packets each, also under compatibility = '26.10').

Session id: cron:clickhouse-impl-slot-4:20261021-130407

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @davenger, could you review this and add the can be tested label so CI runs? Since #123537 the test can shuffle about 1000 tiny two-level partial-state packets whose per-packet framing outweighs the LZ4 saving, so it now sets distributed_plan_force_shuffle_aggregation = 1 (as 478d701 did for 05218) to keep the input-row payload.

@clickhouse-gh

clickhouse-gh Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b42f813]

Summary: ✅


AI Review

Summary

The PR sets distributed_plan_force_shuffle_aggregation = 1 in 05407_distributed_plan_exchange_compression_default so the exchange carries compressible input rows rather than small partial aggregation states. The existing codec, compression-level, and compatibility assertions and reference output remain intact. No actionable findings for head b42f8133e5f8f18c6e8f3032ec53fa808219b244.

Missing context / blind spots
  • ⚠️ No local ClickHouse executable was available, and the targeted stateless CI reports contained no completed test results when inspected. Independent runtime confirmation remains pending; the author's validation reports deterministic before/after runs, 250 randomized passes, and a disabled-compression negative control. A completed targeted CI run would close this gap.
Final Verdict

Status: ✅ Approve. No review changes requested.

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Oct 21, 2026
@davenger davenger added the can be tested Allows running workflows for external contributors label Oct 21, 2026
@davenger davenger self-assigned this Oct 21, 2026
@davenger

Copy link
Copy Markdown
Member

@groeneai Should there be distributed_plan_partial_aggregation_before_shuffle=0 to force non-aggregated rows to be sent?

@clickhouse-gh clickhouse-gh Bot added the comp-testing Test content only (no production code). label Oct 21, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

No. distributed_plan_partial_aggregation_before_shuffle = 0 only turns off the shuffle of partial states, so it sends input rows only where the planner had already chosen a shuffle. With the default basic, uniq_v2 statistics, 1000 groups are not above distributed_plan_max_rows_to_broadcast (makeDistributed.cpp#L829), so the plan stays Aggregating (partial) -> GatherExchange -> MergingAggregated. Under enable_cascades_optimizer = 1 (the stress test sets it in 20% of runs, stress.py#L569-L570) the two-stage split is also still allowed. distributed_plan_force_shuffle_aggregation = 1 rules out both (makeDistributed.cpp#L872-L873, AggregationImplementations.cpp#L325, #L424), so adding the other setting to it changes nothing.

I measured this on the PR's binary for the 05407_default run (LZ4), 3 runs per cell, as exchange packets and serialized -> sent bytes:

Randomized settings Test before this PR ..._before_shuffle = 0
defaults 13 packets, 80 KB -> 19 KB same
two-level, default statistics 778 packets, 96 KB -> 85 KB same
two-level, no NDV (the CI failure) 994 packets, 112 KB -> 133 KB, fails 14 packets, 3.99 MB -> 425 KB
two-level, no NDV, Cascades 994 packets, 112 KB -> 133 KB, fails 516 packets, 96 KB -> 80 KB

With force_shuffle = 1 every row is 14 packets, 3.99 MB -> 425 KB, and adding ..._before_shuffle = 0 to it gives byte-identical counts. With only ..._before_shuffle = 0, rows 2 and 4 still send 120-190 B state packets, where LZ4 saves only 11-17%. So I'd keep the PR as it is.

@davenger
davenger enabled auto-merge October 21, 2026 16:11
@davenger
davenger added this pull request to the merge queue Oct 21, 2026
Merged via the queue into ClickHouse:master with commit 90fce32 Oct 21, 2026
526 of 528 checks passed
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 21, 2026
@clickhouse-gh clickhouse-gh Bot added comp-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... and removed comp-testing Test content only (no production code). labels Nov 22, 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-distributed-query-exchange Distributed Query Execution with Exchange operators: cloud-native query distribution using stream... pr-ci 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