diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java index 82a649be37cf92..6595afb70f7419 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVPartitionUtil.java @@ -325,6 +325,11 @@ public static boolean isSyncWithPartitions(MTMV mtmv, String mtmvPartitionName, if (!relatedTable.needAutoRefresh()) { return true; } + // check if partitions of related table if changed + Set snapshotPartitions = mtmv.getRefreshSnapshot().getSnapshotPartitions(mtmvPartitionName); + if (!Objects.equals(relatedPartitionNames, snapshotPartitions)) { + return false; + } for (String relatedPartitionName : relatedPartitionNames) { MTMVSnapshotIf relatedPartitionCurrentSnapshot = relatedTable .getPartitionSnapshot(relatedPartitionName); diff --git a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java index c1d07b2704951c..d48911275e886b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mtmv/MTMVRefreshSnapshot.java @@ -18,6 +18,7 @@ package org.apache.doris.mtmv; import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import com.google.gson.annotations.SerializedName; import org.apache.commons.collections.MapUtils; @@ -46,6 +47,14 @@ public boolean equalsWithRelatedPartition(String mtmvPartitionName, String relat return relatedPartitionSnapshot.equals(relatedPartitionCurrentSnapshot); } + public Set getSnapshotPartitions(String mtmvPartitionName) { + MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName); + if (partitionSnapshot == null) { + return Sets.newHashSet(); + } + return partitionSnapshot.getPartitions().keySet(); + } + public boolean equalsWithBaseTable(String mtmvPartitionName, long baseTableId, MTMVSnapshotIf baseTableCurrentSnapshot) { MTMVRefreshPartitionSnapshot partitionSnapshot = partitionSnapshots.get(mtmvPartitionName); diff --git a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java index 261b750c79698d..c125e548d06ac6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/mtmv/MTMVPartitionUtilTest.java @@ -130,6 +130,10 @@ public void setUp() throws NoSuchMethodException, SecurityException, AnalysisExc refreshSnapshot.equalsWithRelatedPartition(anyString, anyString, (MTMVSnapshotIf) any); minTimes = 0; result = true; + + refreshSnapshot.getSnapshotPartitions(anyString); + minTimes = 0; + result = Sets.newHashSet("name2"); } }; } @@ -160,6 +164,20 @@ public void testIsSyncWithPartition() throws AnalysisException { Assert.assertTrue(isSyncWithPartition); } + @Test + public void testIsSyncWithPartitionNotEqual() throws AnalysisException { + new Expectations() { + { + refreshSnapshot.getSnapshotPartitions(anyString); + minTimes = 0; + result = Sets.newHashSet("name2", "name3"); + } + }; + boolean isSyncWithPartition = MTMVPartitionUtil + .isSyncWithPartitions(mtmv, "name1", baseOlapTable, Sets.newHashSet("name2")); + Assert.assertFalse(isSyncWithPartition); + } + @Test public void testIsSyncWithPartitionNotSync() throws AnalysisException { new Expectations() {