diff --git a/mysql-test/main/long_unique_bugs.result b/mysql-test/main/long_unique_bugs.result index 1caec209d9f..5ee8b65fbf6 100644 --- a/mysql-test/main/long_unique_bugs.result +++ b/mysql-test/main/long_unique_bugs.result @@ -741,4 +741,10 @@ insert into t1 select seq from seq_1_to_100; alter table t1 add partition (partition p3 values less than (maxvalue)); alter table t1 force; drop table t1; +# veirfy that duplicate has unique is detected +create table t1 (a blob unique); +alter table t1 add constraint constraint_1 unique (a); +Warnings: +Note 1831 Duplicate index `constraint_1`. This is deprecated and will be disallowed in a future release +drop table t1; # End of 10.5 tests diff --git a/mysql-test/main/long_unique_bugs.test b/mysql-test/main/long_unique_bugs.test index 6ad59fe6495..3fbe2a6b777 100644 --- a/mysql-test/main/long_unique_bugs.test +++ b/mysql-test/main/long_unique_bugs.test @@ -721,4 +721,9 @@ alter table t1 force; drop table t1; +--echo # veirfy that duplicate has unique is detected +create table t1 (a blob unique); +alter table t1 add constraint constraint_1 unique (a); +drop table t1; + --echo # End of 10.5 tests diff --git a/sql/sql_alter.h b/sql/sql_alter.h index c5e6cb9ba34..5e7f59650b2 100644 --- a/sql/sql_alter.h +++ b/sql/sql_alter.h @@ -328,6 +328,7 @@ public: /** Name of table for the above error. */ const char *fk_error_table= NULL; bool modified_primary_key= false; + bool fast_alter_partition= false; private: char new_filename[FN_REFLEN + 1]; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 3563c0fa982..aec81d8941e 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -9276,19 +9276,13 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, LEX_CSTRING tmp_name; bzero((char*) &key_create_info, sizeof(key_create_info)); if (key_info->algorithm == HA_KEY_ALG_LONG_HASH) - key_info->algorithm= (alter_info->flags & ALTER_CHANGE_COLUMN) ? - HA_KEY_ALG_UNDEF : HA_KEY_ALG_HASH; + key_info->algorithm= alter_ctx->fast_alter_partition ? + HA_KEY_ALG_HASH : HA_KEY_ALG_UNDEF; /* - This one goes to mysql_prepare_create_table(): - - key_info->algorithm= key->key_create_info.algorithm; - - For HA_KEY_ALG_LONG_HASH if we didn't change ANY column, we pass - HA_KEY_ALG_HASH to ensure mysql_prepare_create_table() does add_hash_field(). - This protects fast alter partition from losing hash properties. - In case of any column changes we drop algorithm to HA_KEY_ALG_UNDEF and - let decide mysql_prepare_create_table() if the hash field is needed - depending on new types. + For fast alter partition we set HA_KEY_ALG_HASH above to make sure it + doesn't lose the hash property. + Otherwise we let mysql_prepare_create_table() decide if the hash field + is needed depending on the (possibly changed) data types. */ key_create_info.algorithm= key_info->algorithm; /* @@ -10317,7 +10311,6 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, TABLE *table, *new_table= nullptr; #ifdef WITH_PARTITION_STORAGE_ENGINE bool partition_changed= false; - bool fast_alter_partition= false; #endif /* Create .FRM for new version of table with a temporary name. @@ -10844,7 +10837,7 @@ do_continue:; Partitioning: part_info is prepared and returned via thd->work_part_info */ if (prep_alter_part_table(thd, table, alter_info, create_info, - &partition_changed, &fast_alter_partition)) + &partition_changed, &alter_ctx.fast_alter_partition)) { DBUG_RETURN(true); } @@ -10879,7 +10872,7 @@ do_continue:; Note, one can run a separate "ALTER TABLE t1 FORCE;" statement before or after the partition change ALTER statement to upgrade data types. */ - if (IF_PARTITIONING(!fast_alter_partition, 1)) + if (!alter_ctx.fast_alter_partition) Create_field::upgrade_data_types(alter_info->create_list); if (create_info->check_fields(thd, alter_info, @@ -10891,7 +10884,7 @@ do_continue:; promote_first_timestamp_column(&alter_info->create_list); #ifdef WITH_PARTITION_STORAGE_ENGINE - if (fast_alter_partition) + if (alter_ctx.fast_alter_partition) { /* ALGORITHM and LOCK clauses are generally not allowed by the