Skip to content

Commit a437c24

Browse files
elianddbclaude
andcommitted
Update auto_increment validation for MySQL 8.4.5 compatibility
- Changed validateAutoIncrementType() to only allow integer types - FLOAT/DOUBLE with AUTO_INCREMENT now properly rejected (MySQL 8.4.5 behavior) - Updated float/double tests to expect "Incorrect column specifier" errors - Matches MySQL 8.4.5 stricter validation requirements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 1615504 commit a437c24

File tree

2 files changed

+7
-19
lines changed

2 files changed

+7
-19
lines changed

enginetest/queries/script_queries.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10065,12 +10065,8 @@ where
1006510065
SetUpScript: []string{},
1006610066
Assertions: []ScriptTestAssertion{
1006710067
{
10068-
Query: "create table float_tbl (f float primary key auto_increment);",
10069-
Expected: []sql.Row{{types.OkResult{}}},
10070-
},
10071-
{
10072-
Query: "show create table float_tbl;",
10073-
Expected: []sql.Row{{"float_tbl", "CREATE TABLE `float_tbl` (\n `f` float NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`f`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
10068+
Query: "create table float_tbl (f float primary key auto_increment);",
10069+
ExpectedErrStr: "Incorrect column specifier for column 'f'",
1007410070
},
1007510071
},
1007610072
},
@@ -10082,12 +10078,8 @@ where
1008210078
SetUpScript: []string{},
1008310079
Assertions: []ScriptTestAssertion{
1008410080
{
10085-
Query: "create table double_tbl (d double primary key auto_increment);",
10086-
Expected: []sql.Row{{types.OkResult{}}},
10087-
},
10088-
{
10089-
Query: "show create table double_tbl;",
10090-
Expected: []sql.Row{{"double_tbl", "CREATE TABLE `double_tbl` (\n `d` double NOT NULL AUTO_INCREMENT,\n PRIMARY KEY (`d`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
10081+
Query: "create table double_tbl (d double primary key auto_increment);",
10082+
ExpectedErrStr: "Incorrect column specifier for column 'd'",
1009110083
},
1009210084
},
1009310085
},

sql/analyzer/validate_create_table.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -790,14 +790,10 @@ func removeInSchema(sch sql.Schema, colName, tableName string) sql.Schema {
790790

791791
// validateAutoIncrementType returns true if the given type can be used with AUTO_INCREMENT
792792
func validateAutoIncrementType(t sql.Type) bool {
793-
// Only integer and floating point numeric types are allowed for auto_increment
793+
// Only integer types are allowed for auto_increment in MySQL 8.4+
794794
// All other types are not allowed: TEXT, VARCHAR, CHAR, BLOB, BINARY, VARBINARY,
795-
// DATE, TIME, DATETIME, TIMESTAMP, YEAR, ENUM, SET, BIT, DECIMAL, JSON, GEOMETRY, etc.
796-
if types.IsNumber(t) {
797-
// DECIMAL, YEAR, and BIT are not allowed for auto_increment per MySQL behavior
798-
if types.IsDecimal(t) || types.IsYear(t) || types.IsBit(t) {
799-
return false
800-
}
795+
// FLOAT, DOUBLE, DATE, TIME, DATETIME, TIMESTAMP, YEAR, ENUM, SET, BIT, DECIMAL, JSON, GEOMETRY, etc.
796+
if types.IsInteger(t) {
801797
return true
802798
}
803799

0 commit comments

Comments
 (0)