Repository navigation
Disable parallel replicas in nested scalar subquery contexts - #107381
alexey-milovidov merged 2 commits into
Conversation
evaluateScalarSubqueryIfNeeded clones the scalar subquery tree and sets allow_experimental_parallel_reading_from_replicas = 0 on the subquery context, but assigns that context only to the top QueryNode/UnionNode of the clone. Nested QueryNode/UnionNode children keep their original parallel-replicas-enabled context. The Planner reads the context from every node, so the scalar's plan is built with parallel replicas during analysis and creates ParallelReplicasReadingCoordinator instances. When the same table is read twice in one such plan (e.g. a correlated scalar that decorrelates into a self-join), both reads announce on the same coordinator with the same replica number and the second announcement trips the assertion "Duplicate announcement received for replica number N" (ParallelReplicasReadingCoordinator.cpp). Found by the AST fuzzer. Walk the whole cloned tree and disable parallel replicas on every nested QueryNode/UnionNode context, mirroring the existing recursive walk in createLocalPlanForParallelReplicas (a scalar subquery must never use parallel replicas by construction). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-0:20260613-083100 |
|
cc @nickitat @novikd — could you review this? A scalar subquery kept parallel replicas enabled in its nested QueryNode/UnionNode contexts (evaluateScalarSubqueryIfNeeded set the flag only on the top node), so the scalar's plan was built with parallel replicas during analysis and two same-table reads announced twice on one coordinator -> "Duplicate announcement received for replica number N" (AST fuzzer finding). The fix applies the same recursive context walk already used by createLocalPlanForParallelReplicas. |
|
Workflow [PR], commit [591768e] Summary: ✅
AI ReviewSummaryThis PR disables Final VerdictStatus: ✅ Approve |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 22/22 (100.00%) | Lost baseline coverage: none · Uncovered code |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix
Logical error: 'Duplicate announcement received for replica number N'that could occur with parallel replicas when a scalar subquery contained nested subqueries reading the same table.Description
A scalar subquery must never use parallel replicas.
evaluateScalarSubqueryIfNeededclones the scalar subquery tree and setsallow_experimental_parallel_reading_from_replicas = 0on the subquery context, but it assigns that context only to the topQueryNode/UnionNodeof the clone. NestedQueryNode/UnionNodechildren keep their original, parallel-replicas-enabled context.The Planner reads the context from every node, so the scalar's plan is built with parallel replicas during analysis and creates
ParallelReplicasReadingCoordinatorinstances. When the same table is read twice in one such plan (for example a correlated scalar that decorrelates into a self-join), both reads announce on the same coordinator with the same replica number, and the second announcement trips the assertionDuplicate announcement received for replica number NinParallelReplicasReadingCoordinator.cpp.The fix walks the whole cloned subquery tree and disables parallel replicas on every nested
QueryNode/UnionNodecontext, mirroring the existing recursive walk increateLocalPlanForParallelReplicas.Found by: AST fuzzer (
AST fuzzer (amd_debug)), two occurrences on unrelated PRs:optimize_or_like_chainby default. #94517, shad8533168dc845614b29d0752187ef16135c33aae, 2026-06-13 (report)No related open issue found. The two PRs above are unrelated to parallel replicas; this is a trunk bug surfaced by the fuzzer.
Regression test
04337_parallel_replicas_scalar_subquery_no_leakasserts (viasystem.text_log) that a scalar subquery over a parallel-replicas table creates no coordinator, while a top-level query over the same data still does. It fails before the fix (1 and 2 coordinators created during scalar analysis) and passes after.Version info
26.6.1.757