Skip to content

Commit

Permalink
planner: explain a physicalPlan with IndexMerge in "dot" format (#12248)
Browse files Browse the repository at this point in the history
  • Loading branch information
hailanwhu authored and sre-bot committed Sep 18, 2019
1 parent 9064c49 commit da6a7bd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cmd/explaintest/r/explain_indexmerge.result
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,36 @@ IndexMerge_17 0.00 root
├─IndexScan_14 9.00 cop table:t, index:d, range:[-inf,10), keep order:false
└─Selection_16 0.00 cop lt(Column#6, 10), or(lt(Column#2, 10000), lt(Column#3, 10000))
└─TableScan_15 18.00 cop table:t, keep order:false
explain format="dot" select * from t where (a < 50 or b < 50) and f > 100;
dot contents

digraph IndexMerge_12 {
subgraph cluster12{
node [style=filled, color=lightgrey]
color=black
label = "root"
"IndexMerge_12"
}
subgraph cluster8{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"TableScan_8"
}
subgraph cluster9{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"IndexScan_9"
}
subgraph cluster11{
node [style=filled, color=lightgrey]
color=black
label = "cop"
"Selection_11" -> "TableScan_10"
}
"IndexMerge_12" -> "TableScan_8"
"IndexMerge_12" -> "IndexScan_9"
"IndexMerge_12" -> "Selection_11"
}

1 change: 1 addition & 0 deletions cmd/explaintest/t/explain_indexmerge.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ explain select * from t where b < 50 or c < 50;
explain select * from t where b < 50 or c < 5000000;
explain select * from t where a < 50 or b < 50 or c < 50;
explain select * from t where (b < 10000 or c < 10000) and (a < 10 or d < 10) and f < 10;
explain format="dot" select * from t where (a < 50 or b < 50) and f > 100;
9 changes: 9 additions & 0 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,15 @@ func (e *Explain) prepareTaskDot(p PhysicalPlan, taskTp string, buffer *bytes.Bu
pipelines = append(pipelines, fmt.Sprintf("\"%s\" -> \"%s\"\n", copPlan.ExplainID(), copPlan.indexPlan.ExplainID()))
copTasks = append(copTasks, copPlan.tablePlan)
copTasks = append(copTasks, copPlan.indexPlan)
case *PhysicalIndexMergeReader:
for i := 0; i < len(copPlan.partialPlans); i++ {
pipelines = append(pipelines, fmt.Sprintf("\"%s\" -> \"%s\"\n", copPlan.ExplainID(), copPlan.partialPlans[i].ExplainID()))
copTasks = append(copTasks, copPlan.partialPlans[i])
}
if copPlan.tablePlan != nil {
pipelines = append(pipelines, fmt.Sprintf("\"%s\" -> \"%s\"\n", copPlan.ExplainID(), copPlan.tablePlan.ExplainID()))
copTasks = append(copTasks, copPlan.tablePlan)
}
}
for _, child := range curPlan.Children() {
fmt.Fprintf(buffer, "\"%s\" -> \"%s\"\n", curPlan.ExplainID(), child.ExplainID())
Expand Down

0 comments on commit da6a7bd

Please sign in to comment.