Skip to content

Commit

Permalink
planner, executor: let 'show [variables|status]' be sorted by… (pingc…
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelice authored Feb 14, 2020
1 parent 8c804f4 commit e5bffd9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
15 changes: 15 additions & 0 deletions executor/seqtest/seq_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,21 @@ func (s *seqTestSuite) TestShow(c *C) {
"c8|datetime|YES||CURRENT_TIMESTAMP|DEFAULT_GENERATED on update CURRENT_TIMESTAMP",
"c9|year(4)|YES||2014|",
))

// Test if 'show [status|variables]' is sorted by Variable_name (#14542)
sqls := []string{
"show global status;",
"show session status;",
"show global variables",
"show session variables"}

for _, sql := range sqls {
res := tk.MustQuery(sql)
c.Assert(res, NotNil)
sorted := tk.MustQuery(sql).Sort()
c.Assert(sorted, NotNil)
c.Check(res, DeepEquals, sorted)
}
}

func (s *seqTestSuite) TestShowStatsHealthy(c *C) {
Expand Down
15 changes: 12 additions & 3 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1650,9 +1650,18 @@ func (b *PlanBuilder) buildShow(ctx context.Context, show *ast.ShowStmt) (Plan,
proj.SetSchema(schema)
proj.SetChildren(np)
proj.SetOutputNames(np.OutputNames())
return proj, nil
}
return p, nil
np = proj
}
if show.Tp == ast.ShowVariables || show.Tp == ast.ShowStatus {
b.curClause = orderByClause
orderByCol := np.Schema().Columns[0].Clone().(*expression.Column)
sort := LogicalSort{
ByItems: []*ByItems{{Expr: orderByCol}},
}.Init(b.ctx, b.getSelectOffset())
sort.SetChildren(np)
np = sort
}
return np, nil
}

func (b *PlanBuilder) buildSimple(node ast.StmtNode) (Plan, error) {
Expand Down

0 comments on commit e5bffd9

Please sign in to comment.