Don't rewrite enum columns when not necessary.

This commit is contained in:
Nick Tobey
2025-01-18 02:16:56 -08:00
parent 4c93a25fbc
commit 1772eac120
2 changed files with 12 additions and 1 deletions

View File

@@ -134,6 +134,17 @@ type TypeInfo interface {
fmt.Stringer
}
// RequiresRewrite returns whether or now changing a column type from |old| to |new| requires rewriting table rows.
func RequiresRewrite(old TypeInfo, new TypeInfo) bool {
oldEnum, isOldEnum := old.ToSqlType().(sql.EnumType)
newEnum, isNewEnum := new.ToSqlType().(sql.EnumType)
if isOldEnum && isNewEnum && oldEnum.IsSubsetOf(newEnum) {
return false
}
return true
}
// FromSqlType takes in a sql.Type and returns the most relevant TypeInfo.
func FromSqlType(sqlType sql.Type) (TypeInfo, error) {
if gmsExtendedType, ok := sqlType.(gmstypes.ExtendedType); ok {

View File

@@ -1682,7 +1682,7 @@ func (t *AlterableDoltTable) isIncompatibleTypeChange(oldColumn *sql.Column, new
if !existingCol.TypeInfo.Equals(newCol.TypeInfo) {
if types.IsFormat_DOLT(t.Format()) {
// This is overly broad, we could narrow this down a bit
return true
return typeinfo.RequiresRewrite(existingCol.TypeInfo, newCol.TypeInfo)
}
if existingCol.Kind != newCol.Kind {
return true