morrySnow commented on code in PR #12008:
URL: https://github.com/apache/doris/pull/12008#discussion_r957547395
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/cost/CostCalculator.java:
##########
@@ -72,13 +72,12 @@ public CostEstimate visitPhysicalOlapScan(PhysicalOlapScan
physicalOlapScan, Pla
}
@Override
- public CostEstimate visitPhysicalProject(PhysicalProject
physicalProject, PlanContext context) {
- StatsDeriveResult statistics = context.getStatisticsWithCheck();
- return CostEstimate.ofCpu(statistics.computeSize());
+ public CostEstimate visitPhysicalProject(PhysicalProject<Plan>
physicalProject, PlanContext context) {
+ return CostEstimate.zero();
Review Comment:
i rethink here, the better way is return a light cost than zero, to let us
choose the plan include less project when we intro merge project rule into
optimize stage
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java:
##########
@@ -177,34 +184,37 @@ public void execute() {
}
StatsCalculator.estimate(groupExpression);
+ curTreeCost -= curNodeCost;
+ curNodeCost = CostCalculator.calculateCost(groupExpression);
+ curTreeCost += curNodeCost;
// record map { outputProperty -> outputProperty }, { ANY ->
outputProperty },
recordPropertyAndCost(groupExpression, outputProperty,
outputProperty, requestChildrenProperty);
recordPropertyAndCost(groupExpression, outputProperty,
PhysicalProperties.ANY, requestChildrenProperty);
enforce(outputProperty, requestChildrenProperty);
- if (curTotalCost < context.getCostUpperBound()) {
- context.setCostUpperBound(curTotalCost);
+ if (curTreeCost < context.getCostUpperBound()) {
+ context.setCostUpperBound(curTreeCost);
}
}
- // Reset child idx and total cost
childrenOutputProperty.clear();
prevChildIndex = -1;
curChildIndex = 0;
- curTotalCost = 0;
+ curTreeCost = 0;
+ curNodeCost = 0;
Review Comment:
wrap them as a method
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/jobs/cascades/CostAndEnforcerJob.java:
##########
@@ -99,22 +102,26 @@ public CostAndEnforcerJob(GroupExpression groupExpression,
JobContext context) {
public void execute() {
// Do init logic of root plan/groupExpr of `subplan`, only run once
per task.
if (curChildIndex == -1) {
- curTotalCost = 0;
-
- // Get property from groupExpression plan (it's root of subplan).
+ curNodeCost = 0;
+ curTreeCost = 0;
Review Comment:
curTotalCost is ok
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/rules/exploration/join/JoinCommuteHelper.java:
##########
@@ -0,0 +1,54 @@
+// 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.rules.exploration.join;
+
+import org.apache.doris.nereids.trees.plans.logical.LogicalJoin;
+import org.apache.doris.nereids.trees.plans.logical.LogicalProject;
+
+import com.google.common.base.Preconditions;
+
+/**
+ * Common function for JoinCommute
+ */
+public class JoinCommuteHelper {
+
+ enum SwapType {
+ BOTTOM_JOIN, ZIG_ZAG, ALL
+ }
+
+ private final boolean swapOuter;
+ private final SwapType swapType;
+
+ public JoinCommuteHelper(boolean swapOuter, SwapType swapType) {
+ this.swapOuter = swapOuter;
+ this.swapType = swapType;
+ }
+
+ public static boolean check(LogicalJoin join) {
+ if (join.getJoinReorderContext().hasCommute() ||
join.getJoinReorderContext().hasExchange()) {
+ return false;
+ }
+ return true;
+ }
+
+ public static boolean check(LogicalProject project) {
+ Preconditions.checkState(project.child() instanceof LogicalJoin);
+ LogicalJoin join = (LogicalJoin) project.child();
+ return check(join);
Review Comment:
```suggestion
public static boolean check(LogicalProject<LogicalJoin> project) {
return check(project.child());
```
##########
fe/fe-core/src/main/java/org/apache/doris/nereids/stats/JoinEstimation.java:
##########
@@ -45,11 +48,16 @@ public static StatsDeriveResult estimate(StatsDeriveResult
leftStats, StatsDeriv
StatsDeriveResult statsDeriveResult = new StatsDeriveResult(leftStats);
statsDeriveResult.merge(rightStats);
List<Expression> eqConjunctList = join.getHashJoinConjuncts();
+ List<Slot> leftSlot =
leftStats.getSlotToColumnStats().entrySet().stream()
+ .map(slot -> slot.getKey()).collect(Collectors.toList());
+ List<Expression> execConjunctList =
eqConjunctList.stream().map(EqualTo.class::cast)
Review Comment:
eqConjunctList -> hashJoinConjuncts
execConjunctList -> normalizedConjuncts
--
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]