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

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

commit a05d738b6ca92e750662d1d40a40a5dd3220dcf7
Author: starocean999 <40539150+starocean...@users.noreply.github.com>
AuthorDate: Thu Apr 18 10:46:10 2024 +0800

    [fix](planner) create view statement should forbid mv rewrite (#33784)
---
 .../apache/doris/analysis/SetOperationStmt.java    |  7 +++++
 .../suites/correctness_p0/test_mv_case.groovy      | 32 ++++++++++++++++++++++
 2 files changed, 39 insertions(+)

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 941f965a3a6..146fae3f64c 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 class SetOperationStmt extends QueryStmt {
         }
     }
 
+    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 d8ba37208c9..4c51582a4ec 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")
+    }
 }


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

Reply via email to