Repository navigation
Fix NOT_FOUND_COLUMN_IN_BLOCK when an alias of a nested single-element tuple comparison is reused by GROUP BY - #124546
Conversation
`ComparisonTupleEliminationPass` replaces `tuple(x) = tuple(y)` by `x = y`, which is again a tuple comparison when `x` is a tuple, and the visitor never re-enters a replacement root, so one visit removed one nesting level. With the identifier resolve cache the GROUP BY key and its ORDER BY / HAVING / WHERE references are one node visited once per reference while the projection keeps its own copy, so their rewrites diverged and the query failed with NOT_FOUND_COLUMN_IN_BLOCK. Re-entering the replacement makes one visit reach the fixed point. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…omparison Replace the EXPLAIN check with result checks: a WHERE equality of nested single-element tuples over a CROSS JOIN is now rewritten to `l.key = r.key`, so the (NULL, NULL) pair is no longer matched, the same as for `tuple(l.key) = tuple(r.key)`; and the shared alias also works over `remote()`. 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 in round 1, 0 in round 2) plus my own cold review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-self-slot-58:20261008-031900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-self-slot-57:20261008-024300 |
|
Workflow [PR], commit [8de8557] Summary: ✅
AI ReviewSummaryThis PR makes Final Verdict✅ Looks good to merge. LLVM Coverage ReportMeasured on commit 8de8557.
Changed lines: Changed C/C++ lines covered: 4/4 (100.00%) · Uncovered code |
Related: #122404
Related: #108553
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
NOT_FOUND_COLUMN_IN_BLOCKwhen a comparison of single-element tuples whose elements are tuples, such astuple((a, b)) = tuple((c, d)), is part of an alias used inGROUP BYand also inORDER BY,HAVINGorWHERE. Such comparisons are now rewritten completely, soWHERE tuple(tuple(x)) = tuple(tuple(y))over a join no longer returns rows wherexandyare bothNULL, the same asWHERE tuple(x) = tuple(y).Description
On 26.8.2.7,
SELECT NOT (tuple(tuple(n, 1)) = tuple(tuple(n, 2))) AS r FROM t GROUP BY r ORDER BY rfails withCode: 10 NOT_FOUND_COLUMN_IN_BLOCKon default settings (also on 26.6, 26.9 and master;1withenable_identifier_resolve_cache = 0).ComparisonTupleEliminationPassreplacestuple(x) = tuple(y)byx = y, which is again a tuple comparison whenxis a tuple, and the visitor never re-enters a replacement, so one visit removes one nesting level. With the identifier resolve cache (default since 26.6) theGROUP BYkey and itsORDER BY/HAVING/WHEREreferences are one node visited once per reference, while the projection copy is visited once, so the two end up with different names.The change: re-enter the replacement, so one visit reaches the fixed point and the result does not depend on node sharing.
Side effect:
l CROSS JOIN r WHERE tuple(tuple(l.key)) = tuple(tuple(r.key))overNullablekeys returned the(NULL, NULL)pair (2 rows, the leftover tuple equality became a join key) and now returns 1 row, liketuple(l.key) = tuple(r.key)does.JOIN ONis still not rewritten (#67493).The new test covers 11 queries (
=/!=, a constant on either side,HAVING,WHERE, 3 levels, a nested tuple inside a 2-element tuple,NullableandLowCardinalitycolumns,WITH ROLLUP,remote(), the join): all fail on master and pass with the fix, 50/50 with random settings. A differential run of 3164 existing tests changed no result.The same issue in other passes is fixed separately:
Related: #123925
Related: #124480
Related: #124482
Workflow [PR]
Sync PR [sync-upstream/pr/124546]
Version info
26.10.1.2090-master(included in26.10and later)