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

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


The following commit(s) were added to refs/heads/branch-3.1 by this push:
     new 292b6bc91c4 branch-3.1:[fix](mtmv) Fix coredump because common expr 
push down to scannode which belongs to an agg materialized view #58038 (#58060)
292b6bc91c4 is described below

commit 292b6bc91c47f6ef664bbd247ae80fa3c233ad87
Author: xy720 <[email protected]>
AuthorDate: Tue Nov 25 11:11:02 2025 +0800

    branch-3.1:[fix](mtmv) Fix coredump because common expr push down to 
scannode which belongs to an agg materialized view #58038 (#58060)
    
    picked from #58038
---
 .../org/apache/doris/planner/OlapScanNode.java     |  6 +-
 ...est_materialized_view_common_expr_push_down.out |  5 ++
 ..._materialized_view_common_expr_push_down.groovy | 76 ++++++++++++++++++++++
 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java 
b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
index cc296cd7219..19684899071 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java
@@ -1554,7 +1554,11 @@ public class OlapScanNode extends ScanNode {
         if (sortLimit != -1) {
             msg.olap_scan_node.setSortLimit(sortLimit);
         }
-        msg.olap_scan_node.setKeyType(olapTable.getKeysType().toThrift());
+        if (selectedIndexId != -1) {
+            
msg.olap_scan_node.setKeyType(olapTable.getIndexMetaByIndexId(selectedIndexId).getKeysType().toThrift());
+        } else {
+            msg.olap_scan_node.setKeyType(olapTable.getKeysType().toThrift());
+        }
         String tableName = olapTable.getName();
         if (selectedIndexId != -1) {
             tableName = tableName + "(" + getSelectedIndexName() + ")";
diff --git 
a/regression-test/data/rollup_p0/test_materialized_view_common_expr_push_down.out
 
b/regression-test/data/rollup_p0/test_materialized_view_common_expr_push_down.out
new file mode 100644
index 00000000000..891d84e9ae6
--- /dev/null
+++ 
b/regression-test/data/rollup_p0/test_materialized_view_common_expr_push_down.out
@@ -0,0 +1,5 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !sql --
+100
+100
+
diff --git 
a/regression-test/suites/rollup_p0/test_materialized_view_common_expr_push_down.groovy
 
b/regression-test/suites/rollup_p0/test_materialized_view_common_expr_push_down.groovy
new file mode 100644
index 00000000000..2e262031b9f
--- /dev/null
+++ 
b/regression-test/suites/rollup_p0/test_materialized_view_common_expr_push_down.groovy
@@ -0,0 +1,76 @@
+// 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.
+
+suite("test_materialized_view_common_expr_push_down") {
+    def baseTable = "test_base_tbl"
+    def mvTable = "test_mv"
+
+    def getJobState = { tableName ->
+        def jobStateResult = sql """  SHOW ALTER TABLE MATERIALIZED VIEW WHERE 
TableName='${tableName}' ORDER BY CreateTime DESC LIMIT 1; """
+        return jobStateResult[0][8]
+    }
+
+    sql """set enable_common_expr_pushdown = true"""
+
+    sql "DROP TABLE IF EXISTS ${baseTable}"
+    sql """
+            CREATE TABLE `${baseTable}` (
+                `companyId` bigint NULL,
+                `jobId` bigint NULL,
+                `province` text NULL,
+                `vCallerId` bigint NULL DEFAULT "0",
+                `aCallerId` bigint NULL DEFAULT "-1"
+            ) ENGINE=OLAP
+            DUPLICATE KEY(`companyId`)
+            DISTRIBUTED BY HASH(`companyId`) BUCKETS 8
+            PROPERTIES (
+                "replication_allocation" = "tag.location.default: 1"
+            );
+        """
+    sql """
+            CREATE materialized VIEW ${mvTable} AS SELECT
+                companyId as company_id,
+                jobId as job_id,
+                province as p,
+                vCallerId as v_caller_id,
+                aCallerId as a_caller_id
+            FROM ${baseTable}
+            GROUP BY company_id, job_id, p, v_caller_id, a_caller_id;
+    """
+    int max_try_secs = 60
+    while (max_try_secs--) {
+        String res = getJobState(baseTable)
+        if (res == "FINISHED" || res == "CANCELLED") {
+            assertEquals("FINISHED", res)
+            sleep(3000)
+            break
+        } else {
+            Thread.sleep(2000)
+            if (max_try_secs < 1) {
+                println "test timeout," + "state:" + res
+                assertEquals("FINISHED",res)
+            }
+        }
+    }
+
+    sql "insert into ${baseTable} values(100,100,'北京',3,3)"
+    sql "insert into ${baseTable} values(100,100,'广东',3,3)"
+
+    qt_sql """ select mv_companyId from ${baseTable} index ${mvTable} where 
mv_vCallerId = 3 and if(`mv_aCallerId` is null,-1, `mv_aCallerId`) = 3 """
+
+    sql "DROP TABLE ${baseTable} FORCE;"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to