morrySnow commented on code in PR #12461: URL: https://github.com/apache/doris/pull/12461#discussion_r970713357
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java: ########## @@ -107,28 +110,29 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass() || !super.equals(o)) { return false; } - return true; + return Objects.equals(selectedPartitionIds, ((LogicalOlapScan) o).selectedPartitionIds) + && Objects.equals(candidateIndexIds, ((LogicalOlapScan) o).candidateIndexIds); } @Override public Plan withGroupExpression(Optional<GroupExpression> groupExpression) { - return new LogicalOlapScan(table, qualifier, groupExpression, Optional.of(getLogicalProperties()), + return new LogicalOlapScan(getId(), table, qualifier, groupExpression, Optional.of(getLogicalProperties()), Review Comment: ```suggestion return new LogicalOlapScan(id, table, qualifier, groupExpression, Optional.of(getLogicalProperties()), ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/RelationId.java: ########## @@ -0,0 +1,71 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package org.apache.doris.nereids.trees.plans; + +import org.apache.doris.common.Id; +import org.apache.doris.common.IdGenerator; + +import java.util.Objects; + +/** + * relation id + */ +public class RelationId extends Id<RelationId> { + public RelationId(int id) { + super(id); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RelationId relationId = (RelationId) o; + return id == relationId.id; + } + + /** + * Should be only called by {@link org.apache.doris.nereids.trees.expressions.NamedExpressionUtil}. + */ + public static IdGenerator<RelationId> createGenerator() { + return new IdGenerator<RelationId>() { + @Override + public RelationId getNextId() { + return new RelationId(nextId++); + } + + @Override + public RelationId getMaxId() { + return new RelationId(nextId); + } + }; + } + + @Override + public int hashCode() { + return Objects.hash(id); + } + + @Override + public String toString() { + return "" + id; Review Comment: ```suggestion return "RelationId#" + id; ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalRelation.java: ########## @@ -44,8 +45,10 @@ public abstract class LogicalRelation extends LogicalLeaf implements Scan { protected final List<String> qualifier; protected final List<Long> selectedPartitionIds; - public LogicalRelation(PlanType type, Table table, List<String> qualifier) { - this(type, table, qualifier, Optional.empty(), Optional.empty(), Collections.emptyList()); + private final RelationId id; Review Comment: ```suggestion protected final RelationId id; ``` ########## fe/fe-core/src/main/java/org/apache/doris/nereids/memo/GroupExpression.java: ########## @@ -209,7 +210,10 @@ public boolean equals(Object o) { // FIXME: Doris not support temporary materialization, so we should not merge same // scan relation plan. We should add id for XxxRelation and compare by id. if (plan instanceof Relation) { - return false; + if (plan instanceof UnboundRelation) { Review Comment: all relation except UnboundRelation should use same process with other plan ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalRelation.java: ########## @@ -38,22 +39,27 @@ public abstract class PhysicalRelation extends PhysicalLeaf implements Scan { protected final List<String> qualifier; + private final RelationId id; Review Comment: ```suggestion protected final RelationId id; ``` -- 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