morrySnow commented on code in PR #64032:
URL: https://github.com/apache/doris/pull/64032#discussion_r3362138736
##########
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:
##########
@@ -1908,6 +1908,29 @@ public long getRowCountForPartitionIndex(long
partitionId, long indexId, boolean
return index.getRowCount() == -1 ? 0 : index.getRowCount();
}
+ /**
+ * Returns row count for selected partitions on the given index. If some
partition row counts
+ * are not reported, estimate them from the base row count.
+ */
+ public double getRowCountForSelectedPartitions(Collection<Long>
selectedPartitionIds,
+ long indexId, double baseRowCount) {
+ double unknownPartitionCount = 0;
+ double selectedPartitionRowCount = 0;
+ for (long partitionId : selectedPartitionIds) {
+ long partitionRowCount = getRowCountForPartitionIndex(partitionId,
indexId, true);
+ if (partitionRowCount == UNKNOWN_ROW_COUNT) {
+ unknownPartitionCount++;
+ } else {
+ selectedPartitionRowCount += partitionRowCount;
+ }
+ }
+ if (unknownPartitionCount > 0) {
+ selectedPartitionRowCount += Math.max(unknownPartitionCount,
+ baseRowCount * unknownPartitionCount / getPartitionNum());
+ }
+ return selectedPartitionRowCount;
Review Comment:
maybe need calc like this:`(unknownPartitionCount / (getPartitionNum() -
(selectedPartitionIds.size() - unknownPartitionCount))) * (baseRowCount -
selectedPartitionRowCount)`
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/PartitionSelection.java:
##########
@@ -0,0 +1,145 @@
+// 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.algebra;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Partition selection carried by scan plans.
+ */
+public abstract class PartitionSelection<P> {
+ /**
+ * true means the partition prune rule has processed this scan.
+ */
+ public final boolean partitionPruned;
+
+ /**
+ * true means this scan's selected partitions are constrained by a
partition predicate
+ * or explicit partition/tablet selection.
+ */
+ public final boolean hasPartitionConstraint;
+
+ private final Set<P> appliedPartitionSnapshot;
+ private final List<Slot> appliedPartitionSlots;
+ private final Set<Expression> appliedPartitionConjuncts;
+
+ protected PartitionSelection(boolean partitionPruned, boolean
hasPartitionConstraint) {
+ this.partitionPruned = partitionPruned;
+ this.hasPartitionConstraint = hasPartitionConstraint;
+ this.appliedPartitionSnapshot = null;
+ this.appliedPartitionSlots = null;
+ this.appliedPartitionConjuncts = null;
+ }
+
+ protected PartitionSelection(boolean partitionPruned,
PartitionSelection<P> source) {
+ PartitionSelection<P> nonNullSource = Objects.requireNonNull(source,
"source is null");
+ this.partitionPruned = partitionPruned;
+ this.hasPartitionConstraint = nonNullSource.hasPartitionConstraint;
+ this.appliedPartitionSnapshot = nonNullSource.appliedPartitionSnapshot;
+ this.appliedPartitionSlots = nonNullSource.appliedPartitionSlots;
+ this.appliedPartitionConjuncts =
nonNullSource.appliedPartitionConjuncts;
+ }
+
+ protected PartitionSelection(boolean partitionPruned, boolean
hasPartitionConstraint,
Review Comment:
maybe you need a Builder
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/algebra/PartitionSelection.java:
##########
@@ -0,0 +1,145 @@
+// 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.algebra;
+
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.Slot;
+import org.apache.doris.nereids.util.ExpressionUtils;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * Partition selection carried by scan plans.
+ */
+public abstract class PartitionSelection<P> {
+ /**
+ * true means the partition prune rule has processed this scan.
+ */
+ public final boolean partitionPruned;
+
+ /**
+ * true means this scan's selected partitions are constrained by a
partition predicate
+ * or explicit partition/tablet selection.
+ */
+ public final boolean hasPartitionConstraint;
+
+ private final Set<P> appliedPartitionSnapshot;
Review Comment:
what does Snapshot mean?
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PruneOlapScanPartition.java:
##########
@@ -96,25 +95,17 @@ public List<Rule> buildRules() {
if (rewrittenLogicalRelation instanceof
LogicalEmptyRelation) {
return rewrittenLogicalRelation;
}
- boolean skipPrunePredicate =
ctx.connectContext.getSessionVariable().skipPrunePredicate
- || ctx.statementContext.isDelete();
- if (!skipPrunePredicate &&
prunedRes.second.isPresent()) {
Review Comment:
why remove `!skipPrunePredicate`?
##########
fe/fe-core/src/main/java/org/apache/doris/planner/ScanNode.java:
##########
@@ -96,7 +96,7 @@ public abstract class ScanNode extends PlanNode implements
SplitGenerator {
protected long selectedPartitionNum = 0;
protected int selectedSplitNum = 0;
- private boolean hasPartitionPredicate = false;
+ private boolean hasPartitionConstraint = false;
Review Comment:
constraint 怎么理解?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]