Skip to content

Commit

Permalink
planner/core, session: fix error message of wrong variable scope (#30510
Browse files Browse the repository at this point in the history
)
  • Loading branch information
morgo committed Dec 8, 2021
1 parent 2a1ea89 commit e520e46
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -1281,11 +1281,11 @@ func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) {
}
if v.ExplicitScope && !sysVar.HasNoneScope() {
if v.IsGlobal && !sysVar.HasGlobalScope() {
er.err = variable.ErrIncorrectScope.GenWithStackByArgs(name, "GLOBAL")
er.err = variable.ErrIncorrectScope.GenWithStackByArgs(name, "SESSION")
return
}
if !v.IsGlobal && !sysVar.HasSessionScope() {
er.err = variable.ErrIncorrectScope.GenWithStackByArgs(name, "SESSION")
er.err = variable.ErrIncorrectScope.GenWithStackByArgs(name, "GLOBAL")
return
}
}
Expand Down
10 changes: 8 additions & 2 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,16 +759,22 @@ func (s *testSessionSuite) TestGetSysVariables(c *C) {
tk.MustExec("select @@max_connections")
tk.MustExec("select @@global.max_connections")
_, err = tk.Exec("select @@session.max_connections")
c.Assert(terror.ErrorEqual(err, variable.ErrIncorrectScope), IsTrue, Commentf("err %v", err))
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'max_connections' is a GLOBAL variable")
_, err = tk.Exec("select @@local.max_connections")
c.Assert(terror.ErrorEqual(err, variable.ErrIncorrectScope), IsTrue, Commentf("err %v", err))
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'max_connections' is a GLOBAL variable")

// Test ScopeNone
tk.MustExec("select @@performance_schema_max_mutex_classes")
tk.MustExec("select @@global.performance_schema_max_mutex_classes")
// For issue 19524, test
tk.MustExec("select @@session.performance_schema_max_mutex_classes")
tk.MustExec("select @@local.performance_schema_max_mutex_classes")

_, err = tk.Exec("select @@global.last_insert_id")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[variable:1238]Variable 'last_insert_id' is a SESSION variable")
}

func (s *testSessionSuite) TestRetryResetStmtCtx(c *C) {
Expand Down

0 comments on commit e520e46

Please sign in to comment.