From 666cba9c2c00c8ad520bd98448374d0d5ba42383 Mon Sep 17 00:00:00 2001 From: lichi <12095047@qq.com> Date: Tue, 2 Jul 2024 18:15:29 +0800 Subject: [PATCH 1/2] [fix](nereids)mv selection should rule out shadow index from schema change --- .../main/java/org/apache/doris/catalog/OlapTable.java | 9 +++++++++ .../exploration/mv/InitMaterializationContextHook.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 d5b1c258c5ddf7..b1ff95df812675 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..66ea199af13167 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,7 +145,8 @@ private List createSyncMvContexts(OlapTable olapTabl keyCount += column.isKey() ? 1 : 0; } for (Map.Entry entry : olapTable.getIndexNameToId().entrySet()) { - if (entry.getValue() != baseIndexId) { + long indexId = entry.getValue(); + if (indexId != baseIndexId && !olapTable.isShadowIndex(indexId)) { MaterializedIndexMeta meta = olapTable.getIndexMetaByIndexId(entry.getValue()); String createMvSql; if (meta.getDefineStmt() != null) { From afb00eee5e6c0679316a0e04ab050896008cd7b3 Mon Sep 17 00:00:00 2001 From: lichi <12095047@qq.com> Date: Wed, 3 Jul 2024 15:33:07 +0800 Subject: [PATCH 2/2] add comments --- .../rules/exploration/mv/InitMaterializationContextHook.java | 2 ++ 1 file changed, 2 insertions(+) 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 66ea199af13167..b649d4cf276f57 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 @@ -146,6 +146,8 @@ private List createSyncMvContexts(OlapTable olapTabl } for (Map.Entry entry : olapTable.getIndexNameToId().entrySet()) { long indexId = entry.getValue(); + // 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;