Skip to content

Commit a0a19db

Browse files
authored
[Bug](materialized-view) forbid create mv with value column before key column (#33436)
forbid create mv with value column before key column
1 parent ee7c394 commit a0a19db

File tree

2 files changed

+12
-0
lines changed
  • fe/fe-core/src/main/java/org/apache/doris/catalog
  • regression-test/suites/mv_p0/unique

2 files changed

+12
-0
lines changed

Diff for: fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java

+6
Original file line numberDiff line numberDiff line change
@@ -4217,9 +4217,15 @@ public static short calcShortKeyColumnCount(List<Column> columns, Map<String, St
42174217
boolean isKeysRequired) throws DdlException {
42184218
List<Column> indexColumns = new ArrayList<Column>();
42194219
Map<Integer, Column> clusterColumns = new TreeMap<>();
4220+
boolean hasValueColumn = false;
42204221
for (Column column : columns) {
42214222
if (column.isKey()) {
4223+
if (hasValueColumn && isKeysRequired) {
4224+
throw new DdlException("The materialized view not support value column before key column");
4225+
}
42224226
indexColumns.add(column);
4227+
} else {
4228+
hasValueColumn = true;
42234229
}
42244230
if (column.isClusterKey()) {
42254231
clusterColumns.put(column.getClusterKeyId(), column);

Diff for: regression-test/suites/mv_p0/unique/unique.groovy

+6
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,17 @@ suite ("unique") {
4141
sql """create materialized view k12s3m as select k1,sum(k2),max(k2) from u_table group by k1;"""
4242
exception "must not has grouping columns"
4343
}
44+
4445
test {
4546
sql """create materialized view kadj as select k4 from u_table"""
4647
exception "The materialized view need key column"
4748
}
4849

50+
test {
51+
sql """create materialized view kadj as select k4,k1 from u_table"""
52+
exception "The materialized view not support value column before key column"
53+
}
54+
4955
createMV("create materialized view kadj as select k3,k2,k1,k4 from u_table;")
5056

5157
createMV("create materialized view kadj2 as select k3,k2,length(k4) from u_table;")

0 commit comments

Comments
 (0)