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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalJoin.java:
##########
@@ -357,6 +364,91 @@ public LogicalJoin<Plan, Plan> 
withOtherJoinConjuncts(List<Expression> otherJoin
                 markJoinSlotReference, children);
     }
 
+    private @Nullable Pair<Set<Slot>, Set<Slot>> extractHashKeys() {
+        Set<Slot> leftKeys = new HashSet<>();
+        Set<Slot> rightKeys = new HashSet<>();
+        for (Expression expression : hashJoinConjuncts) {
+            if (!(expression instanceof EqualPredicate
+                    && ((EqualTo) expression).left() instanceof Slot
+                    && ((EqualTo) expression).right() instanceof Slot)) {
+                return null;
+            }
+            Slot leftKey = (Slot) ((EqualTo) expression).left();
+            Slot rightKey = (Slot) ((EqualTo) expression).right();
+            if (left().getOutputSet().contains(leftKey)) {
+                leftKeys.add(leftKey);
+                rightKeys.add(rightKey);
+            } else {
+                leftKeys.add(rightKey);
+                rightKeys.add(leftKey);
+            }
+        }
+        return Pair.of(leftKeys, rightKeys);
+    }
+
+    @Override
+    public FunctionalDependencies computeFuncDeps(Supplier<List<Slot>> 
outputSupplier) {
+        //1. NALAJ and FOJ block functional dependencies
+        if (joinType.isNullAwareLeftAntiJoin() || joinType.isFullOuterJoin()) {
+            return FunctionalDependencies.EMPTY_FUNC_DEPS;
+        }
+
+        // left/right semi/anti join propagate left/right functional 
dependencies
+        if (joinType.isLeftAntiJoin() || joinType.isLefSemiJoin()) {
+            return left().getLogicalProperties().getFunctionalDependencies();
+        }
+        if (joinType.isRightSemiJoin() || joinType.isRightAntiJoin()) {
+            return right().getLogicalProperties().getFunctionalDependencies();
+        }
+
+        // if there is non-equal join conditions, block functional dependencies
+        if (!otherJoinConjuncts.isEmpty()) {
+            return FunctionalDependencies.EMPTY_FUNC_DEPS;
+        }
+
+        Pair<Set<Slot>, Set<Slot>> keys = extractHashKeys();
+        if (keys == null) {
+            return FunctionalDependencies.EMPTY_FUNC_DEPS;
+        }
+
+        // Note here we only check whether the left is unique.
+        // So the hash condition can be null-safe
+        // TODO: consider rejecting Null-safe hash condition when left and 
rigth can be null
+        boolean isLeftUnique = left().getLogicalProperties()

Review Comment:
   for non-null-safe equal join, remove the not null restriction.



-- 
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