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


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java:
##########
@@ -188,19 +189,24 @@ private void mergeGroup(Group source, Group destination) {
                     children.set(i, destination);
                 }
             }
-            if (groupExpressions.containsKey(groupExpression)) {
-                // TODO: need to merge group recursively
-                
groupExpression.getOwnerGroup().removeGroupExpression(groupExpression);
+            GroupExpression that = groupExpressions.get(groupExpression);
+            if (that != null) {
+                mergeGroup(groupExpression.getOwnerGroup(), 
that.getOwnerGroup());
             } else {
                 groupExpressions.put(groupExpression, groupExpression);
             }
         }
-        for (GroupExpression groupExpression : source.getLogicalExpressions()) 
{
-            source.removeGroupExpression(groupExpression);
+
+        Iterator<GroupExpression> iterator = 
source.getLogicalExpressions().iterator();
+        while (iterator.hasNext()) {
+            GroupExpression groupExpression = iterator.next();
+            iterator.remove();
             destination.addGroupExpression(groupExpression);
         }
-        for (GroupExpression groupExpression : 
source.getPhysicalExpressions()) {
-            source.removeGroupExpression(groupExpression);
+        iterator = source.getPhysicalExpressions().iterator();

Review Comment:
   ```suggestion
           if (source != destination) {
               // copy sourceGroup's physicalExpressions to destination group
               
destination.addPhysicalExpressions(source.getPhysicalExpressions());
               source.clearPhysicalExpressions();
           }
   ```



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