Repository navigation
Send only the shard scalars with a plan-based parallel replicas fragment - #133844
devcrafter wants to merge 1 commit into
Conversation
Scalar subquery values are constants in the plan; shipping all scalars could send megabytes per replica. #127014 (review) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Workflow [PR], commit [83d79b7] Summary: ✅
AI ReviewSummaryThe PR avoids resending scalar-subquery results with plan-based parallel replica fragments while preserving Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 15 s compile time in total, 7 of them have a recent master baseline. |
groeneai
left a comment
There was a problem hiding this comment.
LGTM. Checked with the CI release builds of this PR (83d79b7, merged with master cd61bfb) and of master cd61bfb itself, on a local 1-shard x 3-replica cluster with parallel_replicas_plan_based = 1, parallel_replicas_prefer_local_replica = 0:
- 05871 fails on master (initiator
NetworkSendBytes10,133,908, last line0) and passes here (19,483), so the oracle can fail, with a wide margin on both sides of 1 MB. - Scalar subquery values reach the replicas as constants of the fragment: 26 queries with an Array / Tuple / LowCardinality / AggregateFunction scalar subquery in SELECT, WHERE, PREWHERE, GROUP BY, ORDER BY, lambdas, ARRAY JOIN, IN, JOIN, and through a
Distributedtable over the parallel replicas cluster (the shard gets__getScalarcalls plus the scalars, then ships fragments), return the same results on both builds, with fragments executed on the remote replicas.
One note on the test, not blocking: the shardNum() query over test_cluster_two_shards ships no plan fragment (the shard queries spawn no replica queries), and it returns the same 1 100000 / 2 100000 on a build from before #127014 (96b7402) that sends Scalars{}, so it cannot fail for this change. With a fragment (Distributed over test_cluster_one_shard_three_replicas_localhost), shardNum() / shardCount() are still folded on the parallel replicas initiator, whose table is not remote (isSuitableForConstantFolding returns !is_distributed, src/Functions/getScalar.cpp:157): that old build returns 1 1 there too. So the follower only reads _shard_num in canUseLocalPlanForParallelReplicas, which 05428 (plan_based_distributed) covers; sending _shard_count as well is harmless.
ReadFromParallelReplicassent every scalar of the query context with a plan-based fragment, although scalar subquery values are already constants in the plan. A query with a large scalar subquery could send megabytes to each replica: for a 1M-element array, the initiator sent 10 MB instead of 15 KB. Now only_shard_numand_shard_countare sent, whichshardNum/shardCountand the follower's index analysis need.Related: #127014 (review)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Plan-based parallel replicas no longer send the results of scalar subqueries to the replicas, as they are already part of the shipped query plan.
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/133844]