From 8e800eae2c4f0d1c0fab6df9c57c7b16c9c2f31b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E5=87=AF?= Date: Wed, 9 Aug 2023 19:09:32 +0800 Subject: [PATCH] revert and refactor --- .../translator/PhysicalPlanTranslator.java | 6 +- .../doris/nereids/jobs/executor/Rewriter.java | 6 -- .../apache/doris/nereids/rules/RuleType.java | 2 +- .../implementation/AggregateStrategies.java | 81 ++++++++++++++++++- .../LogicalOlapScanToPhysicalOlapScan.java | 1 - .../rules/rewrite/PushdownCountOnIndex.java | 80 ------------------ .../trees/plans/logical/LogicalOlapScan.java | 66 ++------------- .../plans/physical/PhysicalOlapScan.java | 34 ++------ .../PhysicalStorageLayerAggregate.java | 6 +- 9 files changed, 100 insertions(+), 182 deletions(-) delete mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownCountOnIndex.java diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java index 57825418ec78a99..ce8d0cf83122a60 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/glue/translator/PhysicalPlanTranslator.java @@ -567,9 +567,6 @@ public PlanFragment visitPhysicalOlapScan(PhysicalOlapScan olapScan, PlanTransla ); // TODO: we need to remove all finalizeForNereids olapScanNode.finalizeForNereids(); - if (olapScan.getPushDownCountOnIndex()) { - olapScanNode.setPushDownAggNoGrouping(TPushAggOp.COUNT_ON_INDEX); - } // Create PlanFragment // TODO: use a util function to convert distribution to DataPartition DataPartition dataPartition = DataPartition.RANDOM; @@ -799,6 +796,9 @@ public PlanFragment visitPhysicalStorageLayerAggregate( case COUNT: pushAggOp = TPushAggOp.COUNT; break; + case COUNT_ON_MATCH: + pushAggOp = TPushAggOp.COUNT_ON_INDEX; + break; case MIN_MAX: pushAggOp = TPushAggOp.MINMAX; break; diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java index 14a41c8859da6d6..eeb484ee5138a33 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Rewriter.java @@ -82,7 +82,6 @@ import org.apache.doris.nereids.rules.rewrite.PushFilterInsideJoin; import org.apache.doris.nereids.rules.rewrite.PushProjectIntoOneRowRelation; import org.apache.doris.nereids.rules.rewrite.PushProjectThroughUnion; -import org.apache.doris.nereids.rules.rewrite.PushdownCountOnIndex; import org.apache.doris.nereids.rules.rewrite.PushdownFilterThroughProject; import org.apache.doris.nereids.rules.rewrite.PushdownFilterThroughWindow; import org.apache.doris.nereids.rules.rewrite.PushdownLimit; @@ -291,11 +290,6 @@ public class Rewriter extends AbstractBatchJobExecutor { topic("topn optimize", topDown(new DeferMaterializeTopNResult()) ), - topic("Count agg push down", - topDown( - new PushdownCountOnIndex() - ) - ), // this rule batch must keep at the end of rewrite to do some plan check topic("Final rewrite and check", custom(RuleType.ENSURE_PROJECT_ON_TOP_JOIN, EnsureProjectOnTopJoin::new), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java index c29b691a6756c7d..1c83c01271c54d9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/RuleType.java @@ -221,7 +221,6 @@ public enum RuleType { PUSH_CONJUNCTS_INTO_JDBC_SCAN(RuleTypeClass.REWRITE), OLAP_SCAN_TABLET_PRUNE(RuleTypeClass.REWRITE), PUSH_AGGREGATE_TO_OLAP_SCAN(RuleTypeClass.REWRITE), - PUSH_COUNT_ON_INDEX_TO_OLAP_SCAN(RuleTypeClass.REWRITE), EXTRACT_SINGLE_TABLE_EXPRESSION_FROM_DISJUNCTION(RuleTypeClass.REWRITE), HIDE_ONE_ROW_RELATION_UNDER_UNION(RuleTypeClass.REWRITE), PUSH_PROJECT_THROUGH_UNION(RuleTypeClass.REWRITE), @@ -323,6 +322,7 @@ public enum RuleType { LOGICAL_ASSERT_NUM_ROWS_TO_PHYSICAL_ASSERT_NUM_ROWS(RuleTypeClass.IMPLEMENTATION), STORAGE_LAYER_AGGREGATE_WITHOUT_PROJECT(RuleTypeClass.IMPLEMENTATION), STORAGE_LAYER_AGGREGATE_WITH_PROJECT(RuleTypeClass.IMPLEMENTATION), + COUNT_ON_INDEX(RuleTypeClass.IMPLEMENTATION), ONE_PHASE_AGGREGATE_WITHOUT_DISTINCT(RuleTypeClass.IMPLEMENTATION), TWO_PHASE_AGGREGATE_WITHOUT_DISTINCT(RuleTypeClass.IMPLEMENTATION), TWO_PHASE_AGGREGATE_WITH_COUNT_DISTINCT_MULTI(RuleTypeClass.IMPLEMENTATION), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java index 3912315f4aec2be..e9ecc6adb038124 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/AggregateStrategies.java @@ -36,6 +36,7 @@ import org.apache.doris.nereids.trees.expressions.Cast; import org.apache.doris.nereids.trees.expressions.Expression; import org.apache.doris.nereids.trees.expressions.IsNull; +import org.apache.doris.nereids.trees.expressions.Match; import org.apache.doris.nereids.trees.expressions.NamedExpression; import org.apache.doris.nereids.trees.expressions.SlotReference; import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait; @@ -56,6 +57,7 @@ import org.apache.doris.nereids.trees.plans.algebra.Project; import org.apache.doris.nereids.trees.plans.logical.LogicalAggregate; import org.apache.doris.nereids.trees.plans.logical.LogicalFileScan; +import org.apache.doris.nereids.trees.plans.logical.LogicalFilter; import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; import org.apache.doris.nereids.trees.plans.logical.LogicalProject; import org.apache.doris.nereids.trees.plans.logical.LogicalRelation; @@ -85,10 +87,12 @@ import java.util.stream.Collectors; import javax.annotation.Nullable; -/** AggregateStrategies */ +/** + * AggregateStrategies + */ @DependsRules({ - NormalizeAggregate.class, - FoldConstantRuleOnFE.class + NormalizeAggregate.class, + FoldConstantRuleOnFE.class }) public class AggregateStrategies implements ImplementationRuleFactory { @@ -97,6 +101,28 @@ public List buildRules() { PatternDescriptor> basePattern = logicalAggregate(); return ImmutableList.of( + RuleType.COUNT_ON_INDEX.build( + logicalAggregate( + logicalProject( + logicalFilter( + logicalOlapScan() + ).when(filter -> containsMatchExpression(filter.getExpressions()) + && filter.getExpressions().size() == 1) + )) + .when(agg -> enablePushDownCountOnIndex()) + .when(agg -> agg.getGroupByExpressions().size() == 0) + .when(agg -> { + Set funcs = agg.getAggregateFunctions(); + return !funcs.isEmpty() && funcs.stream().allMatch(f -> f instanceof Count && !f.isDistinct()); + }) + .thenApply(ctx -> { + LogicalAggregate>> agg = ctx.root; + LogicalProject> project = agg.child(); + LogicalFilter filter = project.child(); + LogicalOlapScan olapScan = filter.child(); + return pushdownCountOnIndex(agg, project, filter, olapScan, ctx.cascadesContext); + }) + ), RuleType.STORAGE_LAYER_AGGREGATE_WITHOUT_PROJECT.build( logicalAggregate( logicalOlapScan() @@ -188,6 +214,55 @@ && couldConvertToMulti(agg)) ); } + private boolean containsMatchExpression(List expressions) { + return expressions.stream().allMatch(expr -> expr instanceof Match); + } + + private boolean enablePushDownCountOnIndex() { + ConnectContext connectContext = ConnectContext.get(); + return connectContext == null || connectContext.getSessionVariable().isEnablePushDownCountOnIndex(); + } + + /** + * sql: select count(*) from tbl where column match 'token' + *

+ * before: + *

+ * LogicalAggregate(groupBy=[], output=[count(*)]) + * | + * LogicalFilter(column match 'token') + * | + * LogicalOlapScan(table=tbl) + *

+ * after: + *

+ * LogicalAggregate(groupBy=[], output=[count(*)]) + * | + * LogicalFilter(column match 'token') + * | + * PhysicalStorageLayerAggregate(pushAggOp=COUNT_ON_INDEX, table=PhysicalOlapScan(table=tbl)) + * + */ + private LogicalAggregate pushdownCountOnIndex( + LogicalAggregate agg, + LogicalProject project, + LogicalFilter filter, + LogicalOlapScan olapScan, + CascadesContext cascadesContext) { + PhysicalOlapScan physicalOlapScan + = (PhysicalOlapScan) new LogicalOlapScanToPhysicalOlapScan() + .build() + .transform(olapScan, cascadesContext) + .get(0); + return agg.withChildren(ImmutableList.of( + project.withChildren(ImmutableList.of( + filter.withChildren(ImmutableList.of( + new PhysicalStorageLayerAggregate( + physicalOlapScan, + PushDownAggOp.COUNT_ON_MATCH))))) + )); + } + /** * sql: select count(*) from tbl *

diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java index b70e69350a7593a..b578247d06c01d7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/implementation/LogicalOlapScanToPhysicalOlapScan.java @@ -59,7 +59,6 @@ public Rule build() { convertDistribution(olapScan), olapScan.getPreAggStatus(), olapScan.getOutputByIndex(olapScan.getTable().getBaseIndexId()), - olapScan.isCountOnIndexPushedDown(), Optional.empty(), olapScan.getLogicalProperties()) ).toRule(RuleType.LOGICAL_OLAP_SCAN_TO_PHYSICAL_OLAP_SCAN_RULE); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownCountOnIndex.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownCountOnIndex.java deleted file mode 100644 index 8ccc8001896f8f4..000000000000000 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/rewrite/PushdownCountOnIndex.java +++ /dev/null @@ -1,80 +0,0 @@ -// 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.rules.rewrite; - -import org.apache.doris.nereids.rules.Rule; -import org.apache.doris.nereids.rules.RuleType; -import org.apache.doris.nereids.trees.expressions.Expression; -import org.apache.doris.nereids.trees.expressions.Match; -import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction; -import org.apache.doris.nereids.trees.expressions.functions.agg.Count; -import org.apache.doris.nereids.trees.plans.logical.LogicalFilter; -import org.apache.doris.nereids.trees.plans.logical.LogicalOlapScan; -import org.apache.doris.nereids.trees.plans.logical.LogicalProject; -import org.apache.doris.qe.ConnectContext; - -import com.google.common.collect.ImmutableList; - -import java.util.List; -import java.util.Set; - -/** - * Rewriter of pushing down count on index. - */ -public class PushdownCountOnIndex extends OneRewriteRuleFactory { - - @Override - public Rule build() { - return logicalAggregate( - logicalProject( - logicalFilter( - logicalOlapScan().whenNot(LogicalOlapScan::isCountOnIndexPushedDown) - ).when(filter -> containsMatchExpression(filter.getExpressions()) - && filter.getExpressions().size() == 1) - )) - .when(agg -> enablePushDownCountOnIndex()) - .when(agg -> agg.getGroupByExpressions().size() == 0) - .when(agg -> { - Set funcs = agg.getAggregateFunctions(); - return !funcs.isEmpty() && funcs.stream() - .allMatch(f -> f instanceof Count && !f.isDistinct()); - }) - .then(agg -> { - LogicalProject> project = agg.child(); - LogicalFilter filter = project.child(); - LogicalOlapScan olapScan = filter.child(); - - return agg.withChildren(ImmutableList.of( - project.withChildren( - ImmutableList.of( - filter.withChildren(olapScan.withPushDownCountOnIndex(true)) - ) - ))); - }) - .toRule(RuleType.PUSH_COUNT_ON_INDEX_TO_OLAP_SCAN); - } - - private boolean containsMatchExpression(List expressions) { - return expressions.stream().allMatch(expr -> expr instanceof Match); - } - - private boolean enablePushDownCountOnIndex() { - ConnectContext connectContext = ConnectContext.get(); - return connectContext == null || connectContext.getSessionVariable().isEnablePushDownCountOnIndex(); - } -} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java index 1d44945134d8a89..60458eb2a243fe5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java @@ -73,12 +73,7 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan private final PreAggStatus preAggStatus; /** - * Push count to scan when indexed column is selected. - */ - private boolean pushDownCountOnIndex; - - /** - * When the Slotreference is generated through fromColumn, + * When the SlotReference is generated through fromColumn, * the exprId will be generated incrementally, * causing the slotId of the base to change when the output is recalculated. * This structure is responsible for storing the generated SlotReference @@ -163,33 +158,6 @@ public LogicalOlapScan(RelationId id, Table table, List qualifier, this.cacheSlotWithSlotName = Objects.requireNonNull(cacheSlotWithSlotName, "mvNameToSlot can not be null"); } - /** - * Constructor for LogicalOlapScan. - */ - public LogicalOlapScan(RelationId id, Table table, List qualifier, - Optional groupExpression, Optional logicalProperties, - List selectedPartitionIds, boolean partitionPruned, - List selectedTabletIds, long selectedIndexId, boolean indexSelected, boolean pushDownCountOnIndex, - PreAggStatus preAggStatus, List partitions, - List hints, Map cacheSlotWithSlotName) { - - super(id, PlanType.LOGICAL_OLAP_SCAN, table, qualifier, - groupExpression, logicalProperties); - Preconditions.checkArgument(selectedPartitionIds != null, "selectedPartitionIds can not be null"); - this.selectedTabletIds = ImmutableList.copyOf(selectedTabletIds); - this.partitionPruned = partitionPruned; - this.selectedIndexId = selectedIndexId <= 0 ? getTable().getBaseIndexId() : selectedIndexId; - this.indexSelected = indexSelected; - this.pushDownCountOnIndex = pushDownCountOnIndex; - this.preAggStatus = preAggStatus; - this.manuallySpecifiedPartitions = ImmutableList.copyOf(partitions); - this.selectedPartitionIds = selectedPartitionIds.stream() - .filter(partitionId -> this.getTable().getPartition(partitionId).hasData()).collect( - Collectors.toList()); - this.hints = Objects.requireNonNull(hints, "hints can not be null"); - this.cacheSlotWithSlotName = Objects.requireNonNull(cacheSlotWithSlotName, "mvNameToSlot can not be null"); - } - public List getSelectedPartitionIds() { return selectedPartitionIds; } @@ -206,8 +174,7 @@ public String toString() { "qualified", qualifiedName(), "indexName", getSelectedMaterializedIndexName().orElse(""), "selectedIndexId", selectedIndexId, - "preAgg", preAggStatus, - "pushDownCountOnIndex", pushDownCountOnIndex + "preAgg", preAggStatus ); } @@ -224,7 +191,6 @@ public boolean equals(Object o) { } LogicalOlapScan that = (LogicalOlapScan) o; return selectedIndexId == that.selectedIndexId && indexSelected == that.indexSelected - && pushDownCountOnIndex == that.pushDownCountOnIndex && partitionPruned == that.partitionPruned && Objects.equals(preAggStatus, that.preAggStatus) && Objects.equals(selectedTabletIds, that.selectedTabletIds) && Objects.equals(manuallySpecifiedPartitions, that.manuallySpecifiedPartitions) @@ -238,20 +204,12 @@ public int hashCode() { selectedTabletIds, partitionPruned, manuallySpecifiedPartitions, selectedPartitionIds, hints); } - public LogicalOlapScan withPushDownCountOnIndex(Boolean pushDownCountOnIndex) { - return new LogicalOlapScan(relationId, (Table) table, qualifier, groupExpression, - Optional.of(getLogicalProperties()), - selectedPartitionIds, partitionPruned, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, - hints, cacheSlotWithSlotName); - } - @Override public LogicalOlapScan withGroupExpression(Optional groupExpression) { return new LogicalOlapScan(relationId, (Table) table, qualifier, groupExpression, Optional.of(getLogicalProperties()), selectedPartitionIds, partitionPruned, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, + selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } @@ -260,7 +218,7 @@ public Plan withGroupExprLogicalPropChildren(Optional groupExpr Optional logicalProperties, List children) { return new LogicalOlapScan(relationId, (Table) table, qualifier, groupExpression, logicalProperties, selectedPartitionIds, partitionPruned, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, + selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } @@ -268,7 +226,7 @@ public LogicalOlapScan withSelectedPartitionIds(List selectedPartitionIds) return new LogicalOlapScan(relationId, (Table) table, qualifier, Optional.empty(), Optional.of(getLogicalProperties()), selectedPartitionIds, true, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, + selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } @@ -276,14 +234,14 @@ public LogicalOlapScan withMaterializedIndexSelected(PreAggStatus preAgg, long i return new LogicalOlapScan(relationId, (Table) table, qualifier, Optional.empty(), Optional.of(getLogicalProperties()), selectedPartitionIds, partitionPruned, selectedTabletIds, - indexId, true, pushDownCountOnIndex, preAgg, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); + indexId, true, preAgg, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } public LogicalOlapScan withSelectedTabletIds(List selectedTabletIds) { return new LogicalOlapScan(relationId, (Table) table, qualifier, Optional.empty(), Optional.of(getLogicalProperties()), selectedPartitionIds, partitionPruned, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, + selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } @@ -291,7 +249,7 @@ public LogicalOlapScan withPreAggStatus(PreAggStatus preAggStatus) { return new LogicalOlapScan(relationId, (Table) table, qualifier, Optional.empty(), Optional.of(getLogicalProperties()), selectedPartitionIds, partitionPruned, selectedTabletIds, - selectedIndexId, indexSelected, pushDownCountOnIndex, preAggStatus, manuallySpecifiedPartitions, + selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions, hints, cacheSlotWithSlotName); } @@ -317,14 +275,6 @@ public boolean isIndexSelected() { return indexSelected; } - public boolean isCountOnIndexPushedDown() { - return pushDownCountOnIndex; - } - - public void setPushDownCountOnIndex(boolean pushDownCountOnIndex) { - this.pushDownCountOnIndex = pushDownCountOnIndex; - } - public PreAggStatus getPreAggStatus() { return preAggStatus; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapScan.java index c0d3e0d5d65b74e..8462705c5475d4c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalOlapScan.java @@ -50,8 +50,6 @@ public class PhysicalOlapScan extends PhysicalCatalogRelation implements OlapSca private final ImmutableList selectedTabletIds; private final ImmutableList selectedPartitionIds; private final PreAggStatus preAggStatus; - private final boolean pushDownCountOnIndex; - private final List baseOutputs; /** @@ -62,7 +60,7 @@ public PhysicalOlapScan(RelationId id, OlapTable olapTable, List qualifi PreAggStatus preAggStatus, List baseOutputs, Optional groupExpression, LogicalProperties logicalProperties) { this(id, olapTable, qualifier, selectedIndexId, selectedTabletIds, selectedPartitionIds, distributionSpec, - preAggStatus, baseOutputs, false, groupExpression, logicalProperties, null, null); + preAggStatus, baseOutputs, groupExpression, logicalProperties, null, null); } /** @@ -70,18 +68,7 @@ public PhysicalOlapScan(RelationId id, OlapTable olapTable, List qualifi */ public PhysicalOlapScan(RelationId id, OlapTable olapTable, List qualifier, long selectedIndexId, List selectedTabletIds, List selectedPartitionIds, DistributionSpec distributionSpec, - PreAggStatus preAggStatus, List baseOutputs, boolean pushDownCountOnIndex, - Optional groupExpression, LogicalProperties logicalProperties) { - this(id, olapTable, qualifier, selectedIndexId, selectedTabletIds, selectedPartitionIds, distributionSpec, - preAggStatus, baseOutputs, pushDownCountOnIndex, groupExpression, logicalProperties, null, null); - } - - /** - * Constructor for PhysicalOlapScan. - */ - public PhysicalOlapScan(RelationId id, OlapTable olapTable, List qualifier, long selectedIndexId, - List selectedTabletIds, List selectedPartitionIds, DistributionSpec distributionSpec, - PreAggStatus preAggStatus, List baseOutputs, boolean pushDownCountOnIndex, + PreAggStatus preAggStatus, List baseOutputs, Optional groupExpression, LogicalProperties logicalProperties, PhysicalProperties physicalProperties, Statistics statistics) { super(id, PlanType.PHYSICAL_OLAP_SCAN, olapTable, qualifier, @@ -92,7 +79,6 @@ public PhysicalOlapScan(RelationId id, OlapTable olapTable, List qualifi this.distributionSpec = distributionSpec; this.preAggStatus = preAggStatus; this.baseOutputs = ImmutableList.copyOf(baseOutputs); - this.pushDownCountOnIndex = pushDownCountOnIndex; } @Override @@ -126,10 +112,6 @@ public List getBaseOutputs() { return baseOutputs; } - public boolean getPushDownCountOnIndex() { - return pushDownCountOnIndex; - } - @Override public String toString() { return Utils.toSqlString("PhysicalOlapScan[" + relationId.asInt() + "]" + getGroupIdAsString(), @@ -150,8 +132,7 @@ public boolean equals(Object o) { return false; } PhysicalOlapScan olapScan = (PhysicalOlapScan) o; - return selectedIndexId == olapScan.selectedIndexId && pushDownCountOnIndex == olapScan.pushDownCountOnIndex - && Objects.equals(distributionSpec, + return selectedIndexId == olapScan.selectedIndexId && Objects.equals(distributionSpec, olapScan.distributionSpec) && Objects.equals(selectedTabletIds, olapScan.selectedTabletIds) && Objects.equals(selectedPartitionIds, olapScan.selectedPartitionIds) && Objects.equals(preAggStatus, olapScan.preAggStatus) && Objects.equals(baseOutputs, @@ -173,7 +154,7 @@ public R accept(PlanVisitor visitor, C context) { @Override public PhysicalOlapScan withGroupExpression(Optional groupExpression) { return new PhysicalOlapScan(relationId, getTable(), qualifier, selectedIndexId, selectedTabletIds, - selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, pushDownCountOnIndex, + selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, groupExpression, getLogicalProperties()); } @@ -181,8 +162,7 @@ public PhysicalOlapScan withGroupExpression(Optional groupExpre public Plan withGroupExprLogicalPropChildren(Optional groupExpression, Optional logicalProperties, List children) { return new PhysicalOlapScan(relationId, getTable(), qualifier, selectedIndexId, selectedTabletIds, - selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, pushDownCountOnIndex, - groupExpression, + selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, groupExpression, logicalProperties.get()); } @@ -190,8 +170,7 @@ public Plan withGroupExprLogicalPropChildren(Optional groupExpr public PhysicalOlapScan withPhysicalPropertiesAndStats( PhysicalProperties physicalProperties, Statistics statistics) { return new PhysicalOlapScan(relationId, getTable(), qualifier, selectedIndexId, selectedTabletIds, - selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, pushDownCountOnIndex, - groupExpression, + selectedPartitionIds, distributionSpec, preAggStatus, baseOutputs, groupExpression, getLogicalProperties(), physicalProperties, statistics); } @@ -210,7 +189,6 @@ public JSONObject toJson() { properties.put("SelectedTabletIds", selectedTabletIds.toString()); properties.put("SelectedPartitionIds", selectedPartitionIds.toString()); properties.put("PreAggStatus", preAggStatus.toString()); - properties.put("pushDownCountOnIndex", pushDownCountOnIndex); olapScan.put("Properties", properties); return olapScan; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalStorageLayerAggregate.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalStorageLayerAggregate.java index 7a9550adc321f84..59ad8031a474658 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalStorageLayerAggregate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/physical/PhysicalStorageLayerAggregate.java @@ -108,13 +108,15 @@ public PhysicalPlan withPhysicalPropertiesAndStats(PhysicalProperties physicalPr /** PushAggOp */ public enum PushDownAggOp { - COUNT, MIN_MAX, MIX; + COUNT, MIN_MAX, MIX, COUNT_ON_MATCH; + /** supportedFunctions */ public static Map, PushDownAggOp> supportedFunctions() { return ImmutableMap., PushDownAggOp>builder() .put(Count.class, PushDownAggOp.COUNT) + .put(Count.class, PushDownAggOp.COUNT_ON_MATCH) .put(Min.class, PushDownAggOp.MIN_MAX) - .put(Max.class, PushDownAggOp.MIN_MAX) + .put(Max.class, PushDownAggOp.MIX) .build(); } }