diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java index f37f112c0c14704..0a6c1e298ff9b06 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/NereidsPlanner.java @@ -269,7 +269,7 @@ private Plan planWithoutLock( .collectToList(LogicalOlapScan.class::isInstance); Optional disableJoinReorderReason = StatsCalculator .disableJoinReorderIfStatsInvalid(scans, cascadesContext); - statementContext.setDisableJoinReorderReason(disableJoinReorderReason); + disableJoinReorderReason.ifPresent(statementContext::setDisableJoinReorderReason); } optimize(); @@ -578,13 +578,6 @@ public String getHintExplainString(List hints) { public String getExplainString(ExplainOptions explainOptions) { ExplainLevel explainLevel = getExplainLevel(explainOptions); String plan = ""; - String mvSummary = ""; - if (this.getPhysicalPlan() != null && cascadesContext != null) { - mvSummary = cascadesContext.getMaterializationContexts().isEmpty() ? "" : - "\n\n========== MATERIALIZATIONS ==========\n" - + MaterializationContext.toSummaryString(cascadesContext.getMaterializationContexts(), - this.getPhysicalPlan()); - } switch (explainLevel) { case PARSED_PLAN: plan = parsedPlan.treeString(); @@ -637,23 +630,23 @@ public String getExplainString(ExplainOptions explainOptions) { + getTimeMetricString(SummaryProfile::getPrettyNereidsDistributeTime) + " ==========\n"; plan += DistributedPlan.toString(Lists.newArrayList(distributedPlans.values())) + "\n\n"; } - plan += mvSummary; break; default: plan = super.getExplainString(explainOptions); - plan += mvSummary; - plan += "\n\n\n========== STATISTICS ==========\n"; - if (statementContext != null) { - if (statementContext.isHasUnknownColStats()) { - plan += "planed with unknown column statistics\n"; - } - } } - + if (this.getPhysicalPlan() != null && cascadesContext != null) { + plan += cascadesContext.getMaterializationContexts().isEmpty() ? "" : + "\n\n========== MATERIALIZATIONS ==========\n" + + MaterializationContext.toSummaryString(cascadesContext.getMaterializationContexts(), + this.getPhysicalPlan()); + } if (statementContext != null) { + if (statementContext.isHasUnknownColStats()) { + plan += "planed with unknown column statistics\n"; + } if (statementContext.getDisableJoinReorderReason().isPresent()) { - plan += "\n\n\n========== DISABLE JOIN REORDER ==========\n"; - plan += statementContext.getDisableJoinReorderReason().get(); + plan += "\ndisable join reorder reason\n"; + plan += statementContext.getDisableJoinReorderReason().get() + "\n"; } if (!statementContext.getHints().isEmpty()) { String hint = getHintExplainString(statementContext.getHints()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java index 64088a9a2de20f1..ed64864da5079fb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/StatementContext.java @@ -169,7 +169,7 @@ public class StatementContext implements Closeable { private List plannerHooks = new ArrayList<>(); - private Optional disableJoinReorderReason; + private String disableJoinReorderReason; public StatementContext() { this(ConnectContext.get(), null, 0); @@ -562,10 +562,10 @@ public TableId getTableId(TableIf tableIf) { } public Optional getDisableJoinReorderReason() { - return disableJoinReorderReason; + return Optional.ofNullable(disableJoinReorderReason); } - public void setDisableJoinReorderReason(Optional disableJoinReorderReason) { + public void setDisableJoinReorderReason(String disableJoinReorderReason) { this.disableJoinReorderReason = disableJoinReorderReason; } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java index cb0545926b10e86..e3f385f2871f6b7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java @@ -221,17 +221,18 @@ public static Optional disableJoinReorderIfStatsInvalid(List reason = calculator.checkNdvValidation(scan, rowCount); if (reason.isPresent()) { try {