morrySnow commented on code in PR #10891: URL: https://github.com/apache/doris/pull/10891#discussion_r923315243
########## fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java: ########## @@ -69,10 +70,10 @@ public Map<GroupExpression, GroupExpression> getGroupExpressions() { * @param rewrite whether to rewrite the node to the target group * @return Reference of node in Memo */ - public GroupExpression copyIn(Plan node, @Nullable Group target, boolean rewrite) { + public Pair<Boolean, GroupExpression> copyIn(Plan node, @Nullable Group target, boolean rewrite) { Optional<GroupExpression> groupExpr = node.getGroupExpression(); if (!rewrite && groupExpr.isPresent() && groupExpressions.containsKey(groupExpr.get())) { - return groupExpr.get(); + return new Pair(true, groupExpr.get()); Review Comment: i think it is better to use `true` represent insert a new GroupExpression ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteBottomUpJob.java: ########## @@ -81,11 +82,14 @@ public void execute() throws AnalysisException { Preconditions.checkArgument(afters.size() == 1); Plan after = afters.get(0); if (after != before) { - GroupExpression groupExpr = context.getPlannerContext() + Pair<Boolean, GroupExpression> pair = context.getPlannerContext() .getMemo() .copyIn(after, group, rule.isRewrite()); + GroupExpression groupExpr = pair.second; groupExpr.setApplied(rule); Review Comment: we need move this line out of the inner for loop, i.e. after Line 91 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java: ########## @@ -72,9 +73,10 @@ public void execute() { Preconditions.checkArgument(afters.size() == 1); Plan after = afters.get(0); if (after != before) { - GroupExpression expression = context.getPlannerContext() + Pair<Boolean, GroupExpression> pair = context.getPlannerContext() .getMemo().copyIn(after, group, rule.isRewrite()); - expression.setApplied(rule); + Review Comment: i think if we return a exists GroupExpression, we should skip Line 80 and 81 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/rewrite/RewriteTopDownJob.java: ########## @@ -72,9 +73,10 @@ public void execute() { Preconditions.checkArgument(afters.size() == 1); Plan after = afters.get(0); if (after != before) { - GroupExpression expression = context.getPlannerContext() + Pair<Boolean, GroupExpression> pair = context.getPlannerContext() .getMemo().copyIn(after, group, rule.isRewrite()); - expression.setApplied(rule); + + pair.second.setApplied(rule); Review Comment: we need move this line out of the inner for loop, i.e. after Line 81 ########## fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java: ########## @@ -69,10 +70,10 @@ public Map<GroupExpression, GroupExpression> getGroupExpressions() { * @param rewrite whether to rewrite the node to the target group * @return Reference of node in Memo */ - public GroupExpression copyIn(Plan node, @Nullable Group target, boolean rewrite) { + public Pair<Boolean, GroupExpression> copyIn(Plan node, @Nullable Group target, boolean rewrite) { Review Comment: please modify return comment in java doc ########## fe/fe-core/src/main/java/org/apache/doris/nereids/memo/Memo.java: ########## @@ -120,14 +122,14 @@ private Plan groupToTreeNode(Group group) { * @param rewrite whether to rewrite the groupExpression to target group * @return existing groupExpression in memo or newly generated groupExpression */ - private GroupExpression insertOrRewriteGroupExpression(GroupExpression groupExpression, Group target, - boolean rewrite, LogicalProperties logicalProperties) { + private Pair<Boolean, GroupExpression> insertOrRewriteGroupExpression(GroupExpression groupExpression, Group target, Review Comment: please modify return comment in java doc -- 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