Repository navigation
Fix duplicated rows of ANY RIGHT JOIN with any_join_distinct_right_table_keys under parallel replicas - #123683
Conversation
…across parallel replicas With `any_join_distinct_right_table_keys = 1`, `ANY RIGHT JOIN` becomes kind `Right` with strictness `RightAny`: each left row takes the first right row of its key, and the whole key is marked used. That choice is made over ALL right rows of the key. The leftmost-leaf gate `allowParallelReplicasForJoinTree` admitted every `RIGHT` join, so the whole join was shipped to the replicas, each replica read only its coordinated share of the right table, and a left row that matched on several replicas was emitted once per replica (`01660_join_or_any` returned `6 4` twice in the new ParallelReplicas job). The plan-based pass had the same gap: `liftSplitAboveJoin` lifted the right-side split above such a join. The query-tree walk `getSupportingParallelReplicasQueries` already refuses this shape (ClickHouse#75262). Make the leftmost-leaf gate refuse it too, and in plan-based mode refuse only the lift, so the right read stays distributed below the join and the join runs once over all right rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding in the first pass, 0 in the re-review of the final PR description), plus my own review (1 nit).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20261003-111900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261003-102500 |
|
Workflow [PR], commit [ff9b30d] Summary: ✅
AI ReviewSummaryThis PR fixes a real correctness hole in parallel replicas for Final Verdict✅ No new findings. LLVM Coverage ReportMeasured on commit ff9b30d.
Changed lines: Changed C/C++ lines covered: 11/12 (91.67%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 510cc85Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these goes through the Session id: cron:our-pr-ci-monitor:20261003-170255 |
|
Fixing PR for 05257_sql_security_view_sealed (parallel replicas) created: #123729 |
|
Fixing PR for 05237_with_expression_alias_scope_descendant (DBReplicated): #123774 |
In plan-based mode `allowParallelReplicasForJoinTree` does not ship the join; it only guards the planner-side sizing by `parallel_replicas_min_number_of_rows_per_replica`. Refusing RightAny there skipped that sizing while `applyParallelReplicas` still distributed the right read, so the query fanned out to `max_parallel_replicas` replicas regardless of the threshold. Refuse RightAny in this gate only in the query-tree mode; in plan-based mode `liftSplitAboveJoin` already keeps the join on the initiator. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #123683 to 26.9: Fix duplicated rows of `ANY RIGHT JOIN` with `any_join_distinct_right_table_keys` under parallel replicas
Backport #123683 to 26.8: Fix duplicated rows of `ANY RIGHT JOIN` with `any_join_distinct_right_table_keys` under parallel replicas
… JOIN` with `any_join_distinct_right_table_keys` under parallel replicas
The bugs behind their `no-parallel-replicas` / `no-replicated-database` tags are fixed on master: - `01660_join_or_any`: ClickHouse#123683 - `04653_bloom_filter_fixed_string_constant_scalar`: ClickHouse#118988 - `04819_dynamic_aggregate_function_state_version`: ClickHouse#123649 - `04825_quantile_deterministic_alter_add_modify_column`: ClickHouse#115393, ClickHouse#123070 - `04494_atomic_populate_materialized_view_parallel_replicas`: ClickHouse#124477 - `04266_text_index_tokens_cardinality_order`: ClickHouse#124500 already disables parallel replicas for the log-checked query Related: ClickHouse#124015
Closes: #123992
Related: #75262
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed duplicated rows returned by
ANY RIGHT JOINwithany_join_distinct_right_table_keys = 1when parallel replicas are enabled.Description
On 26.3.33.24, with
any_join_distinct_right_table_keys = 1and parallel replicas,SELECT a2, b2 FROM tab2 ANY RIGHT JOIN tab3 ON a2 = a3 OR b2 = b3(the01660_join_or_anytables) returns the row6 4twice in 79 of 100 runs; 26.8.10.6 does the same. Failing CI job:01660_join_or_any, Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel).Root cause: under this setting
ANY RIGHT JOINgets strictnessRightAny, which gives each left row one right row of its key, chosen from all right rows.allowParallelReplicasForJoinTreeadmitted everyRIGHTjoin, so the whole join was shipped to the replicas. Each replica read only its share of the right table, so a left row that matched on two replicas was emitted twice. The plan-based pass had the same gap inliftSplitAboveJoin. The query-tree walk already refuses this shape (#75262).Change: in query-tree mode
allowParallelReplicasForJoinTreerefusesRIGHT+RightAny. In plan-based mode only the lift is refused, so the right table is still read with parallel replicas, withinparallel_replicas_min_number_of_rows_per_replica, and the join runs once on the initiator. OtherRIGHTstrictnesses are unchanged.Validation: the new test
05320_parallel_replicas_right_join_right_anyfails 60/60 on master and passes 150/150 with the fix, including runs under the ParallelReplicas profile at bothparallel_replicas_local_planvalues. Reverting either change turns its own test line red. On the01660_join_or_anytables, 273 of 800 master runs return the duplicate, against 0 of 800 with the fix.Workflow [PR]
Sync PR [sync-upstream/pr/123683]
Version info
26.10.1.1880-master(included in26.10and later)26.9.15.7,26.8.23.8