morrySnow commented on code in PR #64559:
URL: https://github.com/apache/doris/pull/64559#discussion_r3510352646
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/executor/Optimizer.java:
##########
@@ -135,6 +136,9 @@ private void dpHypOptimize() {
// Due to EnsureProjectOnTopJoin, root group can't be Join Group, so
DPHyp doesn't change the root group
cascadesContext.pushJob(new JoinOrderJob(root,
cascadesContext.getCurrentJobContext()));
cascadesContext.getJobScheduler().executeJobPool(cascadesContext);
+ MemoStatsAndCostRecomputer.recompute(root, PhysicalProperties.ANY,
cascadesContext,
+ MemoStatsAndCostRecomputer.LogicalExpressionRowCountSyncPolicy
+ .KEEP_INDIVIDUAL_EXPRESSION_ROW_COUNT);
Review Comment:
add comment
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/FilterEstimation.java:
##########
@@ -145,7 +145,8 @@ public Statistics visitOr(Or or, EstimationContext context)
{
List<Expression> children = or.children();
Set<Slot> leftInputSlots =
Sets.newHashSet(children.get(0).getInputSlots());
Statistics leftStats = children.get(0).accept(this, context);
- leftStats.normalizeColumnStatistics(context.statistics.getRowCount(),
true);
+ leftStats.normalizeColumnStatistics(context.statistics.getRowCount(),
+ true);
Review Comment:
Don't make these unnecessary changes
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostModel.java:
##########
@@ -566,8 +566,9 @@ public Cost visitPhysicalNestedLoopJoin(
if (leftStatistics.getRowCount() < 10 * rightStatistics.getRowCount())
{
nljPenalty = Math.min(leftStatistics.getRowCount(),
rightStatistics.getRowCount());
}
+ nljPenalty = Math.max(nljPenalty, 1.0);
return Cost.of(context.getSessionVariable(),
- leftStatistics.getRowCount() * rightStatistics.getRowCount(),
+ leftStatistics.getRowCount() * rightStatistics.getRowCount() *
nljPenalty,
Review Comment:
add comment
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java:
##########
@@ -63,6 +74,30 @@ private static EqualPredicate
normalizeEqualPredJoinCondition(EqualPredicate equ
}
}
+ static boolean hasTrustableEqualCondition(Statistics leftStats, Statistics
rightStats, Join join) {
Review Comment:
add comment
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/MemoStatsAndCostRecomputer.java:
##########
@@ -0,0 +1,824 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.doris.nereids.stats;
+
+import org.apache.doris.common.Pair;
+import org.apache.doris.nereids.CascadesContext;
+import org.apache.doris.nereids.cost.Cost;
+import org.apache.doris.nereids.cost.CostCalculator;
+import org.apache.doris.nereids.memo.Group;
+import org.apache.doris.nereids.memo.GroupExpression;
+import org.apache.doris.nereids.properties.PhysicalProperties;
+import org.apache.doris.nereids.trees.expressions.CTEId;
+import org.apache.doris.nereids.trees.plans.Plan;
+import org.apache.doris.nereids.trees.plans.algebra.Join;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEConsumer;
+import org.apache.doris.nereids.trees.plans.logical.LogicalCTEProducer;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalCTEConsumer;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalCTEProducer;
+import org.apache.doris.nereids.trees.plans.physical.PhysicalProject;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.statistics.Statistics;
+
+import com.google.common.collect.Lists;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+
+/**
+ * Re-estimate memo logical row counts and rebuild physical costs.
+ * and rebuild physical cost state.
+ */
+public final class MemoStatsAndCostRecomputer {
Review Comment:
Add detailed annotations to explain the workflow
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]