Skip to content

Commit

Permalink
[Enhancement] should do compensation when mv is loose mode (StarRocks…
Browse files Browse the repository at this point in the history
…#53562)

Signed-off-by: kaijian.ding <[email protected]>
  • Loading branch information
kaijianding authored Dec 9, 2024
1 parent ea6b33d commit ad5973a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ protected Map<Table, Set<String>> collectBaseTableUpdatePartitionNames(Map<Table
return baseChangedPartitionNames;
}

protected void collectBaseTableUpdatePartitionNamesInLoose(MvUpdateInfo mvUpdateInfo) {
Map<Table, List<Column>> refBaseTableAndColumns = mv.getRefBaseTablePartitionColumns();
// collect & update mv's to refresh partitions based on base table's partition changes
collectBaseTableUpdatePartitionNames(refBaseTableAndColumns, mvUpdateInfo);
Set<Table> refBaseTables = mv.getRefBaseTablePartitionColumns().keySet();
MaterializedView.AsyncRefreshContext context = mv.getRefreshScheme().getAsyncRefreshContext();
for (Table table : refBaseTables) {
Map<String, MaterializedView.BasePartitionInfo> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public MvUpdateInfo getMVTimelinessUpdateInfoInLoose() {
mvUpdateInfo.getMvToRefreshPartitionNames().add(mvPartitionName);
}
addEmptyPartitionsToRefresh(mvUpdateInfo);
collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo);
return mvUpdateInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ protected MvUpdateInfo getMVTimelinessUpdateInfoInLoose() {
mvUpdateInfo.addMvToRefreshPartitionNames(mvPartitionName);
}
addEmptyPartitionsToRefresh(mvUpdateInfo);
collectBaseTableUpdatePartitionNamesInLoose(mvUpdateInfo);
return mvUpdateInfo;
}
}

0 comments on commit ad5973a

Please sign in to comment.