jackwener commented on code in PR #10479: URL: https://github.com/apache/doris/pull/10479#discussion_r920968243
########## fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinLAsscom.java: ########## @@ -38,14 +50,101 @@ public class JoinLAsscom extends OneExplorationRuleFactory { @Override public Rule<Plan> build() { return innerLogicalJoin(innerLogicalJoin(), any()).then(topJoin -> { + if (!check(topJoin)) { + return null; + } + LogicalJoin<GroupPlan, GroupPlan> bottomJoin = topJoin.left(); GroupPlan a = bottomJoin.left(); GroupPlan b = bottomJoin.right(); Plan c = topJoin.right(); - Plan newBottomJoin = new LogicalJoin(bottomJoin.getJoinType(), bottomJoin.getCondition(), a, c); - return new LogicalJoin(bottomJoin.getJoinType(), topJoin.getCondition(), newBottomJoin, b); + Optional<Expression> optTopJoinOnClause = topJoin.getCondition(); + assert (optTopJoinOnClause.isPresent()); Review Comment: use preconditon.assert() ########## 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: Add TODO -- 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