@@ -168,6 +168,7 @@ func (w *worker) onModifyColumn(jobCtx *jobContext, job *model.Job) (ver int64,
168
168
}
169
169
}
170
170
171
+ defer checkColumnOrderByStates (tblInfo )
171
172
return w .doModifyColumnTypeWithData (
172
173
jobCtx , job , dbInfo , tblInfo , changingCol , oldCol , args )
173
174
}
@@ -436,7 +437,7 @@ func (w *worker) doModifyColumnTypeWithData(
436
437
}
437
438
}
438
439
// none -> delete only
439
- updateChangingObjState (changingCol , changingIdxs , model .StateDeleteOnly )
440
+ updateObjectState (changingCol , changingIdxs , model .StateDeleteOnly )
440
441
failpoint .Inject ("mockInsertValueAfterCheckNull" , func (val failpoint.Value ) {
441
442
if valStr , ok := val .(string ); ok {
442
443
var sctx sessionctx.Context
@@ -488,7 +489,7 @@ func (w *worker) doModifyColumnTypeWithData(
488
489
}
489
490
}
490
491
// delete only -> write only
491
- updateChangingObjState (changingCol , changingIdxs , model .StateWriteOnly )
492
+ updateObjectState (changingCol , changingIdxs , model .StateWriteOnly )
492
493
ver , err = updateVersionAndTableInfo (jobCtx , job , tblInfo , originalState != changingCol .State )
493
494
if err != nil {
494
495
return ver , errors .Trace (err )
@@ -497,7 +498,7 @@ func (w *worker) doModifyColumnTypeWithData(
497
498
failpoint .InjectCall ("afterModifyColumnStateDeleteOnly" , job .ID )
498
499
case model .StateWriteOnly :
499
500
// write only -> reorganization
500
- updateChangingObjState (changingCol , changingIdxs , model .StateWriteReorganization )
501
+ updateObjectState (changingCol , changingIdxs , model .StateWriteReorganization )
501
502
ver , err = updateVersionAndTableInfo (jobCtx , job , tblInfo , originalState != changingCol .State )
502
503
if err != nil {
503
504
return ver , errors .Trace (err )
@@ -528,16 +529,65 @@ func (w *worker) doModifyColumnTypeWithData(
528
529
job .State = model .JobStateRollingback
529
530
return ver , errors .Trace (err )
530
531
}
532
+ << << << < HEAD
533
+ == == == =
534
+ changingIdxInfos := buildRelatedIndexInfos (tblInfo , changingCol .ID )
535
+ intest .Assert (len (oldIdxInfos ) == len (changingIdxInfos ))
536
+
537
+ updateObjectState (oldCol , oldIdxInfos , model .StateWriteOnly )
538
+ updateObjectState (changingCol , changingIdxInfos , model .StatePublic )
539
+ markOldObjectRemoving (oldCol , changingCol , oldIdxInfos , changingIdxInfos , colName )
540
+ moveChangingColumnInfoToDest (tblInfo , oldCol , changingCol , pos )
541
+ moveOldColumnInfo (tblInfo , oldCol )
542
+ moveIndexInfoToDest (tblInfo , changingCol , oldIdxInfos , changingIdxInfos )
543
+ updateModifyingCols (oldCol , changingCol )
544
+ >> >> >> > deb4d6563df (table : keep `table.Columns` order by states during modifying column (#62979 ))
531
545
532
546
updateChangingObjState (changingCol , changingIdxs , model .StatePublic )
533
547
ver , err = updateVersionAndTableInfo (jobCtx , job , tblInfo , originalState != changingCol .State )
534
548
if err != nil {
535
549
return ver , errors .Trace (err )
536
550
}
551
+ << << << < HEAD
537
552
modifyColumnEvent := notifier .NewModifyColumnEvent (tblInfo , []* model.ColumnInfo {changingCol })
538
553
err = asyncNotifyEvent (jobCtx , modifyColumnEvent , job , noSubJob , w .sess )
539
554
if err != nil {
540
555
return ver , errors .Trace (err )
556
+ == == == =
557
+ case model.StatePublic :
558
+ oldIdxInfos := buildRelatedIndexInfos (tblInfo , oldCol .ID )
559
+ switch oldCol .State {
560
+ case model .StateWriteOnly :
561
+ updateObjectState (oldCol , oldIdxInfos , model .StateDeleteOnly )
562
+ moveOldColumnInfo (tblInfo , oldCol )
563
+ ver , err = updateVersionAndTableInfo (jobCtx , job , tblInfo , true )
564
+ if err != nil {
565
+ return ver , errors .Trace (err )
566
+ }
567
+ case model .StateDeleteOnly :
568
+ removedIdxIDs := removeOldObjects (tblInfo , oldCol , oldIdxInfos )
569
+ modifyColumnEvent := notifier .NewModifyColumnEvent (tblInfo , []* model.ColumnInfo {changingCol })
570
+ err = asyncNotifyEvent (jobCtx , modifyColumnEvent , job , noSubJob , w .sess )
571
+ if err != nil {
572
+ return ver , errors .Trace (err )
573
+ }
574
+
575
+ ver , err = updateVersionAndTableInfo (jobCtx , job , tblInfo , true )
576
+ if err != nil {
577
+ return ver , errors .Trace (err )
578
+ }
579
+ // Finish this job.
580
+ job .FinishTableJob (model .JobStateDone , model .StatePublic , ver , tblInfo )
581
+ // Refactor the job args to add the old index ids into delete range table.
582
+ rmIdxs := append (removedIdxIDs , args .RedundantIdxs ... )
583
+ args .IndexIDs = rmIdxs
584
+ args .PartitionIDs = getPartitionIDs (tblInfo )
585
+ job .FillFinishedArgs (args )
586
+ default :
587
+ errMsg := fmt .Sprintf ("unexpected column state %s in modify column job" , oldCol .State )
588
+ intest .Assert (false , errMsg )
589
+ return ver , errors .Errorf (errMsg )
590
+ >> >> >> > deb4d6563df (table : keep `table.Columns` order by states during modifying column (#62979 ))
541
591
}
542
592
543
593
// Finish this job.
@@ -549,7 +599,6 @@ func (w *worker) doModifyColumnTypeWithData(
549
599
default :
550
600
err = dbterror .ErrInvalidDDLState .GenWithStackByArgs ("column" , changingCol .State )
551
601
}
552
-
553
602
return ver , errors .Trace (err )
554
603
}
555
604
@@ -671,6 +720,41 @@ func checkModifyColumnWithGeneratedColumnsConstraint(allCols []*table.Column, ol
671
720
return nil
672
721
}
673
722
723
+ var colStateOrd = map [model.SchemaState ]int {
724
+ model .StateNone : 0 ,
725
+ model .StateDeleteOnly : 1 ,
726
+ model .StateDeleteReorganization : 2 ,
727
+ model .StateWriteOnly : 3 ,
728
+ model .StateWriteReorganization : 4 ,
729
+ model .StatePublic : 5 ,
730
+ }
731
+
732
+ func checkColumnOrderByStates (tblInfo * model.TableInfo ) {
733
+ if intest .InTest {
734
+ minState := model .StatePublic
735
+ for _ , col := range tblInfo .Columns {
736
+ if colStateOrd [col .State ] < colStateOrd [minState ] {
737
+ minState = col .State
738
+ } else if colStateOrd [col .State ] > colStateOrd [minState ] {
739
+ intest .Assert (false , fmt .Sprintf ("column %s state %s is not in order, expect at least %s" , col .Name , col .State , minState ))
740
+ }
741
+ if col .ChangeStateInfo != nil {
742
+ offset := col .ChangeStateInfo .DependencyColumnOffset
743
+ intest .Assert (offset >= 0 && offset < len (tblInfo .Columns ))
744
+ depCol := tblInfo .Columns [offset ]
745
+ switch {
746
+ case strings .HasPrefix (col .Name .O , changingColumnPrefix ):
747
+ name := getChangingColumnOriginName (col )
748
+ intest .Assert (name == depCol .Name .O , "%s != %s" , name , depCol .Name .O )
749
+ case strings .HasPrefix (depCol .Name .O , removingObjPrefix ):
750
+ name := getRemovingObjOriginName (depCol .Name .O )
751
+ intest .Assert (name == col .Name .O , "%s != %s" , name , col .Name .O )
752
+ }
753
+ }
754
+ }
755
+ }
756
+ }
757
+
674
758
// GetModifiableColumnJob returns a DDL job of model.ActionModifyColumn.
675
759
func GetModifiableColumnJob (
676
760
ctx context.Context ,
0 commit comments