Repository navigation
Conversation
Since ClickHouse#129971 the decorrelation join of a correlated scalar or EXISTS subquery compares a Nullable correlated key with `NullSafeEquals`. `JoinStepLogical` turns such a key into `isNull(x)` plus `if(isNull(x), d, assumeNotNull(x))` (or `tuple(x)`), and these wrappers took the default DAG name built from the key, e.g. `isNull(__table3.a)`. The outer side of the decorrelation join is the stream after `GROUP BY`, so it can already carry a column of that exact name: the GROUP BY key `isNull(a)`. The join header then had two columns of one name: - with `group_by_use_nulls = 1` and ROLLUP/CUBE/GROUPING SETS they differ in type (`Nullable(UInt8)` vs `UInt8`) and the query fails with `Code: 352 ... columns with identical name must have identical structure (AMBIGUOUS_COLUMN_NAME)`; - with equal types the name-keyed lookup binds the synthesized key, so the outer `isNull(a)` of a ROLLUP subtotal row reads 1 instead of the rolled-up 0. Ordinary joins never hit this because their inputs are `__tableN.`-qualified columns. Name the three wrappers like `TableJoin`'s `__wrapNullsafe` does: keep the default name unless an input of the join's DAG has it, then append `_<i>`. Plans without a collision keep byte-identical names. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The earlier queries of 05828 collide only with the `isNull(x)` key, so a regression in the naming of the `if(isNull(x), d, assumeNotNull(x))` value key, of the `tuple(x)` wrap, or of the `_N` suffix loop would go unnoticed. Ordinary expressions do not take those names, so the new queries forge an outer `GROUP BY` key with the internal `__actionName`: one named like the `if` key, one like the `tuple` key, and one occupying `isNull(x)_0` next to the colliding `isNull(x)` key. Each fails on master (Code 352) and fails again when only its own naming path is reverted to the default name (or, for the loop, to an unchecked `_0`). 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 over 2 rounds) plus my own review.
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-9:20261118-030700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20261118-024900 |
|
Workflow [PR], commit [261735f] Summary: ✅
AI ReviewSummaryThe PR prevents synthesized null-safe join keys from shadowing input expressions, fixing exceptions and incorrect results for correlated subqueries over Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units7 translation units recompiled, 33 s compile time in total, 7 of them have a recent master baseline. |
Related: #129971
Related: #104350
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
Since #129971 (master only, not in any release branch), this query fails:
With
group_by_use_nulls = 0it runs, butisNull(a)selected next to it reads1instead of the rolled-up0in thegrand-total row. It turned
test
04210of #104350 red (CI report).Root cause: #129971 joins the decorrelated subquery on its Nullable key with
NullSafeEquals.JoinStepLogicalsplits such a key into
isNull(x)andif(isNull(x), d, assumeNotNull(x))(or wraps it intuple(x)), and thesetook their default names. The outer side of that join is the stream after
GROUP BY, which already has a columnisNull(__table3.a), so the join saw two columns of one name.The change names these key expressions like
TableJoinnames its__wrapNullsafewrapper: the default name unless aninput of the join already has it, then a
_Nsuffix. Joins without such a collision keep identical names.Validation: each query of the new test fails on master and passes with the fix (ROLLUP, CUBE, GROUPING SETS, EXISTS,
group_by_use_nulls = 0, bothcorrelated_subqueries_default_join_kindvalues). The existing correlated-subquery,null-safe-join and
group_by_use_nullstests pass, except 3 that need fixtures I do not have locally and fail the sameway on master. Ordinary expressions I tried do not take the
if(...)ortuple(x)key names (the analyzer unwraps atuple in
GROUP BY), so the test forges them, and an occupied_0, with the internal__actionName.Reverting #129971 also removes the error, but brings back the wrong results it fixed (#112576).
Workflow [PR]
Sync PR [sync-upstream/pr/132567]