starocean999 opened a new pull request, #67144:
URL: https://github.com/apache/doris/pull/67144
…
### What problem does this PR solve?
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
When an IN subquery contains two layers of correlated predicates, e.g.
```sql
SELECT l.x,
l.x IN (
SELECT q.r1
FROM (
SELECT r.r1, r.r2
FROM (
SELECT 0 AS r1, 2 AS r2
UNION ALL
SELECT 2 AS r1, 0 AS r2
) r
WHERE r.r1 = l.x
) q
WHERE q.r2 = l.x
) AS pred
FROM (SELECT 0 AS x UNION ALL SELECT 2) l
ORDER BY x;
```
the Nereids rewrite rules UnCorrelatedApplyFilter /
UnCorrelatedApplyProjectFilter /
UnCorrelatedApplyAggregateFilter run twice on the same apply. The second
application
rebuilt LogicalApply with only the newly extracted correlated predicate,
silently
dropping the predicate extracted by the first application from the
accumulated
correlation filter. The dropped predicate therefore never appears in the
final
(physical) join, and the query returns TRUE where the correct result is
FALSE:
before this fix both rows return pred=1, while the finite right side
{(r1,r2)} in
{(0,2),(2,0)} has no row satisfying both r1 = x and r2 = x, so the expected
result
is pred=0 for both rows.
The fix adds ExpressionUtils.mergeCorrelationFilter(), which AND-merges the
existing
correlation filter with the newly extracted correlated predicates
(duplicates are
removed by ExpressionUtils.and), and makes all three rules use it instead of
overwriting the filter. After the fix the final semi join keeps both
correlated
predicates: equal join conjuncts are (x = r2) and (x = r1) together with the
IN
equality, and the query returns 0/0 as expected.
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]