Skip to content

Commit

Permalink
*: remove session variable statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Nov 19, 2015
1 parent 06f285c commit 65dc9e9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 52 deletions.
23 changes: 1 addition & 22 deletions plan/plans/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,7 @@ func (s *ShowPlan) fetchShowVariables(ctx context.Context) error {
return nil
}

func getSessionStatusVar(ctx context.Context, sessionVars *variable.SessionVars,
name string, globalVal *variable.StatusVal) (string, error) {
sv, ok := sessionVars.StatusVars[name]
if ok {
return sv, nil
}

gv, err := types.ToString(globalVal.Value)
if err != nil {
return "", errors.Trace(err)
}

return gv, nil
}

func (s *ShowPlan) fetchShowStatus(ctx context.Context) error {
sessionVars := variable.GetSessionVars(ctx)
m := map[interface{}]interface{}{}

statusVars, err := variable.GetStatusVars()
Expand Down Expand Up @@ -514,12 +498,7 @@ func (s *ShowPlan) fetchShowStatus(ctx context.Context) error {
}

var value string
if !s.GlobalScope {
value, err = getSessionStatusVar(ctx, sessionVars, status, v)
if err != nil {
return errors.Trace(err)
}
} else if v.Scope != variable.ScopeSession {
if !s.GlobalScope || (s.GlobalScope && v.Scope != variable.ScopeSession) {
value, err = types.ToString(v.Value)
if err != nil {
return errors.Trace(err)
Expand Down
30 changes: 3 additions & 27 deletions plan/plans/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ func (p *testShowSuit) TestShowStatusVariables(c *C) {
c.Assert(fls[0].Col.Tp, Equals, mysql.TypeVarchar)
c.Assert(fls[1].Col.Tp, Equals, mysql.TypeVarchar)

sessionVars := variable.GetSessionVars(p.ctx)
ret := map[string]string{}
rset := rsets.Recordset{
Ctx: p.ctx,
Expand All @@ -244,59 +243,36 @@ func (p *testShowSuit) TestShowStatusVariables(c *C) {
c.Assert(v, DeepEquals, testStatusValBothScope)
pln.Close()

sessionVars.StatusVars[testStatusBothScopes] = "changed_val"
pln.GlobalScope = false
rset.Do(func(data []interface{}) (bool, error) {
ret[data[0].(string)] = data[1].(string)
return true, nil
})
c.Assert(ret, HasLen, 1)
v, ok = ret[testStatusBothScopes]
c.Assert(ok, IsTrue)
c.Assert(v, DeepEquals, "changed_val")
pln.Close()

pln.GlobalScope = true
pln.Pattern = &expression.PatternLike{
Pattern: &expression.Value{
Val: testStatusSessionScope,
},
}
sessionVars.StatusVars[testStatusSessionScope] = "on"
pln.GlobalScope = true
ret = map[string]string{}
rset.Do(func(data []interface{}) (bool, error) {
ret[data[0].(string)] = data[1].(string)
return true, nil
})
c.Assert(ret, HasLen, 0)

pln.GlobalScope = false
rset.Do(func(data []interface{}) (bool, error) {
ret[data[0].(string)] = data[1].(string)
return true, nil
})
c.Assert(ret, HasLen, 1)
v, ok = ret[testStatusSessionScope]
c.Assert(ok, IsTrue)
c.Assert(v, Equals, "on")
pln.Close()

pln.Pattern = nil
pln.GlobalScope = false
pln.Where = &expression.BinaryOperation{
L: &expression.Ident{CIStr: model.NewCIStr("Variable_name")},
R: expression.Value{Val: testStatusBothScopes},
Op: opcode.EQ,
}
ret = map[string]string{}
sessionVars.StatusVars[testStatusBothScopes] = "0"
rset.Do(func(data []interface{}) (bool, error) {
ret[data[0].(string)] = data[1].(string)
return true, nil
})
c.Assert(ret, HasLen, 1)
v, ok = ret[testStatusBothScopes]
c.Assert(ok, IsTrue)
c.Assert(v, Equals, "0")
c.Assert(v, Equals, testStatusValBothScope)
}

func (p *testShowSuit) TestIssue540(c *C) {
Expand Down
3 changes: 0 additions & 3 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ type SessionVars struct {
Users map[string]string
// system variables
Systems map[string]string
// status variables
StatusVars map[string]string
// prepared statement
PreparedStmts map[string]interface{}
// prepared statement auto increment id
Expand Down Expand Up @@ -60,7 +58,6 @@ func BindSessionVars(ctx context.Context) {
v := &SessionVars{
Users: make(map[string]string),
Systems: make(map[string]string),
StatusVars: make(map[string]string),
PreparedStmts: make(map[string]interface{}),
}

Expand Down

0 comments on commit 65dc9e9

Please sign in to comment.