nooneuse commented on code in PR #66307:
URL: https://github.com/apache/doris/pull/66307#discussion_r3842109624


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/util/JoinUtils.java:
##########
@@ -307,12 +356,85 @@ public static boolean 
couldColocateJoin(DistributionSpecHash leftHashSpec, Distr
                 equalIndices.add(leftIndex);
             }
         }
-        // on conditions must contain all distributed columns
-        if 
(equalIndices.containsAll(leftHashSpec.getExprIdToEquivalenceSet().values())) {
-            return true;
-        } else {
+        return 
equalIndices.containsAll(leftHashSpec.getExprIdToEquivalenceSet().values());
+    }
+
+    private static boolean 
couldColocateJoinOnDistributionMappings(DistributionSpecHash leftHashSpec,
+            DistributionSpecHash rightHashSpec, List<Expression> conjuncts) {
+        return couldColocateJoinOnDistributionMappings(
+                leftHashSpec.getExprIdToEquivalenceSet(), 
leftHashSpec.getDistributionMappings(),
+                rightHashSpec.getExprIdToEquivalenceSet(), 
rightHashSpec.getDistributionMappings(),
+                leftHashSpec.getOrderedShuffledColumns().size(), conjuncts);
+    }
+
+    private static boolean couldColocateJoinOnDistributionMappings(
+            Map<ExprId, Integer> leftDistributionExprToIndex, 
List<DistributionMapping> leftMappings,
+            Map<ExprId, Integer> rightDistributionExprToIndex, 
List<DistributionMapping> rightMappings,
+            int distributionKeyCount, List<Expression> conjuncts) {
+        if (!areAllSlotEqualPredicates(conjuncts)) {
             return false;
         }
+        List<Pair<ExprId, ExprId>> equalExprIds = Lists.newArrayList();
+        Set<Integer> coveredIndices = new HashSet<>();
+        for (Expression expr : conjuncts) {
+            ExprId first = ((SlotReference) ((EqualPredicate) 
expr).left()).getExprId();
+            ExprId second = ((SlotReference) ((EqualPredicate) 
expr).right()).getExprId();
+            equalExprIds.add(Pair.of(first, second));
+
+            Integer leftIndex = leftDistributionExprToIndex.get(first);
+            Integer rightIndex = rightDistributionExprToIndex.get(second);
+            if (leftIndex == null) {
+                leftIndex = leftDistributionExprToIndex.get(second);
+                rightIndex = rightDistributionExprToIndex.get(first);
+            }
+            if (leftIndex != null && Objects.equals(leftIndex, rightIndex)) {
+                coveredIndices.add(leftIndex);
+            }
+        }
+
+        for (DistributionMapping leftMapping : leftMappings) {

Review Comment:
   okay



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