[Performance](Nereids) refactor code speedup analyze (#21458)

refactor those code which cost much time.
This commit is contained in:
jakevin
2023-07-04 10:59:07 +08:00
committed by GitHub
parent 599ba4529c
commit d5f39a6e54
5 changed files with 12 additions and 9 deletions

View File

@ -317,7 +317,7 @@ public class CostAndEnforcerJob extends Job implements Cloneable {
groupExpression.putOutputPropertiesMap(outputProperty, requestProperty);
}
this.groupExpression.getOwnerGroup().setBestPlan(groupExpression, curTotalCost, requestProperty);
NereidsTracer.logPropertyAndCostEvent(groupExpression.getOwnerGroup().getGroupId().toString(),
NereidsTracer.logPropertyAndCostEvent(groupExpression.getOwnerGroup().getGroupId(),
groupExpression.children(), groupExpression.getPlan(), requestProperty, curTotalCost);
}

View File

@ -21,6 +21,7 @@ import org.apache.doris.common.util.DebugUtil;
import org.apache.doris.common.util.TimeUtils;
import org.apache.doris.nereids.cost.Cost;
import org.apache.doris.nereids.memo.Group;
import org.apache.doris.nereids.memo.GroupId;
import org.apache.doris.nereids.pattern.Pattern;
import org.apache.doris.nereids.properties.PhysicalProperties;
import org.apache.doris.nereids.trees.plans.AbstractPlan;
@ -99,7 +100,7 @@ public class NereidsTracer {
/** log property and cost pair when doing cost and enforcer task */
public static void logPropertyAndCostEvent(
String groupId, List<Group> children, Plan plan, PhysicalProperties requestProperty, Cost cost) {
GroupId groupId, List<Group> children, Plan plan, PhysicalProperties requestProperty, Cost cost) {
if (!shouldLog) {
return;
}
@ -120,13 +121,13 @@ public class NereidsTracer {
/** log enforcer event when we need to add enforcer */
public static void logEnforcerEvent(
String groupId, Plan plan, PhysicalProperties inputProperty, PhysicalProperties outputProperty) {
GroupId groupId, Plan plan, PhysicalProperties inputProperty, PhysicalProperties outputProperty) {
if (!shouldLog) {
return;
}
JSONObject enforcerEventJson = new JSONObject();
JSONObject enforcerMsg = new JSONObject();
enforcerMsg.put("GroupId", groupId);
enforcerMsg.put("GroupId", groupId.toString());
enforcerMsg.put("Plan", ((AbstractPlan) plan).toJson());
enforcerMsg.put("InputProperty", inputProperty.toString());
enforcerMsg.put("OutputProperty", outputProperty.toString());

View File

@ -90,7 +90,7 @@ public class ChildrenPropertiesRegulator extends PlanVisitor<Boolean, Void> {
@Override
public Boolean visitPhysicalHashJoin(PhysicalHashJoin<? extends Plan, ? extends Plan> hashJoin,
Void context) {
Preconditions.checkArgument(children.size() == 2, String.format("children.size() is %d", children.size()));
Preconditions.checkArgument(children.size() == 2, "children.size() != 2");
Preconditions.checkArgument(childrenProperties.size() == 2);
Preconditions.checkArgument(requiredProperties.size() == 2);
DistributionSpec leftDistributionSpec = childrenProperties.get(0).getDistributionSpec();

View File

@ -150,7 +150,7 @@ public class EnforceMissingPropertiesHelper {
PhysicalProperties oldOutputProperty,
PhysicalProperties newOutputProperty) {
context.getCascadesContext().getMemo().addEnforcerPlan(enforcer, groupExpression.getOwnerGroup());
NereidsTracer.logEnforcerEvent(enforcer.getOwnerGroup().getGroupId().toString(), groupExpression.getPlan(),
NereidsTracer.logEnforcerEvent(enforcer.getOwnerGroup().getGroupId(), groupExpression.getPlan(),
oldOutputProperty, newOutputProperty);
ENFORCER_TRACER.log(EnforcerEvent.of(groupExpression, ((PhysicalPlan) enforcer.getPlan()),
oldOutputProperty, newOutputProperty));

View File

@ -151,9 +151,11 @@ public class Statistics {
private double computeTupleSize() {
if (tupleSize <= 0) {
tupleSize = expressionToColumnStats.values().stream()
.map(s -> s.avgSizeByte).reduce(0D, Double::sum);
tupleSize = Math.max(1, tupleSize);
double tempSize = 0.0;
for (ColumnStatistic s : expressionToColumnStats.values()) {
tempSize += s.avgSizeByte;
}
tupleSize = Math.max(1, tempSize);
}
return tupleSize;
}