This is an automated email from the ASF dual-hosted git repository.

morrysnow pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new e82a582b846 [feature](nereids) using rollup column stats (#30852)
e82a582b846 is described below

commit e82a582b846ef7d44238ea138974e6f3e4e363cb
Author: minghong <engle...@gmail.com>
AuthorDate: Tue Feb 6 17:02:41 2024 +0800

    [feature](nereids) using rollup column stats (#30852)
---
 .../apache/doris/nereids/stats/StatsCalculator.java   | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

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 cf1803705c2..2709d7a7f27 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
@@ -44,6 +44,7 @@ import 
org.apache.doris.nereids.trees.plans.algebra.EmptyRelation;
 import org.apache.doris.nereids.trees.plans.algebra.Filter;
 import org.apache.doris.nereids.trees.plans.algebra.Generate;
 import org.apache.doris.nereids.trees.plans.algebra.Limit;
+import org.apache.doris.nereids.trees.plans.algebra.OlapScan;
 import org.apache.doris.nereids.trees.plans.algebra.PartitionTopN;
 import org.apache.doris.nereids.trees.plans.algebra.Project;
 import org.apache.doris.nereids.trees.plans.algebra.Repeat;
@@ -608,7 +609,7 @@ public class StatsCalculator extends 
DefaultPlanVisitor<Statistics, Void> {
         return new FilterEstimation().estimate(filter.getPredicate(), stats);
     }
 
-    private ColumnStatistic getColumnStatistic(TableIf table, String colName) {
+    private ColumnStatistic getColumnStatistic(TableIf table, String colName, 
long idxId) {
         ConnectContext connectContext = ConnectContext.get();
         if (connectContext != null && 
connectContext.getSessionVariable().internalSession) {
             return ColumnStatistic.UNKNOWN;
@@ -633,9 +634,8 @@ public class StatsCalculator extends 
DefaultPlanVisitor<Statistics, Void> {
                 return ColumnStatistic.UNKNOWN;
             }
         } else {
-            // TODO. Get index id for materialized view.
             return 
Env.getCurrentEnv().getStatisticsCache().getColumnStatistics(
-                catalogId, dbId, table.getId(), -1, colName);
+                catalogId, dbId, table.getId(), idxId, colName);
         }
     }
 
@@ -649,8 +649,17 @@ public class StatsCalculator extends 
DefaultPlanVisitor<Statistics, Void> {
         TableIf table = catalogRelation.getTable();
         double rowCount = catalogRelation.getTable().estimatedRowCount();
         boolean hasUnknownCol = false;
+        long idxId = -1;
+        if (catalogRelation instanceof OlapScan) {
+            OlapScan olapScan = (OlapScan) catalogRelation;
+            if (olapScan.getTable().getBaseIndexId() != 
olapScan.getSelectedIndexId()) {
+                idxId = olapScan.getSelectedIndexId();
+            }
+        }
         for (SlotReference slotReference : slotSet) {
-            String colName = slotReference.getName();
+            String colName = slotReference.getColumn().isPresent()
+                    ? slotReference.getColumn().get().getName()
+                    : slotReference.getName();
             boolean shouldIgnoreThisCol = 
StatisticConstants.shouldIgnoreCol(table, slotReference.getColumn().get());
 
             if (colName == null) {
@@ -661,7 +670,7 @@ public class StatsCalculator extends 
DefaultPlanVisitor<Statistics, Void> {
                     || shouldIgnoreThisCol) {
                 cache = ColumnStatistic.UNKNOWN;
             } else {
-                cache = getColumnStatistic(table, colName);
+                cache = getColumnStatistic(table, colName, idxId);
             }
             if (cache.avgSizeByte <= 0) {
                 cache = new ColumnStatisticBuilder(cache)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to