From 677d85e8ff40db1183e60d06c9a2dda06ac17d6f Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Wed, 10 Oct 2018 16:35:36 +0800 Subject: [PATCH 1/5] add an variable to compatible with MySQL insert for OGG --- executor/insert_common.go | 6 ++++-- session/session.go | 1 + sessionctx/variable/session.go | 5 +++++ sessionctx/variable/sysvar.go | 1 + sessionctx/variable/tidb_vars.go | 5 +++++ sessionctx/variable/varsutil.go | 2 +- 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/executor/insert_common.go b/executor/insert_common.go index 628bead17cfbe..2561442d123d9 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -518,9 +518,11 @@ func (e *InsertValues) batchCheckAndInsert(rows [][]types.Datum, addRecord func( } func (e *InsertValues) addRecord(row []types.Datum) (int64, error) { - e.ctx.Txn().SetOption(kv.PresumeKeyNotExists, nil) + if !e.ctx.GetSessionVars().CompatibleInsert { + e.ctx.Txn().SetOption(kv.PresumeKeyNotExists, nil) + defer e.ctx.Txn().DelOption(kv.PresumeKeyNotExists) + } h, err := e.Table.AddRecord(e.ctx, row, false) - e.ctx.Txn().DelOption(kv.PresumeKeyNotExists) if err != nil { return 0, errors.Trace(err) } diff --git a/session/session.go b/session/session.go index bf6de1a3d2b1c..38262507ccc10 100644 --- a/session/session.go +++ b/session/session.go @@ -1275,6 +1275,7 @@ const loadCommonGlobalVarsSQL = "select HIGH_PRIORITY * from mysql.global_variab variable.TiDBHashAggPartialConcurrency + quoteCommaQuote + variable.TiDBHashAggFinalConcurrency + quoteCommaQuote + variable.TiDBBackoffLockFast + quoteCommaQuote + + variable.TiDBCompatibleInsert + quoteCommaQuote + variable.TiDBDDLReorgWorkerCount + quoteCommaQuote + variable.TiDBOptInSubqUnFolding + quoteCommaQuote + variable.TiDBDistSQLScanConcurrency + quoteCommaQuote + diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index e9fc0aa336d92..bea0ed5d02984 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -304,6 +304,9 @@ type SessionVars struct { // EnableRadixJoin indicates whether to use radix hash join to execute // HashJoin. EnableRadixJoin bool + + // CompatibleInsert indicates whether to check key exists when execute insert. + CompatibleInsert bool } // NewSessionVars creates a session vars object. @@ -566,6 +569,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.IndexSerialScanConcurrency = tidbOptPositiveInt32(val, DefIndexSerialScanConcurrency) case TiDBBackoffLockFast: s.KVVars.BackoffLockFast = tidbOptPositiveInt32(val, kv.DefBackoffLockFast) + case TiDBCompatibleInsert: + s.CompatibleInsert = TiDBOptOn(val) case TiDBBatchInsert: s.BatchInsert = TiDBOptOn(val) case TiDBBatchDelete: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 1be040e0d8919..bc4c98c4f3c8b 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -657,6 +657,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, TiDBBackoffLockFast, strconv.Itoa(kv.DefBackoffLockFast)}, {ScopeGlobal | ScopeSession, TiDBRetryLimit, strconv.Itoa(DefTiDBRetryLimit)}, {ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, boolToIntStr(DefTiDBDisableTxnAutoRetry)}, + {ScopeGlobal | ScopeSession, TiDBCompatibleInsert, boolToIntStr(DefTiDBCompatibleInsert)}, {ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)}, /* The following variable is defined as session scope but is actually server scope. */ {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 823d044d52beb..32687456d523b 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -195,6 +195,10 @@ const ( // tidb_enable_radix_join indicates to use radix hash join algorithm to execute // HashJoin. TiDBEnableRadixJoin = "tidb_enable_radix_join" + + // tidb_compatible_insert indicates to check the to-be-insert key exists or not when SQL is + // executing. It could hurt the performance of insert statement. + TiDBCompatibleInsert = "tidb_compatible_insert" ) // Default TiDB system variable values. @@ -228,6 +232,7 @@ const ( DefTiDBGeneralLog = 0 DefTiDBRetryLimit = 10 DefTiDBDisableTxnAutoRetry = false + DefTiDBCompatibleInsert = false DefTiDBHashJoinConcurrency = 5 DefTiDBProjectionConcurrency = 4 DefTiDBOptimizerSelectivityLevel = 0 diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index ff27620b55cef..2e1ac5a2216a8 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -281,7 +281,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, case WarningCount, ErrorCount: return value, ErrReadOnly.GenWithStackByArgs(name) case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, - PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates: + PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBCompatibleInsert: if strings.EqualFold(value, "ON") || value == "1" { return "1", nil } else if strings.EqualFold(value, "OFF") || value == "0" { From 23f90a68be321e724280da6033a2b63ebf6cc7dd Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Wed, 10 Oct 2018 17:08:15 +0800 Subject: [PATCH 2/5] add test cases --- executor/insert_common.go | 2 +- executor/set_test.go | 5 +++++ executor/write_test.go | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/executor/insert_common.go b/executor/insert_common.go index 2561442d123d9..c751b45459596 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -520,9 +520,9 @@ func (e *InsertValues) batchCheckAndInsert(rows [][]types.Datum, addRecord func( func (e *InsertValues) addRecord(row []types.Datum) (int64, error) { if !e.ctx.GetSessionVars().CompatibleInsert { e.ctx.Txn().SetOption(kv.PresumeKeyNotExists, nil) - defer e.ctx.Txn().DelOption(kv.PresumeKeyNotExists) } h, err := e.Table.AddRecord(e.ctx, row, false) + e.ctx.Txn().DelOption(kv.PresumeKeyNotExists) if err != nil { return 0, errors.Trace(err) } diff --git a/executor/set_test.go b/executor/set_test.go index 147bc22d16636..d93810effb184 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -234,6 +234,11 @@ func (s *testSuite) TestSetVar(c *C) { tk.MustQuery(`select @@tidb_force_priority;`).Check(testkit.Rows("NO_PRIORITY")) _, err = tk.Exec(`set global tidb_force_priority = ""`) c.Assert(err, NotNil) + + tk.MustExec("set tidb_compatible_insert = 1") + tk.MustQuery(`select @@session.tidb_compatible_insert;`).Check(testkit.Rows("1")) + tk.MustExec("set global tidb_compatible_insert = 0") + tk.MustQuery(`select @@global.tidb_compatible_insert;`).Check(testkit.Rows("0")) } func (s *testSuite) TestSetCharset(c *C) { diff --git a/executor/write_test.go b/executor/write_test.go index 033798c754a82..9d50a2ed7c13f 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -2079,3 +2079,17 @@ func (s *testSuite) TestRebaseIfNeeded(c *C) { tk.MustExec(`insert into t (b) values (6);`) tk.MustQuery(`select a from t where b = 6;`).Check(testkit.Rows("30003")) } + +func (s *testSuite) TestCompatibleInsert(c *C) { + tk := testkit.NewTestKit(c, s.store) + tk.MustExec(`use test`) + tk.MustExec(`drop table if exists t;create table t (i int key);`) + tk.MustExec(`insert t values (1);`) + tk.MustExec(`set tidb_compatible_insert = 1;`) + tk.MustExec(`begin;`) + _, err := tk.Exec(`insert t values (1);`) + c.Assert(err, NotNil) + tk.MustExec(`update t set i = 2 where i = 1;`) + tk.MustExec(`commit;`) + tk.MustQuery(`select * from t;`).Check(testkit.Rows("2")) +} From e556d71e2b3494e4cdd468e7758e462002a743d0 Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Thu, 11 Oct 2018 11:34:24 +0800 Subject: [PATCH 3/5] rename the variable --- executor/insert_common.go | 2 +- executor/set_test.go | 8 ++++---- executor/write_test.go | 2 +- session/session.go | 2 +- sessionctx/variable/session.go | 8 ++++---- sessionctx/variable/sysvar.go | 2 +- sessionctx/variable/tidb_vars.go | 10 ++++++---- sessionctx/variable/varsutil.go | 2 +- 8 files changed, 19 insertions(+), 17 deletions(-) diff --git a/executor/insert_common.go b/executor/insert_common.go index c751b45459596..c8c00e7e8bf70 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -518,7 +518,7 @@ func (e *InsertValues) batchCheckAndInsert(rows [][]types.Datum, addRecord func( } func (e *InsertValues) addRecord(row []types.Datum) (int64, error) { - if !e.ctx.GetSessionVars().CompatibleInsert { + if e.ctx.GetSessionVars().DeferConstraintCheck { e.ctx.Txn().SetOption(kv.PresumeKeyNotExists, nil) } h, err := e.Table.AddRecord(e.ctx, row, false) diff --git a/executor/set_test.go b/executor/set_test.go index d93810effb184..1f357558783e6 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -235,10 +235,10 @@ func (s *testSuite) TestSetVar(c *C) { _, err = tk.Exec(`set global tidb_force_priority = ""`) c.Assert(err, NotNil) - tk.MustExec("set tidb_compatible_insert = 1") - tk.MustQuery(`select @@session.tidb_compatible_insert;`).Check(testkit.Rows("1")) - tk.MustExec("set global tidb_compatible_insert = 0") - tk.MustQuery(`select @@global.tidb_compatible_insert;`).Check(testkit.Rows("0")) + tk.MustExec("set tidb_defer_constraint_check = 1") + tk.MustQuery(`select @@session.tidb_defer_constraint_check;`).Check(testkit.Rows("1")) + tk.MustExec("set global tidb_defer_constraint_check = 0") + tk.MustQuery(`select @@global.tidb_defer_constraint_check;`).Check(testkit.Rows("0")) } func (s *testSuite) TestSetCharset(c *C) { diff --git a/executor/write_test.go b/executor/write_test.go index 9d50a2ed7c13f..9a97a75af32ef 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -2085,7 +2085,7 @@ func (s *testSuite) TestCompatibleInsert(c *C) { tk.MustExec(`use test`) tk.MustExec(`drop table if exists t;create table t (i int key);`) tk.MustExec(`insert t values (1);`) - tk.MustExec(`set tidb_compatible_insert = 1;`) + tk.MustExec(`set tidb_defer_constraint_check = 0;`) tk.MustExec(`begin;`) _, err := tk.Exec(`insert t values (1);`) c.Assert(err, NotNil) diff --git a/session/session.go b/session/session.go index 38262507ccc10..65c75577cbb12 100644 --- a/session/session.go +++ b/session/session.go @@ -1275,7 +1275,7 @@ const loadCommonGlobalVarsSQL = "select HIGH_PRIORITY * from mysql.global_variab variable.TiDBHashAggPartialConcurrency + quoteCommaQuote + variable.TiDBHashAggFinalConcurrency + quoteCommaQuote + variable.TiDBBackoffLockFast + quoteCommaQuote + - variable.TiDBCompatibleInsert + quoteCommaQuote + + variable.TiDBDeferConstraintCheck + quoteCommaQuote + variable.TiDBDDLReorgWorkerCount + quoteCommaQuote + variable.TiDBOptInSubqUnFolding + quoteCommaQuote + variable.TiDBDistSQLScanConcurrency + quoteCommaQuote + diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index bea0ed5d02984..2baada3b7a675 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -305,8 +305,8 @@ type SessionVars struct { // HashJoin. EnableRadixJoin bool - // CompatibleInsert indicates whether to check key exists when execute insert. - CompatibleInsert bool + // DeferConstraintCheck indicates whether to defer the constraint check. + DeferConstraintCheck bool } // NewSessionVars creates a session vars object. @@ -569,8 +569,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.IndexSerialScanConcurrency = tidbOptPositiveInt32(val, DefIndexSerialScanConcurrency) case TiDBBackoffLockFast: s.KVVars.BackoffLockFast = tidbOptPositiveInt32(val, kv.DefBackoffLockFast) - case TiDBCompatibleInsert: - s.CompatibleInsert = TiDBOptOn(val) + case TiDBDeferConstraintCheck: + s.DeferConstraintCheck = TiDBOptOn(val) case TiDBBatchInsert: s.BatchInsert = TiDBOptOn(val) case TiDBBatchDelete: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index bc4c98c4f3c8b..db0e4a760f6b1 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -657,7 +657,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, TiDBBackoffLockFast, strconv.Itoa(kv.DefBackoffLockFast)}, {ScopeGlobal | ScopeSession, TiDBRetryLimit, strconv.Itoa(DefTiDBRetryLimit)}, {ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, boolToIntStr(DefTiDBDisableTxnAutoRetry)}, - {ScopeGlobal | ScopeSession, TiDBCompatibleInsert, boolToIntStr(DefTiDBCompatibleInsert)}, + {ScopeGlobal | ScopeSession, TiDBDeferConstraintCheck, boolToIntStr(DefTiDBDeferConstraintCheck)}, {ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)}, /* The following variable is defined as session scope but is actually server scope. */ {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 32687456d523b..2b6bbd55cea7c 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -196,9 +196,11 @@ const ( // HashJoin. TiDBEnableRadixJoin = "tidb_enable_radix_join" - // tidb_compatible_insert indicates to check the to-be-insert key exists or not when SQL is - // executing. It could hurt the performance of insert statement. - TiDBCompatibleInsert = "tidb_compatible_insert" + // tidb_defer_constraint_check indicates to defer the constraint check when committing the + // transaction or not. If it is ON, TiDB will defer the check when committing, + // otherwise it will do the constraint check when the SQL executing. + // It could hurt the performance of bulking insert when it is ON. + TiDBDeferConstraintCheck = "tidb_defer_constraint_check" ) // Default TiDB system variable values. @@ -232,7 +234,7 @@ const ( DefTiDBGeneralLog = 0 DefTiDBRetryLimit = 10 DefTiDBDisableTxnAutoRetry = false - DefTiDBCompatibleInsert = false + DefTiDBDeferConstraintCheck = true DefTiDBHashJoinConcurrency = 5 DefTiDBProjectionConcurrency = 4 DefTiDBOptimizerSelectivityLevel = 0 diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 2e1ac5a2216a8..f5a69f4f770c6 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -281,7 +281,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, case WarningCount, ErrorCount: return value, ErrReadOnly.GenWithStackByArgs(name) case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, - PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBCompatibleInsert: + PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBDeferConstraintCheck: if strings.EqualFold(value, "ON") || value == "1" { return "1", nil } else if strings.EqualFold(value, "OFF") || value == "0" { From 51d568fafc51ee16437072e69fb4bad2c2fc0b1f Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Thu, 11 Oct 2018 11:40:24 +0800 Subject: [PATCH 4/5] address comments --- executor/write_test.go | 2 +- sessionctx/variable/tidb_vars.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/executor/write_test.go b/executor/write_test.go index 9a97a75af32ef..be501c18a0b03 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -2080,7 +2080,7 @@ func (s *testSuite) TestRebaseIfNeeded(c *C) { tk.MustQuery(`select a from t where b = 6;`).Check(testkit.Rows("30003")) } -func (s *testSuite) TestCompatibleInsert(c *C) { +func (s *testSuite) TestDeferConstraintCheckForInsert(c *C) { tk := testkit.NewTestKit(c, s.store) tk.MustExec(`use test`) tk.MustExec(`drop table if exists t;create table t (i int key);`) diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 2b6bbd55cea7c..14d028eca908d 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -198,7 +198,7 @@ const ( // tidb_defer_constraint_check indicates to defer the constraint check when committing the // transaction or not. If it is ON, TiDB will defer the check when committing, - // otherwise it will do the constraint check when the SQL executing. + // otherwise it will check the constraint when the SQL executing. // It could hurt the performance of bulking insert when it is ON. TiDBDeferConstraintCheck = "tidb_defer_constraint_check" ) From 68b2d8db10e649756f1690223e5f7ac8a5bee690 Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Tue, 16 Oct 2018 11:25:52 +0800 Subject: [PATCH 5/5] rename once again --- executor/insert_common.go | 2 +- executor/set_test.go | 8 ++++---- executor/write_test.go | 2 +- session/session.go | 2 +- sessionctx/variable/session.go | 8 ++++---- sessionctx/variable/sysvar.go | 2 +- sessionctx/variable/tidb_vars.go | 8 +++----- sessionctx/variable/varsutil.go | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/executor/insert_common.go b/executor/insert_common.go index b68c27b5c3c24..8e53f899d72c5 100644 --- a/executor/insert_common.go +++ b/executor/insert_common.go @@ -516,7 +516,7 @@ func (e *InsertValues) batchCheckAndInsert(rows [][]types.Datum, addRecord func( } func (e *InsertValues) addRecord(row []types.Datum) (int64, error) { - if e.ctx.GetSessionVars().DeferConstraintCheck { + if !e.ctx.GetSessionVars().ConstraintCheckInPlace { e.ctx.Txn().SetOption(kv.PresumeKeyNotExists, nil) } h, err := e.Table.AddRecord(e.ctx, row, false) diff --git a/executor/set_test.go b/executor/set_test.go index 1f357558783e6..1bba2c11f2f67 100644 --- a/executor/set_test.go +++ b/executor/set_test.go @@ -235,10 +235,10 @@ func (s *testSuite) TestSetVar(c *C) { _, err = tk.Exec(`set global tidb_force_priority = ""`) c.Assert(err, NotNil) - tk.MustExec("set tidb_defer_constraint_check = 1") - tk.MustQuery(`select @@session.tidb_defer_constraint_check;`).Check(testkit.Rows("1")) - tk.MustExec("set global tidb_defer_constraint_check = 0") - tk.MustQuery(`select @@global.tidb_defer_constraint_check;`).Check(testkit.Rows("0")) + tk.MustExec("set tidb_constraint_check_in_place = 1") + tk.MustQuery(`select @@session.tidb_constraint_check_in_place;`).Check(testkit.Rows("1")) + tk.MustExec("set global tidb_constraint_check_in_place = 0") + tk.MustQuery(`select @@global.tidb_constraint_check_in_place;`).Check(testkit.Rows("0")) } func (s *testSuite) TestSetCharset(c *C) { diff --git a/executor/write_test.go b/executor/write_test.go index 3534e344ca391..4b5ab134f6e51 100644 --- a/executor/write_test.go +++ b/executor/write_test.go @@ -2097,7 +2097,7 @@ func (s *testSuite) TestDeferConstraintCheckForInsert(c *C) { tk.MustExec(`use test`) tk.MustExec(`drop table if exists t;create table t (i int key);`) tk.MustExec(`insert t values (1);`) - tk.MustExec(`set tidb_defer_constraint_check = 0;`) + tk.MustExec(`set tidb_constraint_check_in_place = 1;`) tk.MustExec(`begin;`) _, err := tk.Exec(`insert t values (1);`) c.Assert(err, NotNil) diff --git a/session/session.go b/session/session.go index 3c8b6000c0286..a66bb1cfe85c1 100644 --- a/session/session.go +++ b/session/session.go @@ -1276,7 +1276,7 @@ const loadCommonGlobalVarsSQL = "select HIGH_PRIORITY * from mysql.global_variab variable.TiDBHashAggPartialConcurrency + quoteCommaQuote + variable.TiDBHashAggFinalConcurrency + quoteCommaQuote + variable.TiDBBackoffLockFast + quoteCommaQuote + - variable.TiDBDeferConstraintCheck + quoteCommaQuote + + variable.TiDBConstraintCheckInPlace + quoteCommaQuote + variable.TiDBDDLReorgWorkerCount + quoteCommaQuote + variable.TiDBOptInSubqUnFolding + quoteCommaQuote + variable.TiDBDistSQLScanConcurrency + quoteCommaQuote + diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 81f6b7ef9b5d2..954a72a568718 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -308,8 +308,8 @@ type SessionVars struct { // HashJoin. EnableRadixJoin bool - // DeferConstraintCheck indicates whether to defer the constraint check. - DeferConstraintCheck bool + // ConstraintCheckInPlace indicates whether to check the constraint when the SQL executing. + ConstraintCheckInPlace bool // CommandValue indicates which command current session is doing. CommandValue uint32 @@ -576,8 +576,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.IndexSerialScanConcurrency = tidbOptPositiveInt32(val, DefIndexSerialScanConcurrency) case TiDBBackoffLockFast: s.KVVars.BackoffLockFast = tidbOptPositiveInt32(val, kv.DefBackoffLockFast) - case TiDBDeferConstraintCheck: - s.DeferConstraintCheck = TiDBOptOn(val) + case TiDBConstraintCheckInPlace: + s.ConstraintCheckInPlace = TiDBOptOn(val) case TiDBBatchInsert: s.BatchInsert = TiDBOptOn(val) case TiDBBatchDelete: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index 5a9574f8c171a..4e4534935c819 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -658,7 +658,7 @@ var defaultSysVars = []*SysVar{ {ScopeGlobal | ScopeSession, TiDBBackoffLockFast, strconv.Itoa(kv.DefBackoffLockFast)}, {ScopeGlobal | ScopeSession, TiDBRetryLimit, strconv.Itoa(DefTiDBRetryLimit)}, {ScopeGlobal | ScopeSession, TiDBDisableTxnAutoRetry, boolToIntStr(DefTiDBDisableTxnAutoRetry)}, - {ScopeGlobal | ScopeSession, TiDBDeferConstraintCheck, boolToIntStr(DefTiDBDeferConstraintCheck)}, + {ScopeGlobal | ScopeSession, TiDBConstraintCheckInPlace, boolToIntStr(DefTiDBConstraintCheckInPlace)}, {ScopeSession, TiDBOptimizerSelectivityLevel, strconv.Itoa(DefTiDBOptimizerSelectivityLevel)}, /* The following variable is defined as session scope but is actually server scope. */ {ScopeSession, TiDBGeneralLog, strconv.Itoa(DefTiDBGeneralLog)}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 73b50a2ad0c96..c754743d5ac8b 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -199,11 +199,9 @@ const ( // HashJoin. TiDBEnableRadixJoin = "tidb_enable_radix_join" - // tidb_defer_constraint_check indicates to defer the constraint check when committing the - // transaction or not. If it is ON, TiDB will defer the check when committing, - // otherwise it will check the constraint when the SQL executing. + // tidb_constraint_check_in_place indicates to check the constraint when the SQL executing. // It could hurt the performance of bulking insert when it is ON. - TiDBDeferConstraintCheck = "tidb_defer_constraint_check" + TiDBConstraintCheckInPlace = "tidb_constraint_check_in_place" ) // Default TiDB system variable values. @@ -237,7 +235,7 @@ const ( DefTiDBGeneralLog = 0 DefTiDBRetryLimit = 10 DefTiDBDisableTxnAutoRetry = false - DefTiDBDeferConstraintCheck = true + DefTiDBConstraintCheckInPlace = false DefTiDBHashJoinConcurrency = 5 DefTiDBProjectionConcurrency = 4 DefTiDBOptimizerSelectivityLevel = 0 diff --git a/sessionctx/variable/varsutil.go b/sessionctx/variable/varsutil.go index 78de46377b12a..a64f0a31a7a67 100644 --- a/sessionctx/variable/varsutil.go +++ b/sessionctx/variable/varsutil.go @@ -281,7 +281,7 @@ func ValidateSetSystemVar(vars *SessionVars, name string, value string) (string, case WarningCount, ErrorCount: return value, ErrReadOnly.GenWithStackByArgs(name) case GeneralLog, TiDBGeneralLog, AvoidTemporalUpgrade, BigTables, CheckProxyUsers, CoreFile, EndMakersInJSON, SQLLogBin, OfflineMode, - PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBDeferConstraintCheck: + PseudoSlaveMode, LowPriorityUpdates, SkipNameResolve, ForeignKeyChecks, SQLSafeUpdates, TiDBConstraintCheckInPlace: if strings.EqualFold(value, "ON") || value == "1" { return "1", nil } else if strings.EqualFold(value, "OFF") || value == "0" {