Skip to content

Commit b0b7b2a

Browse files
branch-4.0: [fix](nereids)where clause should only contains key column when create mv on unique table #57915 (#58179)
Cherry-picked from #57915 Co-authored-by: starocean999 <[email protected]>
1 parent 03da50f commit b0b7b2a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateMaterializedViewCommand.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ public Plan visitLogicalFilter(LogicalFilter<? extends Plan> filter, ValidateCon
304304
Column column = ((SlotReference) slot).getOriginalColumn().orElse(null);
305305
if (column != null) {
306306
if (column.isVisible()) {
307-
AggregateType aggregateType = column.getAggregationType();
308-
if (aggregateType != null && aggregateType != AggregateType.NONE) {
307+
if (context.keysType.isAggregationFamily() && !column.isKey()) {
309308
throw new AnalysisException(String.format(
310309
"The where clause contained aggregate column is not supported, expr is %s",
311310
expr));

regression-test/suites/mv_p0/test_mv_useless/test_uniq_mv_useless/test_uniq_mv_useless.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,20 @@ suite ("test_uniq_mv_useless") {
4848

4949
createMV ("create materialized view k1_k2_u21 as select k2 as a1,k1 as a2 from ${testTable};")
5050
sql "insert into ${testTable} select 4,4,4;"
51+
52+
sql """ DROP TABLE IF EXISTS test_uniq_mv_useless_mow_table; """
53+
sql """
54+
create table test_uniq_mv_useless_mow_table (
55+
k1 int null,
56+
k2 int null,
57+
k3 int
58+
)
59+
unique key (k1,k2)
60+
distributed BY hash(k1) buckets 3
61+
properties("replication_num" = "1", "enable_unique_key_merge_on_write" = "true");
62+
"""
63+
test {
64+
sql "create materialized view k1_k2_u12 as select k1 as a1,k2 as a2 from test_uniq_mv_useless_mow_table where k3 > 0;"
65+
exception "The where clause contained aggregate column is not supported"
66+
}
5167
}

0 commit comments

Comments
 (0)