Skip to content

Commit

Permalink
opt
Browse files Browse the repository at this point in the history
  • Loading branch information
924060929 committed Nov 15, 2024
1 parent 5d99f2b commit d9b7698
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,14 @@ public synchronized void updateSummary(Map<String, String> summaryInfo, boolean
NereidsPlanner nereidsPlanner = ((NereidsPlanner) planner);
physicalPlan = nereidsPlanner.getPhysicalPlan();
physicalRelations.addAll(nereidsPlanner.getPhysicalRelations());
FragmentIdMapping<DistributedPlan> distributedPlans = nereidsPlanner.getDistributedPlans();
if (distributedPlans != null) {
summaryInfo.put(SummaryProfile.DISTRIBUTED_PLAN,
if (profileLevel >= 3) {
FragmentIdMapping<DistributedPlan> distributedPlans = nereidsPlanner.getDistributedPlans();
if (distributedPlans != null) {
summaryInfo.put(SummaryProfile.DISTRIBUTED_PLAN,
DistributedPlan.toString(Lists.newArrayList(distributedPlans.values()))
.replace("\n", "\n ")
);
.replace("\n", "\n ")
);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,52 +234,61 @@ public void execute() {
* @return false if error occurs, the caller will return.
*/
private boolean calculateEnforce(List<PhysicalProperties> requestChildrenProperties,
List<PhysicalProperties> outputChildrenProperties) {
List<PhysicalProperties> originOutputChildrenProperties) {

// to ensure distributionSpec has been added sufficiently.
// it's certain that lowestCostChildren is equals to arity().
ChildrenPropertiesRegulator regulator = new ChildrenPropertiesRegulator(groupExpression,
lowestCostChildren, outputChildrenProperties, requestChildrenProperties, context);
boolean success = regulator.adjustChildrenProperties();
if (!success) {
lowestCostChildren, new ArrayList<>(originOutputChildrenProperties),
requestChildrenProperties, context);
List<List<PhysicalProperties>> childrenOutputSpace = regulator.adjustChildrenProperties();
if (childrenOutputSpace.isEmpty()) {
// invalid enforce, return.
return false;
}

// Not need to do pruning here because it has been done when we get the
// best expr from the child group
ChildOutputPropertyDeriver childOutputPropertyDeriver
= new ChildOutputPropertyDeriver(outputChildrenProperties);
// the physical properties the group expression support for its parent.
PhysicalProperties outputProperty = childOutputPropertyDeriver.getOutputProperties(getConnectContext(),
groupExpression);

// update current group statistics and re-compute costs.
if (groupExpression.children().stream().anyMatch(group -> group.getStatistics() == null)
&& groupExpression.getOwnerGroup().getStatistics() == null) {
// if we come here, mean that we have some error in stats calculator and should fix it.
LOG.warn("Nereids try to calculate cost without stats for group expression {}", groupExpression);
return false;
}
boolean hasSuccess = false;
for (List<PhysicalProperties> outputChildrenProperties : childrenOutputSpace) {
// Not need to do pruning here because it has been done when we get the
// best expr from the child group
ChildOutputPropertyDeriver childOutputPropertyDeriver
= new ChildOutputPropertyDeriver(outputChildrenProperties);
// the physical properties the group expression support for its parent.
// some cases maybe output some possibilities, for example, shuffle join
// maybe select left shuffle to right, or right shuffle to left, so their
// are 2 output properties possibilities
PhysicalProperties outputProperty
= childOutputPropertyDeriver.getOutputProperties(getConnectContext(), groupExpression);

// update current group statistics and re-compute costs.
if (groupExpression.children().stream().anyMatch(group -> group.getStatistics() == null)
&& groupExpression.getOwnerGroup().getStatistics() == null) {
// if we come here, mean that we have some error in stats calculator and should fix it.
LOG.warn("Nereids try to calculate cost without stats for group expression {}", groupExpression);
}

// recompute cost after adjusting property
curNodeCost = CostCalculator.calculateCost(getConnectContext(), groupExpression, requestChildrenProperties);
groupExpression.setCost(curNodeCost);
curTotalCost = curNodeCost;
for (int i = 0; i < outputChildrenProperties.size(); i++) {
PhysicalProperties childProperties = outputChildrenProperties.get(i);
curTotalCost = CostCalculator.addChildCost(
getConnectContext(),
groupExpression.getPlan(),
curTotalCost,
groupExpression.child(i).getLowestCostPlan(childProperties).get().first,
i);
}
// recompute cost after adjusting property
curNodeCost = CostCalculator.calculateCost(getConnectContext(), groupExpression, requestChildrenProperties);
groupExpression.setCost(curNodeCost);
curTotalCost = curNodeCost;
for (int i = 0; i < outputChildrenProperties.size(); i++) {
PhysicalProperties childProperties = outputChildrenProperties.get(i);
curTotalCost = CostCalculator.addChildCost(
getConnectContext(),
groupExpression.getPlan(),
curTotalCost,
groupExpression.child(i).getLowestCostPlan(childProperties).get().first,
i);
}

// record map { outputProperty -> outputProperty }, { ANY -> outputProperty },
recordPropertyAndCost(groupExpression, outputProperty, PhysicalProperties.ANY, outputChildrenProperties);
recordPropertyAndCost(groupExpression, outputProperty, outputProperty, outputChildrenProperties);
enforce(outputProperty, outputChildrenProperties);
return true;
// record map { outputProperty -> outputProperty }, { ANY -> outputProperty },
recordPropertyAndCost(groupExpression, outputProperty, PhysicalProperties.ANY, outputChildrenProperties);
recordPropertyAndCost(groupExpression, outputProperty, outputProperty, outputChildrenProperties);
enforce(outputProperty, outputChildrenProperties);

hasSuccess = true;
}
return hasSuccess;
}

/**
Expand Down
Loading

0 comments on commit d9b7698

Please sign in to comment.