diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java index 017fcd524d565b..2ad3291681d640 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java @@ -271,6 +271,9 @@ public Plan visitLogicalOlapScan(LogicalOlapScan olapScan, ValidateContext valid if (olapTable.isTemporary()) { throw new AnalysisException("do not support create materialized view on temporary table"); } + if (olapScan.isDirectMvScan()) { + throw new AnalysisException("do not support create materialized view on another synchronized mv"); + } validateContext.baseIndexName = olapTable.getName(); validateContext.dbName = olapTable.getDBName(); validateContext.keysType = olapTable.getKeysType(); diff --git a/regression-test/suites/mv_p0/test_create_mv/test_create_mv.groovy b/regression-test/suites/mv_p0/test_create_mv/test_create_mv.groovy index ac76978043e983..edbbc6093d528e 100644 --- a/regression-test/suites/mv_p0/test_create_mv/test_create_mv.groovy +++ b/regression-test/suites/mv_p0/test_create_mv/test_create_mv.groovy @@ -85,4 +85,16 @@ suite("test_create_mv") { } } } + multi_sql """ + drop table if exists t_mv_on_mv; + create table t_mv_on_mv( id int, value int) + partition by range(id)( partition p1 values[('1'), ('2')), partition p2 values[('2'), ('3')), partition p3 values[('3'), ('4')), partition p4 values[('4'), ('5')), partition p5 values[('5'), ('6')))distributed by hash(id)properties( 'replication_num'='1'); + + insert into t_mv_on_mv values (1, 1), (1, 2),(2, 1), (2, 2), (3, 1), (3, 2),(4, 1), (4, 2),(5, 1), (5, 2); + """ + createMV("""CREATE MATERIALIZED VIEW mv1 as select id as col1, sum(value) as col2 from t_mv_on_mv group by id;""") + test { + sql """CREATE MATERIALIZED VIEW mv2 as select col1 as aa, count(col2) as bb from t_mv_on_mv index mv1 group by col1; """ + exception "do not support create materialized view on another synchronized mv" + } }