diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index 853eff71d64ac..207ec0018186d 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -158,3 +158,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 d955e8853471d..239db2bacf9df 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -827,7 +827,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)...)