feiniaofeiafei opened a new pull request, #58372:
URL: https://github.com/apache/doris/pull/58372
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
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.
```sql
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.
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
https://github.com/apache/doris-website/pull/1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR should
merge into -->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]