Skip to content

Commit e57e563

Browse files
committed
rm extra func
1 parent 7bb7438 commit e57e563

File tree

1 file changed

+3
-43
lines changed

1 file changed

+3
-43
lines changed

sql/analyzer/validate_create_table.go

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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,24 +788,12 @@ 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-
// Only integer types are allowed for auto_increment in MySQL 8.4+
794-
// All other types are not allowed: TEXT, VARCHAR, CHAR, BLOB, BINARY, VARBINARY,
795-
// FLOAT, DOUBLE, DATE, TIME, DATETIME, TIMESTAMP, YEAR, ENUM, SET, BIT, DECIMAL, JSON, GEOMETRY, etc.
796-
if types.IsInteger(t) {
797-
return true
798-
}
799-
800-
return false
801-
}
802-
803791
func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool) error {
804792
seen := false
805793
for _, col := range schema {
806794
if col.AutoIncrement {
807-
// Check if column type is valid for auto_increment
808-
if !validateAutoIncrementType(col.Type) {
795+
// Under MySQL 8.4+, AUTO_INCREMENT columns must be integer types.
796+
if !types.IsInteger(col.Type) {
809797
return sql.ErrInvalidColumnSpecifier.New(col.Name)
810798
}
811799
// keyedColumns == nil means they are trying to add auto_increment column
@@ -827,34 +815,6 @@ func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool
827815
return nil
828816
}
829817

830-
func validateAutoIncrementAdd(schema sql.Schema, keyColumns map[string]bool) error {
831-
seen := false
832-
for _, col := range schema {
833-
if col.AutoIncrement {
834-
{
835-
// Check if column type is valid for auto_increment
836-
if !validateAutoIncrementType(col.Type) {
837-
return sql.ErrInvalidColumnSpecifier.New(col.Name)
838-
}
839-
if !col.PrimaryKey && !keyColumns[col.Name] {
840-
// AUTO_INCREMENT col must be a key
841-
return sql.ErrInvalidAutoIncCols.New()
842-
}
843-
if col.Default != nil {
844-
// AUTO_INCREMENT col cannot have default
845-
return sql.ErrInvalidAutoIncCols.New()
846-
}
847-
if seen {
848-
// there can be at most one AUTO_INCREMENT col
849-
return sql.ErrInvalidAutoIncCols.New()
850-
}
851-
seen = true
852-
}
853-
}
854-
}
855-
return nil
856-
}
857-
858818
func schToColMap(sch sql.Schema) map[string]*sql.Column {
859819
colMap := make(map[string]*sql.Column, len(sch))
860820
for _, col := range sch {

0 commit comments

Comments
 (0)