Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK for an IN over a parameterized view in a distributed query - #123662
Conversation
…ch on shards An `IN` set is named `__set_<tree hash of its subquery>`, and that name is part of every column a shard returns whose expression contains the `IN` (an aggregate argument, a `GROUP BY` key, a `SELECT` item); the initiator matches those columns by name. `TableFunctionNode::updateTreeHashImpl` hashed a parameterized view call as typed (`pv`), while `toASTImpl` sends it qualified (`default.pv(...)`, ClickHouse#113550), so each shard hashed a different name and the query failed with `NOT_FOUND_COLUMN_IN_BLOCK`, or `THERE_IS_NO_COLUMN` with `serialize_query_plan = 1`. A resolved parameterized view is now hashed by `storage_id.getFullNameNotQuoted()`, the way `TableNode` hashes its storage. For a call typed qualified the hash bytes are unchanged, so a fixed initiator works with 26.9 and unfixed master shards and a 26.9 initiator behaves as before. Hashing only the storage id (without the name bytes) also fixes a single-version cluster, but breaks the qualified spelling against 26.9 and unfixed master shards in both directions (measured), so the name bytes are kept. `isEqualImpl`, `toASTImpl` and `dumpTreeImpl` are unchanged, so `EXPLAIN QUERY TREE` and `EXPLAIN SYNTAX` output does not change. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The runner draws `automatic_parallel_replicas_mode = 2` in a quarter of the runs, and then the analyzer turns `enable_parallel_replicas` off for the query, so the arm read `data` locally and printed the expected row on master too. `enable_parallel_replicas = 1` also falls back to a local read silently. Pin `automatic_parallel_replicas_mode = 0`, use `enable_parallel_replicas = 2` so an unsupported shape throws, and check in `system.query_log` that the query reached the parallel-replicas coordinator (`ParallelReplicasHandleAnnouncementMicroseconds`, as in 04907). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense the tree-hash comment in TableFunctionNode::updateTreeHashImpl to one invariant line. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261003-070500 |
|
Workflow [PR], commit [236e48f] Summary: ✅
AI ReviewSummaryThis PR correctly targets the tree-hash mismatch behind Findings❌ Blockers
Final Verdict❌ Not ready yet: one correctness hole remains in the storage-spelling hash for dotted databases, and the two new regression tests are still non-deterministic with respect to the analyzer/old-analyzer split. |
| @@ -0,0 +1,50 @@ | |||
| -- Tags: shard | |||
|
|
|||
| -- An `IN` over a parameterized view, called unqualified, inside an expression that the shards | |||
There was a problem hiding this comment.
Could you pin enable_analyzer = 1 near the top? This fix lives in TableFunctionNode, so the regression only exists on the analyzer path. The stateless runner still randomizes enable_analyzer (see tests/queries/0_stateless/05042_streaming_queries_lazy_materialization.sql:4), and sibling parameterized-view shard tests already pin it (tests/queries/0_stateless/04678_parameterized_view_database_on_shard.sh:14, tests/queries/0_stateless/04907_parallel_replicas_parameterized_view_in_subquery.sql:33). As written, a randomized run can bypass the repaired code path and still pass.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units28 translation units recompiled, 252 s compile time in total, 28 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.07 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
CI finish ledger - f14a9b4Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these touches the parameterized-view hash this PR changes. All 160 checks completed and Session id: cron:our-pr-ci-monitor:20261003-130342 |
|
Fixing PR for the Correction to that row: the failing request is the fetch with |
|
Fixing PR for 05237_with_expression_alias_scope_descendant (DBReplicated): #123774 |
…er servers `isEqualImpl` still compared the name as typed, so `pv(p = 0)` and `db.pv(p = 0)` hashed alike but were different nodes, and a query that spells one view both ways (e.g. a `SELECT` item and its `GROUP BY` key) failed with `NOT_AN_AGGREGATE`. A plain table already compares by storage. The hash qualified every parameterized view, while `toASTImpl` sends a view in a dotted database (`a.b`) unqualified. In a cluster with `default_database` set to such a database, an upgraded initiator and an older shard then named the `IN` set differently in both directions. Both now use one predicate, so the hash covers exactly the name that is sent. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A view stores its body with the parameterized view's name qualified, so the inlined call already hashes like the one the shards parse and the arm passes without the fix. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…meterized view The predicate now runs on every tree hash of the node, and `Identifier` splits the name into a vector of parts on each call. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e storage `TableFunctionNode::isEqualImpl` returned early on equal storages, so it ignored `FINAL`/`SAMPLE` and per-call `SETTINGS`, which the tree hash does include. With parameterized views now compared by storage across spellings, `x IN (SELECT y FROM pv(p = 0) FINAL) ... GROUP BY x IN (SELECT y FROM db.pv(p = 0))` passed the GROUP BY check and then failed in the planner with `NOT_FOUND_COLUMN_IN_BLOCK` instead of `NOT_AN_AGGREGATE`. The same happened on master for one spelling, e.g. `merge(...) FINAL` against `merge(...)`. Compare the storage, then fall through to the settings and modifiers, as `TableNode::isEqualImpl` does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The serialized-plan variant fails with THERE_IS_NO_COLUMN instead of NOT_FOUND_COLUMN_IN_BLOCK; check it outside the distributed-plan CI flavor too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| const auto full_name = storage ? storage_id.getFullNameNotQuoted() : String{}; | ||
|
|
||
| /// Hash the name `toASTImpl` sends to other servers: `IN` set names derive from this hash. | ||
| const auto & name = isSentQualified(*this) ? full_name : table_function_name; |
There was a problem hiding this comment.
isEqualImpl now makes pv(...) and db.pv(...) the same parameterized-view node whenever they resolve to the same storage_id, but the hash here only normalizes the unqualified spelling when the database name has no dot.
That breaks the equality/hash invariant again for databases like `a.b`: pv(p = 0) and `a.b`.pv(p = 0) compare equal, but the first hashes pv + a.b.pv while the second hashes a.b.pv + a.b.pv. Anything keyed by tree hash can still split one logical expression into two and reproduce the NOT_AN_AGGREGATE / prepared-set bugs this PR is trying to close.
Can we hash parameterized views by the same storage-based canonical spelling that isEqualImpl uses, and keep isSentQualified only for choosing the wire form in toASTImpl?
| # shellcheck source=../shell_config.sh | ||
| . "$CUR_DIR"/../shell_config.sh | ||
|
|
||
| $CLICKHOUSE_CLIENT -q " |
There was a problem hiding this comment.
This new regression script still inherits the runner's randomized enable_analyzer, but the behavior under test lives in TableFunctionNode. In an old-analyzer / random-settings run these queries can go through the legacy planner and pass without ever touching the repaired equality/hash path, so the test becomes a false green.
Please pin --enable_analyzer=1 (or tag the file no-old-analyzer) before the first query, like the neighboring parameterized-view shard tests do.
CI finish ledger - 01ccfdaEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
None of these touches the parameterized-view code this PR changes. The red job dropped the later jobs, so most stateless jobs did not run on this head. CIDB has no other Session id: cron:our-pr-ci-monitor:20261009-003008 |
CI finish ledger - c1122e2Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261010-003008 |
…zed-view-in-set-on-shard
Related: #113550
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCK(orTHERE_IS_NO_COLUMN) when a query sent to other servers (aDistributedtable,remote, parallel replicas) has anINover a parameterized view called without its database name inside an expression the servers return, for examplecountIf(x IN (SELECT y FROM pv(p = 1))), aGROUP BYkey or aSELECTitem. Also fixedNOT_AN_AGGREGATEwhen one query spells the same parameterized view call both with and without its database name.Description
On 26.8.2.7 and 26.9.7.6:
An
INset is named after the tree hash of its subquery, and the shards return that name inside the column.TableFunctionNodehashed the call as typed (pv), while #113550 sends it to the shards qualified (default.pv(...)), so the shards hash a different name and the initiator does not find the column.WHERE IN,GLOBAL INand a single shard are not affected.TableFunctionNode::updateTreeHashImplnow hashes a resolved parameterized view by the nametoASTImplsends (one shared predicate: qualified unless the database name contains a dot), asTableNodehashes its storage. For a call typed qualified the hash bytes are unchanged, so a fixed initiator works with 26.9 and unfixed master shards and a 26.9 initiator behaves as before (measured, also with a dotteddefault_database; 26.8 names everyINset differently from 26.9+ anyway).isEqualImplnow compares two parameterized views by storage too (still comparingFINALandSETTINGS), soSELECT x IN (SELECT y FROM pv(p = 0)) ... GROUP BY x IN (SELECT y FROM db.pv(p = 0))no longer fails withNOT_AN_AGGREGATE.EXPLAIN QUERY TREEandEXPLAIN SYNTAXare unchanged, andtests/performance/parameterized_view_analysis.xmltakes the same time.05320 covers
countIf,NOT IN, aGROUP BYkey, aSELECTitem,remote,serialize_query_plan = 1, two calls with different arguments and parallel replicas; 05339 covers both spellings in one query; each fails on master. Also measured: a lambda, a CTE, aUNION, a non-default database.Workflow [PR]
Sync PR [sync-upstream/pr/123662]
Version info
26.10.1.1995-master(included in26.10and later)