diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 6135f9c8c204d..7d936842a1d82 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -2315,6 +2315,9 @@ func (d *ddl) AlterTable(ctx sessionctx.Context, ident ast.Ident, specs []*ast.A } if len(validSpecs) > 1 { + if !ctx.GetSessionVars().EnableChangeMultiSchema { + return errRunMultiSchemaChanges + } if isSameTypeMultiSpecs(validSpecs) { switch validSpecs[0].Tp { case ast.AlterTableAddColumns: diff --git a/session/bootstrap.go b/session/bootstrap.go index e0abf419351be..3722aaf668994 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -1335,6 +1335,13 @@ func doDMLWorks(s Session) { vVal = string(variable.DynamicOnly) } } + if v.Name == variable.TiDBEnableChangeMultiSchema { + vVal = variable.BoolOff + if flag.Lookup("test.v") != nil || flag.Lookup("check.v") != nil { + // enable change multi schema in test case for compatibility with old cases. + vVal = variable.BoolOn + } + } value := fmt.Sprintf(`("%s", "%s")`, strings.ToLower(k), vVal) values = append(values, value) } diff --git a/session/session.go b/session/session.go index 82c872759f6cb..34072792a2d1b 100644 --- a/session/session.go +++ b/session/session.go @@ -2283,6 +2283,7 @@ var builtinGlobalVariable = []string{ variable.TiDBEnableTelemetry, variable.TiDBShardAllocateStep, variable.TiDBEnableChangeColumnType, + variable.TiDBEnableChangeMultiSchema, variable.TiDBEnableAmendPessimisticTxn, variable.TiDBMemoryUsageAlarmRatio, variable.TiDBEnableRateLimitAction, diff --git a/sessionctx/variable/session.go b/sessionctx/variable/session.go index 32ef90dbbd8e8..66bf237403f8d 100644 --- a/sessionctx/variable/session.go +++ b/sessionctx/variable/session.go @@ -572,6 +572,9 @@ type SessionVars struct { // EnableChangeColumnType is used to control whether to enable the change column type. EnableChangeColumnType bool + // EnableChangeMultiSchema is used to control whether to enable the multi schema change. + EnableChangeMultiSchema bool + // WaitSplitRegionFinish defines the split region behaviour is sync or async. WaitSplitRegionFinish bool @@ -907,6 +910,7 @@ func NewSessionVars() *SessionVars { EnableParallelApply: DefTiDBEnableParallelApply, ShardAllocateStep: DefTiDBShardAllocateStep, EnableChangeColumnType: DefTiDBChangeColumnType, + EnableChangeMultiSchema: DefTiDBChangeMultiSchema, EnableAmendPessimisticTxn: DefTiDBEnableAmendPessimisticTxn, PartitionPruneMode: *atomic2.NewString(DefTiDBPartitionPruneMode), TxnScope: config.GetGlobalConfig().TxnScope, @@ -1617,6 +1621,8 @@ func (s *SessionVars) SetSystemVar(name string, val string) error { s.ShardAllocateStep = tidbOptInt64(val, DefTiDBShardAllocateStep) case TiDBEnableChangeColumnType: s.EnableChangeColumnType = TiDBOptOn(val) + case TiDBEnableChangeMultiSchema: + s.EnableChangeMultiSchema = TiDBOptOn(val) case TiDBEnableAmendPessimisticTxn: s.EnableAmendPessimisticTxn = TiDBOptOn(val) case TiDBTxnScope: diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index a91c9a8ec36bc..ace7948bb86c8 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1046,6 +1046,7 @@ var defaultSysVars = []*SysVar{ {Scope: ScopeSession, Name: TiDBDDLReorgPriority, Value: "PRIORITY_LOW"}, {Scope: ScopeGlobal, Name: TiDBMaxDeltaSchemaCount, Value: strconv.Itoa(DefTiDBMaxDeltaSchemaCount), Type: TypeUnsigned, MinValue: 100, MaxValue: 16384, AutoConvertOutOfRange: true}, {Scope: ScopeGlobal, Name: TiDBEnableChangeColumnType, Value: BoolToOnOff(DefTiDBChangeColumnType), Type: TypeBool}, + {Scope: ScopeGlobal, Name: TiDBEnableChangeMultiSchema, Value: BoolToOnOff(DefTiDBChangeMultiSchema), Type: TypeBool}, {Scope: ScopeSession, Name: TiDBForcePriority, Value: mysql.Priority2Str[DefTiDBForcePriority]}, {Scope: ScopeSession, Name: TiDBEnableRadixJoin, Value: BoolToOnOff(DefTiDBUseRadixJoin), Type: TypeBool}, {Scope: ScopeGlobal | ScopeSession, Name: TiDBOptJoinReorderThreshold, Value: strconv.Itoa(DefTiDBOptJoinReorderThreshold), Type: TypeUnsigned, MinValue: 0, MaxValue: 63}, diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index a3366874fa35f..eca34f02f22ae 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -351,6 +351,9 @@ const ( // TiDBEnableChangeColumnType is used to control whether to enable the change column type. TiDBEnableChangeColumnType = "tidb_enable_change_column_type" + // TiDBEnableChangeMultiSchema is used to control whether to enable the change multi schema. + TiDBEnableChangeMultiSchema = "tidb_enable_change_multi_schema" + // tidb_max_delta_schema_count defines the max length of deltaSchemaInfos. // deltaSchemaInfos is a queue that maintains the history of schema changes. TiDBMaxDeltaSchemaCount = "tidb_max_delta_schema_count" @@ -560,6 +563,7 @@ const ( DefTiDBDDLErrorCountLimit = 512 DefTiDBMaxDeltaSchemaCount = 1024 DefTiDBChangeColumnType = false + DefTiDBChangeMultiSchema = false DefTiDBHashAggPartialConcurrency = ConcurrencyUnset DefTiDBHashAggFinalConcurrency = ConcurrencyUnset DefTiDBWindowConcurrency = ConcurrencyUnset