From 518b143caa4c1a94cc89156558886400b8c00a27 Mon Sep 17 00:00:00 2001 From: minghong Date: Mon, 20 May 2024 10:06:51 +0800 Subject: [PATCH] [feat](Nereids)choose agg mv in cbo #35020 --- .../org/apache/doris/nereids/cost/CostModelV1.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java index d469dd3b40..87e0f8ab9f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModelV1.java @@ -17,6 +17,8 @@ package org.apache.doris.nereids.cost; +import org.apache.doris.catalog.KeysType; +import org.apache.doris.catalog.OlapTable; import org.apache.doris.nereids.PlanContext; import org.apache.doris.nereids.properties.DistributionSpec; import org.apache.doris.nereids.properties.DistributionSpecGather; @@ -97,8 +99,17 @@ class CostModelV1 extends PlanVisitor { @Override public Cost visitPhysicalOlapScan(PhysicalOlapScan physicalOlapScan, PlanContext context) { + OlapTable table = physicalOlapScan.getTable(); Statistics statistics = context.getStatisticsWithCheck(); - return CostV1.ofCpu(context.getSessionVariable(), statistics.getRowCount()); + double rows = statistics.getRowCount(); + double aggMvBonus = 0.0; + if (table.getBaseIndexId() != physicalOlapScan.getSelectedIndexId()) { + if (table.getIndexMetaByIndexId(physicalOlapScan.getSelectedIndexId()) + .getKeysType().equals(KeysType.AGG_KEYS)) { + aggMvBonus = rows > 1.0 ? 1.0 : rows * 0.5; + } + } + return CostV1.ofCpu(context.getSessionVariable(), rows - aggMvBonus); } @Override