[fix](mtmv)return MTMV with at least one available partition #30156

This commit is contained in:
zhangdong
2024-01-22 20:42:25 +08:00
committed by yiguolei
parent bb6fff3455
commit 510d88f315
2 changed files with 17 additions and 6 deletions

View File

@ -33,6 +33,7 @@ import org.apache.doris.nereids.trees.plans.commands.info.RefreshMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.ResumeMTMVInfo;
import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
import org.apache.doris.persist.AlterMTMV;
import org.apache.doris.qe.ConnectContext;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
@ -53,16 +54,26 @@ public class MTMVRelationManager implements MTMVHookService {
private static final Logger LOG = LogManager.getLogger(MTMVRelationManager.class);
private Map<BaseTableInfo, Set<BaseTableInfo>> tableMTMVs = Maps.newConcurrentMap();
public Set<BaseTableInfo> getMtmvsByBaseTable(BaseTableInfo table) {
private Set<BaseTableInfo> getMtmvsByBaseTable(BaseTableInfo table) {
return tableMTMVs.getOrDefault(table, ImmutableSet.of());
}
public Set<MTMV> getAvailableMTMVs(List<BaseTableInfo> tableInfos) {
/**
* if At least one partition is available, return this mtmv
*
* @param tableInfos
* @param ctx
* @return
*/
public Set<MTMV> getAvailableMTMVs(List<BaseTableInfo> tableInfos, ConnectContext ctx) {
Set<MTMV> res = Sets.newHashSet();
Set<BaseTableInfo> mvInfos = getAvailableMTMVInfos(tableInfos);
Set<BaseTableInfo> mvInfos = getMTMVInfos(tableInfos);
for (BaseTableInfo tableInfo : mvInfos) {
try {
res.add((MTMV) MTMVUtil.getTable(tableInfo));
MTMV mtmv = (MTMV) MTMVUtil.getTable(tableInfo);
if (!CollectionUtils.isEmpty(MTMVUtil.getMTMVCanRewritePartitions(mtmv, ctx))) {
res.add(mtmv);
}
} catch (AnalysisException e) {
// not throw exception to client, just ignore it
LOG.warn("getTable failed: {}", tableInfo.toString(), e);
@ -71,7 +82,7 @@ public class MTMVRelationManager implements MTMVHookService {
return res;
}
public Set<BaseTableInfo> getAvailableMTMVInfos(List<BaseTableInfo> tableInfos) {
private Set<BaseTableInfo> getMTMVInfos(List<BaseTableInfo> tableInfos) {
Set<BaseTableInfo> mvInfos = Sets.newHashSet();
for (BaseTableInfo tableInfo : tableInfos) {
mvInfos.addAll(getMtmvsByBaseTable(tableInfo));

View File

@ -70,7 +70,7 @@ public class InitMaterializationContextHook implements PlannerHook {
List<BaseTableInfo> usedBaseTables =
collectedTables.stream().map(BaseTableInfo::new).collect(Collectors.toList());
Set<MTMV> availableMTMVs = Env.getCurrentEnv().getMtmvService().getRelationManager()
.getAvailableMTMVs(usedBaseTables);
.getAvailableMTMVs(usedBaseTables, cascadesContext.getConnectContext());
if (availableMTMVs.isEmpty()) {
return;
}