Skip to content

Commit 0eac2f8

Browse files
author
Shlomi Noach
authored
Merge pull request #488 from github/check-unique-key-types
Check unique key types
2 parents ed0fc1c + 227f1de commit 0eac2f8

File tree

8 files changed

+44
-2
lines changed

8 files changed

+44
-2
lines changed

go/logic/inspect.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,33 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) {
121121
if err != nil {
122122
return err
123123
}
124-
if len(sharedUniqueKeys) == 0 {
124+
for i, sharedUniqueKey := range sharedUniqueKeys {
125+
this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &sharedUniqueKey.Columns)
126+
uniqueKeyIsValid := true
127+
for _, column := range sharedUniqueKey.Columns.Columns() {
128+
switch column.Type {
129+
case sql.FloatColumnType:
130+
{
131+
log.Warning("Will not use %+v as shared key due to FLOAT data type", sharedUniqueKey.Name)
132+
uniqueKeyIsValid = false
133+
}
134+
case sql.JSONColumnType:
135+
{
136+
// Noteworthy that at this time MySQL does not allow JSON indexing anyhow, but this code
137+
// will remain in place to potentially handle the future case where JSON is supported in indexes.
138+
log.Warning("Will not use %+v as shared key due to JSON data type", sharedUniqueKey.Name)
139+
uniqueKeyIsValid = false
140+
}
141+
}
142+
}
143+
if uniqueKeyIsValid {
144+
this.migrationContext.UniqueKey = sharedUniqueKeys[i]
145+
break
146+
}
147+
}
148+
if this.migrationContext.UniqueKey == nil {
125149
return fmt.Errorf("No shared unique key can be found after ALTER! Bailing out")
126150
}
127-
this.migrationContext.UniqueKey = sharedUniqueKeys[0]
128151
log.Infof("Chosen shared unique key is %s", this.migrationContext.UniqueKey.Name)
129152
if this.migrationContext.UniqueKey.HasNullable {
130153
if this.migrationContext.NullableUniqueKeyAllowed {
@@ -550,6 +573,11 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
550573
columnsList.GetColumn(columnName).Type = sql.JSONColumnType
551574
}
552575
}
576+
if strings.Contains(columnType, "float") {
577+
for _, columnsList := range columnsLists {
578+
columnsList.GetColumn(columnName).Type = sql.FloatColumnType
579+
}
580+
}
553581
if strings.HasPrefix(columnType, "enum") {
554582
for _, columnsList := range columnsLists {
555583
columnsList.GetColumn(columnName).Type = sql.EnumColumnType

go/sql/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
EnumColumnType = iota
2222
MediumIntColumnType = iota
2323
JSONColumnType = iota
24+
FloatColumnType = iota
2425
)
2526

2627
const maxMediumintUnsigned int32 = 16777215
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
drop table if exists gh_ost_test;
2+
create table gh_ost_test (
3+
f float,
4+
i int not null,
5+
ts timestamp default current_timestamp,
6+
dt datetime,
7+
key i_idx(i),
8+
unique key f_uidx(f)
9+
) auto_increment=1;
10+
11+
drop event if exists gh_ost_test;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
No shared unique key can be found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--alter="add column v varchar(32)"

0 commit comments

Comments
 (0)