924060929 commented on code in PR #12147:
URL: https://github.com/apache/doris/pull/12147#discussion_r957339706


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -277,12 +346,172 @@ public void addEnforcerPlan(GroupExpression 
groupExpression, Group group) {
         groupExpression.setOwnerGroup(group);
     }
 
+    private CopyInResult rewriteByExistsPlan(Group targetGroup, Plan 
existsPlan) {
+        GroupExpression existedLogicalExpression = existsPlan instanceof 
GroupPlan
+                ? ((GroupPlan) existsPlan).getGroup().getLogicalExpression() 
// get first logicalGroupExpression
+                : existsPlan.getGroupExpression().get();
+        if (targetGroup != null) {
+            Group existedGroup = existedLogicalExpression.getOwnerGroup();
+            // clear targetGroup, from exist group move all logical 
groupExpression
+            // and logicalProperties to target group
+            eliminateFromGroupAndMoveToTargetGroup(existedGroup, targetGroup, 
existsPlan.getLogicalProperties());
+        }
+        return CopyInResult.of(false, existedLogicalExpression);
+    }
+
+    private CopyInResult rewriteByNewGroupExpression(Group targetGroup, Plan 
newPlan,
+            GroupExpression newGroupExpression) {
+        if (targetGroup == null) {
+            // case 2:
+            // if not exist target group and not exist the same group 
expression,
+            // then create new group with the newGroupExpression
+            Group newGroup = new Group(groupIdGenerator.getNextId(), 
newGroupExpression,
+                    newPlan.getLogicalProperties());
+            groups.put(newGroup.getGroupId(), newGroup);
+            groupExpressions.put(newGroupExpression, newGroupExpression);
+        } else {
+            // case 3:
+            // if exist the target group, clear all origin group expressions 
in the
+            // existedExpression's owner group and reset logical properties, 
the
+            // newGroupExpression is the init logical group expression
+            reInitGroup(targetGroup, newGroupExpression, 
newPlan.getLogicalProperties());
+        }
+        return CopyInResult.of(true, newGroupExpression);
+    }
+
+    private CopyInResult rewriteByExistedGroupExpression(Group targetGroup, 
Plan existedPlan,

Review Comment:
   I think transformedPlan is more reasonable



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

Reply via email to