From 7202076c77c49d175e4283e69c4bad8b08e711ff Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 19 Jan 2021 13:27:00 +0200 Subject: [PATCH 1/2] Generated column as part of UNIQUE (or PRIMARY) KEY Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- .../generated-columns57-unique/create.sql | 30 +++++++++++++++++++ .../ignore_versions | 1 + 2 files changed, 31 insertions(+) create mode 100644 localtests/generated-columns57-unique/create.sql create mode 100644 localtests/generated-columns57-unique/ignore_versions diff --git a/localtests/generated-columns57-unique/create.sql b/localtests/generated-columns57-unique/create.sql new file mode 100644 index 0000000..c75b5ff --- /dev/null +++ b/localtests/generated-columns57-unique/create.sql @@ -0,0 +1,30 @@ +drop table if exists gh_ost_test; +create table gh_ost_test ( + id int auto_increment, + `idb` varchar(36) CHARACTER SET utf8mb4 GENERATED ALWAYS AS (json_unquote(json_extract(`jsonobj`,_utf8mb4'$._id'))) STORED NOT NULL, + `jsonobj` json NOT NULL, + PRIMARY KEY (`id`,`idb`) +) auto_increment=1; + +insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":2}''); +insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":3}''); + +drop event if exists gh_ost_test; +delimiter ;; +create event gh_ost_test + on schedule every 1 second + starts current_timestamp + ends current_timestamp + interval 60 second + on completion not preserve + enable + do +begin + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":5}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":7}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":11}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":13}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":17}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":19}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":23}''); + insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":27}''); +end ;; diff --git a/localtests/generated-columns57-unique/ignore_versions b/localtests/generated-columns57-unique/ignore_versions new file mode 100644 index 0000000..b6de5f8 --- /dev/null +++ b/localtests/generated-columns57-unique/ignore_versions @@ -0,0 +1 @@ +(5.5|5.6) From b7b3bfbd34a405813549ffd1ce96032520d8cf73 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Tue, 19 Jan 2021 13:42:45 +0200 Subject: [PATCH 2/2] skip analysis of generated column data type in unique key Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/logic/inspect.go | 4 ++++ .../generated-columns57-unique/create.sql | 20 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/go/logic/inspect.go b/go/logic/inspect.go index fc70017..f36df0f 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -188,6 +188,10 @@ func (this *Inspector) inspectOriginalAndGhostTables() (err error) { } for _, column := range this.migrationContext.UniqueKey.Columns.Columns() { + if this.migrationContext.GhostTableVirtualColumns.GetColumn(column.Name) != nil { + // this is a virtual column + continue + } if this.migrationContext.MappedSharedColumns.HasTimezoneConversion(column.Name) { return fmt.Errorf("No support at this time for converting a column from DATETIME to TIMESTAMP that is also part of the chosen unique key. Column: %s, key: %s", column.Name, this.migrationContext.UniqueKey.Name) } diff --git a/localtests/generated-columns57-unique/create.sql b/localtests/generated-columns57-unique/create.sql index c75b5ff..7a63dd9 100644 --- a/localtests/generated-columns57-unique/create.sql +++ b/localtests/generated-columns57-unique/create.sql @@ -6,8 +6,8 @@ create table gh_ost_test ( PRIMARY KEY (`id`,`idb`) ) auto_increment=1; -insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":2}''); -insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":3}''); +insert into gh_ost_test (id, jsonobj) values (null, '{"_id":2}'); +insert into gh_ost_test (id, jsonobj) values (null, '{"_id":3}'); drop event if exists gh_ost_test; delimiter ;; @@ -19,12 +19,12 @@ create event gh_ost_test enable do begin - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":5}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":7}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":11}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":13}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":17}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":19}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":23}''); - insert into gh_ost_test (id, jsonobj) values (null, ''{"_id":27}''); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":5}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":7}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":11}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":13}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":17}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":19}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":23}'); + insert into gh_ost_test (id, jsonobj) values (null, '{"_id":27}'); end ;;