Skip to content

Backport #114523 to 26.6: Fix wrong results of the partial aggregation strategy in distributed query plans - #118813

Merged
clickhouse-gh[bot] merged 5 commits into
26.6from
backport/26.6/114523
Sep 13, 2026
Merged

clickhouse-gh[bot] merged 5 commits into
26.6from
backport/26.6/114523

Conversation

@robot-clickhouse-ci-1

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Original pull-request #114523
Cherry-pick pull-request #118798

This pull-request is a last step of an automated backporting.
Treat it as a standard pull-request: look at the checks and resolve conflicts.
Merge it only if you intend to backport changes to the target branch, otherwise just close it.

The PR source

The PR is created in the CI job

Version info

  • Merged into: 26.6.6.14

@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backport Changes, backported to release branch. Do not use manually - automated use only! label Sep 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [dbe0425]

Summary: ✅

@nickitat

nickitat commented Sep 8, 2026

Copy link
Copy Markdown
Member

@copilot pls fix the build

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@copilot pls fix the build

Fixed in bb3a6e19: make the bucket-order flag writable so the new setter compiles.

@CLAassistant

CLAassistant commented Sep 8, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ PedroTadim
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

PedroTadim and others added 3 commits September 10, 2026 12:12
…n 26.6

  Code: 115. DB::Exception: Setting explain_query_plan_default is neither a builtin
  setting nor started with the prefix 'SQL_' or 'custom_' ... (UNKNOWN_SETTING)

The test failed on its very first statement, deterministically (45/45 and
103/103 in the harness's own diagnosis). The setting pins the legacy EXPLAIN
renderer, which arrived together with the new one in 26.7; 26.6 has only the
legacy renderer, so the EXPLAIN below already prints the form the reference
expects and the pin is unnecessary.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The read-rows estimator on this branch does not reach the per-column NDV hint
for the aggregation key, so the group estimate falls back to the hinted row
count of 50000, that exceeds `distributed_plan_max_rows_to_broadcast`, and the
planner picks Shuffle instead of the partial aggregation the test is about.

Lowering the hint keeps the reader-bucket split intact: it is gated on the real
row count from range analysis, not on the hint.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`04869_distributed_plan_partial_aggregation_bucket_order` fails
reproducibly on this backport: the planner picks `Shuffle` instead of
partial aggregation plus a memory-efficient merge, so the `EXPLAIN`
prints `GatherExchange / Aggregating / ShuffleExchange` where the
reference has `MergingAggregated (merge) / GatherExchange /
Aggregating (partial)` - and the test never reaches the code this
pull request fixes.

The distributed rewrites run post-order, so `tryMakeDistributedRead`
has already inserted a `GatherExchangeStep` above the read by the time
`tryMakeDistributedAggregation` calls `estimateReadRowsCount`. With
the estimation unable to look through an exchange it returns no stats
at all, and the strategy falls back to `Shuffle` "to be safe". The
row-count hint never reaches the read step, which is why lowering
`cardinality` did not help.

`0fae364ef698` ("Make row count estimation look through exchange steps
in non-cloud builds") is a commit of this very pull request and it
removed those two `CLICKHOUSE_CLOUD` guards. It was lost from the
backport: PR #86353 (Cascades) removed the same guards on `master`
three days before #114523 merged, so by merge time the hunk was a
no-op in the pull request's net diff, and the backport carries only
that net diff. `master` and `26.8` have no `CLICKHOUSE_CLOUD` left in
this file; this branch still had both guards.

The guarded include is dropped rather than unguarded, because the
same header is already included unguarded further down, which leaves
this file exactly as `master` has it.
@clickhouse-gh
clickhouse-gh Bot merged commit c5cf63b into 26.6 Sep 13, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.6/114523 branch September 13, 2026 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backport Changes, backported to release branch. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants