Repository navigation
Add a test for PREWHERE steps computing two columns with one name - #127016
alexey-milovidov merged 6 commits into
Conversation
…h one name With join_use_nulls = 1, the WHERE copy of a JOIN ON condition repeated in WHERE is computed on toNullable(col) but keeps the name of the ON copy, so the PREWHERE DAG holds two different nodes with one name and two types (e.g. equals(__table2.enabled, 1_Bool) as Nullable(UInt8) and UInt8). tryBuildPrewhereSteps clones every node into its step under its own name, the steps pass columns to each other through a Block by name, and a non-last step keeps its filter column in the block. When the two copies fall into non-adjacent, non-last steps, the later step inserts a column of the same name and another type and Block::insert throws 352. Two repeated two-condition groups collide the same way through the generated `and` name. Clone the non-INPUT nodes whose name is shared with another node, and that are not outputs of PREWHERE, under new names (`__prewhere_<name>`). Only the step clones are renamed: the original DAG, and so its conjunct hashes used by the query condition cache attribution, are unchanged, and the step boundaries stay where they are, so an earlier condition still filters the rows a later default expression is evaluated on (a one-step fallback would throw there). The helper has the same shape as the one in ClickHouse#125670, which renames for a computed node named like a stored column. Same class as ClickHouse#111955, fixed for the FilterStep split by ClickHouse#112007. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new names given to the step clones of nodes that share a name were made unique only against the names of the PREWHERE DAG. Stored columns read after PREWHERE are not in that DAG but land in the same block, and the readers skip a stored column whose name a step already produced (`getReadTaskColumns` for MergeTree, `read_missing_columns` for Memory). So a table with a column named like a new name, e.g. `__prewhere_equals(__table2.enabled, 1_Bool)`, returned the step's predicate value instead of the stored value. Also skip a candidate name that is a physical column or subcolumn of the table, with the same `is_stored_column` helper as ClickHouse#125670. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A step with two or more conditions gets a generated `and` filter named after its children. With the renamed children that name is new, and a non-last step keeps the filter in the block, so a stored column with the same name is not read and the query returns the filter value instead. Alias such a filter to a fresh name, as ClickHouse#125670 does, and share its two name helpers so the two PRs fold mechanically. 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; 3 findings over 3 rounds) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261020-182700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-7:20261020-163900 |
|
cc @CurtizJ @Avogar, could you review this and add the |
|
Workflow [PR], commit [e88fc6c] Summary: ✅ AI ReviewSummaryPR #127016 at Final Verdict✅ Approve. |
|
I'd keep it. The pin is not only there to avoid the 352: since #116248 a The If you would still like 04650 to run with |
|
This no longer reproduces on master. Since #128452 (merged 2026-11-01) an intermediate @alexey-milovidov, should I reduce this PR to the |
|
@groeneai, yes - let it be test-only. |
Master no longer reproduces the AMBIGUOUS_COLUMN_NAME: since ClickHouse#128452 an intermediate PREWHERE step removes its filter column when nothing later uses it, so the ON copy is gone before the WHERE copy with the same name is computed. The renaming in `tryBuildPrewhereSteps` is therefore dropped, and the file is restored to its version at the base of this branch (which also stops the PR from conflicting with ClickHouse#124553, which removed `columns` from that function). `05427` stays as a regression test: it passes on master 5b24a5f and fails on 26.10.2.103 with Code 352 in 8 of its 9 queries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
They checked that the dropped renaming did not pick the name of a stored column. Without the renaming nothing generates `__prewhere_` names, so they no longer test anything the other cases do not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AMBIGUOUS_COLUMN_NAME when a PREWHERE split into steps computes two different columns with one namePREWHERE steps computing two columns with one name
|
Done: the PR now only adds |
CI finish ledger - 6f98a2cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The three Session id: cron:our-pr-ci-monitor:20261107-233003 |
|
Fixing PR for 00673_subquery_prepared_set_performance created: #130153 |
Related: #128452
Related: #111955
Related: #122160
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Description
This PR only adds a regression test.
SELECT t1.id, t2.reviewer FROM t1 LEFT JOIN t2 ON t1.id = t2.id AND t2.enabled = true AND t2.reviewer > 0 WHERE t2.enabled = true AND t2.reviewer = 100 SETTINGS join_use_nulls = 1, allow_reorder_prewhere_conditions = 0fails on 26.10.2.103 and 26.8.21.12 withAMBIGUOUS_COLUMN_NAME(Block structure mismatch). Withjoin_use_nulls = 1theWHEREcopy of the repeatedONcondition is computed ontoNullable(col)under the same name, and aPREWHEREsplit into steps kept the first copy in the block when it computed the second one. CI hit it in04650_join_use_nulls_repeated_on_condition_in_whereon #122160 (report).Master no longer fails since #128452, which removes the filter column of an intermediate
PREWHEREstep when nothing later reads it.05427_prewhere_steps_duplicate_computed_namecovers bothONorders, aMemorytable, a step with two conditions, and a default expression evaluated after the steps. It passes on master 5b24a5f (also 100 randomized runs and with parallel replicas) and fails on 26.10.2.103 in 4 of its 5 queries.An earlier version of this PR also changed
tryBuildPrewhereSteps; that change is dropped.Workflow [PR]
Sync PR [sync-upstream/pr/127016]
Version info
26.11.1.1650-master(included in26.11and later)