diff --git a/executor/show_test.go b/executor/show_test.go index 72b7f80bac114..7bebc1843db76 100644 --- a/executor/show_test.go +++ b/executor/show_test.go @@ -1233,27 +1233,37 @@ func (s *testSerialSuite1) TestShowCreateTableWithIntegerDisplayLengthWarnings(c func (s *testSuite5) TestShowVar(c *C) { tk := testkit.NewTestKit(c, s.store) var showSQL string + sessionVars := make([]string, 0, len(variable.GetSysVars())) + globalVars := make([]string, 0, len(variable.GetSysVars())) for _, v := range variable.GetSysVars() { if variable.FilterImplicitFeatureSwitch(v) { continue } - // When ScopeSession only. `show global variables` must return empty. + if v.Scope == variable.ScopeSession { - showSQL = "show variables like '" + v.Name + "'" - res := tk.MustQuery(showSQL) - c.Check(res.Rows(), HasLen, 1) - showSQL = "show global variables like '" + v.Name + "'" - res = tk.MustQuery(showSQL) - c.Check(res.Rows(), HasLen, 0) + sessionVars = append(sessionVars, v.Name) } else { - showSQL = "show global variables like '" + v.Name + "'" - res := tk.MustQuery(showSQL) - c.Check(res.Rows(), HasLen, 1) - showSQL = "show variables like '" + v.Name + "'" - res = tk.MustQuery(showSQL) - c.Check(res.Rows(), HasLen, 1) + globalVars = append(globalVars, v.Name) } } + + // When ScopeSession only. `show global variables` must return empty. + sessionVarsStr := strings.Join(sessionVars, "','") + showSQL = "show variables where variable_name in('" + sessionVarsStr + "')" + res := tk.MustQuery(showSQL) + c.Check(res.Rows(), HasLen, len(sessionVars)) + showSQL = "show global variables where variable_name in('" + sessionVarsStr + "')" + res = tk.MustQuery(showSQL) + c.Check(res.Rows(), HasLen, 0) + + globalVarsStr := strings.Join(globalVars, "','") + showSQL = "show variables where variable_name in('" + globalVarsStr + "')" + res = tk.MustQuery(showSQL) + c.Check(res.Rows(), HasLen, len(globalVars)) + showSQL = "show global variables where variable_name in('" + globalVarsStr + "')" + res = tk.MustQuery(showSQL) + c.Check(res.Rows(), HasLen, len(globalVars)) + // Test for switch variable which shouldn't seen by users. for _, one := range variable.FeatureSwitchVariables { res := tk.MustQuery("show variables like '" + one + "'")