@@ -41,6 +41,7 @@ import (
41
41
"github.com/pingcap/tidb/parser"
42
42
"github.com/pingcap/tidb/parser/ast"
43
43
"github.com/pingcap/tidb/parser/charset"
44
+ "github.com/pingcap/tidb/parser/duration"
44
45
"github.com/pingcap/tidb/parser/format"
45
46
"github.com/pingcap/tidb/parser/model"
46
47
"github.com/pingcap/tidb/parser/mysql"
@@ -3024,7 +3025,7 @@ func SetDirectPlacementOpt(placementSettings *model.PlacementSettings, placement
3024
3025
3025
3026
// handleTableOptions updates tableInfo according to table options.
3026
3027
func handleTableOptions (options []* ast.TableOption , tbInfo * model.TableInfo ) error {
3027
- var handledTTLOrTTLEnable bool
3028
+ var ttlOptionsHandled bool
3028
3029
3029
3030
for _ , op := range options {
3030
3031
switch op .Tp {
@@ -3062,23 +3063,28 @@ func handleTableOptions(options []*ast.TableOption, tbInfo *model.TableInfo) err
3062
3063
tbInfo .PlacementPolicyRef = & model.PolicyRefInfo {
3063
3064
Name : model .NewCIStr (op .StrValue ),
3064
3065
}
3065
- case ast .TableOptionTTL , ast .TableOptionTTLEnable :
3066
- if handledTTLOrTTLEnable {
3066
+ case ast .TableOptionTTL , ast .TableOptionTTLEnable , ast . TableOptionTTLJobInterval :
3067
+ if ttlOptionsHandled {
3067
3068
continue
3068
3069
}
3069
3070
3070
- ttlInfo , ttlEnable , err := getTTLInfoInOptions (options )
3071
+ ttlInfo , ttlEnable , ttlJobInterval , err := getTTLInfoInOptions (options )
3071
3072
if err != nil {
3072
3073
return err
3073
3074
}
3074
3075
// It's impossible that `ttlInfo` and `ttlEnable` are all nil, because we have met this option.
3075
3076
// After exclude the situation `ttlInfo == nil && ttlEnable != nil`, we could say `ttlInfo != nil`
3076
- if ttlInfo == nil && ttlEnable != nil {
3077
- return errors .Trace (dbterror .ErrSetTTLEnableForNonTTLTable )
3077
+ if ttlInfo == nil {
3078
+ if ttlEnable != nil {
3079
+ return errors .Trace (dbterror .ErrSetTTLOptionForNonTTLTable .FastGenByArgs ("TTL_ENABLE" ))
3080
+ }
3081
+ if ttlJobInterval != nil {
3082
+ return errors .Trace (dbterror .ErrSetTTLOptionForNonTTLTable .FastGenByArgs ("TTL_JOB_INTERVAL" ))
3083
+ }
3078
3084
}
3079
3085
3080
3086
tbInfo .TTLInfo = ttlInfo
3081
- handledTTLOrTTLEnable = true
3087
+ ttlOptionsHandled = true
3082
3088
}
3083
3089
}
3084
3090
shardingBits := shardingBits (tbInfo )
@@ -3270,7 +3276,7 @@ func (d *ddl) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt *ast
3270
3276
}
3271
3277
for _ , spec := range validSpecs {
3272
3278
var handledCharsetOrCollate bool
3273
- var handledTTLOrTTLEnable bool
3279
+ var ttlOptionsHandled bool
3274
3280
switch spec .Tp {
3275
3281
case ast .AlterTableAddColumns :
3276
3282
err = d .AddColumn (sctx , ident , spec )
@@ -3407,20 +3413,21 @@ func (d *ddl) AlterTable(ctx context.Context, sctx sessionctx.Context, stmt *ast
3407
3413
Name : model .NewCIStr (opt .StrValue ),
3408
3414
}
3409
3415
case ast .TableOptionEngine :
3410
- case ast .TableOptionTTL , ast .TableOptionTTLEnable :
3416
+ case ast .TableOptionTTL , ast .TableOptionTTLEnable , ast . TableOptionTTLJobInterval :
3411
3417
var ttlInfo * model.TTLInfo
3412
3418
var ttlEnable * bool
3419
+ var ttlJobInterval * duration.Duration
3413
3420
3414
- if handledTTLOrTTLEnable {
3421
+ if ttlOptionsHandled {
3415
3422
continue
3416
3423
}
3417
- ttlInfo , ttlEnable , err = getTTLInfoInOptions (spec .Options )
3424
+ ttlInfo , ttlEnable , ttlJobInterval , err = getTTLInfoInOptions (spec .Options )
3418
3425
if err != nil {
3419
3426
return err
3420
3427
}
3421
- err = d .AlterTableTTLInfoOrEnable (sctx , ident , ttlInfo , ttlEnable )
3428
+ err = d .AlterTableTTLInfoOrEnable (sctx , ident , ttlInfo , ttlEnable , ttlJobInterval )
3422
3429
3423
- handledTTLOrTTLEnable = true
3430
+ ttlOptionsHandled = true
3424
3431
default :
3425
3432
err = dbterror .ErrUnsupportedAlterTableOption
3426
3433
}
@@ -5348,11 +5355,13 @@ func (d *ddl) AlterTableSetTiFlashReplica(ctx sessionctx.Context, ident ast.Iden
5348
5355
}
5349
5356
5350
5357
// AlterTableTTLInfoOrEnable submit ddl job to change table info according to the ttlInfo, or ttlEnable
5351
- // at least one of the `ttlInfo` or `ttlEnable ` should be not nil.
5358
+ // at least one of the `ttlInfo`, `ttlEnable` or `ttlCronJobSchedule ` should be not nil.
5352
5359
// When `ttlInfo` is nil, and `ttlEnable` is not, it will use the original `.TTLInfo` in the table info and modify the
5353
5360
// `.Enable`. If the `.TTLInfo` in the table info is empty, this function will return an error.
5361
+ // When `ttlInfo` is nil, and `ttlCronJobSchedule` is not, it will use the original `.TTLInfo` in the table info and modify the
5362
+ // `.JobInterval`. If the `.TTLInfo` in the table info is empty, this function will return an error.
5354
5363
// When `ttlInfo` is not nil, it simply submits the job with the `ttlInfo` and ignore the `ttlEnable`.
5355
- func (d * ddl ) AlterTableTTLInfoOrEnable (ctx sessionctx.Context , ident ast.Ident , ttlInfo * model.TTLInfo , ttlEnable * bool ) error {
5364
+ func (d * ddl ) AlterTableTTLInfoOrEnable (ctx sessionctx.Context , ident ast.Ident , ttlInfo * model.TTLInfo , ttlEnable * bool , ttlCronJobSchedule * duration. Duration ) error {
5356
5365
is := d .infoCache .GetLatest ()
5357
5366
schema , ok := is .SchemaByName (ident .Schema )
5358
5367
if ! ok {
@@ -5375,29 +5384,25 @@ func (d *ddl) AlterTableTTLInfoOrEnable(ctx sessionctx.Context, ident ast.Ident,
5375
5384
if err != nil {
5376
5385
return err
5377
5386
}
5378
- job = & model.Job {
5379
- SchemaID : schema .ID ,
5380
- TableID : tableID ,
5381
- SchemaName : schema .Name .L ,
5382
- TableName : tableName ,
5383
- Type : model .ActionAlterTTLInfo ,
5384
- BinlogInfo : & model.HistoryInfo {},
5385
- Args : []interface {}{ttlInfo , ttlEnable },
5386
- }
5387
5387
} else {
5388
5388
if tblInfo .TTLInfo == nil {
5389
- return errors .Trace (dbterror .ErrSetTTLEnableForNonTTLTable )
5389
+ if ttlEnable != nil {
5390
+ return errors .Trace (dbterror .ErrSetTTLOptionForNonTTLTable .FastGenByArgs ("TTL_ENABLE" ))
5391
+ }
5392
+ if ttlCronJobSchedule != nil {
5393
+ return errors .Trace (dbterror .ErrSetTTLOptionForNonTTLTable .FastGenByArgs ("TTL_JOB_INTERVAL" ))
5394
+ }
5390
5395
}
5396
+ }
5391
5397
5392
- job = & model.Job {
5393
- SchemaID : schema .ID ,
5394
- TableID : tableID ,
5395
- SchemaName : schema .Name .L ,
5396
- TableName : tableName ,
5397
- Type : model .ActionAlterTTLInfo ,
5398
- BinlogInfo : & model.HistoryInfo {},
5399
- Args : []interface {}{ttlInfo , ttlEnable },
5400
- }
5398
+ job = & model.Job {
5399
+ SchemaID : schema .ID ,
5400
+ TableID : tableID ,
5401
+ SchemaName : schema .Name .L ,
5402
+ TableName : tableName ,
5403
+ Type : model .ActionAlterTTLInfo ,
5404
+ BinlogInfo : & model.HistoryInfo {},
5405
+ Args : []interface {}{ttlInfo , ttlEnable , ttlCronJobSchedule },
5401
5406
}
5402
5407
5403
5408
err = d .DoDDLJob (ctx , job )
0 commit comments