From 084f2c9a159230eec196492b49afe0a4ef663097 Mon Sep 17 00:00:00 2001 From: xiaojian cai Date: Tue, 5 Dec 2017 11:12:35 +0800 Subject: [PATCH 1/5] show: fix variable scope error (#5291) --- new_session_test.go | 10 ++++++++++ plan/planbuilder.go | 15 ++++++++------- session.go | 4 +--- sessionctx/varsutil/varsutil.go | 4 +--- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/new_session_test.go b/new_session_test.go index 1d1a19a3666d8..14cd983da503b 100644 --- a/new_session_test.go +++ b/new_session_test.go @@ -286,6 +286,16 @@ func (s *testSessionSuite) TestGlobalVarAccessor(c *C) { v, err = se.GetGlobalSysVar(varName) c.Assert(err, IsNil) c.Assert(v, Equals, varValue2) + + result := tk.MustQuery("show global variables where variable_name='sql_select_limit';") + result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) + result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") + result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) + tk.MustExec("set session sql_select_limit=100000000000;") + result = tk.MustQuery("show global variables where variable_name='sql_select_limit';") + result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) + result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") + result.Check(testkit.Rows("sql_select_limit 100000000000")) } func (s *testSessionSuite) TestRetryResetStmtCtx(c *C) { diff --git a/plan/planbuilder.go b/plan/planbuilder.go index 8afe9066e7f9b..e27e3305e755a 100644 --- a/plan/planbuilder.go +++ b/plan/planbuilder.go @@ -534,13 +534,14 @@ func splitWhere(where ast.ExprNode) []ast.ExprNode { func (b *planBuilder) buildShow(show *ast.ShowStmt) Plan { var resultPlan Plan p := Show{ - Tp: show.Tp, - DBName: show.DBName, - Table: show.Table, - Column: show.Column, - Flag: show.Flag, - Full: show.Full, - User: show.User, + Tp: show.Tp, + DBName: show.DBName, + Table: show.Table, + Column: show.Column, + Flag: show.Flag, + Full: show.Full, + User: show.User, + GlobalScope: show.GlobalScope, }.init(b.allocator, b.ctx) resultPlan = p switch show.Tp { diff --git a/session.go b/session.go index 888b9806ea714..a54c1a3d66abb 100644 --- a/session.go +++ b/session.go @@ -586,9 +586,7 @@ func (s *session) GetGlobalSysVar(name string) (string, error) { sysVar, err := s.getExecRet(s, sql) if err != nil { if executor.ErrResultIsEmpty.Equal(err) { - sv, ok := variable.SysVars[name] - isUninitializedGlobalVariable := ok && sv.Scope|variable.ScopeGlobal > 0 - if isUninitializedGlobalVariable { + if sv, ok := variable.SysVars[name]; ok { return sv.Value, nil } return "", variable.UnknownSystemVar.GenByArgs(name) diff --git a/sessionctx/varsutil/varsutil.go b/sessionctx/varsutil/varsutil.go index 3ae9a1f29a62d..f409987de7921 100644 --- a/sessionctx/varsutil/varsutil.go +++ b/sessionctx/varsutil/varsutil.go @@ -62,9 +62,7 @@ func GetGlobalSystemVar(s *variable.SessionVars, key string) (string, error) { if sysVar == nil { return "", variable.UnknownSystemVar.GenByArgs(key) } - if sysVar.Scope == variable.ScopeSession { - return "", variable.ErrIncorrectScope - } else if sysVar.Scope == variable.ScopeNone { + if sysVar.Scope == variable.ScopeNone { return sysVar.Value, nil } gVal, err := s.GlobalVarsAccessor.GetGlobalSysVar(key) From 769a3b0ea75bc9373798c1f21aa6417f9f71e4d0 Mon Sep 17 00:00:00 2001 From: HuaiyuXu <391585975@qq.com> Date: Tue, 5 Dec 2017 19:23:52 +0800 Subject: [PATCH 2/5] *: improve performance of show variables (#5297) --- context/context.go | 2 +- executor/show.go | 41 ++++++++++++++++++---- new_session_test.go | 4 +-- session.go | 19 +++++++++++ sessionctx/variable/sysvar.go | 2 ++ sessionctx/varsutil/varsutil.go | 51 ++++++++++++++++++++-------- sessionctx/varsutil/varsutil_test.go | 4 +++ 7 files changed, 98 insertions(+), 25 deletions(-) diff --git a/context/context.go b/context/context.go index d742d67e161b6..a9105e3be436c 100644 --- a/context/context.go +++ b/context/context.go @@ -86,7 +86,7 @@ func (t basicCtxType) String() string { const ( // QueryString is the key for original query string. QueryString basicCtxType = 1 - // Initing is the key for indicating if the server is running bootstrap or upgrad job. + // Initing is the key for indicating if the server is running bootstrap or upgrade job. Initing basicCtxType = 2 // LastExecuteDDL is the key for whether the session execute a ddl command last time. LastExecuteDDL basicCtxType = 3 diff --git a/executor/show.go b/executor/show.go index e7cc0d93a0ad0..45b13f945a3dd 100644 --- a/executor/show.go +++ b/executor/show.go @@ -358,23 +358,50 @@ func (e *ShowExec) fetchShowCharset() error { return nil } -func (e *ShowExec) fetchShowVariables() error { - sessionVars := e.ctx.GetSessionVars() +func (e *ShowExec) fetchShowVariables() (err error) { + var ( + value string + ok bool + sessionVars = e.ctx.GetSessionVars() + unreachedVars = make([]string, 0, len(variable.SysVars)) + ) for _, v := range variable.SysVars { - var err error - var value string if !e.GlobalScope { - // Try to get Session Scope variable value first. - value, err = varsutil.GetSessionSystemVar(sessionVars, v.Name) + // For a session scope variable, + // 1. try to fetch value from SessionVars.Systems; + // 2. if this variable is session-only, fetch value from SysVars + // otherwise, fetch the value from table `mysql.Global_Variables`. + value, ok, err = varsutil.GetSessionOnlySysVars(sessionVars, v.Name) } else { - value, err = varsutil.GetGlobalSystemVar(sessionVars, v.Name) + // If the scope of a system variable is ScopeNone, + // it's a read-only variable, so we return the default value of it. + // Otherwise, we have to fetch the values from table `mysql.Global_Variables` for global variable names. + value, ok, err = varsutil.GetScopeNoneSystemVar(v.Name) } if err != nil { return errors.Trace(err) } + if !ok { + unreachedVars = append(unreachedVars, v.Name) + continue + } row := types.MakeDatums(v.Name, value) e.rows = append(e.rows, row) } + if len(unreachedVars) != 0 { + systemVars, err := sessionVars.GlobalVarsAccessor.GetAllSysVars() + if err != nil { + return errors.Trace(err) + } + for _, varName := range unreachedVars { + varValue, ok := systemVars[varName] + if !ok { + varValue = variable.SysVars[varName].Value + } + row := types.MakeDatums(varName, varValue) + e.rows = append(e.rows, row) + } + } return nil } diff --git a/new_session_test.go b/new_session_test.go index 14cd983da503b..fe11c61efb990 100644 --- a/new_session_test.go +++ b/new_session_test.go @@ -292,9 +292,9 @@ func (s *testSessionSuite) TestGlobalVarAccessor(c *C) { result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) tk.MustExec("set session sql_select_limit=100000000000;") - result = tk.MustQuery("show global variables where variable_name='sql_select_limit';") + result = tk.MustQuery("show global variables where variable_name='sql_select_limit';") result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) - result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") + result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") result.Check(testkit.Rows("sql_select_limit 100000000000")) } diff --git a/session.go b/session.go index a54c1a3d66abb..8c9693fddba13 100644 --- a/session.go +++ b/session.go @@ -575,6 +575,25 @@ func (s *session) getExecRet(ctx context.Context, sql string) (string, error) { return value, nil } +// GetAllSysVars implements GlobalVarAccessor.GetAllSysVars interface. +func (s *session) GetAllSysVars() (map[string]string, error) { + if s.Value(context.Initing) != nil { + return nil, nil + } + sql := `SELECT VARIABLE_NAME, VARIABLE_VALUE FROM %s.%s;` + sql = fmt.Sprintf(sql, mysql.SystemDB, mysql.GlobalVariablesTable) + rows, _, err := s.ExecRestrictedSQL(s, sql) + if err != nil { + return nil, errors.Trace(err) + } + ret := make(map[string]string) + for _, r := range rows { + k, v := r.GetString(0), r.GetString(1) + ret[k] = v + } + return ret, nil +} + // GetGlobalSysVar implements GlobalVarAccessor.GetGlobalSysVar interface. func (s *session) GetGlobalSysVar(name string) (string, error) { if s.Value(context.Initing) != nil { diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index a056486b128b6..1555f6299bc04 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -639,6 +639,8 @@ const ( // GlobalVarAccessor is the interface for accessing global scope system and status variables. type GlobalVarAccessor interface { + // GetAllSysVars gets all the global system variable values. + GetAllSysVars() (map[string]string, error) // GetGlobalSysVar gets the global system variable value for name. GetGlobalSysVar(name string) (string, error) // SetGlobalSysVar sets the global system variable name to value. diff --git a/sessionctx/varsutil/varsutil.go b/sessionctx/varsutil/varsutil.go index f409987de7921..9daa442efb8c1 100644 --- a/sessionctx/varsutil/varsutil.go +++ b/sessionctx/varsutil/varsutil.go @@ -30,24 +30,49 @@ import ( // Returns error if there is no such variable. func GetSessionSystemVar(s *variable.SessionVars, key string) (string, error) { key = strings.ToLower(key) + gVal, ok, err := GetSessionOnlySysVars(s, key) + if err != nil || ok { + return gVal, errors.Trace(err) + } + gVal, err = s.GlobalVarsAccessor.GetGlobalSysVar(key) + if err != nil { + return "", errors.Trace(err) + } + s.Systems[key] = gVal + return gVal, nil +} + +// GetSessionOnlySysVars get the default value defined in code for session only variable. +// The return bool value indicates whether it's a session only variable. +func GetSessionOnlySysVars(s *variable.SessionVars, key string) (string, bool, error) { sysVar := variable.SysVars[key] if sysVar == nil { - return "", variable.UnknownSystemVar.GenByArgs(key) + return "", false, variable.UnknownSystemVar.GenByArgs(key) } // For virtual system variables: switch sysVar.Name { case variable.TiDBCurrentTS: - return fmt.Sprintf("%d", s.TxnCtx.StartTS), nil + return fmt.Sprintf("%d", s.TxnCtx.StartTS), true, nil } sVal, ok := s.Systems[key] if ok { - return sVal, nil + return sVal, true, nil } if sysVar.Scope&variable.ScopeGlobal == 0 { // None-Global variable can use pre-defined default value. - return sysVar.Value, nil + return sysVar.Value, true, nil } - gVal, err := s.GlobalVarsAccessor.GetGlobalSysVar(key) + return "", false, nil +} + +// GetGlobalSystemVar gets a global system variable. +func GetGlobalSystemVar(s *variable.SessionVars, key string) (string, error) { + key = strings.ToLower(key) + gVal, ok, err := GetScopeNoneSystemVar(key) + if err != nil || ok { + return gVal, errors.Trace(err) + } + gVal, err = s.GlobalVarsAccessor.GetGlobalSysVar(key) if err != nil { return "", errors.Trace(err) } @@ -55,21 +80,17 @@ func GetSessionSystemVar(s *variable.SessionVars, key string) (string, error) { return gVal, nil } -// GetGlobalSystemVar gets a global system variable. -func GetGlobalSystemVar(s *variable.SessionVars, key string) (string, error) { - key = strings.ToLower(key) +// GetScopeNoneSystemVar checks the validation of `key`, +// and return the default value if its scope is `ScopeNone`. +func GetScopeNoneSystemVar(key string) (string, bool, error) { sysVar := variable.SysVars[key] if sysVar == nil { - return "", variable.UnknownSystemVar.GenByArgs(key) + return "", false, variable.UnknownSystemVar.GenByArgs(key) } if sysVar.Scope == variable.ScopeNone { - return sysVar.Value, nil + return sysVar.Value, true, nil } - gVal, err := s.GlobalVarsAccessor.GetGlobalSysVar(key) - if err != nil { - return "", errors.Trace(err) - } - return gVal, nil + return "", false, nil } // epochShiftBits is used to reserve logical part of the timestamp. diff --git a/sessionctx/varsutil/varsutil_test.go b/sessionctx/varsutil/varsutil_test.go index 94bbed5bcd336..dba257c3d3e99 100644 --- a/sessionctx/varsutil/varsutil_test.go +++ b/sessionctx/varsutil/varsutil_test.go @@ -185,3 +185,7 @@ func (m *mockGlobalAccessor) SetGlobalSysVar(name string, value string) error { m.vars[name] = value return nil } + +func (m *mockGlobalAccessor) GetAllSysVars() (map[string]string, error) { + return m.vars, nil +} From 4dd637890a36159c1cdc9e221f5b52c4cd4da9a0 Mon Sep 17 00:00:00 2001 From: HuaiyuXu <391585975@qq.com> Date: Wed, 6 Dec 2017 13:17:29 +0800 Subject: [PATCH 3/5] *: session variable value should not be modified when get global variable (#5317) --- new_session_test.go | 11 +++++++++++ sessionctx/varsutil/varsutil.go | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/new_session_test.go b/new_session_test.go index fe11c61efb990..0f6d3b942918f 100644 --- a/new_session_test.go +++ b/new_session_test.go @@ -296,6 +296,17 @@ func (s *testSessionSuite) TestGlobalVarAccessor(c *C) { result.Check(testkit.Rows("sql_select_limit 18446744073709551615")) result = tk.MustQuery("show session variables where variable_name='sql_select_limit';") result.Check(testkit.Rows("sql_select_limit 100000000000")) + + result = tk.MustQuery("select @@global.autocommit;") + result.Check(testkit.Rows("ON")) + result = tk.MustQuery("select @@autocommit;") + result.Check(testkit.Rows("ON")) + tk.MustExec("set @@global.autocommit = 0;") + result = tk.MustQuery("select @@global.autocommit;") + result.Check(testkit.Rows("0")) + result = tk.MustQuery("select @@autocommit;") + result.Check(testkit.Rows("ON")) + tk.MustExec("set @@global.autocommit=1") } func (s *testSessionSuite) TestRetryResetStmtCtx(c *C) { diff --git a/sessionctx/varsutil/varsutil.go b/sessionctx/varsutil/varsutil.go index 9daa442efb8c1..71fa08f2fb20d 100644 --- a/sessionctx/varsutil/varsutil.go +++ b/sessionctx/varsutil/varsutil.go @@ -76,7 +76,6 @@ func GetGlobalSystemVar(s *variable.SessionVars, key string) (string, error) { if err != nil { return "", errors.Trace(err) } - s.Systems[key] = gVal return gVal, nil } From 3ea8d48507e48a3e8d257b632a244b24dcbd2ad5 Mon Sep 17 00:00:00 2001 From: XuHuaiyu <391585975@qq.com> Date: Mon, 11 Dec 2017 15:25:43 +0800 Subject: [PATCH 4/5] fix ci --- session.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session.go b/session.go index 8c9693fddba13..adb68bdefec05 100644 --- a/session.go +++ b/session.go @@ -588,7 +588,7 @@ func (s *session) GetAllSysVars() (map[string]string, error) { } ret := make(map[string]string) for _, r := range rows { - k, v := r.GetString(0), r.GetString(1) + k, v := r.Data[0].GetString(), r.Data[1].GetString() ret[k] = v } return ret, nil From 0a6798720d35a9a2764779c02affbc21f30e952c Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 25 Oct 2017 06:29:32 -0500 Subject: [PATCH 5/5] ddl,expression: make leak test more stable (#4895) --- ddl/foreign_key_test.go | 3 +- expression/integration_test.go | 117 +++++++-------------------------- 2 files changed, 26 insertions(+), 94 deletions(-) diff --git a/ddl/foreign_key_test.go b/ddl/foreign_key_test.go index ade733c995b60..d15b77edf93ca 100644 --- a/ddl/foreign_key_test.go +++ b/ddl/foreign_key_test.go @@ -38,12 +38,14 @@ type testForeighKeySuite struct { } func (s *testForeighKeySuite) SetUpSuite(c *C) { + testleak.BeforeTest() s.store = testCreateStore(c, "test_foreign") } func (s *testForeighKeySuite) TearDownSuite(c *C) { err := s.store.Close() c.Assert(err, IsNil) + testleak.AfterTest(c)() } func (s *testForeighKeySuite) testCreateForeignKey(c *C, tblInfo *model.TableInfo, fkName string, keys []string, refTable string, refKeys []string, onDelete ast.ReferOptionType, onUpdate ast.ReferOptionType) *model.Job { @@ -110,7 +112,6 @@ func getForeignKey(t table.Table, name string) *model.FKInfo { } func (s *testForeighKeySuite) TestForeignKey(c *C) { - defer testleak.AfterTest(c)() d := testNewDDL(goctx.Background(), nil, s.store, nil, nil, testLease) defer d.Stop() s.d = d diff --git a/expression/integration_test.go b/expression/integration_test.go index 5c7f6aab1d533..d0df3f4015a63 100644 --- a/expression/integration_test.go +++ b/expression/integration_test.go @@ -59,6 +59,7 @@ func (s *testIntegrationSuite) cleanEnv(c *C) { func (s *testIntegrationSuite) SetUpSuite(c *C) { var err error + testleak.BeforeTest() s.store, s.dom, err = newStoreWithBootstrap() c.Assert(err, IsNil) s.ctx = mock.NewContext() @@ -67,14 +68,12 @@ func (s *testIntegrationSuite) SetUpSuite(c *C) { func (s *testIntegrationSuite) TearDownSuite(c *C) { s.dom.Close() s.store.Close() + testleak.AfterTest(c)() } func (s *testIntegrationSuite) TestFuncREPEAT(c *C) { tk := testkit.NewTestKit(c, s.store) - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk.MustExec("USE test;") tk.MustExec("DROP TABLE IF EXISTS table_string;") tk.MustExec("CREATE TABLE table_string(a CHAR(20), b VARCHAR(20), c TINYTEXT, d TEXT(20), e MEDIUMTEXT, f LONGTEXT, g BIGINT);") @@ -108,10 +107,7 @@ func (s *testIntegrationSuite) TestFuncREPEAT(c *C) { func (s *testIntegrationSuite) TestFuncLpadAndRpad(c *C) { tk := testkit.NewTestKit(c, s.store) - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk.MustExec(`USE test;`) tk.MustExec(`DROP TABLE IF EXISTS t;`) tk.MustExec(`CREATE TABLE t(a BINARY(10), b CHAR(10));`) @@ -131,10 +127,7 @@ func (s *testIntegrationSuite) TestFuncLpadAndRpad(c *C) { } func (s *testIntegrationSuite) TestMiscellaneousBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -213,10 +206,7 @@ func (s *testIntegrationSuite) TestMiscellaneousBuiltin(c *C) { } func (s *testIntegrationSuite) TestConvertToBit(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("drop table if exists t, t1") @@ -242,10 +232,7 @@ func (s *testIntegrationSuite) TestConvertToBit(c *C) { } func (s *testIntegrationSuite) TestMathBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -531,10 +518,7 @@ func (s *testIntegrationSuite) TestMathBuiltin(c *C) { } func (s *testIntegrationSuite) TestStringBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -896,10 +880,7 @@ func (s *testIntegrationSuite) TestStringBuiltin(c *C) { } func (s *testIntegrationSuite) TestEncryptionBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -1022,7 +1003,6 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { defer func() { s.ctx.GetSessionVars().StrictSQLMode = originSQLMode s.cleanEnv(c) - testleak.AfterTest(c)() }() tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -1706,10 +1686,7 @@ func (s *testIntegrationSuite) TestTimeBuiltin(c *C) { } func (s *testIntegrationSuite) TestOpBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -1749,10 +1726,7 @@ func (s *testIntegrationSuite) TestOpBuiltin(c *C) { } func (s *testIntegrationSuite) TestBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2120,10 +2094,7 @@ func (s *testIntegrationSuite) TestBuiltin(c *C) { } func (s *testIntegrationSuite) TestInfoBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2209,10 +2180,7 @@ func (s *testIntegrationSuite) TestInfoBuiltin(c *C) { } func (s *testIntegrationSuite) TestControlBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2271,10 +2239,7 @@ func (s *testIntegrationSuite) TestControlBuiltin(c *C) { } func (s *testIntegrationSuite) TestArithmeticBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2444,10 +2409,7 @@ func (s *testIntegrationSuite) TestArithmeticBuiltin(c *C) { } func (s *testIntegrationSuite) TestCompareBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2607,10 +2569,7 @@ func (s *testIntegrationSuite) TestCompareBuiltin(c *C) { } func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") tk.MustExec("create table t(a decimal(7, 6))") @@ -2620,10 +2579,7 @@ func (s *testIntegrationSuite) TestAggregationBuiltin(c *C) { } func (s *testIntegrationSuite) TestOtherBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("use test") @@ -2707,11 +2663,7 @@ func (s *testIntegrationSuite) TestOtherBuiltin(c *C) { } func (s *testIntegrationSuite) TestDateBuiltin(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() - + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) tk.MustExec("USE test;") tk.MustExec("DROP TABLE IF EXISTS t;") @@ -2798,11 +2750,7 @@ func (s *testIntegrationSuite) TestDateBuiltin(c *C) { } func (s *testIntegrationSuite) TestTimeLiteral(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() - + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) r := tk.MustQuery("select time '117:01:12';") @@ -2846,11 +2794,7 @@ func (s *testIntegrationSuite) TestTimeLiteral(c *C) { } func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() - + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) r := tk.MustQuery("select timestamp '2017-01-01 00:00:00';") @@ -2879,11 +2823,7 @@ func (s *testIntegrationSuite) TestTimestampLiteral(c *C) { } func (s *testIntegrationSuite) TestLiterals(c *C) { - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() - + defer s.cleanEnv(c) tk := testkit.NewTestKit(c, s.store) r := tk.MustQuery("SELECT LENGTH(b''), LENGTH(B''), b''+1, b''-1, B''+1;") r.Check(testkit.Rows("0 0 1 -1 1")) @@ -2891,10 +2831,7 @@ func (s *testIntegrationSuite) TestLiterals(c *C) { func (s *testIntegrationSuite) TestFuncJSON(c *C) { tk := testkit.NewTestKit(c, s.store) - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) tk.MustExec("USE test;") tk.MustExec("DROP TABLE IF EXISTS table_json;") tk.MustExec("CREATE TABLE table_json(a json, b VARCHAR(255));") @@ -2936,10 +2873,7 @@ func (s *testIntegrationSuite) TestFuncJSON(c *C) { func (s *testIntegrationSuite) TestColumnInfoModified(c *C) { testKit := testkit.NewTestKit(c, s.store) - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) testKit.MustExec("use test") testKit.MustExec("drop table if exists tab0") testKit.MustExec("CREATE TABLE tab0(col0 INTEGER, col1 INTEGER, col2 INTEGER)") @@ -2953,10 +2887,7 @@ func (s *testIntegrationSuite) TestColumnInfoModified(c *C) { func (s *testIntegrationSuite) TestSetVariables(c *C) { tk := testkit.NewTestKit(c, s.store) - defer func() { - s.cleanEnv(c) - testleak.AfterTest(c)() - }() + defer s.cleanEnv(c) _, err := tk.Exec("set sql_mode='adfasdfadsfdasd';") c.Assert(err, NotNil) _, err = tk.Exec("set @@sql_mode='adfasdfadsfdasd';")