Repository navigation
Cherry pick #123829 to 26.8: Do not read a JOIN input that cannot contribute under a WHERE no row passes - #124218
Merged
Conversation
…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]>
…ut-under-false-where 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job