This is an automated email from the ASF dual-hosted git repository. dataroaring pushed a commit to branch branch-3.0 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-3.0 by this push: new 21d66ca2b8e branch-3.0: [fix](mtmv) Fix nest mtmv rewrite fail when bottom mtmv cache is invalid #48222 (#49129) 21d66ca2b8e is described below commit 21d66ca2b8e4f551f677c3fabc8a301f64eebda3 Author: seawinde <w...@selectdb.com> AuthorDate: Wed Mar 19 10:43:10 2025 +0800 branch-3.0: [fix](mtmv) Fix nest mtmv rewrite fail when bottom mtmv cache is invalid #48222 (#49129) ### What problem does this PR solve? cherry-pick: https://github.com/apache/doris/pull/48222 commitId: 3806b97f --- .../main/java/org/apache/doris/catalog/MTMV.java | 4 -- .../trees/plans/logical/LogicalOlapScan.java | 55 ++++++++++++++++++---- 2 files changed, 46 insertions(+), 13 deletions(-) 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 c540ee5c541..d96a4997a80 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 class MTMV extends OlapTable { } } - public MTMVCache getCache() { - return cache; - } - public Map<String, String> 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 2216e58c4fa..6f89af71d7b 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.Column; 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; @@ -36,6 +37,7 @@ import org.apache.doris.nereids.trees.plans.RelationId; import org.apache.doris.nereids.trees.plans.algebra.OlapScan; import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; import org.apache.doris.nereids.util.Utils; +import org.apache.doris.qe.ConnectContext; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; @@ -46,6 +48,8 @@ import com.google.common.collect.ImmutableSet; 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 +66,8 @@ import java.util.Set; */ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan { + private static final Logger LOG = LogManager.getLogger(LogicalOlapScan.class); + /////////////////////////////////////////////////////////////////////////// // Members for materialized index. /////////////////////////////////////////////////////////////////////////// @@ -527,9 +533,15 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan Set<Slot> 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 +566,15 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan 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 +587,15 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan 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 +608,15 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan 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 +629,14 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan Map<Slot, Slot> replaceMap = new HashMap<>(); // Need remove invisible column, and then mapping them List<Slot> 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); } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org