diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java index 0298ce88c5ae0b7..fadb9538371073f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewAggregateRule.java @@ -82,14 +82,14 @@ protected Plan rewriteQueryByView(MatchMode matchMode, Pair> viewTopPlanAndAggPair = splitToTopPlanAndAggregate(viewStructInfo); if (viewTopPlanAndAggPair == null) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("split to view to top plan and agg fail, view plan is %s", + String.format("view split to top plan and agg fail, view plan = %s\n", viewStructInfo.getOriginalPlan().treeString())); return null; } Pair> queryTopPlanAndAggPair = splitToTopPlanAndAggregate(queryStructInfo); if (queryTopPlanAndAggPair == null) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("split to query to top plan and agg fail, query plan is %s", + String.format("query split to top plan and agg fail, query plan = %s\n", queryStructInfo.getOriginalPlan().treeString())); return null; } @@ -120,9 +120,11 @@ protected Plan rewriteQueryByView(MatchMode matchMode, if (rewrittenQueryGroupExpr.isEmpty()) { // can not rewrite, bail out. materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("can not rewrite expression when not need roll up, expressionToWrite is %s," - + "mvExprToMvScanExprMapping is %s", queryTopPlan.getExpressions(), - materializationContext.getMvExprToMvScanExprMapping())); + String.format("can not rewrite expression when need no roll up, expressionToWrite = %s,\n" + + "mvExprToMvScanExprMapping = %s,\n queryToViewSlotMapping = %s", + queryTopPlan.getExpressions(), + materializationContext.getMvExprToMvScanExprMapping(), + queryToViewSlotMapping)); return null; } return new LogicalProject<>( @@ -138,7 +140,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode, && ((AggregateFunction) expr).isDistinct()))) { // if mv aggregate function contains distinct, can not roll up, bail out. materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("view contains distinct function so can not roll up, view plan is %s", + String.format("view contains distinct function so can not roll up, view plan = %s", viewAggregate.getOutputExpressions())); return null; } @@ -148,7 +150,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode, if (queryGroupAndFunctionPair == null) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), String.format("query top plan split to group by and function fail," - + "queryTopPlan is %s, agg is %s", + + "queryTopPlan = %s,\n agg = %s", queryTopPlanAndAggPair.key().treeString(), queryTopPlanAndAggPair.value().treeString())); return null; } @@ -176,6 +178,10 @@ protected Plan rewriteQueryByView(MatchMode matchMode, Function rollupAggregateFunction = rollup(queryFunction, queryFunctionShuttled, mvExprToMvScanExprQueryBased); if (rollupAggregateFunction == null) { + materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), + String.format("query function roll up fail, queryFunction = %s,\n" + + "mvExprToMvScanExprQueryBased = %s", + queryFunction, mvExprToMvScanExprQueryBased)); return null; } // key is query need roll up expr, value is mv scan based roll up expr @@ -189,8 +195,9 @@ protected Plan rewriteQueryByView(MatchMode matchMode, false); if (rewrittenFunctionExpression == null) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("roll up expression can not rewrite by view, topExpression is %s," - + "needRollupExprMapping is %s", topExpression, needRollupExprMapping)); + String.format("roll up expression can not rewrite by view, topExpression = %s,\n" + + "needRollupExprMapping = %s,\n queryToViewSlotMapping = %s", + topExpression, needRollupExprMapping, queryToViewSlotMapping)); return null; } finalAggregateExpressions.add((NamedExpression) rewrittenFunctionExpression); @@ -202,7 +209,7 @@ protected Plan rewriteQueryByView(MatchMode matchMode, // group expr can not rewrite by view materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), String.format("view group expressions doesn't not contains the query group by expression," - + "mvExprToMvScanExprQueryBased is %s,queryGroupShuttledExpr is %s", + + "mvExprToMvScanExprQueryBased is %s,\nqueryGroupShuttledExpr is %s", mvExprToMvScanExprQueryBased, queryGroupShuttledExpr)); return null; } @@ -219,8 +226,9 @@ protected Plan rewriteQueryByView(MatchMode matchMode, if (rewrittenGroupExpression == null) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), String.format("query top group expression can not be rewritten by view," - + "topExpression is %s, groupRewrittenExprMapping is %s", - topExpression, groupRewrittenExprMapping)); + + "topExpression is %s,\n groupRewrittenExprMapping is %s,\n" + + "queryToViewSlotMapping = %s", + topExpression, groupRewrittenExprMapping, queryToViewSlotMapping)); return null; } finalAggregateExpressions.add((NamedExpression) rewrittenGroupExpression); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewJoinRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewJoinRule.java index 21039dbc9bab77e..e33a533b7f0a068 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewJoinRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewJoinRule.java @@ -61,9 +61,10 @@ protected Plan rewriteQueryByView(MatchMode matchMode, if (expressionsRewritten.isEmpty() || expressionsRewritten.stream().anyMatch(expr -> !(expr instanceof NamedExpression))) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - String.format("join rewrite query by view fail, expressionToRewritten is %s, " - + "mvExprToMvScanExprMapping is %s", - queryStructInfo.getExpressions(), materializationContext.getMvExprToMvScanExprMapping())); + String.format("join rewrite query by view fail, expressionToRewritten is %s,\n" + + "mvExprToMvScanExprMapping is %s,\n queryToViewSlotMapping = %s", + queryStructInfo.getExpressions(), materializationContext.getMvExprToMvScanExprMapping(), + queryToViewSlotMapping)); return null; } // record the group id in materializationContext, and when rewrite again in diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java index 1c41d4635c62882..2b12bbb98b733ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/AbstractMaterializedViewRule.java @@ -105,7 +105,8 @@ protected List rewrite(Plan queryPlan, CascadesContext cascadesContext) { if (viewStructInfos.size() > 1) { // view struct info should only have one materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), - "the num of view struct info is more then one"); + String.format("the num of view struct info is more then one, mv plan is %s", + materializationContext.getMvPlan().treeString())); return rewriteResults; } StructInfo viewStructInfo = viewStructInfos.get(0); @@ -175,9 +176,10 @@ protected List rewrite(Plan queryPlan, CascadesContext cascadesContext) { true); if (rewriteCompensatePredicates.isEmpty()) { materializationContext.recordFailReason(queryStructInfo.getOriginalPlanId(), String.format( - "rewrite compensate predicate fail, compensatePredicates = %s," - + "mvExprToMvScanExprMapping = %s", compensatePredicates, - materializationContext.getMvExprToMvScanExprMapping())); + "rewrite compensate predicate fail, compensatePredicates = %s,\n" + + "mvExprToMvScanExprMapping = %s\n, queryToViewSlotMapping = %s", + compensatePredicates, materializationContext.getMvExprToMvScanExprMapping(), + queryToViewSlotMapping)); continue; } rewrittenPlan = new LogicalFilter<>(Sets.newHashSet(rewriteCompensatePredicates), mvScan); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/HyperGraphComparator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/HyperGraphComparator.java index dd268c8acb6d01a..a0490eb29320070 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/HyperGraphComparator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/HyperGraphComparator.java @@ -130,7 +130,7 @@ private ComparisonResult buildComparisonRes() { */ public String getErrorMessage() { return String.format( - "graph logical not equals, query join edges is %s,\n" + "query filter edges is %s,\n" + "graph logical is not equal, query join edges is %s,\n" + "query filter edges is %s,\n" + "view join edges is %s,\n" + "view filter edges is %s\n" + "inferred edge with conds %s", getQueryJoinEdges(), getQueryFilterEdges(), diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/Mapping.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/Mapping.java index 3d9f95a5049dc00..18fa282267c2cc8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/Mapping.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/Mapping.java @@ -135,6 +135,11 @@ public boolean equals(Object o) { public int hashCode() { return Objects.hash(exprId); } + + @Override + public String toString() { + return "MappedSlot{" + "slot=" + slot + '}'; + } } /** Chain fold tow mapping, such as this mapping is {[a -> b]}, the target mapping is diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java index 3de99ea05a88d96..f95bcedd2fab5e2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/mv/mapping/SlotMapping.java @@ -95,4 +95,9 @@ public Map toSlotReferenceMap() { this.slotReferenceMap = slotReferenceSlotReferenceMap; return this.slotReferenceMap; } + + @Override + public String toString() { + return "SlotMapping{" + "relationSlotMap=" + relationSlotMap + '}'; + } }