Skip to content

Commit

Permalink
planner: check plan type when executing explain format="dot". (#17144
Browse files Browse the repository at this point in the history
…) (#17157)

Co-authored-by: Zhi Qi <30543181+LittleFall@users.noreply.github.com>
Co-authored-by: Yiding Cui <winoros@gmail.com>
  • Loading branch information
3 people authored Jul 27, 2020
1 parent 1096a77 commit 8603b8a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
18 changes: 18 additions & 0 deletions executor/explainfor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions planner/core/common_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 8603b8a

Please sign in to comment.