From 20c89f9f376dfd05a1eef5b2abc136d2f32c277d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 27 Feb 2019 03:36:37 +0100 Subject: [PATCH] MDEV-18712 InnoDB indexes are inconsistent with what defined in .frm for table after rebuilding table with index on blob when auto-adding a virtual LONG_UNIQUE_HASH_FIELD, fill in a Virtual_column_info for it, so that fill_alter_inplace_info() would know we're adding a virtual field (ALTER_ADD_VIRTUAL_COLUMN). --- mysql-test/main/long_unique_bugs.result | 10 ++++++++++ mysql-test/main/long_unique_bugs.test | 11 +++++++++++ sql/sql_table.cc | 2 ++ sql/unireg.cc | 2 +- 4 files changed, 24 insertions(+), 1 deletion(-) diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index 338b4072516..9a5f35a2e70 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -10,3 +10,13 @@ create temporary table tmp (a varchar(1024), b int, c int, d int, e linestring, load data infile 'load.data' into table tmp; delete from tmp; drop table t1; +create table t1 (b blob) engine=innodb; +alter table t1 add unique (b); +alter table t1 force; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `b` blob DEFAULT NULL, + UNIQUE KEY `b` (`b`) USING HASH +) ENGINE=InnoDB DEFAULT CHARSET=latin1 +drop table t1; diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index 3664cda66aa..d979a052547 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -1,3 +1,5 @@ +--source include/have_innodb.inc + # # MDEV-18707 Server crash in my_hash_sort_bin, ASAN heap-use-after-free in Field::is_null, server hang, corrupted double-linked list # @@ -15,3 +17,12 @@ delete from tmp; drop table t1; --let $datadir= `SELECT @@datadir` --remove_file $datadir/test/load.data + +# +# MDEV-18712 InnoDB indexes are inconsistent with what defined in .frm for table after rebuilding table with index on blob +# +create table t1 (b blob) engine=innodb; +alter table t1 add unique (b); +alter table t1 force; +show create table t1; +drop table t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 70a3b6044d9..cdf418a7cab 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3321,6 +3321,8 @@ static Create_field * add_hash_field(THD * thd, List *create_list, cf->length= cf->char_length= cf->pack_length= HA_HASH_FIELD_LENGTH; cf->invisible= INVISIBLE_FULL; cf->pack_flag|= FIELDFLAG_MAYBE_NULL; + cf->vcol_info= new (thd->mem_root) Virtual_column_info(); + cf->vcol_info->stored_in_db= false; uint num= 1; LEX_CSTRING field_name; field_name.str= (char *)thd->alloc(LONG_HASH_FIELD_NAME_LENGTH); diff --git a/sql/unireg.cc b/sql/unireg.cc index c84c4eaa973..25017400ba1 100644 --- a/sql/unireg.cc +++ b/sql/unireg.cc @@ -691,7 +691,7 @@ static bool pack_vcols(String *buf, List &create_fields, for (uint field_nr=0; (field= it++); field_nr++) { - if (field->vcol_info) + if (field->vcol_info && field->vcol_info->expr) if (pack_expression(buf, field->vcol_info, field_nr, field->vcol_info->stored_in_db ? VCOL_GENERATED_STORED : VCOL_GENERATED_VIRTUAL))