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

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


The following commit(s) were added to refs/heads/branch-4.0 by this push:
     new efb3f4a5176 branch-4.0: [fix](nereids)allow sync mv has same columns 
as base table when it has where clause #58105 (#58180)
efb3f4a5176 is described below

commit efb3f4a51763cc0793649659d360cb4a9d5f487f
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sun Nov 23 08:24:01 2025 +0800

    branch-4.0: [fix](nereids)allow sync mv has same columns as base table when 
it has where clause #58105 (#58180)
    
    Cherry-picked from #58105
    
    Co-authored-by: starocean999 <[email protected]>
---
 .../java/org/apache/doris/alter/MaterializedViewHandler.java  |  4 ++--
 regression-test/data/nereids_syntax_p0/mv/where/k123/k123.out |  4 ++++
 .../suites/nereids_syntax_p0/mv/where/k123/k123.groovy        | 11 +++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java 
b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
index 2206b58b9a4..b40bfb85c4b 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java
@@ -628,8 +628,8 @@ public class MaterializedViewHandler extends AlterHandler {
                     break;
                 }
             }
-            if (allKeysMatch) {
-                throw new DdlException("MV same with base table is useless.");
+            if (allKeysMatch && createMvCommand.getWhereClauseItem() == null) {
+                throw new DdlException("MV same with base table without where 
clause is useless.");
             }
         }
 
diff --git a/regression-test/data/nereids_syntax_p0/mv/where/k123/k123.out 
b/regression-test/data/nereids_syntax_p0/mv/where/k123/k123.out
index faeb23fbb62..ec7d079caf4 100644
--- a/regression-test/data/nereids_syntax_p0/mv/where/k123/k123.out
+++ b/regression-test/data/nereids_syntax_p0/mv/where/k123/k123.out
@@ -47,3 +47,7 @@
 \N
 \N
 
+-- !select_mv --
+1      1       1       a
+1      1       1       a
+
diff --git a/regression-test/suites/nereids_syntax_p0/mv/where/k123/k123.groovy 
b/regression-test/suites/nereids_syntax_p0/mv/where/k123/k123.groovy
index 5c8bf05def9..474d87ade9d 100644
--- a/regression-test/suites/nereids_syntax_p0/mv/where/k123/k123.groovy
+++ b/regression-test/suites/nereids_syntax_p0/mv/where/k123/k123.groovy
@@ -73,4 +73,15 @@ suite ("nereids_k123p") {
     qt_select_mv """select k1,k2+k3 from d_table where k1 = 2 and k4 = "b" 
order by k1;"""
 
     qt_select_mv_constant """select bitmap_empty() from d_table where true;"""
+
+    create_sync_mv(db, "d_table", "k1234","""select k1 as x1, k2 as x2, k3 as 
x3, k4 as x4 from d_table where k1 = 1;""")
+    mv_rewrite_success_without_check_chosen("select k1 as x1, k2 as x2, k3 as 
x3, k4 as x4 from d_table where k1 = 1;", "k1234")
+    qt_select_mv "select k1 as x1, k2 as x2, k3 as x3, k4 as x4 from d_table 
where k1 = 1 order by k1;"
+    test {
+        sql """
+              create materialized view kx1234 as select k1 as y1, k2 as y2, k3 
as y3, k4 as y4 from d_table;
+        """
+
+        exception "MV same with base table without where clause is useless"
+    }
 }
\ No newline at end of file


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

Reply via email to