Repository navigation
Conversation
A parameterized view used as an IN-subquery resolves as a TableFunctionNode, so Planner/CollectSets.cpp puts its arguments in skip_children and the view call survives verbatim into the query text sent to the replicas. The initiator plans the outer read in order from the sort key and announces WithOrder while each replica re-plans the view body, an unordered scan, and announces Default. Both announcements key on the bare table name, so the second one reaches the first's coordinator and getOrCreateCoordinator raises "Coordination mode mismatch for stream <table>: got Default, expected WithOrder". The follower guard in PlannerJoinTree.cpp exists to stop a nested planner from reading with parallel replicas, but it compares table_node against the chosen parallel_replicas_table and for a table function both are null, so the null-vs-null comparison concludes the view is the chosen carrier. Treat a null table_node as not chosen instead. That is always sound: parallel_replicas_table is a const TableNode * and both walks in findTableForParallelReplicas bail out on a table function, so a table function can never be the carrier. The union-children comparison just below matches null against null for the same reason and is now skipped rather than re-enabling parallel replicas for the view. The regression test pins the five settings the divergence depends on, since the runner randomizes all of them and each one alone stops the two reads from being planned in different modes; each pin was confirmed load-bearing by forcing it back on a pre-fix build. Because the expected rows are also what a query returns when parallel replicas never engage, every query additionally asserts ParallelReplicasHandleAnnouncementMicroseconds > 0, which is incremented in the same function that raised the mismatch. Closes: ClickHouse#106039
Resolves the adjacent-line conflict in PlannerJoinTree.cpp: master's trivial-view-pushdown plumbing (effective_context / effective_storage / effective_snapshot) is kept verbatim, and this branch's two changed lines (the !table_node disjunct and the table_node-conditional table_union lookup) are kept as they are independent statements in the same block.
system.query_log is a non-replicated MergeTree, so with parallel_replicas_for_non_replicated_merge_tree = 1 it is eligible for parallel replicas, and the session sets enable_parallel_replicas = 2, which throws on a shape it does not support rather than falling back. The verification query could therefore fail instead of measuring the queries under test. All four in-tree precedents that read query_log for parallel replicas profile events pin enable_parallel_replicas = 0. The comment above the query no longer implies the assertion identifies which replica announced: ParallelReplicasLocalPlan installs the same announcement callback on the initiator, and the profile event is incremented before the coordination mode check, so the initiator's own local plan increments it too. The event shows coordination was reached; the two-sided randomized run is what shows the repaired path.
Internal second-model review (3 rounds, all findings resolved)An independent model reviewed this change three times. Rounds 1 and 2 raised 6 findings; all Round 3 re-raised two of them. Both are answered by measurement rather than argument. ❌ A view body's own
💡 Noted, not changed: the comment above the |
Pre-PR validation gate
Also checked, all re-measured after merging current master rather than inherited from an earlier |
|
Workflow [PR], commit [0b40bd4] Summary: ✅
AI ReviewSummaryThis PR closes the common follower-side parameterized-view mismatch by forcing nested table-function reads off the parallel-replicas path and by preserving the copied context for pipeline lifetime. I found one remaining correctness gap: a parameterized view whose stored Findings❌ Blockers
Final VerdictLLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 15/15 (100.00%) · Uncovered code |
|
cc @devcrafter @novikd, could you review this? A parameterized view resolves as a |
Admitting a null table_node routes a table function into the arm that reads with a Context::createCopy. That copy was only kept alive until read() returned, while source processors deriving from WithContext store a weak_ptr and resolve it lazily from a pipeline thread: StorageURLSource's initialize lambda then threw "Context has expired" (LOGICAL_ERROR) on urlCluster reads, which broke 02221_parallel_replicas_bug in Fast test. Hand the copy to QueryPlanResourceHolder::interpreter_context, which exists for this case and outlives the pipeline. The same createCopy / setSetting / read / addInterpreterContext sequence is already used in resolveStorages.cpp for the identical reason. Verified on the failing test's own content with the build ids asserted: pre-PR master is clean, the previous head aborts, and this build is clean with output byte-identical to pre-PR master. 04907 still reproduces its committed reference.
|
Fixed the Root cause was in this PR. Admitting a null The copy is now handed to Verified on the failing test's own content, with build ids asserted on each server: pre-PR master |
| @@ -2462,6 +2465,9 @@ JoinTreeQueryPlan buildQueryPlanForTableExpression(TableExpressionNodePtr table_ | |||
| auto mutable_context = Context::createCopy(effective_context); | |||
| mutable_context->setSetting("allow_experimental_parallel_reading_from_replicas", Field(0)); | |||
There was a problem hiding this comment.
If the parameterized view body itself carries SETTINGS enable_parallel_replicas = 1/2 (or the allow_experimental_parallel_reading_from_replicas alias), this one-shot override does not actually stick. StorageView::read reparses the stored SELECT, QueryTreeBuilder::buildSelectExpression reapplies the view body's SETTINGS into the inner QueryNode context, and buildPlannerContext then uses that re-enabled context when it chooses the inner parallel_replicas_table. At that point the follower is back to planning a coordinated inner read, so the same Coordination mode mismatch path is still reachable for a view like CREATE VIEW pv AS SELECT ... SETTINGS enable_parallel_replicas = 2.
I think this needs to strip those two setting names from the inner view query on the follower path (similar to the blacklist in InterpreterCreateQuery.cpp for MV POPULATE), or otherwise override them after the inner query tree is built. A focused regression case with a parameterized view that sets enable_parallel_replicas in its body would catch it.
There was a problem hiding this comment.
The reparse-and-reapply part is right: I probed it directly with a getSetting('allow_experimental_parallel_reading_from_replicas') column inside the view body, and it returns 2 on the fixed binary, so the body's clause does reach the inner query node and the guard's cleared copy does not.
The abort does not follow from it. Four arms, one server restart each, build id asserted per arm, on a pristine-master binary (pinned c8dacba9, these lines reverted) and on the current head 0b40bd4:
| view body | base | head |
|---|---|---|
| none | mismatch, got Default expected WithOrder | clean |
enable_parallel_replicas = 1 |
mismatch | clean |
enable_parallel_replicas = 2 |
mismatch | clean |
allow_experimental_parallel_reading_from_replicas = 1 |
mismatch | clean |
Base aborts in all four, so the arms reach the defect; head is clean in all four, with the positive-output rows present and a post-arm liveness check passing. Both directions reproduce on an independent re-run.
What decides it is which context is threaded into StorageView::read, not the inner query node's context: StorageMergeTree::read takes enable_parallel_reading from its local_context (StorageMergeTree.cpp:385), and the follower gate reads the planner's query context (PlannerJoinTree.cpp:2443). In the = 2 arm the followers running the outer query text show plain default reading with zero ReadPoolParallelReplicas lines, so they no longer announce for that table; the only coordinated pool left is the initiator-side remote subquery.
I re-ran this rather than reusing the earlier measurement because 0b40bd4 changed context handling on this exact path.
So no change here. A regression case for the body-SETTINGS shape would be a real oracle (base does abort on it), but it exercises the same one-line guard that 04907_parallel_replicas_parameterized_view_in_subquery already covers, so I would rather not add a second arm for it.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction. Compile time of recompiled translation units7 translation units recompiled, 24 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger for 0b40bd4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The stack confirms the owner: the abort is raised in |
|
📊 Cloud Performance Report ✅ AI verdict: This is a narrow null-safety fix in the parallel-replicas planner: it guards against a null table_node when a parameterized view is used as an IN-subquery and extends the read context's lifetime for the pipeline. ClickBench runs single-node and does not use parameterized views or parallel replicas, so neither flagged query executes the changed path. Both Q18 (+5.5%) and Q33 (+6.0%) are already non-directional (not_sure) and read as run-to-run variance rather than a real PR effect; Q33's delta also falls within master's current variance band. clickbenchFlagged queries (2 of 43)
Change = percent below ×2; the ratio of medians (×N faster/slower) beyond, where percent understates the scale. q-value = BH-FDR adjusted p; smaller is stronger evidence. MIRAI flags a query when q < fdr_q (default 0.10) — the value the verdict is based on. tpch_adapted_1_official🟢 No significant changes Debug info
|
5dd9252
On master `enable_analyzer` is frozen at 1, `parallel_replicas_only_with_analyzer` is obsolete and the old-analyzer CI jobs are gone, so the pins that kept the arms meaningful there, and the separate settings block the EXPLAIN arm needed, no longer do anything. All arms now share one settings block. The table is no longer partitioned by the per-row `DateTime`, which created 100 single-row partitions. Measured with the real runner after merging master: the test fails on a build with both this fix and the ClickHouse#114916 follower guard reverted (the server dies on "Coordinator for parallel reading from replicas is not initialized"), and passes with either change alone and with both. The single-partition table gives the same results as the old one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Closes: #106039
Related: #113622
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
Coordination mode mismatch for stream <table>: got Default, expected WithOrderwhen a parameterized view is used as anIN-subquery of an ordered query with parallel replicas enabled. A parameterized view used this way no longer plans its inner read with parallel replicas coordination on a replica.Description
SELECT ... FROM t WHERE id IN (SELECT id FROM pv(id = 'a')) AND id IN (SELECT id FROM pv(id = 'b')) ORDER BY idwith parallel replicas enabled aborted the server in debug and sanitizer builds, and threw in release.
Root cause. A parameterized view resolves as a
TableFunctionNode, so its arguments land inskip_childreninPlanner/CollectSets.cppand the view call survives verbatim into the text sentto the replicas. The initiator plans the outer read in order from the sort key and announces
WithOrder; each replica re-plans the view body, an unordered scan, and announcesDefault. Bothkey on the bare table name, so the second announcement reaches the first's coordinator and throws.
PlannerJoinTree.cppalready guards a view planning its own read on a follower, but it comparestable_nodeagainst the chosenparallel_replicas_table, and both are null, so it concludes "thisis the chosen table" and leaves coordination enabled for the view.
A table expression that is not a
TableNodeis now treated as not chosen, which is always correct:parallel_replicas_tableis aconst TableNode *, and both walks infindTableForParallelReplicasbail out on a table function. The union-children comparison is skipped for the same reason. A view
referenced by name is a
TableNode, soparallel_replicas_allow_view_over_mergetree = 1isunaffected.
Validation. The test pins the five settings the divergence depends on, three of which the runner
randomizes; each of the four that can vary was confirmed load-bearing by a negative control on the
unfixed binary. It fails 8 of 8 randomized runs on master with the reported error and passes 100 of
100 here. Expected rows are parallel-replicas-off ground truth, so each query also asserts
ParallelReplicasHandleAnnouncementMicroseconds > 0to show coordination was reached. The in-treeview, parameterized-view, trivial-view-pushdown and table-function tests are unchanged.
Version info
26.9.1.132(included in26.9and later)