Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions enginetest/queries/script_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -7620,6 +7620,20 @@ where
{3, "c", float64(4)},
},
},
{
Query: "alter table t modify column e enum('asdf', 'a', 'b', 'c', 'd');",
Expected: []sql.Row{
{types.NewOkResult(0)},
},
},
{
Query: "select i, e, e + 0 from t;",
Expected: []sql.Row{
{1, "a", float64(2)},
{2, "b", float64(3)},
{3, "c", float64(4)},
},
},
{
Query: "alter table t modify column e enum('abc');",
ExpectedErr: types.ErrConvertingToEnum,
Expand Down
2 changes: 1 addition & 1 deletion sql/rowexec/ddl_iters.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ func (i *modifyColumnIter) rewriteTable(ctx *sql.Context, rwt sql.RewritableTabl

oldEnum, isOldEnum := oldCol.Type.(sql.EnumType)
newEnum, isNewEnum := newCol.Type.(sql.EnumType)
if isOldEnum && isNewEnum && !oldEnum.Equals(newEnum) {
if isOldEnum && isNewEnum && !oldEnum.IsSubsetOf(newEnum) {
rewriteRequired = true
}

Expand Down
3 changes: 3 additions & 0 deletions sql/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ type EnumType interface {
Collation() CollationID
// IndexOf returns the index of the given string. If the string was not found, then this returns -1.
IndexOf(v string) int
// IsSubsetOf returns whether every element in this is also in |otherType|, with the same indexes.
// |otherType| may contain additional elements not in this.
IsSubsetOf(otherType EnumType) bool
// NumberOfElements returns the number of enumerations.
NumberOfElements() uint16
// Values returns the elements, in order, of every enumeration.
Expand Down
13 changes: 13 additions & 0 deletions sql/types/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ func (t EnumType) IndexOf(v string) int {
return -1
}

// IsSubsetOf implements the sql.EnumType interface.
func (t EnumType) IsSubsetOf(otherType sql.EnumType) bool {
if ot, ok := otherType.(EnumType); ok && t.collation.Equals(ot.collation) && len(t.idxToVal) <= len(ot.idxToVal) {
for i, val := range t.idxToVal {
if ot.idxToVal[i] != val {
return false
}
}
return true
}
return false
}

// NumberOfElements implements EnumType interface.
func (t EnumType) NumberOfElements() uint16 {
return uint16(len(t.idxToVal))
Expand Down
Loading