You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2022/07/14 09:36:12 UTC

[GitHub] [doris] jackwener commented on a diff in pull request #10479: [feature](nereids): join reorder

jackwener commented on code in PR #10479:
URL: https://github.com/apache/doris/pull/10479#discussion_r920957774


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommutative.java:
##########
@@ -50,11 +51,54 @@ enum SwapType {
 
     @Override
     public Rule<Plan> build() {
-        return innerLogicalJoin().then(join -> new LogicalJoin(
-                join.getJoinType().swap(),
-                join.getCondition(),
-                join.right(),
-                join.left())
-        ).toRule(RuleType.LOGICAL_JOIN_COMMUTATIVE);
+        return innerLogicalJoin().then(join -> {
+            if (check(join)) {
+                return null;
+            }
+            boolean isBottomJoin = isBottomJoin(join);
+            if (swapType == SwapType.BOTTOM_JOIN && !isBottomJoin) {
+                return null;
+            }
+
+            LogicalJoin newJoin = new LogicalJoin(
+                    join.getJoinType(),
+                    join.getCondition(),
+                    join.right(), join.left()
+            );
+            newJoin.getJoinReorderContext().copyFrom(join.getJoinReorderContext());
+            newJoin.getJoinReorderContext().setHasCommute(true);
+            if (swapType == SwapType.ZIG_ZAG && !isBottomJoin) {
+                newJoin.getJoinReorderContext().setHasCommuteZigZag(true);
+            }
+
+            return newJoin;
+        }).toRule(RuleType.LOGICAL_JOIN_COMMUTATIVE);
+    }
+
+
+    private boolean check(LogicalJoin join) {
+        if (join.getJoinReorderContext().hasCommute() || join.getJoinReorderContext().hasExchange()) {
+            return false;
+        }
+        return true;
+    }
+
+    private boolean isBottomJoin(LogicalJoin join) {
+        if (join.left() instanceof LogicalProject) {

Review Comment:
   Great👍



-- 
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-unsubscribe@doris.apache.org

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


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