From da6a7bdcab7d2c594eedf74590920861f1611bcd Mon Sep 17 00:00:00 2001 From: hailanwhu <2013301500074@whu.edu.cn> Date: Wed, 18 Sep 2019 18:06:15 +1000 Subject: [PATCH] planner: explain a physicalPlan with IndexMerge in "dot" format (#12248) --- cmd/explaintest/r/explain_indexmerge.result | 33 +++++++++++++++++++++ cmd/explaintest/t/explain_indexmerge.test | 1 + planner/core/common_plans.go | 9 ++++++ 3 files changed, 43 insertions(+) diff --git a/cmd/explaintest/r/explain_indexmerge.result b/cmd/explaintest/r/explain_indexmerge.result index 314da1ea59439..4498ee0ec9e00 100644 --- a/cmd/explaintest/r/explain_indexmerge.result +++ b/cmd/explaintest/r/explain_indexmerge.result @@ -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" +} + diff --git a/cmd/explaintest/t/explain_indexmerge.test b/cmd/explaintest/t/explain_indexmerge.test index 20a6afb3ef88c..507e7559a0979 100644 --- a/cmd/explaintest/t/explain_indexmerge.test +++ b/cmd/explaintest/t/explain_indexmerge.test @@ -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; diff --git a/planner/core/common_plans.go b/planner/core/common_plans.go index 1ae6965873688..9a628c7c484c4 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -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())