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 065865141cc69d..4467dda3b912ce 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/mv_p0/test_base/test_base.groovy b/regression-test/suites/mv_p0/test_base/test_base.groovy index f3229813e2f9dc..607388baf25a70 100644 --- a/regression-test/suites/mv_p0/test_base/test_base.groovy +++ b/regression-test/suites/mv_p0/test_base/test_base.groovy @@ -54,4 +54,36 @@ suite ("test_base") { contains "(dwd)" } qt_select_mv "SELECT id,created_at FROM dwd order by 1, 2;" + + 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") + } }