From 458b1eb6383ba052cae4c81d8328655be2899a68 Mon Sep 17 00:00:00 2001 From: Morgan Tocker Date: Tue, 7 Dec 2021 17:48:13 -0700 Subject: [PATCH] planner/core, session: fix error message of wrong variable scope --- planner/core/expression_rewriter.go | 4 ++-- session/session_test.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/planner/core/expression_rewriter.go b/planner/core/expression_rewriter.go index ab57b29c2096d..a370fdaa36697 100644 --- a/planner/core/expression_rewriter.go +++ b/planner/core/expression_rewriter.go @@ -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 } } diff --git a/session/session_test.go b/session/session_test.go index d0abd9d9f160a..130aa895c01f2 100644 --- a/session/session_test.go +++ b/session/session_test.go @@ -759,9 +759,11 @@ 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") @@ -769,6 +771,10 @@ func (s *testSessionSuite) TestGetSysVariables(c *C) { // 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) {