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

lijibing pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 54a4f354c9d branch-3.0: [fix](mv)Fix direct select mv pre agg bug. 
#47658 (#47699)
54a4f354c9d is described below

commit 54a4f354c9d8ce22c1528d03fc22173dfa87ac8a
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Feb 10 19:33:08 2025 +0800

    branch-3.0: [fix](mv)Fix direct select mv pre agg bug. #47658 (#47699)
    
    Cherry-picked from #47658
    
    Co-authored-by: James <lijib...@selectdb.com>
---
 .../doris/nereids/rules/analysis/BindRelation.java   |   4 +++-
 regression-test/data/statistics/test_analyze_mv.out  | Bin 0 -> 124 bytes
 .../suites/statistics/test_analyze_mv.groovy         |  19 +++++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
index 734f5d9bd67..41a00b422d4 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/analysis/BindRelation.java
@@ -250,7 +250,9 @@ public class BindRelation extends OneAnalysisRuleFactory {
         List<Slot> childOutputSlots = olapScan.computeOutput();
         List<Expression> groupByExpressions = new ArrayList<>();
         List<NamedExpression> outputExpressions = new ArrayList<>();
-        List<Column> columns = olapTable.getBaseSchema();
+        List<Column> columns = olapScan.isIndexSelected()
+                ? olapTable.getSchemaByIndexId(olapScan.getSelectedIndexId())
+                : olapTable.getBaseSchema();
 
         for (Column col : columns) {
             // use exist slot in the plan
diff --git a/regression-test/data/statistics/test_analyze_mv.out 
b/regression-test/data/statistics/test_analyze_mv.out
new file mode 100644
index 00000000000..a7249335430
Binary files /dev/null and 
b/regression-test/data/statistics/test_analyze_mv.out differ
diff --git a/regression-test/suites/statistics/test_analyze_mv.groovy 
b/regression-test/suites/statistics/test_analyze_mv.groovy
index daa8d780aee..aafac346f5a 100644
--- a/regression-test/suites/statistics/test_analyze_mv.groovy
+++ b/regression-test/suites/statistics/test_analyze_mv.groovy
@@ -789,6 +789,25 @@ suite("test_analyze_mv") {
     assertEquals("1", result[0][7])
     assertEquals("5", result[0][8])
 
+    sql """drop table if exists testMvDirectSelect"""
+    sql """
+        CREATE TABLE testMvDirectSelect (
+            key1      int NOT NULL,
+            key2      int NOT NULL,
+            value     int SUM
+        )ENGINE=OLAP
+        AGGREGATE KEY(key1, key2)
+        COMMENT "OLAP"
+        DISTRIBUTED BY RANDOM BUCKETS 2
+        PROPERTIES (
+            "replication_num" = "1"
+        );
+    """
+
+    createMV("CREATE MATERIALIZED VIEW aggMv as select key1, SUM(value) from 
testMvDirectSelect group by key1;")
+    sql """insert into testMvDirectSelect values (1, 1, 1), (1, 2, 2), (1, 3, 
3), (2, 1, 4), (2, 2, 5), (3, 2, 6)"""
+    qt_test_agg """select * from testMvDirectSelect index aggMv order by 
mv_key1"""
+
     sql """drop database if exists test_analyze_mv"""
 }
 


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

Reply via email to