xzj7019 commented on code in PR #31854:
URL: https://github.com/apache/doris/pull/31854#discussion_r1515404530


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/ConvertOuterJoinToAntiJoin.java:
##########
@@ -73,36 +66,29 @@ private Plan 
toAntiJoin(LogicalProject<LogicalFilter<LogicalJoin<Plan, Plan>>> p
                 .filter(s -> alwaysNullSlots.contains(s) && !s.nullable())
                 .collect(Collectors.toSet());
 
-        Plan res = project;
-        if (join.getJoinType().isLeftOuterJoin() && 
!rightAlwaysNullSlots.isEmpty() && leftOutput) {
-            // When there is right slot always null, we can turn left outer 
join to left anti join
-            Set<Expression> predicates = filter.getExpressions().stream()
-                    .filter(p -> !(TypeUtils.isNull(p).isPresent()
-                            && 
rightAlwaysNullSlots.containsAll(p.getInputSlots())))
-                    .collect(ImmutableSet.toImmutableSet());
-            boolean containRightSlot = predicates.stream()
-                    .flatMap(p -> p.getInputSlots().stream())
-                    .anyMatch(join.right().getOutputSet()::contains);
-            if (!containRightSlot) {
-                res = join.withJoinType(JoinType.LEFT_ANTI_JOIN, 
join.getJoinReorderContext());
-                res = predicates.isEmpty() ? res : 
filter.withConjuncts(predicates).withChildren(res);
-                res = project.withChildren(res);
-            }
+        Plan newJoin = null;
+        if (join.getJoinType().isLeftOuterJoin() && 
!rightAlwaysNullSlots.isEmpty()) {
+            newJoin = join.withJoinType(JoinType.LEFT_ANTI_JOIN, 
join.getJoinReorderContext());
         }
-        if (join.getJoinType().isRightOuterJoin() && 
!leftAlwaysNullSlots.isEmpty() && rightOutput) {
-            Set<Expression> predicates = filter.getExpressions().stream()
-                    .filter(p -> !(TypeUtils.isNull(p).isPresent()
-                            && 
leftAlwaysNullSlots.containsAll(p.getInputSlots())))
-                    .collect(ImmutableSet.toImmutableSet());
-            boolean containLeftSlot = predicates.stream()
-                    .flatMap(p -> p.getInputSlots().stream())
-                    .anyMatch(join.left().getOutputSet()::contains);
-            if (!containLeftSlot) {
-                res = join.withJoinType(JoinType.RIGHT_ANTI_JOIN, 
join.getJoinReorderContext());
-                res = predicates.isEmpty() ? res : 
filter.withConjuncts(predicates).withChildren(res);
-                res = project.withChildren(res);
-            }
+        if (join.getJoinType().isRightOuterJoin() && 
!leftAlwaysNullSlots.isEmpty()) {
+            newJoin = join.withJoinType(JoinType.RIGHT_ANTI_JOIN, 
join.getJoinReorderContext());
+        }
+        if (newJoin == null) {
+            return null;
+        }
+
+        if (!newJoin.getOutputSet().containsAll(filter.getInputSlots())) {

Review Comment:
   do we need to add cases to cover null as (b.id1 + b.id2)?



-- 
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: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to