diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java index ffcf975ecd9fa..4627feffc66d2 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessArbiter.java @@ -175,6 +175,25 @@ protected Map> collectBaseTableUpdatePartitionNames(Map> refBaseTableAndColumns = mv.getRefBaseTablePartitionColumns(); + // collect & update mv's to refresh partitions based on base table's partition changes + collectBaseTableUpdatePartitionNames(refBaseTableAndColumns, mvUpdateInfo); + Set
refBaseTables = mv.getRefBaseTablePartitionColumns().keySet(); + MaterializedView.AsyncRefreshContext context = mv.getRefreshScheme().getAsyncRefreshContext(); + for (Table table : refBaseTables) { + Map mvBaseTableVisibleVersionMap = + context.getBaseTableVisibleVersionMap() + .computeIfAbsent(table.getId(), k -> Maps.newHashMap()); + for (String partitionName : mvBaseTableVisibleVersionMap.keySet()) { + if (mvUpdateInfo.getBaseTableToRefreshPartitionNames(table) != null) { + // in loose mode, ignore partition that both exists in baseTable and mv + mvUpdateInfo.getBaseTableToRefreshPartitionNames(table).remove(partitionName); + } + } + } + } + /** * If base table is materialized view, add partition name to cell mapping into base table partition mapping; * otherwise base table(mv) may lose partition names of the real base table changed partitions. diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java index b30a2d3ff0a8c..98346b5d9f9dc 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessListPartitionArbiter.java @@ -149,6 +149,7 @@ public MvUpdateInfo getMVTimelinessUpdateInfoInLoose() { mvUpdateInfo.getMvToRefreshPartitionNames().add(mvPartitionName); } addEmptyPartitionsToRefresh(mvUpdateInfo); + collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo); return mvUpdateInfo; } } \ No newline at end of file diff --git a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java index 7972318351bf5..b691671b38856 100644 --- a/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java +++ b/fe/fe-core/src/main/java/com/starrocks/catalog/mv/MVTimelinessRangePartitionArbiter.java @@ -180,6 +180,7 @@ protected MvUpdateInfo getMVTimelinessUpdateInfoInLoose() { mvUpdateInfo.addMvToRefreshPartitionNames(mvPartitionName); } addEmptyPartitionsToRefresh(mvUpdateInfo); + collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo); return mvUpdateInfo; } }