Repository navigation
Fix Cannot fold actions for projection when the join order optimizer reorders an outer join converted to INNER - #127416
Conversation
With `join_use_nulls = 1`, `tryConvertOuterJoinToInnerJoin` turns an outer join into INNER but keeps its `toNullable` actions, because the join output must stay Nullable. `chooseJoinOrder` applied those type changes at the step that joins the relation alone and from then on replaced the relation's original inputs. After the conversion nothing pins the relation to its ON partners anymore, so the optimizer may join it first (through a transitive equality or another ON edge); a later step that reads an original column of the relation (an ON predicate or a predicate synthesized from the column equivalences) then failed with `Cannot fold actions for projection`. An INNER join pads nothing, so its type change is value-preserving and is not tied to any step. Apply a type change at the step that joins the relation alone only when an outer join NULL-pads that relation (it has an outer `join_kinds` entry); apply every other type change at the last step, when all predicates over the original columns have been evaluated. The chosen join order does not change, only where the columns become Nullable. Closes ClickHouse#127331 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merge the two-line type-change comment in chooseJoinOrder into one invariant line. 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; bounded: 1 full pass + 1 fix round + 1 delta recheck).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261022-133600 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261022-114200 |
|
cc @vdimir @davenger, could you review this and add the |
|
Workflow [PR], commit [5d12b3c] Summary: ✅
AI ReviewSummaryPR #127416 defers the retained Final VerdictStatus: ✅ Approve |
CI finish ledger - d9d5870Every 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-010008 |
20ce5b5
Cherry pick #127416 to 26.10: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
…hen the join order optimizer reorders an outer join converted to INNER
Backport #127416 to 26.10: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
Cherry pick #127416 to 26.3: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
Cherry pick #127416 to 26.8: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
Cherry pick #127416 to 26.9: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
Backport #127416 to 26.9: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
Backport #127416 to 26.8: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
Backport #127416 to 26.3: Fix `Cannot fold actions for projection` when the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
…en the join order optimizer reorders an outer join converted to INNER
…hen the join order optimizer reorders an outer join converted to INNER
Closes: #127331
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the
Cannot fold actions for projectionlogical error for queries withjoin_use_nulls = 1in which aLEFTorRIGHT JOINis turned into an inner join by aWHEREcondition and then reordered by the join order optimizer, for examplea JOIN b ON ... LEFT JOIN c ON b.x = c.x ... WHERE c.v = 'x'. Closes #127331.Description
On 26.8.28.14 (also 26.6, 26.7 and 26.9) this valid query is rejected with
Code: 49. ... Cannot fold actions for projection. Node equals(__table2.x, __table3.x) requires input __table3.x which does not belong to projection. (LOGICAL_ERROR), with onlyjoin_use_nulls = 1set:On master it still fails with default settings for some row estimates, and with other join orders.
WHERE c.v = 'x'rejects NULLs, so theLEFT JOINbecomesINNER, but itstoNullable(c.*)actions stay because the result columns must remainNullable. The join order optimizer applied that type change at the step that joinscalone and dropped the originalccolumns. After the conversion nothing keepscnext tob, so it can be joined withafirst (througha.t = b.t = c.t), and the later step that evaluatesb.x = c.xno longer finds the originalc.x.Now the type change is applied at the step that joins the relation alone only when an outer join pads that relation with NULLs. Any other type change is applied at the last join step. The chosen join order does not change.
The new test covers the greedy, DPsize, DPhyp and DPsub algorithms (with and without conflict detectors), the
RIGHT JOINform, and a predicate synthesized from the column equivalences. Every query in it fails on master. Sweeping 5 query shapes x 6 algorithms x 201 random seeds gives no errors with the fix, the same results as without the conversion, and the same join trees as before for every order that already worked.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/127416]
Version info
26.11.1.1120-master(included in26.11and later)