diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java index 7d3b9baf3417ec..471cbdf0ec642a 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.java @@ -2990,4 +2990,13 @@ public long getRemoteDataSize() { public long getReplicaCount() { return statistics.getReplicaCount(); } + + public boolean isShadowIndex(long indexId) { + String indexName = getIndexNameById(indexId); + if (indexName != null && indexName.startsWith(org.apache.doris.alter.SchemaChangeHandler.SHADOW_NAME_PREFIX)) { + return true; + } else { + return false; + } + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java index 072765fb2a4a49..53a352e2ef80e9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/InitMaterializationContextHook.java @@ -145,38 +145,46 @@ private List createSyncMvContexts(OlapTable olapTabl keyCount += column.isKey() ? 1 : 0; } for (Map.Entry entry : olapTable.getIndexNameToId().entrySet()) { - if (entry.getValue() != baseIndexId) { - MaterializedIndexMeta meta = olapTable.getIndexMetaByIndexId(entry.getValue()); - String createMvSql; - if (meta.getDefineStmt() != null) { - // get the original create mv sql - createMvSql = meta.getDefineStmt().originStmt; - } else { - // it's rollup, need assemble create mv sql manually - if (olapTable.getKeysType() == KeysType.AGG_KEYS) { - createMvSql = assembleCreateMvSqlForAggTable(olapTable.getQualifiedName(), - entry.getKey(), meta.getSchema(false), keyCount); + long indexId = entry.getValue(); + try { + // when doing schema change, a shadow index would be created and put together with mv indexes + // we must roll out these unexpected shadow indexes here + if (indexId != baseIndexId && !olapTable.isShadowIndex(indexId)) { + MaterializedIndexMeta meta = olapTable.getIndexMetaByIndexId(entry.getValue()); + String createMvSql; + if (meta.getDefineStmt() != null) { + // get the original create mv sql + createMvSql = meta.getDefineStmt().originStmt; } else { - createMvSql = - assembleCreateMvSqlForDupOrUniqueTable(olapTable.getQualifiedName(), - entry.getKey(), meta.getSchema(false)); + // it's rollup, need assemble create mv sql manually + if (olapTable.getKeysType() == KeysType.AGG_KEYS) { + createMvSql = assembleCreateMvSqlForAggTable(olapTable.getQualifiedName(), + entry.getKey(), meta.getSchema(false), keyCount); + } else { + createMvSql = + assembleCreateMvSqlForDupOrUniqueTable(olapTable.getQualifiedName(), + entry.getKey(), meta.getSchema(false)); + } } - } - if (createMvSql != null) { - Optional querySql = - new NereidsParser().parseForSyncMv(createMvSql); - if (!querySql.isPresent()) { - LOG.warn(String.format("can't parse %s ", createMvSql)); - continue; + if (createMvSql != null) { + Optional querySql = + new NereidsParser().parseForSyncMv(createMvSql); + if (!querySql.isPresent()) { + LOG.warn(String.format("can't parse %s ", createMvSql)); + continue; + } + MTMVCache mtmvCache = MaterializedViewUtils.createMTMVCache(querySql.get(), + cascadesContext.getConnectContext()); + contexts.add(new SyncMaterializationContext(mtmvCache.getLogicalPlan(), + mtmvCache.getOriginalPlan(), olapTable, meta.getIndexId(), entry.getKey(), + cascadesContext, mtmvCache.getStatistics())); + } else { + LOG.warn(String.format("can't assemble create mv sql for index ", entry.getKey())); } - MTMVCache mtmvCache = MaterializedViewUtils.createMTMVCache(querySql.get(), - cascadesContext.getConnectContext()); - contexts.add(new SyncMaterializationContext(mtmvCache.getLogicalPlan(), - mtmvCache.getOriginalPlan(), olapTable, meta.getIndexId(), entry.getKey(), - cascadesContext, mtmvCache.getStatistics())); - } else { - LOG.warn(String.format("can't assemble create mv sql for index ", entry.getKey())); } + } catch (Exception exception) { + LOG.warn(String.format("createSyncMvContexts exception, index id is %s, index name is %s", + entry.getValue(), entry.getValue()), exception); } } return contexts;