Repository navigation
Remove Context::positional_arguments_already_resolved - #126813
PedroTadim merged 2 commits into
Conversation
The context flag told the analyzer that the query was printed from a resolved query tree, so its integer constants are not positions. Being context state, it was inherited by every context copy, so every fresh query analyzed from a local-plan context had to reset it (`Context::withUnresolvedPositionalArguments` and the manual resets), or it silently skipped positional arguments. Since ClickHouse#126075 and ClickHouse#124870 the same fact is carried per analysis by `SelectQueryOptions::positional_arguments_already_resolved`, and the flag is dead: - `createLocalPlan` sets the option for the printed local shard query, which was the only analysis the flag was meant for. - `createLocalPlanForParallelReplicas` and `createRemotePlanForParallelReplicas` hand the interpreter an already resolved query tree, which `QueryAnalyzer` does not resolve again, and disable parallel replicas on those contexts, so the automatic parallel replicas builder never re-analyzes a printed AST there. - The other queries printed from a resolved tree (`Merge` child, `Buffer`, `IStorageCluster`, `ReadFromRemote` `GLOBAL IN` header, a received secondary query and its `INSERT SELECT`) carry the option since ClickHouse#126075. - Everything else that inherited the flag is a fresh query, where skipping is wrong: table function arguments, row policies, `executable` inputs and the `mergeTreeAnalyzeIndexes` predicate (the resets removed here), and the analyses that inherited the flag without a reset (the inner query of a view pushed down to `Distributed`, `loop`, the generated `TimeSeries` and `prometheusQuery` queries). Inside a view the flag was already ignored, so outside a view the behaviour now equals the in-view one. The query tree constructor of `InterpreterSelectQueryAnalyzer` builds the plan for automatic parallel replicas by re-analyzing `tree->toAST()` with the caller's options, which never carry the option. A recursive CTE member executed by `RecursiveCTESource` goes through it, so with `automatic_parallel_replicas_mode` enabled `WITH RECURSIVE r AS (SELECT 5 AS c, k FROM t ORDER BY ALL ...)` failed with `Positional argument number 5 is out of bounds`. That lambda now passes the option, since the AST it analyzes is always printed from the resolved tree. `Context::is_view_inner_query` stays, it has other users (view source replacement, scalar subqueries, `extractTableReferencesOutsideViews`); only the comments that justified it by positional arguments are updated. Tests: the bot's `Buffer` over `Distributed` case and the recursive CTE case are added to `05340_positional_arguments_view_over_remote`, and the `serialize_query_plan = 0` pin in `05401` is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…allel replicas candidate plan The rows alone are also what the single-node plan returns, so the case now asserts through `query_log` that `AutomaticParallelReplicasProbePlansBuilt` fired, with `automatic_parallel_replicas_remember_boundary = 0` so every run builds the candidate plan. 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; one finding raised in 2 rounds, 0 findings on the final head) plus my own cold review (nits only).
Severity: ❌ blocker / |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261017-223900 |
|
cc @novikd @devcrafter, could you review this and add the |
|
Workflow [PR], commit [dcafbf5] Summary: ✅
AI ReviewSummaryRemoves the inherited Missing context / blind spots
Final VerdictStatus: ✅ Approve. No changes requested. |
dceb0cc
…r read A local Merge child re-analyzes its query, so an expression over a missing column comes back with its constants folded: `id * (a + 1)` is named `multiply(__table1.id, _CAST(1_UInt16, 'UInt16'_String))`. The fan-out looked it up by the unfolded name, recomputed it, and then rejected the child column it left unread, so addMissingDefaults returned 0 for every expression of the query. The fan-out now also tries the name with the constants folded (foldConstantCast, skipping IN, whose set only the child's analysis builds), and on the missing-column path accepts a child column it does not read: every output is then a name match or a deterministic expression of the child's columns. A Distributed child names its header from the unfolded tree, so the unfolded name is tried first. The query_tree_already_optimized flag lived in Context, so every context copy inherited it, and the body of a view child, which the initiator never optimized, ran only the resolving passes and kept `_shard_num` of its Distributed table as a column (UNKNOWN_IDENTIFIER). It is now carried by the read, like positional_arguments_already_resolved (ClickHouse#126075, ClickHouse#126813): SelectQueryInfo of the Merge child, which ReadFromMerge and StorageBuffer copy into the SelectQueryOptions of the query they re-analyze. A view body inlined into that query (analyzer_inline_views) still skips the later passes, so ShardNumColumnToFunctionPass runs for it. The PR no longer changes Context, which conflicted with ClickHouse#126813. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #124870
Related: #126075
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
With the experimental
automatic_parallel_replicas_mode, a recursive CTE member that orders or groups by an integer constant of its projection (for exampleSELECT 5 AS c, k FROM t ORDER BY ALL) no longer fails withPositional argument number 5 is out of bounds.Description
Follow-up to #124870, as asked in #124870 (comment).
Context::positional_arguments_already_resolvedtold the analyzer that a query is printed from a resolved query tree. Being context state, every context copy inherits it, so each fresh query analyzed from a local plan context had to reset it (#124870 added five resets), or it silently skipped positional arguments.The same fact is now carried per analysis by
SelectQueryOptions::positional_arguments_already_resolved(#126075, andcreateLocalPlanin #124870), and the flag has no remaining use: the parallel replicas local and remote plans pass an already resolved query tree, which is not resolved again. This PR removes the flag, its setters,Context::withUnresolvedPositionalArgumentsand the resets. Every other analysis that inherited the flag reads a query that is not printed from a resolved tree, so it now resolves positional arguments, as it already did inside a view.Checking every analysis that re-reads a printed AST found one that never had the option: automatic parallel replicas re-analyzes
tree->toAST()of a query tree to build its candidate plan. On master, withautomatic_parallel_replicas_mode = 1,WITH RECURSIVE r AS ((SELECT 5 AS c, k FROM t ORDER BY ALL LIMIT 1) UNION ALL (SELECT c, k + 1 FROM r WHERE k < 2)) SELECT * FROM rfails withPositional argument number 5 is out of bounds ... While executing RecursiveCTESource. That re-analysis now passes the option.Validation:
05340gains theBufferoverDistributedcase from the review of #124870 and the recursive CTE case (fails before this PR, passes with it);05401no longer pinsserialize_query_plan = 0. 50 randomized runs pass, 20 more withserialize_query_plan = 1. 570 related tests give the same results as before the change, 157 of them also withserialize_query_plan = 1.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126813]
Version info
26.11.1.336-master(included in26.11and later)