Skip to content

Commit e5e24a7

Browse files
elianddbclaude
andcommitted
dolthub/dolt#9481 - Fix auto_increment validation and test expectations
- Use existing types.Is*() functions instead of vitess constants - Fix blob test expectations (column names were incorrect) - Comprehensive validation matches MySQL behavior exactly - All 22 data types tested: 8 valid, 14 invalid with proper errors 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent b26af40 commit e5e24a7

File tree

2 files changed

+24
-38
lines changed

2 files changed

+24
-38
lines changed

enginetest/queries/script_queries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8219,15 +8219,15 @@ where
82198219
},
82208220
{
82218221
Query: "create table bad (tb tinyblob primary key auto_increment);",
8222-
ExpectedErrStr: "Incorrect column specifier for column 'b'",
8222+
ExpectedErrStr: "Incorrect column specifier for column 'tb'",
82238223
},
82248224
{
82258225
Query: "create table bad (mb mediumblob primary key auto_increment);",
8226-
ExpectedErrStr: "Incorrect column specifier for column 'b'",
8226+
ExpectedErrStr: "Incorrect column specifier for column 'mb'",
82278227
},
82288228
{
82298229
Query: "create table bad (lb longblob primary key auto_increment);",
8230-
ExpectedErrStr: "Incorrect column specifier for column 'b'",
8230+
ExpectedErrStr: "Incorrect column specifier for column 'lb'",
82318231
},
82328232
},
82338233
},

sql/analyzer/validate_create_table.go

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ package analyzer
1717
import (
1818
"strings"
1919

20-
"github.com/dolthub/vitess/go/vt/proto/query"
21-
2220
"github.com/dolthub/go-mysql-server/sql"
2321
"github.com/dolthub/go-mysql-server/sql/expression"
2422
"github.com/dolthub/go-mysql-server/sql/plan"
@@ -792,44 +790,32 @@ func removeInSchema(sch sql.Schema, colName, tableName string) sql.Schema {
792790

793791
// validateAutoIncrementType returns true if the given type can be used with AUTO_INCREMENT
794792
func validateAutoIncrementType(t sql.Type) bool {
795-
if t == nil {
793+
// Check for invalid types first
794+
if types.IsEnum(t) || types.IsSet(t) || types.IsBit(t) {
796795
return false
797796
}
798-
799-
switch t.Type() {
800-
// Integer types - allowed
801-
case query.Type_INT8, query.Type_UINT8, query.Type_INT16, query.Type_UINT16,
802-
query.Type_INT24, query.Type_UINT24, query.Type_INT32, query.Type_UINT32,
803-
query.Type_INT64, query.Type_UINT64:
804-
return true
805-
806-
// Floating point types - allowed
807-
case query.Type_FLOAT32, query.Type_FLOAT64:
808-
return true
809-
810-
// Text/string types - not allowed
811-
case query.Type_CHAR, query.Type_VARCHAR, query.Type_TEXT,
812-
query.Type_BLOB, query.Type_BINARY, query.Type_VARBINARY:
813-
return false
814-
815-
// Decimal - not allowed per MySQL behavior
816-
case query.Type_DECIMAL:
817-
return false
818-
819-
// Date/time types - not allowed
820-
case query.Type_DATE, query.Type_TIME, query.Type_DATETIME,
821-
query.Type_TIMESTAMP, query.Type_YEAR:
797+
798+
// Check for text/string types - not allowed (includes TEXT, VARCHAR, CHAR, BLOB, BINARY, etc.)
799+
if types.IsText(t) {
822800
return false
823-
824-
// Other types - not allowed
825-
case query.Type_ENUM, query.Type_SET, query.Type_BIT,
826-
query.Type_JSON, query.Type_GEOMETRY:
827-
return false
828-
829-
// Default to false for any other types
830-
default:
801+
}
802+
803+
// Check for datetime/time types - not allowed
804+
if types.IsTime(t) || types.IsDateType(t) || types.IsDatetimeType(t) || types.IsTimestampType(t) || types.IsYear(t) {
831805
return false
832806
}
807+
808+
// Check for numeric types - only these are potentially allowed
809+
if types.IsNumber(t) {
810+
// DECIMAL is not allowed for auto_increment per MySQL behavior
811+
if types.IsDecimal(t) {
812+
return false
813+
}
814+
return true
815+
}
816+
817+
// Default to false for any other types (JSON, Geometry, etc.)
818+
return false
833819
}
834820

835821
func validateAutoIncrementModify(schema sql.Schema, keyedColumns map[string]bool) error {

0 commit comments

Comments
 (0)