Pull Request Overview
- Opened on September 19, 2026
- Status Open
- Commit count 0
Total Delta
Open Days
Test Delta
How long has this pull request spent in each phase of its lifecycle?
Data pending calculation for pull request
Fix the distributed INSERT SELECT with plan-based parallel replicas
Closes: https://github.com/ClickHouse/ClickHouse/issues/118276
Related: https://github.com/ClickHouse/ClickHouse/pull/112351
parallel_distributed_insert_select = 2 silently stopped distributing the insert when
parallel_replicas_plan_based was on: the INSERT SELECT ran on the initiator alone, reading with
parallel replicas instead of being executed by every replica. The data stayed correct, so the only
visible effect was the lost parallelism - 03394_pr_insert_select logs 4 Insert queries with the
query-based implementation and 1 with the plan-based one.
The whole path is gated on ClusterProxy::isSuitableForInsertSelectWithParallelReplicas, which scans
the SELECT's plan for ReadFromParallelRemoteReplicasStep. With parallel_replicas_plan_based the
planner builds a plain local plan and the parallel-replicas step (ReadFromParallelReplicasStep) is
created later, by the applyParallelReplicas optimization pass, so the probe never found anything.
The fix pins the query-based implementation for the whole distributed INSERT SELECT rather than
teaching the probe to recognize the plan-based step. The transport here is query shipping: the entire
INSERT is sent to every replica, and a replica executing it has collaborate_with_initiator set, so
canUseParallelReplicasOnInitiator - and with it the plan-based optimization pass - is off. Followers
therefore always read the query-tree-based way, and the initiator, taking part as one more replica, has
to read the same way; letting it use the plan-based implementation would buy nothing (the SELECT is
restricted to a single table expression with no GROUP BY / ORDER BY / LIMIT / aggregates) and
would make the two disagree about what can be distributed - a Merge source, for instance, is
distributed by the plan-based implementation under parallel_replicas_allow_merge_tables and left on a
single replica by the query-based one.
05213_pr_plan_based_insert_select covers both local-pipeline variants with the setting on, and
test_parallel_replicas_insert_select gains two cases that assert the same distributed query counts
with parallel_replicas_plan_based enabled.
Changelog category (leave one):
- Not for changelog (changelog entry is not required)
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not for changelog: parallel_replicas_plan_based is experimental and disabled by default.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/121097]
<!-- CI automatic block end :ci_links: -->
Comments Threads Pending Resolution
Resolved Comment Threads
No resolved comments have been left on this PR.