Skip to content

Commit a5aa884

Browse files
branch-4.0: [fix](mtmx) Fix coredump because common expr push down to scannode which belongs to an agg materialized view #58038 (#58096)
Cherry-picked from #58038 Co-authored-by: xy720 <[email protected]>
1 parent 6067568 commit a5aa884

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

fe/fe-core/src/main/java/org/apache/doris/planner/OlapScanNode.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,11 @@ protected void toThrift(TPlanNode msg) {
12151215
if (annSortLimit != -1) {
12161216
msg.olap_scan_node.setAnnSortLimit(annSortLimit);
12171217
}
1218-
msg.olap_scan_node.setKeyType(olapTable.getKeysType().toThrift());
1218+
if (selectedIndexId != -1) {
1219+
msg.olap_scan_node.setKeyType(olapTable.getIndexMetaByIndexId(selectedIndexId).getKeysType().toThrift());
1220+
} else {
1221+
msg.olap_scan_node.setKeyType(olapTable.getKeysType().toThrift());
1222+
}
12191223
String tableName = olapTable.getName();
12201224
if (selectedIndexId != -1) {
12211225
tableName = tableName + "(" + getSelectedIndexName() + ")";
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- This file is automatically generated. You should know what you did if you want to edit this
2+
-- !sql --
3+
100
4+
100
5+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("test_materialized_view_common_expr_push_down") {
19+
def baseTable = "test_base_tbl"
20+
def mvTable = "test_mv"
21+
22+
def getJobState = { tableName ->
23+
def jobStateResult = sql """ SHOW ALTER TABLE MATERIALIZED VIEW WHERE TableName='${tableName}' ORDER BY CreateTime DESC LIMIT 1; """
24+
return jobStateResult[0][8]
25+
}
26+
27+
sql """set enable_common_expr_pushdown = true"""
28+
29+
sql "DROP TABLE IF EXISTS ${baseTable}"
30+
sql """
31+
CREATE TABLE `${baseTable}` (
32+
`companyId` bigint NULL,
33+
`jobId` bigint NULL,
34+
`province` text NULL,
35+
`vCallerId` bigint NULL DEFAULT "0",
36+
`aCallerId` bigint NULL DEFAULT "-1"
37+
) ENGINE=OLAP
38+
DUPLICATE KEY(`companyId`)
39+
DISTRIBUTED BY HASH(`companyId`) BUCKETS 8
40+
PROPERTIES (
41+
"replication_allocation" = "tag.location.default: 1"
42+
);
43+
"""
44+
sql """
45+
CREATE materialized VIEW ${mvTable} AS SELECT
46+
companyId as company_id,
47+
jobId as job_id,
48+
province as p,
49+
vCallerId as v_caller_id,
50+
aCallerId as a_caller_id
51+
FROM ${baseTable}
52+
GROUP BY company_id, job_id, p, v_caller_id, a_caller_id;
53+
"""
54+
int max_try_secs = 60
55+
while (max_try_secs--) {
56+
String res = getJobState(baseTable)
57+
if (res == "FINISHED" || res == "CANCELLED") {
58+
assertEquals("FINISHED", res)
59+
sleep(3000)
60+
break
61+
} else {
62+
Thread.sleep(2000)
63+
if (max_try_secs < 1) {
64+
println "test timeout," + "state:" + res
65+
assertEquals("FINISHED",res)
66+
}
67+
}
68+
}
69+
70+
sql "insert into ${baseTable} values(100,100,'北京',3,3)"
71+
sql "insert into ${baseTable} values(100,100,'广东',3,3)"
72+
73+
qt_sql """ select company_id from ${baseTable} index ${mvTable} where v_caller_id = 3 and if(`a_caller_id` is null,-1, `a_caller_id`) = 3 """
74+
75+
sql "DROP TABLE ${baseTable} FORCE;"
76+
}

0 commit comments

Comments
 (0)