-
Notifications
You must be signed in to change notification settings - Fork 3.6k
branch-3.1:[fix](nereids) pull up left join right predicate with or is null #58372 #58664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
…che#58372) Related PR: apache#41731 Problem Summary: The optimizer cannot derive predicates across multiple LEFT JOINs. For example, given a filter on the leftmost table in a chain of LEFT JOINs, the optimizer should be able to derive predicates on the rightmost table, but it currently fails to do so. create table t1(a int, b int); create table t2(a int, b int); create table t3(a int, b int); insert into t1 values(1,2); insert into t2 values(1,2); insert into t3 values(1,2); insert into t3 values(null,2); explain logical plan select * from t1 left join t2 on t1.a=t2.a left join t3 on t2.a=t3.a where t1.a=1; LogicalResultSink[110] ( outputExprs=[a#0, b#1, a#2, b#3, a#4, b#5] ) +--LogicalProject[109] ( distinct=false, projects=[a#0, b#1, a#2, b#3, a#4, b#5] ) +--LogicalJoin[108] ( type=LEFT_OUTER_JOIN, markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(a#2 = a#4)], otherJoinConjuncts=[], markJoinConjuncts=[] ) |--LogicalProject[105] ( distinct=false, projects=[a#0, b#1, a#2, b#3] ) | +--LogicalJoin[104] ( type=LEFT_OUTER_JOIN, markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(a#0 = a#2)], otherJoinConjuncts=[], markJoinConjuncts=[] ) | |--LogicalFilter[101] ( predicates=(a#0 = 1) ) | | +--LogicalOlapScan ( qualified=internal.maldb.t1, indexName=<index_not_selected>, selectedIndexId=1764043369852, preAgg=ON, operativeCol=[a#0], virtualColumns=[] ) | +--LogicalFilter[103] ( predicates=(a#2 = 1) ) | +--LogicalOlapScan ( qualified=internal.maldb.t2, indexName=<index_not_selected>, selectedIndexId=1764043369875, preAgg=ON, operativeCol=[a#2], virtualColumns=[] ) +--LogicalOlapScan ( qualified=internal.maldb.t3, indexName=<index_not_selected>, selectedIndexId=1764043369898, preAgg=ON, operativeCol=[a#4], virtualColumns=[] ) The optimizer should derive t3.a=1 from t1.a=1 and the join conditions, but it currently doesn't. The root cause is that the PullUpPredicates rule doesn't properly handle predicate pull-up from the right side of LEFT JOINs. This PR fixes this by generating null-tolerant predicates when pulling up from RIGHT JOIN's right table and strengthening them when possible based on upper-level join conditions. after this pr: LogicalResultSink[110] ( outputExprs=[a#0, b#1, a#2, b#3, a#4, b#5] ) +--LogicalProject[109] ( distinct=false, projects=[a#0, b#1, a#2, b#3, a#4, b#5] ) +--LogicalJoin[108] ( type=LEFT_OUTER_JOIN, markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(a#2 = a#4)], otherJoinConjuncts=[], markJoinConjuncts=[] ) |--LogicalProject[105] ( distinct=false, projects=[a#0, b#1, a#2, b#3] ) | +--LogicalJoin[104] ( type=LEFT_OUTER_JOIN, markJoinSlotReference=Optional.empty, hashJoinConjuncts=[(a#0 = a#2)], otherJoinConjuncts=[], markJoinConjuncts=[] ) | |--LogicalFilter[101] ( predicates=(a#0 = 1) ) | | +--LogicalOlapScan ( qualified=internal.maldb.t1, indexName=<index_not_selected>, selectedIndexId=1764043369852, preAgg=ON, operativeCol=[a#0], virtualColumns=[] ) | +--LogicalFilter[103] ( predicates=(a#2 = 1) ) | +--LogicalOlapScan ( qualified=internal.maldb.t2, indexName=<index_not_selected>, selectedIndexId=1764043369875, preAgg=ON, operativeCol=[a#2], virtualColumns=[] ) +--LogicalFilter[107] ( predicates=(a#4 = 1) ) +--LogicalOlapScan ( qualified=internal.maldb.t3, indexName=<index_not_selected>, selectedIndexId=1764043369898, preAgg=ON, operativeCol=[a#4], virtualColumns=[] )
Contributor
|
Thank you for your contribution to Apache Doris. Please clearly describe your PR:
|
Contributor
Author
|
run buildall |
Contributor
Author
|
run buildall |
Contributor
Author
|
run buildall |
morrySnow
approved these changes
Dec 4, 2025
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.
picked from #58372