Skip to content

Commit

Permalink
Merge pull request pingcap#541 from pingcap/shenli/issue-540
Browse files Browse the repository at this point in the history
plans: Fix bug in show variables plan
  • Loading branch information
shenli committed Nov 9, 2015
2 parents 34100b6 + 3bafc50 commit b0c54b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plan/plans/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,16 @@ func (s *ShowPlan) fetchShowVariables(ctx context.Context) error {

var value string
if !s.GlobalScope {
// Try to get Session Scope variable value
// Try to get Session Scope variable value first.
sv, ok := sessionVars.Systems[v.Name]
if ok {
value = sv
} else {
// If session scope variable is not set, get the global scope value.
value, err = ctx.(variable.GlobalSysVarAccessor).GetGlobalSysVar(ctx, v.Name)
if err != nil {
return errors.Trace(err)
}
}
} else {
value, err = ctx.(variable.GlobalSysVarAccessor).GetGlobalSysVar(ctx, v.Name)
Expand Down
22 changes: 22 additions & 0 deletions plan/plans/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ func (p *testShowSuit) TestShowVariables(c *C) {
c.Assert(v, Equals, "on")
}

func (p *testShowSuit) TestIssue540(c *C) {
// Show variables where variable_name="time_zone"
pln := &plans.ShowPlan{
Target: stmt.ShowVariables,
GlobalScope: false,
Pattern: &expression.PatternLike{
Pattern: &expression.Value{
Val: "time_zone",
},
},
}
// Make sure the session scope var is not set.
sessionVars := variable.GetSessionVars(p.ctx)
_, ok := sessionVars.Systems["time_zone"]
c.Assert(ok, IsFalse)

r, err := pln.Next(p.ctx)
c.Assert(err, IsNil)
c.Assert(r.Data[0], Equals, "time_zone")
c.Assert(r.Data[1], Equals, "SYSTEM")
}

func (p *testShowSuit) TestShowCollation(c *C) {
pln := &plans.ShowPlan{}

Expand Down

0 comments on commit b0c54b0

Please sign in to comment.