diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java index 6a8d123405..4d4f68bb29 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java @@ -760,6 +760,21 @@ public class StatsCalculator extends DefaultPlanVisitor { // 2. Consider the influence of runtime filter // 3. Get NDV and column data size from StatisticManger, StatisticManager doesn't support it now. private Statistics computeCatalogRelation(CatalogRelation catalogRelation) { + if (catalogRelation instanceof LogicalOlapScan) { + LogicalOlapScan olap = (LogicalOlapScan) catalogRelation; + if (olap.getSelectedIndexId() != olap.getTable().getBaseIndexId()) { + // mv is selected, return its estimated stats + Optional optStats = cascadesContext.getStatementContext() + .getStatistics(olap.getRelationId()); + if (optStats.isPresent()) { + double actualRowCount = catalogRelation.getTable().getRowCountForNereids(); + if (actualRowCount > optStats.get().getRowCount()) { + return optStats.get(); + } + } + } + } + List output = catalogRelation.getOutput(); ImmutableSet.Builder slotSetBuilder = ImmutableSet.builderWithExpectedSize(output.size()); for (Slot slot : output) {