Skip to content

Skip read-in-order-through-join optimization for parallel replicas - #98685

Merged
devcrafter merged 9 commits into
masterfrom
fix-parallel-replicas-read-in-order-through-join
Mar 5, 2026
Merged

devcrafter merged 9 commits into
masterfrom
fix-parallel-replicas-read-in-order-through-join

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Mar 4, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Skip read_in_order_through_join optimization when ReadFromMergeTree has parallel replicas enabled
  • Applies to all three variants: sorting, aggregation-in-order, and distinct-in-order
  • Prevents coordination mode mismatch ("Replica decided to read in Default mode, not in WithOrder") caused by plan construction differences between initiator and remote replicas

With parallel replicas, the initiator's local plan is built with ignoreASTOptimizations() while the remote replica is not, which can cause different plan structures. When read_in_order_through_join applies on one side but not the other, they end up with different coordination modes (WithOrder vs Default), triggering a LOGICAL_ERROR in ParallelReplicasReadingCoordinator.

This fix is consistent with the existing check that already skips read-in-order for parallel replicas in the Union case (lines 1409-1416 of optimizeReadInOrder.cpp).

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98548&sha=8a781939137bab7b45291ac4d013e5f444ccf41a&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29
#98548

Test plan

  • Verify the fix compiles
  • CI passes stress tests without the coordination mode mismatch error

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix LOGICAL_ERROR "Replica decided to read in Default mode, not in WithOrder" when using read_in_order_through_join with parallel replicas.

🤖 Generated with Claude Code

Version info

  • Merged into: 26.3.1.430

With parallel replicas, the `read_in_order_through_join` optimization
can produce different results on the initiator and remote replicas
(due to differences in plan construction such as AST optimizations),
leading to coordination mode mismatch: "Replica decided to read in
Default mode, not in WithOrder".

Skip this optimization for parallel replicas when it goes through a
JOIN, for all three variants: sorting, aggregation, and distinct.
This is consistent with the existing check that skips read-in-order
for parallel replicas in the Union case.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=98548&sha=8a781939137bab7b45291ac4d013e5f444ccf41a&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [934e463]

Summary: ❌

job_name test_name status info comment
AST fuzzer (amd_tsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-40bb) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 4, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member Author

@devcrafter, this effectively removes the wrong optimization (read-in-order through JOIN with parallel replicas).

alexey-milovidov and others added 3 commits March 4, 2026 04:43
…icas

The test verifies that the `read_in_order_through_join` optimization
is correctly skipped when parallel replicas are enabled, for all three
variants: sorting, aggregation-in-order, and distinct-in-order.

It checks via EXPLAIN that ReadType changes from InOrder (without
parallel replicas) to Default (with parallel replicas), and also runs
the actual queries with failpoints to detect any coordination mode
mismatch.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@devcrafter devcrafter self-assigned this Mar 4, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Mar 4, 2026
@devcrafter
devcrafter removed this pull request from the merge queue due to a manual request Mar 4, 2026
@devcrafter
devcrafter enabled auto-merge March 4, 2026 17:07
@devcrafter

Copy link
Copy Markdown
Member

AST fuzzer failed due to #97470

@devcrafter
devcrafter added this pull request to the merge queue Mar 5, 2026
Merged via the queue into master with commit 607824a Mar 5, 2026
287 of 290 checks passed
@devcrafter
devcrafter deleted the fix-parallel-replicas-read-in-order-through-join branch March 5, 2026 13:36
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants