diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index 96ceb1768ae1b..4a9bb14eabe98 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -185,3 +185,21 @@ func (s *testPrepareSerialSuite) TestExplainForConnPlanCache(c *C) { " └─TableFullScan_5 10000.00 cop[tikv] table:t keep order:false, stats:pseudo", )) } + +func (s *testPrepareSerialSuite) TestExplainDotForExplainPlan(c *C) { + tk := testkit.NewTestKit(c, s.store) + + rows := tk.MustQuery("select connection_id()").Rows() + c.Assert(len(rows), Equals, 1) + connID := rows[0][0].(string) + tk.MustQuery("explain select 1").Check(testkit.Rows( + "Projection_3 1.00 root 1->Column#1", + "└─TableDual_4 1.00 root rows:1", + )) + + tkProcess := tk.Se.ShowProcess() + ps := []*util.ProcessInfo{tkProcess} + tk.Se.SetSessionManager(&mockSessionManager1{PS: ps}) + + tk.MustQuery(fmt.Sprintf("explain format=\"dot\" for connection %s", connID)).Check(nil) +} diff --git a/planner/core/common_plans.go b/planner/core/common_plans.go index dfc896e9b18e3..cf45c46da260a 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -831,7 +831,9 @@ func (e *Explain) RenderResult() error { return err } case ast.ExplainFormatDOT: - e.prepareDotInfo(e.TargetPlan.(PhysicalPlan)) + if physicalPlan, ok := e.TargetPlan.(PhysicalPlan); ok { + e.prepareDotInfo(physicalPlan) + } case ast.ExplainFormatHint: hints := GenHintsFromPhysicalPlan(e.TargetPlan) hints = append(hints, hint.ExtractTableHintsFromStmtNode(e.ExecStmt)...)