You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/19 13:34:43 UTC

[doris] 17/36: [fix](Nereids): when GroupExpr already exists, we need to remove ParentExpression (#18749)

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

morningman pushed a commit to branch branch-2.0-alpha
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 06b61711e92c9ca4ba68c91d21935996e848a21c
Author: jakevin <ja...@gmail.com>
AuthorDate: Mon Apr 17 23:12:26 2023 +0800

    [fix](Nereids): when GroupExpr already exists, we need to remove ParentExpression (#18749)
---
 .../src/main/java/org/apache/doris/nereids/memo/GroupExpression.java   | 2 +-
 fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java       | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

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 12e9816f8e..afa6d51f9b 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
@@ -182,7 +182,7 @@ public class GroupExpression {
      */
     public boolean isUnused() {
         if (isUnused) {
-            Preconditions.checkState(children.isEmpty() || ownerGroup == null);
+            Preconditions.checkState(children.isEmpty() && ownerGroup == null);
             return true;
         }
         Preconditions.checkState(ownerGroup != null);
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 7a8d62338d..4ad1b118dc 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
@@ -427,6 +427,9 @@ public class Memo {
             if (target != null && !target.getGroupId().equals(existedGroupExpression.getOwnerGroup().getGroupId())) {
                 mergeGroup(existedGroupExpression.getOwnerGroup(), target);
             }
+            // When we create a GroupExpression, we will add it into ParentExpression of childGroup.
+            // But if it already exists, we should remove it from ParentExpression of childGroup.
+            groupExpression.children().forEach(childGroup -> childGroup.removeParentExpression(groupExpression));
             return CopyInResult.of(false, existedGroupExpression);
         }
         if (target != null) {


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