Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class RuleMatchVisualizer implements RelOptListener {
private @Nullable RelOptPlanner planner = null;

private boolean includeTransitiveEdges = false;
private boolean includeIntermediateCosts = false;
private boolean includeIntermediateCosts = true;

private final List<StepInfo> steps = new ArrayList<>();
private final Map<String, NodeUpdateHelper> allNodes = new LinkedHashMap<>();
Expand Down Expand Up @@ -133,6 +133,24 @@ public void attachTo(RelOptPlanner planner) {
this.planner = planner;
}

/**
* Register the root node of the planner and adds an INITIAL step.
* This method is automatically invoked when the first rule is attempted.
*/
public void ensureInitialized() {
if (!initialized) {
requireNonNull(planner, "planner");
RelNode root = requireNonNull(planner.getRoot(), "root");
initialized = true;
updateInitialPlan(root);
}
// add the initialState
if (!this.allNodes.isEmpty() && this.steps.isEmpty()) {
this.addStep(INITIAL, null);
this.latestRuleID = INITIAL;
}
}

/**
* Output edges from a subset to the nodes of all subsets that satisfy it.
*/
Expand All @@ -142,19 +160,15 @@ public void setIncludeTransitiveEdges(final boolean includeTransitiveEdges) {

/**
* Output intermediate costs, including all cost updates.
* The default value is true.
*/
public void setIncludeIntermediateCosts(final boolean includeIntermediateCosts) {
this.includeIntermediateCosts = includeIntermediateCosts;
}

@Override public void ruleAttempted(RuleAttemptedEvent event) {
// HepPlanner compatibility
if (!initialized) {
requireNonNull(planner, "planner");
RelNode root = requireNonNull(planner.getRoot());
initialized = true;
updateInitialPlan(root);
}
ensureInitialized();
}

/**
Expand Down Expand Up @@ -217,11 +231,7 @@ private void updateFinalPlan(RelNode node) {
@Override public void ruleProductionSucceeded(RuleProductionEvent event) {
// method is called once before ruleMatch, and once after ruleMatch
if (event.isBefore()) {
// add the initialState
if (latestRuleID.isEmpty()) {
this.addStep(INITIAL, null);
this.latestRuleID = INITIAL;
}
ensureInitialized();
return;
}

Expand Down Expand Up @@ -300,6 +310,11 @@ private void updateNodeInfo(final RelNode rel, final boolean isLastStep) {
RelOptCost cost = planner.getCost(rel, mq);
Double rowCount = mq.getRowCount(rel);
helper.updateAttribute("cost", formatCost(rowCount, cost));
if (rel instanceof RelSubset) {
final RelNode best = ((RelSubset) rel).getBest();
final String bestId = best != null ? Integer.toString(best.getId()) : "";
helper.updateAttribute("best", bestId);
}
}

List<String> inputs = new ArrayList<>();
Expand Down Expand Up @@ -464,7 +479,7 @@ private static String formatCost(Double rowCount, @Nullable RelOptCost cost) {
|| originalStr.contains("tiny")) {
return originalStr;
}
return new MessageFormat("\nrowCount: {0}\nrows: {1}\ncpu: {2}\nio: {3}",
return new MessageFormat("rowCount: {0}\nrows: {1}\ncpu: {2}\nio: {3}",
Locale.ROOT).format(new String[]{
formatCostScientific(rowCount),
formatCostScientific(cost.getRows()),
Expand Down
Loading
Loading