diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java index 941f965a3a66fd..146fae3f64c9de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SetOperationStmt.java @@ -234,6 +234,13 @@ public void getTableRefs(Analyzer analyzer, List tblRefs, Set } } + public void forbiddenMVRewrite() { + super.forbiddenMVRewrite(); + for (SetOperand op : operands) { + op.getQueryStmt().forbiddenMVRewrite(); + } + } + /** * Propagates DISTINCT from left to right, and checks that all * set operands are set compatible, adding implicit casts if necessary. diff --git a/regression-test/suites/correctness_p0/test_mv_case.groovy b/regression-test/suites/correctness_p0/test_mv_case.groovy index d8ba37208c988d..4c51582a4ec3e2 100644 --- a/regression-test/suites/correctness_p0/test_mv_case.groovy +++ b/regression-test/suites/correctness_p0/test_mv_case.groovy @@ -38,4 +38,36 @@ suite("test_mv_case") { sql """insert into test_table_aaa2 select 'cib2205045_1_1s','2023/6/10 3:57:33','{"DB1":168939,"DNT":"2023-06-10 03:57:33"}' ;""" sql """insert into test_table_aaa2 select 'cib2205045_1_1s','2023/6/10 3:58:33','{"DB1":168939,"DNT":"2023-06-10 03:58:33"}' ;""" qt_select_default """ select * from test_table_aaa2 order by dnt;""" + + sql """set enable_nereids_planner=false;""" + sql """drop table if exists test_mv_view_t;""" + sql """drop view if exists test_mv_view_t_view;""" + sql """CREATE TABLE `test_mv_view_t` ( + `day` date NOT NULL, + `game_code` varchar(100) NOT NULL , + `plat_code` varchar(100) NOT NULL + ) ENGINE=OLAP + duplicate KEY(`day`) + DISTRIBUTED BY HASH(`day`) BUCKETS 4 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + );""" + sql """INSERT INTO test_mv_view_t VALUES('2024-04-01', 'x', 'y');""" + createMV ("""create materialized view test_mv_view_t_mv as + select `day`, count(game_code) + from test_mv_view_t group by day;""") + sql """create view test_mv_view_t_view + as + select `day` + from test_mv_view_t + where day<'2024-04-15' + + union all + select `day` + from test_mv_view_t + where day>='2024-04-15';""" + explain { + sql("""SELECT * from test_mv_view_t_view where day='2024-04-15';""") + notContains("mv_day") + } }