MDEV-25654 only force HA_KEY_ALG_HASH for fast alter partition

not for any ALTER TABLE without ALTER_CHANGE_COLUMN.

This fixes galera_sr.MDEV-28971 test

followup for 0dcd30197ade
This commit is contained in:
Sergei Golubchik 2025-01-18 15:11:12 +01:00
parent b1f57a98a8
commit 782c4b94f0
4 changed files with 21 additions and 16 deletions

View File

@ -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 add partition (partition p3 values less than (maxvalue));
alter table t1 force; alter table t1 force;
drop table t1; 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 # End of 10.5 tests

View File

@ -721,4 +721,9 @@ alter table t1 force;
drop table t1; 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 --echo # End of 10.5 tests

View File

@ -328,6 +328,7 @@ public:
/** Name of table for the above error. */ /** Name of table for the above error. */
const char *fk_error_table= NULL; const char *fk_error_table= NULL;
bool modified_primary_key= false; bool modified_primary_key= false;
bool fast_alter_partition= false;
private: private:
char new_filename[FN_REFLEN + 1]; char new_filename[FN_REFLEN + 1];

View File

@ -9276,19 +9276,13 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
LEX_CSTRING tmp_name; LEX_CSTRING tmp_name;
bzero((char*) &key_create_info, sizeof(key_create_info)); bzero((char*) &key_create_info, sizeof(key_create_info));
if (key_info->algorithm == HA_KEY_ALG_LONG_HASH) if (key_info->algorithm == HA_KEY_ALG_LONG_HASH)
key_info->algorithm= (alter_info->flags & ALTER_CHANGE_COLUMN) ? key_info->algorithm= alter_ctx->fast_alter_partition ?
HA_KEY_ALG_UNDEF : HA_KEY_ALG_HASH; HA_KEY_ALG_HASH : HA_KEY_ALG_UNDEF;
/* /*
This one goes to mysql_prepare_create_table(): For fast alter partition we set HA_KEY_ALG_HASH above to make sure it
doesn't lose the hash property.
key_info->algorithm= key->key_create_info.algorithm; Otherwise we let mysql_prepare_create_table() decide if the hash field
is needed depending on the (possibly changed) data types.
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.
*/ */
key_create_info.algorithm= key_info->algorithm; 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; TABLE *table, *new_table= nullptr;
#ifdef WITH_PARTITION_STORAGE_ENGINE #ifdef WITH_PARTITION_STORAGE_ENGINE
bool partition_changed= false; bool partition_changed= false;
bool fast_alter_partition= false;
#endif #endif
/* /*
Create .FRM for new version of table with a temporary name. 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 Partitioning: part_info is prepared and returned via thd->work_part_info
*/ */
if (prep_alter_part_table(thd, table, alter_info, create_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); DBUG_RETURN(true);
} }
@ -10879,7 +10872,7 @@ do_continue:;
Note, one can run a separate "ALTER TABLE t1 FORCE;" statement Note, one can run a separate "ALTER TABLE t1 FORCE;" statement
before or after the partition change ALTER statement to upgrade data types. 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); Create_field::upgrade_data_types(alter_info->create_list);
if (create_info->check_fields(thd, alter_info, if (create_info->check_fields(thd, alter_info,
@ -10891,7 +10884,7 @@ do_continue:;
promote_first_timestamp_column(&alter_info->create_list); promote_first_timestamp_column(&alter_info->create_list);
#ifdef WITH_PARTITION_STORAGE_ENGINE #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 ALGORITHM and LOCK clauses are generally not allowed by the