diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java index c540ee5c5417dd..d96a4997a80e12 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/MTMV.java @@ -332,10 +332,6 @@ public MTMVCache getOrGenerateCache(ConnectContext connectionContext) throws Ana } } - public MTMVCache getCache() { - return cache; - } - public Map getMvProperties() { readMvLock(); try { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java index 2216e58c4fa3b8..a34fa9b356e26e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java @@ -21,6 +21,7 @@ import org.apache.doris.catalog.MTMV; import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.Table; +import org.apache.doris.common.AnalysisException; import org.apache.doris.mtmv.MTMVCache; import org.apache.doris.nereids.memo.GroupExpression; import org.apache.doris.nereids.properties.DataTrait; @@ -46,6 +47,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.json.JSONObject; import java.util.ArrayList; @@ -62,6 +65,8 @@ */ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan { + private static final Logger LOG = LogManager.getLogger(LogicalOlapScan.class); + /////////////////////////////////////////////////////////////////////////// // Members for materialized index. /////////////////////////////////////////////////////////////////////////// @@ -527,9 +532,15 @@ AGGREGATE KEY (siteid,citycode,username) Set outputSet = Utils.fastToImmutableSet(getOutputSet()); if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); - MTMVCache cache = mtmv.getCache(); + MTMVCache cache; + try { + cache = mtmv.getOrGenerateCache(ConnectContext.get()); + } catch (AnalysisException e) { + LOG.warn(String.format("LogicalOlapScan computeUnique fail, mv name is %s", mtmv.getName()), e); + return; + } // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index - if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { + if (this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -554,9 +565,15 @@ AGGREGATE KEY (siteid,citycode,username) public void computeUniform(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); - MTMVCache cache = mtmv.getCache(); + MTMVCache cache; + try { + cache = mtmv.getOrGenerateCache(ConnectContext.get()); + } catch (AnalysisException e) { + LOG.warn(String.format("LogicalOlapScan computeUniform fail, mv name is %s", mtmv.getName()), e); + return; + } // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index - if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { + if (this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -569,9 +586,15 @@ public void computeUniform(DataTrait.Builder builder) { public void computeEqualSet(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); - MTMVCache cache = mtmv.getCache(); + MTMVCache cache; + try { + cache = mtmv.getOrGenerateCache(ConnectContext.get()); + } catch (AnalysisException e) { + LOG.warn(String.format("LogicalOlapScan computeEqualSet fail, mv name is %s", mtmv.getName()), e); + return; + } // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index - if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { + if (this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -584,9 +607,15 @@ public void computeEqualSet(DataTrait.Builder builder) { public void computeFd(DataTrait.Builder builder) { if (getTable() instanceof MTMV) { MTMV mtmv = (MTMV) getTable(); - MTMVCache cache = mtmv.getCache(); + MTMVCache cache; + try { + cache = mtmv.getOrGenerateCache(ConnectContext.get()); + } catch (AnalysisException e) { + LOG.warn(String.format("LogicalOlapScan computeFd fail, mv name is %s", mtmv.getName()), e); + return; + } // Maybe query specified index, should not calc, such as select count(*) from t1 index col_index - if (cache == null || this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { + if (this.getSelectedIndexId() != this.getTable().getBaseIndexId()) { return; } Plan originalPlan = cache.getOriginalPlan(); @@ -599,7 +628,14 @@ Map constructReplaceMap(MTMV mtmv) { Map replaceMap = new HashMap<>(); // Need remove invisible column, and then mapping them List originOutputs = new ArrayList<>(); - for (Slot originSlot : mtmv.getCache().getOriginalPlan().getOutput()) { + MTMVCache cache; + try { + cache = mtmv.getOrGenerateCache(ConnectContext.get()); + } catch (AnalysisException e) { + LOG.warn(String.format("LogicalOlapScan constructReplaceMap fail, mv name is %s", mtmv.getName()), e); + return replaceMap; + } + for (Slot originSlot : cache.getOriginalPlan().getOutput()) { if (!(originSlot instanceof SlotReference) || (((SlotReference) originSlot).isVisible())) { originOutputs.add(originSlot); }