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

This commit is contained in:
jakevin
2023-04-17 23:12:26 +08:00
committed by GitHub
parent b59c4b4702
commit 86b8e95045
2 changed files with 4 additions and 1 deletions

View File

@ -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);

View File

@ -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) {