Repository navigation
Cherry pick #112849 to 26.7: Do not apply parallel replicas to the child plans of a Merge table - #120892
Merged
Conversation
`ReadFromMerge` materializes the plan of every underlying table lazily, while the outer plan is already being executed. Plan-based parallel replicas (`parallel_replicas_plan_based = 1`) was still applied to those child plans, and the shipped fragment was wrong in two ways: * The filters pushed down into the child plan were lost, so any query with a `WHERE` over a `Merge` table silently returned no rows. With `parallel_replicas_local_plan = 0`, `SELECT count() FROM merge(currentDatabase(), 't') WHERE name = '1'` returned `0` instead of `1`. * When the filter referenced a subquery set, the outer plan's `addStepsToBuildSets` had already moved the source plan out of the `FutureSetFromSubquery`, so serializing the fragment threw `Cannot serialize FutureSetFromSubquery with no query plan`. This is the shape the AST fuzzer hit with `SELECT count() FROM merge(currentDatabase(), 'test_local') WHERE name GLOBAL IN (SELECT name FROM test_distributed)`. Disable parallel replicas for `Merge` child plans, both in the optimization settings and in the child context - the conversion re-checks `canUseParallelReplicasOnInitiator` against the context captured by the reading step, not only the optimization settings. This restores the documented behavior that queries over `Merge` tables run on a single replica (#67770); proper support is being added separately by #110972 behind `parallel_replicas_allow_merge_tables`. Co-Authored-By: Claude Fable 5 <[email protected]>
…the regression test The test switched to `parallel_replicas_local_plan = 1` but only re-ran two `count()` queries there. The structural check above it matches only `ReadFromParallelReplicas`, so a regression that distributes the `Merge` child plan in local-plan mode - where the read is wrapped in `ReadFromLocalReplica` / `ReadFromRemoteParallelReplicas` - would not have been caught. Add, for `parallel_replicas_local_plan = 1`: the `GLOBAL IN` reproducer that used to throw `Cannot serialize FutureSetFromSubquery with no query plan`, an `EXPLAIN` assertion that the `Merge` child read carries none of the three distributed-read wrappers, and the matching positive control on a plain table. Verified against a binary with the `StorageMerge.cpp` fix reverted: the new `EXPLAIN` assertion returns `1` instead of `0` and the new `GLOBAL IN` query throws the logical error, so neither assertion is vacuous. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…ns of a `Merge` table `ReadFromMerge::buildPipeline` built the child pipeline with raw `QueryPlanOptimizationSettings(context)` from the outer query context, and `QueryPlan::buildQueryPipeline` runs `convertToDistributed` whenever `make_distributed_plan` is set, regardless of `optimize_plan`. So with `make_distributed_plan = 1`, a `Merge` child plan was converted to a distributed plan mid-execution, failing with `Unknown query plan step: GatherReceive` (and `Cannot serialize FutureSetFromSubquery with no query plan` when the query had subquery sets already consumed by the outer plan's `addStepsToBuildSets`). Clear `make_distributed_plan` in `getChildPlanOptimizationSettings`, use that helper in `buildPipeline`, and clear the setting in the child context as well (mirroring `enable_parallel_replicas`, for nested interpreters). Co-Authored-By: Claude Fable 5 <[email protected]>
…the query has subquery sets Fast test on the previous commit caught that clearing \`make_distributed_plan\` unconditionally breaks 04367_distributed_plan_merge_scatter_multishard: distributing the child plans of a \`Merge\` table is a supported feature (the double-application of the transforms is fenced by \`planContainsLogicalExchange\` in \`optimizeTree.cpp\`, and \`ReadFromMerge::buildPipeline\`'s conversion is the run that materializes the logical exchanges inserted at child-plan creation). The \`Unknown query plan step: GatherReceive\` failure that motivated the blanket clearing was an artifact of reproducing with \`clickhouse local\`, which never calls \`QueryPlanStepRegistry::registerPlanSteps\` (only \`Server.cpp\` does), so any distributed child plan fails to deserialize there; on a server that path works. The genuine bug is narrower: when the query has subquery sets (\`IN (SELECT ...)\`), the outer plan's \`addStepsToBuildSets\` has already moved the source plan out of every \`FutureSetFromSubquery\` by the time the lazily materialized child plans are optimized, so a distributed child fragment referencing such a set fails to serialize with the logical error \`Cannot serialize FutureSetFromSubquery with no query plan\`. Clear \`make_distributed_plan\` for the child plans only in that case, detected via the prepared sets of the outer query's planner context. The test now asserts both directions on a 100k-row \`Merge\` child: without subquery sets the child plan contains exchanges and executes correctly (positive control that the feature still applies), and with \`GLOBAL IN\` the child plan has no exchanges and the query succeeds. Plain \`IN\` and aggregation/ORDER BY shapes are excluded: converting an outer plan whose worker stage would carry an unserializable step (\`ReadFromMerge\`, the EXPLAIN wrapper's \`ReadFromStorage\`) is rejected upfront with \`SUPPORT_IS_DISABLED\` - a pre-existing limitation unrelated to the child plans. Fast test failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112849&sha=425692c16c6deb6481fa26a0617ebb9efbda5ae6&name_0=PR&name_1=Fast%20test (#112849) Co-Authored-By: Claude Fable 5 <[email protected]>
…eplicas Do not apply parallel replicas to the child plans of a Merge table
The only conflict was an unrelated `ProcessList.h` include that master carries next to the new `PreparedSets.h` and 26.7 does not have. Everything else applies verbatim. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #112849
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job