Repository navigation
Conversation
…uter query A correlated column in PREWHERE went through three planner stages that each assume every column belongs to a table of the current query: 1. CollectPrewhereTableExpressionVisitor picked the PREWHERE table from the column sources, so a correlated column selected the OUTER table. Its table expression data is shared with the outer query, whose read is already planned, so the condition was silently dropped (wrong result). Correlated columns are now skipped when choosing the table. 2. The PREWHERE DAG names table columns by their plain names, and every node, including whole expressions, is deduplicated by name. A correlated column, or any expression over it, merged with the inner column or expression of the same text (wrong result), and a shadowing lambda argument made the types disagree (`Unexpected return type`). ActionNodeNameHelper now names a correlated column by its column identifier also in that DAG, which is the name under which the decorrelation provides the outer value. 3. The PREWHERE DAG was handed to the storage as prewhere_info, which the decorrelation never visits, so a PLACEHOLDER reached the MergeTree reader and the Merge table filter (`Trying to execute PLACEHOLDER action`, also under EXPLAIN). A PREWHERE with a correlated column is now applied by a FilterStep directly above the read (the existing build_logical_plan branch), which the decorrelation handles like WHERE. With FINAL it is refused, because such a filter cannot run before the FINAL merge. Test 04058 case 1 used PREWHERE on the implicit `system.one` with only outer columns, which was accepted only because the condition was dropped; it now uses WHERE, which keeps what that test checks. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…outer column The decorrelation joins the outer values to the read under the names of the correlated columns (for example `__table1.value`). A correlated PREWHERE is applied by a filter directly above the read, so a table with a column literally named `__table1.value` produced two columns of that name, and the filter used the inner one: no rows instead of `11`. Such a PREWHERE now throws ILLEGAL_PREWHERE. WHERE is not affected, because its filter runs above the step that renames the columns to their identifiers. Test 05258 gets that case. Its q5 and q6 now also require `t2.value > 10`: both sides read the same rows, so before this change the diagonal satisfied them even when the condition was ignored or the outer column was merged with the inner one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion joins them The decorrelation joins the outer values to the uncorrelated part of a subquery plan under the names of all correlated columns of the subquery. The previous check sat in the read of a correlated PREWHERE and compared only the correlated columns of that query. In a correlated UNION each arm is a separate query that lists only the outer columns it references, while every arm is joined with all of them. So an arm that reads a column named like an outer column referenced only by another arm still got two columns of that name, and the query failed with UNION_ALL_RESULT_STRUCTURES_MISMATCH or bound the column by name. The check now runs at the decorrelation boundary, which sees exactly the header and the names that are joined, and throws NOT_IMPLEMENTED. It replaces the PREWHERE-only check and covers its cases. WHERE is not affected, because its filter runs after the columns are renamed to their unique identifiers. Test 05258 gets the UNION case and a control query without the colliding column; the existing clash query now expects NOT_IMPLEMENTED. 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; round 1: 1 finding, round 2: 4, round 3: 0) plus my
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-10:20260926-053600 |
|
Workflow [PR], commit [caab4a3] Summary: ❌
AI ReviewSummaryThis change fixes dropped predicates and incorrect column binding in correlated subquery Final VerdictStatus: ✅ Approve. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-5:20260926-045300 |
CI finish ledger - 6695cfdEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260926-160139 |
… took The PREWHERE DAG names table columns by their names and a correlated column by its identifier. When an inner column literally named like that identifier (`__table3.value`) was visited first, the correlated column was merged with it: no PLACEHOLDER was added, the PREWHERE was pushed into the storage, and it compared the inner column with itself. A scalar subquery returned 1 instead of NULL. The reverse operand order was already refused at the decorrelation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - caab4a3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20261023-040008 |
Related: #121230
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed wrong results and
Logical error: Trying to execute PLACEHOLDER actionfor a correlated subquery whosePREWHEREreferences a column of the outer query: the condition was ignored, or the outer column was taken from the inner table's column of the same name. Such aPREWHEREnow throwsILLEGAL_PREWHEREwithFINALor on a table withoutPREWHEREsupport, andNOT_IMPLEMENTEDwith aJOINinside the subquery, instead of being ignored.Description
On 26.8.2.7 and 26.3.33.10,
SELECT value FROM t AS t1 WHERE exists(SELECT 1 FROM t AS t2 PREWHERE t1.value + 1 = 12)overt = (10), (11)returns both rows instead of11, andPREWHERE arrayMap(x -> x + t1.value, [1])[1] = 12throwsLOGICAL_ERROR.Found by the AST fuzzer on #121230, which does not cause it: AST fuzzer (amd_debug, targeted), STID 1611-3e1e and 1611-4266.
Three
PREWHEREplanner stages assumed every column belongs to a table of the current query:WHERE. That filter cannot precede FINAL merging, hence theFINALrefusal; aJOINabove it is not decorrelated.That filter sees raw column names, and the step 2 DAG merges by name, so a column named like an outer identifier (
__table1.value) would shadow the outer value; such a subquery is now refused.04058case 1 relied on the dropped condition and now usesWHERE. This also fixes the correlated case of the #121230 collision; both PRs' tests pass together.Validation:
05258fails on master (server abort) and passes with the fix; 50 randomized runs; 364PREWHERE/correlated tests give identical results before and after.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122397]