Repository navigation
Merge the parallel replicas local plan like the single-node plan after join runtime filters - #127628
Merged
Merged
Conversation
…r join runtime filters Pushing a join runtime filter into an aggregated subquery splits the expression it passes through, and once PREWHERE takes the filter, the split part is left as an `Expression` of its own. After the runtime filters are added, `optimizeTreeSecondPass` merges expressions and filters over the whole plan, so the single-node plan folds that part back. With classic parallel replicas the initiator's share of the read is an opaque `ReadFromLocalParallelReplicaStep` while that merge runs, and the local plan is optimized later on its own. It has no joins, so it never gets the merge, and when it is put back only the step where it meets the outer plan is merged. The extra step changes the cache key of every step above it, so automatic parallel replicas cannot find the boundary of the replicas plan (the partial `Aggregating`) in the single-node plan. It counts `AutoParallelReplicasPlansNotComparable`, collects no statistics, and builds the plan with parallel replicas again on every run. On staging TPC-H sf=1 this made a05, a07 and a10 (aggregation pushed into a filtered `lineitem` subquery, then joined) 1.18-1.33x slower than single-node while never using replicas; locally all three match after this change and decide from statistics from the second run, while master still fails to match them. The local plan now gets the same merge loop when the outer plan added runtime filters. Two related mismatches remain and are pinned in the test: the single-node plan can skip the runtime filter for a probe side it estimates below `join_runtime_filter_min_probe_rows` (the replicas plan cannot estimate through `MergingAggregated`), and with `query_plan_merge_filters = 0` the runtime filter stays a `Filter` of its own in the local branch. Both fail on master as well. Related: #118265 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017LMx8PkGBrowNrHvRMw4xi
Each pin was flipped on its own against the fix and against master. Kept are the ones the fix needs (`join_runtime_filter_min_probe_rows`, `query_plan_merge_filters`) and the ones without which the test stops reproducing the problem on master (`optimize_move_to_prewhere`, `enable_join_runtime_filters`, `parallel_replicas_plan_based`). The join order, join algorithm, spilling and table granularity pins changed nothing either way and are dropped. 300 randomized runs pass; master fails every run. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017LMx8PkGBrowNrHvRMw4xi
Contributor
|
Workflow [PR], commit [9b652ce] Summary: ✅
AI ReviewSummaryPR #127628 merges expression and filter steps throughout the restored local parallel-replica plan after join runtime filters are added. This lets automatic parallel replicas match the corresponding single-node aggregation and collect statistics instead of repeatedly building and discarding an incomparable plan. No actionable findings. Missing context / blind spots
Final VerdictStatus: ✅ Approve. No changes requested. |
nickitat
marked this pull request as ready for review
November 2, 2026 16:35
yariks5s
approved these changes
Nov 3, 2026
clickhouse-gh Bot
added a commit
that referenced
this pull request
Nov 3, 2026
Backport #127628 to 26.10: Merge the parallel replicas local plan like the single-node plan after join runtime filters
leshikus
pushed a commit
that referenced
this pull request
Nov 13, 2026
…e the single-node plan after join runtime filters
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.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Automatic parallel replicas (
automatic_parallel_replicas_mode) now collects statistics for queries that join an aggregated subquery whose filter goes to PREWHERE. Previously it could not match the two plans for such queries and built the plan with parallel replicas on every execution without ever using it.Related: #118265
Related: #118657
Pushing a join runtime filter into the subquery splits the expression it passes through: the part the filter needs goes below it, the rest stays above. PREWHERE then takes the filter, and the split part is left as an
Expressionof its own. After the runtime filters are added,optimizeTreeSecondPassmerges expressions and filters over the whole plan, so the single-node plan folds that part back in.With classic parallel replicas, the initiator's share of the read is an opaque
ReadFromLocalParallelReplicaStepwhile that merge runs. The local plan is optimized later, on its own. It has no joins, so it never gets the merge, and when it is put back only the step where it meets the outer plan is merged. The extra step changes the cache key of every step above it, so the boundary of the replicas plan (the partialAggregating) has no counterpart in the single-node plan.Workflow [PR]
Sync PR [sync-upstream/pr/127628]
Version info
26.11.1.1228-master(included in26.11and later)