@@ -337,7 +337,7 @@ func resolveAlterColumn(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.S
337337 // We can't evaluate auto-increment until the end of the analysis, since we break adding a new auto-increment unique
338338 // column into two steps: first add the column, then create the index. If there was no index created, that's an error.
339339 if addedColumn {
340- err = validateAutoIncrementAdd (sch , keyedColumns )
340+ err = validateAutoIncrementModify (sch , keyedColumns )
341341 if err != nil {
342342 return nil , false , err
343343 }
@@ -788,17 +788,13 @@ func removeInSchema(sch sql.Schema, colName, tableName string) sql.Schema {
788788 return schCopy
789789}
790790
791- // validateAutoIncrementType returns true if the given type can be used with AUTO_INCREMENT
792- func validateAutoIncrementType (t sql.Type ) bool {
793- // Under MySQL 8.4+ only integer types can be used with AUTO_INCREMENT
794- return types .IsInteger (t )
795- }
796-
791+ // validateAutoIncrementModify checks that the schema is valid for an ALTER TABLE statement that modifies an AUTO_INCREMENT column.
797792func validateAutoIncrementModify (schema sql.Schema , keyedColumns map [string ]bool ) error {
798793 seen := false
799794 for _ , col := range schema {
800795 if col .AutoIncrement {
801- if ! validateAutoIncrementType (col .Type ) {
796+ // Under MySQL 8.4+ only integer types can be used with AUTO_INCREMENT
797+ if ! types .IsInteger (col .Type ) {
802798 return sql .ErrInvalidColumnSpecifier .New (col .Name )
803799 }
804800 // keyedColumns == nil means they are trying to add auto_increment column
@@ -820,33 +816,6 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
820816 return nil
821817}
822818
823- func validateAutoIncrementAdd (schema sql.Schema , keyColumns map [string ]bool ) error {
824- seen := false
825- for _ , col := range schema {
826- if col .AutoIncrement {
827- {
828- if ! validateAutoIncrementType (col .Type ) {
829- return sql .ErrInvalidColumnSpecifier .New (col .Name )
830- }
831- if ! col .PrimaryKey && ! keyColumns [col .Name ] {
832- // AUTO_INCREMENT col must be a key
833- return sql .ErrInvalidAutoIncCols .New ()
834- }
835- if col .Default != nil {
836- // AUTO_INCREMENT col cannot have default
837- return sql .ErrInvalidAutoIncCols .New ()
838- }
839- if seen {
840- // there can be at most one AUTO_INCREMENT col
841- return sql .ErrInvalidAutoIncCols .New ()
842- }
843- seen = true
844- }
845- }
846- }
847- return nil
848- }
849-
850819func schToColMap (sch sql.Schema ) map [string ]* sql.Column {
851820 colMap := make (map [string ]* sql.Column , len (sch ))
852821 for _ , col := range sch {
0 commit comments