Skip to content

Support the plan-based parallel replicas in automatic parallel replicas - #115788

Merged
devcrafter merged 3 commits into
masterfrom
autopr-support-plan-based-parallel-replicas
Aug 24, 2026
Merged

Support the plan-based parallel replicas in automatic parallel replicas#115788
devcrafter merged 3 commits into
masterfrom
autopr-support-plan-based-parallel-replicas

Conversation

@devcrafter

@devcrafter devcrafter commented Aug 21, 2026

Copy link
Copy Markdown
Member

Automatic parallel replicas builds a plan with parallel replicas, finds the node that would sit at the top of the plan executed on the replicas, and instruments the corresponding node of the single-node plan to collect runtime dataflow statistics. findTopNodeOfReplicasPlan located that node by matching the branch that reads from the other replicas against ReadFromParallelRemoteReplicasStep.

With parallel_replicas_plan_based that branch is a ReadFromParallelReplicas step, which ships a serialized plan fragment instead of a query. The rest of the plan is shaped exactly the same - a Union of the local branch and the branch reading from the other replicas - but the top node was never found, so no statistics were collected and automatic parallel replicas never enabled parallel replicas for any query.

This recognizes both steps. Verified against a local server with parallel_replicas_plan_based=1: 10 of the 12 *_autopr_* stateless tests that fail with the plan-based implementation as the default now pass. The remaining two are left for a follow-up and keep the previous behaviour of skipping the optimization:

  • 04341_autopr_mode1_apply_join - with join runtime filters the plan-based local branch carries an extra pass-through Expression, so the node hashes of the two plans differ and no match is found.
  • 03634_autopr_input_bytes_estimation_compact - for a plain read the plan fragment is the reading step itself, which cannot estimate the number of bytes sent to the initiator.

Related: #112351

Changelog category (leave one):

  • Experimental Feature

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

Automatic parallel replicas can now collect runtime statistics and enable parallel replicas for supported queries when parallel_replicas_plan_based is enabled.


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

Version info

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

Automatic parallel replicas builds a plan with parallel replicas, finds the
node that would sit at the top of the plan executed on the replicas and
instruments the corresponding node of the single-node plan to collect runtime
dataflow statistics. `findTopNodeOfReplicasPlan` located that node by matching
the branch that reads from the other replicas against
`ReadFromParallelRemoteReplicasStep`.

With `parallel_replicas_plan_based` that branch is a `ReadFromParallelReplicas`
step, which ships a serialized plan fragment instead of a query. The rest of the
plan is shaped exactly the same - a `Union` of the local branch and the branch
reading from the other replicas - but the top node was never found, so no
statistics were collected and automatic parallel replicas never enabled
parallel replicas for any query.

Recognize both steps. Two shapes are still not handled and keep the previous
behaviour of skipping the optimization: a join whose plan-based local branch
carries an extra pass-through `Expression` (the node hashes of the two plans
then differ), and a plain read whose plan fragment is the reading step itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [bb89c23]

Summary:


AI Review

Summary

This PR teaches considerEnablingParallelReplicas to recognize the plan-based remote branch (ReadFromParallelReplicasStep) when locating the replica-side top node, then adds a focused stateless regression test that verifies runtime statistics are collected on the first run and reused to enable parallel replicas on the second. I did not find a remaining correctness, safety, or coverage issue in the current patch.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

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

Changed lines: Changed C/C++ lines covered: 9/9 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 21, 2026
@devcrafter
devcrafter requested a review from nickitat August 21, 2026 14:13
@devcrafter

Copy link
Copy Markdown
Member Author

Both points are right — automatic_parallel_replicas_mode and parallel_replicas_plan_based are both EXPERIMENTAL tier in src/Core/Settings.cpp, and the previous entry claimed more than this change delivers.

Updated the changelog entry to the suggested wording. For the category I went with Experimental Feature rather than Improvement, since the change only affects settings on the EXPERIMENTAL tier — happy to switch to Improvement if that reads better.

@clickhouse-gh

clickhouse-gh Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing bb89c2396 with master 494c47005 (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 708.92 MiB 705.88 MiB -3.04 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

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

Job report

@nickitat nickitat self-assigned this Aug 21, 2026
The flaky check hit `Logical error: 'Bucket 7 is pushed twice'` in
`GroupingAggregatedTransform` twice out of 41 runs of the new test. The same
stack trace is already reported for the distributed plan on a release branch,
see #115663, so it is a race in
the memory efficient merging of partial aggregation results, not in what this
test checks - the decision of automatic parallel replicas.

Merge the partial results of the replicas without `GroupingAggregatedTransform`
so the test stops tripping over it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@clickhouse-gh clickhouse-gh Bot added pr-experimental Experimental Feature and removed pr-bugfix Pull request with bugfix, not backported by default labels Aug 22, 2026
@nickitat

Copy link
Copy Markdown
Member

💋

@devcrafter
devcrafter added this pull request to the merge queue Aug 24, 2026
Merged via the queue into master with commit 26bd12d Aug 24, 2026
179 checks passed
@devcrafter
devcrafter deleted the autopr-support-plan-based-parallel-replicas branch August 24, 2026 21:02
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-experimental Experimental Feature 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