seawinde commented on code in PR #64769:
URL: https://github.com/apache/doris/pull/64769#discussion_r3465025165
##########
fe/fe-core/src/main/java/org/apache/doris/alter/MaterializedViewHandler.java:
##########
@@ -202,10 +202,15 @@ public void
processCreateMaterializedView(CreateMaterializedViewCommand createMv
if (olapTable.existTempPartitions()) {
throw new DdlException("Can not alter table when there are
temp partitions in table");
}
- // check no duplicate column name in full schema
+ // check no duplicate column name against the base index schema.
+ // we don't check the duplicate name of historic mv for backwards
compatibility,
+ // so seed the set from the base index schema only (getBaseSchema)
instead of
+ // getFullSchema(), which also contains historic mv/rollup
columns. Otherwise two
+ // sync mv over the same column whose inferred column name
collides (e.g. stddev
+ // and stddev_pop both produce '__stddev_1') would be wrongly
rejected with
+ // ERR_DUP_FIELDNAME. Pass full=true so hidden base columns are
still checked.
Set<String> allColumnNames = new
TreeSet<>(String.CASE_INSENSITIVE_ORDER);
- for (Column column : olapTable.getFullSchema()) {
- // we don't check the duplicate name of historic mv for
backwards compatibility
+ for (Column column : olapTable.getBaseSchema(true)) {
Review Comment:
之前要求同一个表上所有同步物化视图的列名都不能重复,现在改成了只和基表比较不能重复。
fe/fe-core/src/main/java/org/apache/doris/catalog/Table.java:426:
public Column getColumn(String name) {
return nameToColumn.getOrDefault(name, null);
}
OlapTable 没有 override 这个方法,所以同步 MV 所在的 OlapTable 也是走这个实现。
关键是 OlapTable.rebuildFullSchema() 会维护这个全表级 nameToColumn。base column
先放进去,MV/rollup column 后放,如果同名已经存在就跳过:
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java:542
fullSchema.clear();
nameToColumn.clear();
for (Column baseColumn : indexIdToMeta.get(baseIndexId).getSchema()) {
fullSchema.add(baseColumn);
nameToColumn.put(baseColumn.getName(), baseColumn);
}
for (MaterializedIndexMeta indexMeta : indexIdToMeta.values()) {
for (Column column : indexMeta.getSchema()) {
if (!nameToColumn.containsKey(column.getDefineName())) {
fullSchema.add(column);
nameToColumn.put(column.getDefineName(), column);
}
}
}
所以如果两个同步 MV 都有列 x,全表级 nameToColumn 只会记录一个 x。
而且调用点也不少,比如:
- stats:
fe/fe-core/src/main/java/org/apache/doris/statistics/StatisticsJobAppender.java:117
- stats task:
fe/fe-core/src/main/java/org/apache/doris/statistics/BaseAnalysisTask.java:262
- schema change/drop column:
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/DropColumnOp.java:112
- modify column:
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/ModifyColumnOp.java:108
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]