diff --git a/go/logic/inspect.go b/go/logic/inspect.go index bbf375f..b70f900 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -121,10 +121,33 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) { if err != nil { return err } - if len(sharedUniqueKeys) == 0 { + for i, sharedUniqueKey := range sharedUniqueKeys { + this.applyColumnTypes(this.migrationContext.DatabaseName, this.migrationContext.OriginalTableName, &sharedUniqueKey.Columns) + uniqueKeyIsValid := true + for _, column := range sharedUniqueKey.Columns.Columns() { + switch column.Type { + case sql.FloatColumnType: + { + log.Warning("Will not use %+v as shared key due to FLOAT data type", sharedUniqueKey.Name) + uniqueKeyIsValid = false + } + case sql.JSONColumnType: + { + // Noteworthy that at this time MySQL does not allow JSON indexing anyhow, but this code + // will remain in place to potentially handle the future case where JSON is supported in indexes. + log.Warning("Will not use %+v as shared key due to JSON data type", sharedUniqueKey.Name) + uniqueKeyIsValid = false + } + } + } + if uniqueKeyIsValid { + this.migrationContext.UniqueKey = sharedUniqueKeys[i] + break + } + } + if this.migrationContext.UniqueKey == nil { return fmt.Errorf("No shared unique key can be found after ALTER! Bailing out") } - this.migrationContext.UniqueKey = sharedUniqueKeys[0] log.Infof("Chosen shared unique key is %s", this.migrationContext.UniqueKey.Name) if this.migrationContext.UniqueKey.HasNullable { if this.migrationContext.NullableUniqueKeyAllowed { @@ -553,6 +576,11 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL columnsList.GetColumn(columnName).Type = sql.JSONColumnType } } + if strings.Contains(columnType, "float") { + for _, columnsList := range columnsLists { + columnsList.GetColumn(columnName).Type = sql.FloatColumnType + } + } if strings.HasPrefix(columnType, "enum") { for _, columnsList := range columnsLists { columnsList.GetColumn(columnName).Type = sql.EnumColumnType diff --git a/go/sql/types.go b/go/sql/types.go index fd6b01d..15a99ff 100644 --- a/go/sql/types.go +++ b/go/sql/types.go @@ -21,6 +21,7 @@ const ( EnumColumnType = iota MediumIntColumnType = iota JSONColumnType = iota + FloatColumnType = iota ) const maxMediumintUnsigned int32 = 16777215 diff --git a/localtests/fail-float-unique-key/create.sql b/localtests/fail-float-unique-key/create.sql new file mode 100644 index 0000000..a20d397 --- /dev/null +++ b/localtests/fail-float-unique-key/create.sql @@ -0,0 +1,11 @@ +drop table if exists gh_ost_test; +create table gh_ost_test ( + f float, + i int not null, + ts timestamp default current_timestamp, + dt datetime, + key i_idx(i), + unique key f_uidx(f) +) auto_increment=1; + +drop event if exists gh_ost_test; diff --git a/localtests/fail-float-unique-key/expect_failure b/localtests/fail-float-unique-key/expect_failure new file mode 100644 index 0000000..4373a4e --- /dev/null +++ b/localtests/fail-float-unique-key/expect_failure @@ -0,0 +1 @@ +No shared unique key can be found diff --git a/localtests/no-unique-key/extra_args b/localtests/fail-float-unique-key/extra_args similarity index 100% rename from localtests/no-unique-key/extra_args rename to localtests/fail-float-unique-key/extra_args diff --git a/localtests/no-unique-key/create.sql b/localtests/fail-no-unique-key/create.sql similarity index 100% rename from localtests/no-unique-key/create.sql rename to localtests/fail-no-unique-key/create.sql diff --git a/localtests/no-unique-key/expect_failure b/localtests/fail-no-unique-key/expect_failure similarity index 100% rename from localtests/no-unique-key/expect_failure rename to localtests/fail-no-unique-key/expect_failure diff --git a/localtests/fail-no-unique-key/extra_args b/localtests/fail-no-unique-key/extra_args new file mode 100644 index 0000000..b13e72c --- /dev/null +++ b/localtests/fail-no-unique-key/extra_args @@ -0,0 +1 @@ +--alter="add column v varchar(32)"