Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sessionctx/variable: fix select variable return wrong result when variable is only global scope variable #8968

Merged
merged 6 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
sessionctx/variable: fix select variable return wrong result when var…
…iable is only global scope variable
  • Loading branch information
crazycs520 committed Jan 7, 2019
commit eb654e5fbb024c0d3ee2a5dfc5d1fafa3f9b8e33
14 changes: 14 additions & 0 deletions executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,17 @@ func (s *testSuite2) TestValidateSetVar(c *C) {
_, err = tk.Exec("set @@tx_isolation='SERIALIZABLE'")
c.Assert(terror.ErrorEqual(err, variable.ErrUnsupportedValueForVar), IsTrue, Commentf("err %v", err))
}

func (s *testSuite2) TestSelectGlobalVar(c *C) {
tk := testkit.NewTestKit(c, s.store)

tk.MustQuery("select @@global.max_connections;").Check(testkit.Rows("151"))
tk.MustQuery("select @@max_connections;").Check(testkit.Rows("151"))

tk.MustExec("set @@global.max_connections=100;")

tk.MustQuery("select @@global.max_connections;").Check(testkit.Rows("100"))
tk.MustQuery("select @@max_connections;").Check(testkit.Rows("100"))

tk.MustExec("set @@global.max_connections=151;")
}
8 changes: 7 additions & 1 deletion planner/core/expression_rewriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,13 @@ func (er *expressionRewriter) rewriteVariable(v *ast.VariableExpr) {
return
}
}
if v.IsGlobal {
sysVar := variable.SysVars[name]
if sysVar == nil {
er.err = errors.Trace(variable.UnknownSystemVar.GenWithStackByArgs(name))
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
crazycs520 marked this conversation as resolved.
Show resolved Hide resolved
return
}
// Variable is @@gobal.variable_name or variable is only global scope variable.
if v.IsGlobal || sysVar.Scope == variable.ScopeGlobal {
val, err = variable.GetGlobalSystemVar(sessionVars, name)
} else {
val, err = variable.GetSessionSystemVar(sessionVars, name)
Expand Down