This is an automated email from the ASF dual-hosted git repository.

jakevin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new c1438cbad6 [revert](Nereids): revert GroupExpression Children 
ImmutableList. (#13918)
c1438cbad6 is described below

commit c1438cbad6b78f548ddd206df0e89d4ff8447d6d
Author: jakevin <jakevin...@gmail.com>
AuthorDate: Thu Nov 3 16:29:54 2022 +0800

    [revert](Nereids): revert GroupExpression Children ImmutableList. (#13918)
---
 .../apache/doris/nereids/memo/GroupExpression.java | 30 +++-------------------
 .../java/org/apache/doris/nereids/memo/Memo.java   |  8 +++++-
 2 files changed, 11 insertions(+), 27 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
index e43f164d0a..a0ad369664 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java
@@ -27,8 +27,6 @@ import org.apache.doris.nereids.trees.plans.Plan;
 import org.apache.doris.statistics.StatsDeriveResult;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableList.Builder;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 
@@ -45,7 +43,7 @@ public class GroupExpression {
     private double cost = 0.0;
     private CostEstimate costEstimate = null;
     private Group ownerGroup;
-    private ImmutableList<Group> children;
+    private List<Group> children;
     private final Plan plan;
     private final BitSet ruleMasks;
     private boolean statDerived;
@@ -72,7 +70,7 @@ public class GroupExpression {
     public GroupExpression(Plan plan, List<Group> children) {
         this.plan = Objects.requireNonNull(plan, "plan can not be null")
                 .withGroupExpression(Optional.of(this));
-        this.children = ImmutableList.copyOf(Objects.requireNonNull(children, 
"children can not be null"));
+        this.children = Lists.newArrayList(Objects.requireNonNull(children, 
"children can not be null"));
         this.ruleMasks = new BitSet(RuleType.SENTINEL.ordinal());
         this.statDerived = false;
         this.lowestCostTable = Maps.newHashMap();
@@ -110,12 +108,6 @@ public class GroupExpression {
         return children;
     }
 
-    public void setChildren(ImmutableList<Group> children) {
-        this.children.forEach(g -> g.removeParentExpression(this));
-        this.children = children;
-        this.children.forEach(g -> g.addParentExpression(this));
-    }
-
     /**
      * replaceChild.
      *
@@ -124,36 +116,22 @@ public class GroupExpression {
      */
     public void replaceChild(Group originChild, Group newChild) {
         originChild.removeParentExpression(this);
-        ImmutableList.Builder<Group> groupBuilder = 
ImmutableList.builderWithExpectedSize(arity());
         for (int i = 0; i < children.size(); i++) {
             if (children.get(i) == originChild) {
-                groupBuilder.add(newChild);
+                children.set(i, newChild);
                 newChild.addParentExpression(this);
-            } else {
-                groupBuilder.add(child(i));
             }
         }
-        this.children = groupBuilder.build();
     }
 
     public void setChild(int index, Group group) {
-        this.children.get(index).removeParentExpression(this);
-        setChildByIndex(index, group);
+        this.children.set(index, group);
     }
 
     public boolean hasApplied(Rule rule) {
         return ruleMasks.get(rule.getRuleType().ordinal());
     }
 
-    private void setChildByIndex(int index, Group group) {
-        ImmutableList.Builder<Group> builder = new Builder<>();
-        builder.addAll(children.subList(0, index));
-        builder.add(group);
-        builder.addAll(children.subList(index + 1, children.size()));
-        children = builder.build();
-        group.addParentExpression(this);
-    }
-
     public boolean notApplied(Rule rule) {
         return !hasApplied(rule);
     }
diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
index 3583db9f4e..7db42fba56 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java
@@ -381,7 +381,13 @@ public class Memo {
         }
         for (GroupExpression groupExpression : 
source.getParentGroupExpressions()) {
             groupExpressions.remove(groupExpression);
-            groupExpression.replaceChild(source, destination);
+            List<Group> children = groupExpression.children();
+            // TODO: use a better way to replace child, avoid traversing all 
groupExpression
+            for (int i = 0; i < children.size(); i++) {
+                if (children.get(i).equals(source)) {
+                    children.set(i, destination);
+                }
+            }
 
             GroupExpression that = groupExpressions.get(groupExpression);
             if (that != null && that.getOwnerGroup() != null


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

Reply via email to