Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddl: add a switch for multi schema change & make it compatible with old test cases #21533

Merged
merged 11 commits into from
Dec 10, 2020
3 changes: 3 additions & 0 deletions ddl/ddl_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
tangenta marked this conversation as resolved.
Show resolved Hide resolved
// 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)
}
Expand Down
1 change: 1 addition & 0 deletions session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,7 @@ var builtinGlobalVariable = []string{
variable.TiDBEnableTelemetry,
variable.TiDBShardAllocateStep,
variable.TiDBEnableChangeColumnType,
variable.TiDBEnableChangeMultiSchema,
variable.TiDBEnableAmendPessimisticTxn,
variable.TiDBMemoryUsageAlarmRatio,
variable.TiDBEnableRateLimitAction,
Expand Down
6 changes: 6 additions & 0 deletions sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
4 changes: 4 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -560,6 +563,7 @@ const (
DefTiDBDDLErrorCountLimit = 512
DefTiDBMaxDeltaSchemaCount = 1024
DefTiDBChangeColumnType = false
DefTiDBChangeMultiSchema = false
DefTiDBHashAggPartialConcurrency = ConcurrencyUnset
DefTiDBHashAggFinalConcurrency = ConcurrencyUnset
DefTiDBWindowConcurrency = ConcurrencyUnset
Expand Down