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