Skip to content

Commit

Permalink
remember choosen plan in group
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Aug 9, 2023
1 parent 4608dcb commit 4e05753
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public class Group {

private Statistics statistics;

private PhysicalProperties chosenProperties;

private int chosenGroupExpressionId = -1;

/**
* Constructor for Group.
*
Expand Down Expand Up @@ -198,10 +202,17 @@ public double getCostLowerBound() {
* @return {@link Optional} of cost and {@link GroupExpression} of physical plan pair.
*/
public Optional<Pair<Cost, GroupExpression>> getLowestCostPlan(PhysicalProperties physicalProperties) {
chosenProperties = physicalProperties;
if (physicalProperties == null || lowestCostPlans.isEmpty()) {
chosenGroupExpressionId = -1;
return Optional.empty();
}
return Optional.ofNullable(lowestCostPlans.get(physicalProperties));
Optional<Pair<Cost, GroupExpression>> costAndGroupExpression =
Optional.ofNullable(lowestCostPlans.get(physicalProperties));
if (costAndGroupExpression.isPresent()) {
chosenGroupExpressionId = costAndGroupExpression.get().second.getId().asInt();
}
return costAndGroupExpression;
}

public GroupExpression getBestPlan(PhysicalProperties properties) {
Expand Down Expand Up @@ -430,6 +441,9 @@ public String toString() {
str.append(" enforcers:\n");
for (GroupExpression enforcer : enforcers) {
str.append(" ").append(enforcer).append("\n");
if (chosenGroupExpressionId != -1) {
str.append(" chosen expression id: ").append(chosenGroupExpressionId).append("\n");
str.append(" chosen properties: ").append(chosenProperties).append("\n");
}
return str.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,8 @@ public String toString() {
builder.append(" (plan=").append(plan.toString()).append(")");
return builder.toString();
}

public ObjectId getId() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
* Abstract class for all plan node.
*/
public interface Plan extends TreeNode<Plan> {

PlanType getType();

// cache GroupExpression for fast exit from Memo.copyIn.
Expand Down

0 comments on commit 4e05753

Please sign in to comment.