Skip to content

Commit

Permalink
*: show correct result for system variable tidb_capture_plan_baselines (
Browse files Browse the repository at this point in the history
  • Loading branch information
eurekaka authored Apr 3, 2020
1 parent f572c8e commit 0fcece7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
47 changes: 47 additions & 0 deletions bindinfo/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,53 @@ func (s *testSuite) TestDefaultSessionVars(c *C) {
"tidb_use_plan_baselines on"))
}

func (s *testSuite) TestCaptureBaselinesScope(c *C) {
tk1 := testkit.NewTestKit(c, s.store)
tk2 := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk1)
tk1.MustQuery(`show session variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines off",
))
tk1.MustQuery(`show global variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines off",
))
tk1.MustQuery(`select @@session.tidb_capture_plan_baselines`).Check(testkit.Rows(
"off",
))
tk1.MustQuery(`select @@global.tidb_capture_plan_baselines`).Check(testkit.Rows(
"off",
))

tk1.MustExec("set @@session.tidb_capture_plan_baselines = on")
defer func() {
tk1.MustExec(" set @@session.tidb_capture_plan_baselines = off")
}()
tk1.MustQuery(`show session variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines on",
))
tk1.MustQuery(`show global variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines off",
))
tk1.MustQuery(`select @@session.tidb_capture_plan_baselines`).Check(testkit.Rows(
"on",
))
tk1.MustQuery(`select @@global.tidb_capture_plan_baselines`).Check(testkit.Rows(
"off",
))
tk2.MustQuery(`show session variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines on",
))
tk2.MustQuery(`show global variables like "tidb_capture_plan_baselines"`).Check(testkit.Rows(
"tidb_capture_plan_baselines off",
))
tk2.MustQuery(`select @@session.tidb_capture_plan_baselines`).Check(testkit.Rows(
"on",
))
tk2.MustQuery(`select @@global.tidb_capture_plan_baselines`).Check(testkit.Rows(
"off",
))
}

func (s *testSuite) TestDuplicateBindings(c *C) {
tk := testkit.NewTestKit(c, s.store)
s.cleanBindingEnv(tk)
Expand Down
2 changes: 1 addition & 1 deletion executor/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (e *SetExecutor) setSysVariable(name string, v *expression.VarAssignment) e
case variable.TiDBStmtSummaryMaxSQLLength:
return stmtsummary.StmtSummaryByDigestMap.SetMaxSQLLength(valStr, !v.IsGlobal)
case variable.TiDBCapturePlanBaseline:
variable.CapturePlanBaseline.Set(valStr, !v.IsGlobal)
variable.CapturePlanBaseline.Set(strings.ToLower(valStr), !v.IsGlobal)
}

return nil
Expand Down
2 changes: 2 additions & 0 deletions sessionctx/variable/varsutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ func GetSessionOnlySysVars(s *SessionVars, key string) (string, bool, error) {
return strconv.FormatUint(atomic.LoadUint64(&config.GetGlobalConfig().Log.QueryLogMaxLen), 10), true, nil
case TiDBCheckMb4ValueInUTF8:
return BoolToIntStr(config.GetGlobalConfig().CheckMb4ValueInUTF8), true, nil
case TiDBCapturePlanBaseline:
return CapturePlanBaseline.GetVal(), true, nil
}
sVal, ok := s.GetSystemVar(key)
if ok {
Expand Down

0 comments on commit 0fcece7

Please sign in to comment.