englefly commented on code in PR #11812:
URL: https://github.com/apache/doris/pull/11812#discussion_r950149550


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java:
##########
@@ -87,6 +91,117 @@ private static boolean isEqualTo(List<SlotReference> 
leftSlots, List<SlotReferen
                 || (leftSlotsSet.containsAll(rightUsed) && 
rightSlotsSet.containsAll(leftUsed));
     }
 
+    private static class JoinSlotCoverageChecker {
+        HashSet<SlotReference> left;
+        HashSet<ExprId> leftExprIds;
+        HashSet<SlotReference> right;
+        HashSet<ExprId> rightExprIds;
+
+        JoinSlotCoverageChecker(List<SlotReference> left, List<SlotReference> 
right) {
+            this.left = new HashSet<>(left);
+            leftExprIds = new 
HashSet<>(left.stream().map(SlotReference::getExprId).collect(Collectors.toList()));
+            this.right = new HashSet<>(right);
+            rightExprIds = new 
HashSet<>(right.stream().map(SlotReference::getExprId).collect(Collectors.toList()));
+        }
+
+        boolean isCoveredByLeftSlots(List<SlotReference> slots) {
+            boolean covered = left.containsAll(slots);
+            if (covered) {
+                return true;
+            }
+            List<ExprId> slotsExprIds = slots.stream()
+                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+            return leftExprIds.containsAll(slotsExprIds);
+        }
+
+        boolean isCoveredByRightSlots(List<SlotReference> slots) {
+            boolean covered = right.containsAll(slots);
+            if (covered) {
+                return true;
+            }
+            List<ExprId> slotsExprIds = slots.stream()
+                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+            return rightExprIds.containsAll(slotsExprIds);
+        }
+
+        /**
+         *  consider following cases:
+         *  1# A=1 => not for hash table
+         *  2# t1.a=t2.a + t2.b => hash table
+         *  3# t1.a=t1.a + t2.b => not for hash table
+         *  4# t1.a=t2.a or t1.b=t2.b not for hash table
+         *  5# t1.a > 1 not for hash table
+         * @param equalTo a conjunct in on clause condition
+         * @return true if the equal can be used as hash join condition
+         */
+        boolean isHashJoinCondition(EqualTo equalTo) {
+            List<SlotReference> equalLeft =  
equalTo.left().collect(SlotReference.class::isInstance);
+            if (equalLeft.isEmpty()) {
+                return false;
+            }
+
+            List<SlotReference> equalRight = 
equalTo.right().collect(SlotReference.class::isInstance);
+            if (equalRight.isEmpty()) {
+                return false;
+            }
+
+            List<ExprId> equalLeftExprIds = equalLeft.stream()
+                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+
+            List<ExprId> equalRightExprIds = equalRight.stream()
+                    
.map(SlotReference::getExprId).collect(Collectors.toList());
+            return leftExprIds.containsAll(equalLeftExprIds) && 
rightExprIds.containsAll(equalRightExprIds)
+                    || left.containsAll(equalLeft) && 
right.containsAll(equalRight)
+                    || leftExprIds.containsAll(equalRightExprIds) && 
rightExprIds.containsAll(equalLeftExprIds)
+                    || right.containsAll(equalLeft) && 
left.containsAll(equalRight);
+        }
+    }
+
+    /**
+     * collect expressions from on clause, which could be used to build hash 
table
+     * @param join join node
+     * @return pair of expressions, for hash table or not.
+     */
+    public static Pair<List<Expression>, List<Expression>> 
extractExpressionForHashTable(LogicalJoin join,

Review Comment:
   Oh, yes. I refactored the code.



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

Reply via email to