Repository navigation
Fix coordination mode mismatch for parallel replicas with aggregation in order - #98467
Merged
Merged
Conversation
… in order When the initiator replica has no parts to read, `result.read_type` remains `Default` (never updated to `InOrder`), but `query_info.input_order_info` is set with direction=1 by the `optimizeAggregationInOrder` optimization. The coordination mode calculation incorrectly used `result.read_type` to determine the mode, falling into the `ReverseOrder` branch for non-`InOrder` read types. Meanwhile, the remote replica with actual data correctly computed `WithOrder` (direction=1), causing the coordinator to throw: "Replica 0 decided to read in WithOrder mode, not in ReverseOrder." Fix by using `query_info.input_order_info->direction` directly, which is always consistent regardless of whether `result.read_type` was updated. Also enable `parallel_replicas_filter_pushdown` in the existing test for this issue. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=03c7c3d6f2c843cd5f0f681e5032bf968e97e88a&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
Revert modification to the existing test `03810_pr_aggr_in_order_read_mode` and add a new test `04009_pr_aggr_in_order_coordination_mode` that covers the fix with `parallel_replicas_filter_pushdown` enabled. Co-Authored-By: Claude Opus 4.6 <[email protected]>
devcrafter
approved these changes
Mar 2, 2026
1 task
1 task done
nickitat
added a commit
that referenced
this pull request
Aug 31, 2026
`parallel_replicas_filter_pushdown` gates two different things. On the remote half of the read it splices the predicate into the query AST shipped to the replicas (`ReadFromParallelRemoteReplicasStep::initializePipeline` -> `addFilters`). On the local half it only moves a `Filter` into the plan fragment the initiator runs itself, which is an ordinary in-process plan optimization - the fragment is then optimized like any other plan, so the predicate becomes a `PREWHERE` and prunes the index. Stop gating the local half. `ReadFromLocalParallelReplicaStep` exists only when `canUseLocalPlanForParallelReplicas` accepted the query, so this is exactly "ignore the setting in local mode"; the setting keeps governing the remote query, where the AST surgery lives. Nothing is filtered on the initiator only: the union push-down clones the `Filter` into both branches and pushing into a `SourceStepWithFilterBase` keeps the step, so the remote branch still filters what the replicas send back. The replicas also need not agree on which ranges the local plan reads - each announces its own and the coordinator reconciles them. The push-down used to be unconditional; the setting was added in #95510 to mitigate #95524, where a filter reaching the local plan let `optimize_aggregation_in_order` pick a coordination mode the replicas did not use ("Replica 1 decided to read in WithOrder mode, not in ReverseOrder"). That was fixed at its root in #98467, and the local plan now inherits the read-in-order gates from the subquery's own settings, so the mitigation is no longer needed. `03787_pr_group_by_read_mode_error`, `03810_pr_aggr_in_order_read_mode` and `04009_pr_aggr_in_order_coordination_mode` cover it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01WCAGFHu72JG9die3EDo8t4
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.
Summary
optimize_aggregation_in_orderandparallel_replicas_local_plan.result.read_type(Default) to compute coordination mode, incorrectly mapping toReverseOrder, while remote replicas correctly computedWithOrderfrominput_order_info->direction.query_info.input_order_info->directiondirectly, which is always consistent regardless of whether range analysis ran.Fixes #95524
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=03c7c3d6f2c843cd5f0f681e5032bf968e97e88a&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
Test plan
03810_pr_aggr_in_order_read_modepasses with the fixparallel_replicas_filter_pushdown = 1enabled (previously had a TODO to enable after fix)Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix logical error exception "Replica decided to read in WithOrder mode, not in ReverseOrder" when using parallel replicas with
optimize_aggregation_in_order.🤖 Generated with Claude Code
Version info
26.3.1.339