Repository navigation
Fix coordination mode mismatch with parallel replicas and read-in-order optimization - #95052
Closed
alexey-milovidov wants to merge 2 commits into
Closed
alexey-milovidov wants to merge 2 commits into
alexey-milovidov wants to merge 2 commits into
Conversation
…er optimization PR #94103 introduced logic to skip "fixed columns" (columns that become constant after WHERE filtering) when determining the read direction for read-in-order optimization. For example, with `WHERE tenant = 'A' ORDER BY tenant, time DESC`, the `tenant` column is fixed, so the read direction should come from `time DESC`. However, with `parallel_replicas_local_plan`, each replica builds its own query plan independently. Different replicas may have different `fixed_columns` sets due to variations in filter pushdown or other optimizations. This causes replicas to compute different read directions: - Replica 1: identifies column X as fixed, skips it, gets direction from column Y - Replica 2: doesn't identify X as fixed, gets direction from column X When these directions differ (e.g., ASC vs DESC), replicas announce different coordination modes (WithOrder vs ReverseOrder), causing the coordinator to throw: "Replica N decided to read in WithOrder mode, not in ReverseOrder. This is a bug" The fix: when parallel replicas are enabled, ignore fixed columns when determining read direction. This ensures all replicas use the same deterministic direction based on the first ORDER BY column, matching the behavior before PR #94103. This is a conservative fix that disables the optimization only for parallel replicas, preserving the improved behavior for single-node queries. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Test verifies that queries with: - parallel_replicas_local_plan enabled - A fixed column (constant due to WHERE) - ORDER BY that includes the fixed column do not cause coordination mode mismatch between replicas. Co-Authored-By: Claude Opus 4.5 <[email protected]>
Contributor
|
Workflow [PR], commit [758cae5] Summary: ❌
|
Member
Author
|
If we don't succeed with this fix, we will revert #94103. |
Contributor
|
Hi, if I may suggest another approach, maybe the fixed columns should be based on AST (at least in parallel replicas mode) |
Member
Author
|
@matanper, let's try! Could you please send a PR with that fix? (then I will close this one) |
Contributor
|
opened #95077 |
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.
PR #94103 introduced logic to skip "fixed columns" (columns that become constant after WHERE filtering) when determining the read direction for read-in-order optimization. For example, with
WHERE tenant = 'A' ORDER BY tenant, time DESC, thetenantcolumn is fixed, so the read direction should come fromtime DESC.However, with
parallel_replicas_local_plan, each replica builds its own query plan independently. Different replicas may have differentfixed_columnssets due to variations in filter pushdown or other optimizations. This causes replicas to compute different read directions:When these directions differ (e.g., ASC vs DESC), replicas announce different coordination modes (WithOrder vs ReverseOrder), causing the coordinator to throw: "Replica N decided to read in WithOrder mode, not in ReverseOrder. This is a bug"
The fix: when parallel replicas are enabled, ignore fixed columns when determining read direction. This ensures all replicas use the same deterministic direction based on the first ORDER BY column, matching the behavior before PR #94103.
This is a conservative fix that disables the optimization only for parallel replicas, preserving the improved behavior for single-node queries.
Changelog category (leave one):
See #94103 (comment)