Skip to content

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

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

Backport #114523 to 26.7: Fix wrong results of the partial aggregation strategy in distributed query plans#118802
clickhouse-gh[bot] merged 5 commits into
26.7from
backport/26.7/114523

Conversation

@robot-clickhouse

@robot-clickhouse robot-clickhouse commented Sep 8, 2026

Copy link
Copy Markdown
Member

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

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

@robot-clickhouse robot-clickhouse 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 [708c4c9]

Summary:

@PedroTadim PedroTadim assigned PedroTadim and unassigned PedroTadim Sep 8, 2026
@nickitat

nickitat commented Sep 8, 2026

Copy link
Copy Markdown
Member

@copilot pls fix the build

…_bucket_number

Co-authored-by: nickitat <5218483+nickitat@users.noreply.github.com>

Copilot AI commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@copilot pls fix the build

Fixed in ecd... (removed the stray const from should_produce_results_in_order_of_bucket_number in AggregatingStep.h, which conflicted with the new setProduceResultsInBucketOrder setter added by the backport; matches master where the field is non-const).

@copilot pls fix the build

Fixed in 5cbd46b: removed the stray const from should_produce_results_in_order_of_bucket_number in AggregatingStep.h, which conflicted with the new setProduceResultsInBucketOrder setter added by the backport (matches master, where the field is non-const).

@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.
2 out of 3 committers have signed the CLA.

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

PedroTadim and others added 2 commits September 10, 2026 12:10
…ettings

  applyParallelReplicas.cpp:85:55: error: use of undeclared identifier 'optimization_settings'

On master `ApplyParallelReplicasVisitor` holds a `QueryPlanOptimizationSettings`
reference; on 26.7 it does not, and `applyParallelReplicas` ignores its settings
argument. The memory-efficient merge is correspondingly hard-coded to `false`
there, so the cherry-pick only had to move that constant up, not master's
expression. #114523's real fix for this branch is in `makeDistributed.cpp`,
which does have the settings in scope and is unchanged from the original.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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) <noreply@anthropic.com>
`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 1d9bb22 into 26.7 Sep 13, 2026
38 of 39 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport/26.7/114523 branch September 13, 2026 21:46
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.

7 participants