Skip to content

Cherry pick #123829 to 26.8: Do not read a JOIN input that cannot contribute under a WHERE no row passes - #124218

Merged
robot-ch-test-poll merged 6 commits into
backport/26.8/123829from
cherrypick/26.8/123829
Oct 6, 2026
Merged

robot-ch-test-poll merged 6 commits into
backport/26.8/123829from
cherrypick/26.8/123829

Conversation

@robot-ch-test-poll2

Copy link
Copy Markdown
Contributor

Original pull-request #123829

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

groeneai and others added 5 commits October 4, 2026 05:35
…passes

Since the constant-conjunct guard of #107084, a no-input conjunct of a filter
above a JOIN is kept off the side the filter cannot be pushed to (the
non-preserved side of an OUTER join, or a side none of whose columns is used
above the join). A UNION ALL branch made false by an outer WHERE on its
constant column (`materialize(k4)` from the UNION conversion) therefore read,
aggregated and hash-built that side in full (issue #123702).

When the filter above a JoinStepLogical is false for every row, replace each
input it cannot be pushed to with ReadNothing, using the helper extracted from
the constant-false ON short-circuit. A `FULL JOIN` under such a `WHERE` has
both inputs replaced. The helper keeps an input that carries more than rows: a
JoinStepLogicalLookup, also below single-child wrappers, a subtree that can
produce totals (TotalsHavingStep, a remote read, or a query result cache read),
since a join joins its inputs' totals, or a subtree holding one half of a
shared subplan (`CommonSubplanStep` / `CommonSubplanReferenceStep`, which
decorrelation pairs across a join). The totals case also restores the totals
row the ON short-circuit dropped since 26.8.

Join-order estimation now treats ReadNothing as an exact empty relation, as it
already does for an exact empty MergeTree read, so a replaced input keeps its
exact zero estimate. `04516_join_reorder_duplicate_names_merge_expression` now
ignores the `[0]` row estimate an empty table gets in its EXPLAIN label.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Shorten the JoinStepLogicalLookup comment to one line and drop the comment above carriesMoreThanRows, which restated its own doc.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review on #123702 asked to keep the fix local to #107084, so the plan-level
ReadNothing rule is replaced by an exception in that guard.

The guard keeps a conjunct that reads no column off a join input that
push-down is disabled for: pushing it there and dropping it from the
post-join filter changes the result when it is NULL (04335) or true but
pruning (`indexHint`). When no row passes the filter and the join kind
allows filtering one input, that input receives the conjunct and the join
output is empty whatever the other input holds, so the guard is skipped
and the disabled input is filtered too, as before 26.7.

"No row passes" is `filterResultForNotMatchedRows` with no input
defaulted, which the outer join conversions already use, and the filter
must not be sensitive to its evaluation count.

This also drops the ReadNothingStep row estimate and the oracle change in
04516_join_reorder_duplicate_names_merge_expression, which only the
ReadNothing rule needed. The WITH TOTALS row lost by the constant-false
ON short-circuit is unrelated to #107084 and goes to a separate PR.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…false-where

Do not read a JOIN input that cannot contribute under a WHERE no row passes
@robot-ch-test-poll2 robot-ch-test-poll2 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Oct 6, 2026
@robot-ch-test-poll
robot-ch-test-poll merged commit 7c7e402 into backport/26.8/123829 Oct 6, 2026
1 check passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.8/123829 branch October 6, 2026 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants