From 8603b8a3610a313a406e789ac5953b5bbd1067de Mon Sep 17 00:00:00 2001 From: pingcap-github-bot Date: Mon, 27 Jul 2020 17:45:22 +0800 Subject: [PATCH] planner: check plan type when executing `explain format="dot"`. (#17144) (#17157) Co-authored-by: Zhi Qi <30543181+LittleFall@users.noreply.github.com> Co-authored-by: Yiding Cui --- executor/explainfor_test.go | 18 ++++++++++++++++++ planner/core/common_plans.go | 3 +++ 2 files changed, 21 insertions(+) diff --git a/executor/explainfor_test.go b/executor/explainfor_test.go index 7bc150a2b2bd9..3c5910339ff04 100644 --- a/executor/explainfor_test.go +++ b/executor/explainfor_test.go @@ -103,3 +103,21 @@ func (s *testSuite) TestIssue11124(c *C) { c.Assert(rs[i], DeepEquals, rs2[i]) } } + +func (s *testSuite) 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", + "└─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 1189eda16fba5..434c52bbc2a0c 100644 --- a/planner/core/common_plans.go +++ b/planner/core/common_plans.go @@ -578,6 +578,9 @@ func (e *Explain) RenderResult() error { e.explainedPlans = map[int]bool{} e.explainPlanInRowFormat(e.TargetPlan, "root", "", true) case ast.ExplainFormatDOT: + if _, ok := e.TargetPlan.(PhysicalPlan); !ok { + return nil + } e.prepareDotInfo(e.TargetPlan.(PhysicalPlan)) default: return errors.Errorf("explain format '%s' is not supported now", e.Format)