@@ -488,6 +488,10 @@ func (b *Builder) applyTableUpdate(m *meta.Meta, diff *model.SchemaDiff) ([]int6
488
488
b .copySortedTables (oldTableID , newTableID )
489
489
490
490
tblIDs := make ([]int64 , 0 , 2 )
491
+ << << << < HEAD:infoschema / builder .go
492
+ == == == =
493
+ var keptAllocs autoid.Allocators
494
+ >> >> >> > c24dca58f5e (infoschema : load auto id related changes for multi - schema - change diff (#52967 )):pkg / infoschema / builder.go
491
495
// We try to reuse the old allocator, so the cached auto ID can be reused.
492
496
var allocs autoid.Allocators
493
497
if tableIDIsValid (oldTableID ) {
@@ -499,15 +503,27 @@ func (b *Builder) applyTableUpdate(m *meta.Meta, diff *model.SchemaDiff) ([]int6
499
503
diff .Type != model .ActionRepairTable &&
500
504
// Alter sequence will change the sequence info in the allocator, so the old allocator is not valid any more.
501
505
diff .Type != model.ActionAlterSequence {
506
+ << << << < HEAD :infoschema / builder.go
502
507
oldAllocs , _ := b .is .AllocByID (oldTableID )
503
508
allocs = filterAllocators (diff , oldAllocs )
509
+ == == == =
510
+ // TODO: Check how this would work with ADD/REMOVE Partitioning,
511
+ // which may have AutoID not connected to tableID
512
+ // TODO: can there be _tidb_rowid AutoID per partition?
513
+ oldAllocs , _ := allocByID (b , oldTableID )
514
+ keptAllocs = getKeptAllocators (diff , oldAllocs )
515
+ >> >> >> > c24dca58f5e (infoschema : load auto id related changes for multi - schema - change diff (#52967 )):pkg / infoschema / builder .go
504
516
}
505
517
506
518
tmpIDs := tblIDs
507
519
if (diff .Type == model .ActionRenameTable || diff .Type == model .ActionRenameTables ) && diff .OldSchemaID != diff .SchemaID {
508
520
oldRoDBInfo , ok := b .is .SchemaByID (diff .OldSchemaID )
509
521
if ! ok {
522
+ << << << < HEAD:infoschema / builder .go
510
523
return nil , ErrDatabaseNotExists.GenWithStackByArgs (
524
+ == == == =
525
+ return nil , keptAllocs , ErrDatabaseNotExists.GenWithStackByArgs (
526
+ >> >> >> > c24dca58f5e (infoschema : load auto id related changes for multi - schema - change diff (#52967 )):pkg / infoschema / builder.go
511
527
fmt .Sprintf ("(Schema ID %d)" , diff .OldSchemaID ),
512
528
)
513
529
}
@@ -522,6 +538,29 @@ func (b *Builder) applyTableUpdate(m *meta.Meta, diff *model.SchemaDiff) ([]int6
522
538
tblIDs = tmpIDs
523
539
}
524
540
}
541
+ << << << < HEAD:infoschema / builder .go
542
+ == == == =
543
+ return tblIDs , keptAllocs , nil
544
+ }
545
+
546
+ func (b * Builder ) applyTableUpdate (m * meta.Meta , diff * model.SchemaDiff ) ([]int64 , error ) {
547
+ roDBInfo , ok := b .infoSchema .SchemaByID (diff .SchemaID )
548
+ if ! ok {
549
+ return nil , ErrDatabaseNotExists .GenWithStackByArgs (
550
+ fmt .Sprintf ("(Schema ID %d)" , diff .SchemaID ),
551
+ )
552
+ }
553
+ dbInfo := b .getSchemaAndCopyIfNecessary (roDBInfo .Name .L )
554
+ oldTableID , newTableID := b .getTableIDs (diff )
555
+ b .updateBundleForTableUpdate (diff , newTableID , oldTableID )
556
+ b .copySortedTables (oldTableID , newTableID )
557
+
558
+ tblIDs , allocs , err := dropTableForUpdate (b , newTableID , oldTableID , dbInfo , diff )
559
+ if err != nil {
560
+ return nil , err
561
+ }
562
+
563
+ >> >> >> > c24dca58f5e (infoschema : load auto id related changes for multi - schema - change diff (#52967 )):pkg / infoschema / builder.go
525
564
if tableIDIsValid (newTableID ) {
526
565
// All types except DropTableOrView.
527
566
var err error
@@ -533,16 +572,33 @@ func (b *Builder) applyTableUpdate(m *meta.Meta, diff *model.SchemaDiff) ([]int6
533
572
return tblIDs , nil
534
573
}
535
574
536
- func filterAllocators (diff * model.SchemaDiff , oldAllocs autoid.Allocators ) autoid.Allocators {
537
- var newAllocs autoid.Allocators
575
+ // getKeptAllocators get allocators that is not changed by the DDL.
576
+ func getKeptAllocators (diff * model.SchemaDiff , oldAllocs autoid.Allocators ) autoid.Allocators {
577
+ var autoIDChanged , autoRandomChanged bool
538
578
switch diff .Type {
539
579
case model .ActionRebaseAutoID , model .ActionModifyTableAutoIdCache :
580
+ autoIDChanged = true
581
+ case model .ActionRebaseAutoRandomBase :
582
+ autoRandomChanged = true
583
+ case model .ActionMultiSchemaChange :
584
+ for _ , t := range diff .SubActionTypes {
585
+ switch t {
586
+ case model .ActionRebaseAutoID , model .ActionModifyTableAutoIdCache :
587
+ autoIDChanged = true
588
+ case model .ActionRebaseAutoRandomBase :
589
+ autoRandomChanged = true
590
+ }
591
+ }
592
+ }
593
+ var newAllocs autoid.Allocators
594
+ switch {
595
+ case autoIDChanged :
540
596
// Only drop auto-increment allocator.
541
597
newAllocs = oldAllocs .Filter (func (a autoid.Allocator ) bool {
542
598
tp := a .GetType ()
543
599
return tp != autoid .RowIDAllocType && tp != autoid .AutoIncrementType
544
600
})
545
- case model . ActionRebaseAutoRandomBase :
601
+ case autoRandomChanged :
546
602
// Only drop auto-random allocator.
547
603
newAllocs = oldAllocs .Filter (func (a autoid.Allocator ) bool {
548
604
tp := a .GetType ()
0 commit comments