mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
cleanup: key->key_create_info.check_for_duplicate_indexes -> key->old
mark old keys in the ALTER TABLE with the `old` flag, not with the `key_create_info.check_for_duplicate_indexes`. This allows to mark old foreign keys too.
This commit is contained in:
@ -110,7 +110,7 @@ static handlerton *installed_htons[128];
|
||||
#define BITMAP_STACKBUF_SIZE (128/8)
|
||||
|
||||
KEY_CREATE_INFO default_key_create_info=
|
||||
{ HA_KEY_ALG_UNDEF, 0, 0, {NullS, 0}, {NullS, 0}, true };
|
||||
{ HA_KEY_ALG_UNDEF, 0, 0, {NullS, 0}, {NullS, 0} };
|
||||
|
||||
/* number of entries in handlertons[] */
|
||||
ulong total_ha= 0;
|
||||
|
@ -2550,12 +2550,6 @@ typedef struct st_key_create_information
|
||||
uint flags; /* HA_USE.. flags */
|
||||
LEX_CSTRING parser_name;
|
||||
LEX_CSTRING comment;
|
||||
/**
|
||||
A flag to determine if we will check for duplicate indexes.
|
||||
This typically means that the key information was specified
|
||||
directly by the user (set by the parser).
|
||||
*/
|
||||
bool check_for_duplicate_indexes;
|
||||
} KEY_CREATE_INFO;
|
||||
|
||||
|
||||
|
@ -177,7 +177,7 @@ Key::Key(const Key &rhs, MEM_ROOT *mem_root)
|
||||
name(rhs.name),
|
||||
option_list(rhs.option_list),
|
||||
generated(rhs.generated), invisible(false),
|
||||
without_overlaps(rhs.without_overlaps), period(rhs.period)
|
||||
without_overlaps(rhs.without_overlaps), old(rhs.old), period(rhs.period)
|
||||
{
|
||||
list_copy_and_replace_each_value(columns, mem_root);
|
||||
}
|
||||
@ -285,6 +285,8 @@ bool Foreign_key::validate(List<Create_field> &table_fields)
|
||||
List_iterator<Key_part_spec> cols(columns);
|
||||
List_iterator<Create_field> it(table_fields);
|
||||
DBUG_ENTER("Foreign_key::validate");
|
||||
if (old)
|
||||
DBUG_RETURN(FALSE); // must be good
|
||||
while ((column= cols++))
|
||||
{
|
||||
it.rewind();
|
||||
|
@ -423,6 +423,7 @@ public:
|
||||
bool generated;
|
||||
bool invisible;
|
||||
bool without_overlaps;
|
||||
bool old;
|
||||
Lex_ident period;
|
||||
|
||||
Key(enum Keytype type_par, const LEX_CSTRING *name_arg,
|
||||
@ -430,7 +431,7 @@ public:
|
||||
:DDL_options(ddl_options),
|
||||
type(type_par), key_create_info(default_key_create_info),
|
||||
name(*name_arg), option_list(NULL), generated(generated_arg),
|
||||
invisible(false), without_overlaps(false)
|
||||
invisible(false), without_overlaps(false), old(false)
|
||||
{
|
||||
key_create_info.algorithm= algorithm_arg;
|
||||
}
|
||||
@ -441,7 +442,7 @@ public:
|
||||
:DDL_options(ddl_options),
|
||||
type(type_par), key_create_info(*key_info_arg), columns(*cols),
|
||||
name(*name_arg), option_list(create_opt), generated(generated_arg),
|
||||
invisible(false), without_overlaps(false)
|
||||
invisible(false), without_overlaps(false), old(false)
|
||||
{}
|
||||
Key(const Key &rhs, MEM_ROOT *mem_root);
|
||||
virtual ~Key() = default;
|
||||
@ -479,9 +480,7 @@ public:
|
||||
ref_db(*ref_db_arg), ref_table(*ref_table_arg), ref_columns(*ref_cols),
|
||||
delete_opt(delete_opt_arg), update_opt(update_opt_arg),
|
||||
match_opt(match_opt_arg)
|
||||
{
|
||||
// We don't check for duplicate FKs.
|
||||
key_create_info.check_for_duplicate_indexes= false;
|
||||
{
|
||||
}
|
||||
Foreign_key(const Foreign_key &rhs, MEM_ROOT *mem_root);
|
||||
/**
|
||||
|
@ -3187,7 +3187,7 @@ static void check_duplicate_key(THD *thd, const Key *key, const KEY *key_info,
|
||||
Check is requested if the key was explicitly created or altered
|
||||
by the user (unless it's a foreign key).
|
||||
*/
|
||||
if (!key->key_create_info.check_for_duplicate_indexes || key->generated)
|
||||
if (key->old || key->type == Key::FOREIGN_KEY || key->generated)
|
||||
return;
|
||||
|
||||
for (const Key &k : *key_list)
|
||||
@ -9127,12 +9127,6 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
if (key_info->flags & HA_USES_COMMENT)
|
||||
key_create_info.comment= key_info->comment;
|
||||
|
||||
/*
|
||||
We're refreshing an already existing index. Since the index is not
|
||||
modified, there is no need to check for duplicate indexes again.
|
||||
*/
|
||||
key_create_info.check_for_duplicate_indexes= false;
|
||||
|
||||
if (key_info->flags & HA_SPATIAL)
|
||||
key_type= Key::SPATIAL;
|
||||
else if (key_info->flags & HA_NOSAME)
|
||||
@ -9165,6 +9159,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
|
||||
&key_parts, key_info->option_list, DDL_options());
|
||||
key->without_overlaps= key_info->without_overlaps;
|
||||
key->period= table->s->period.name;
|
||||
key->old= true;
|
||||
new_key_list.push_back(key, thd->mem_root);
|
||||
}
|
||||
if (long_hash_key)
|
||||
@ -9716,7 +9711,7 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table,
|
||||
|
||||
while (Key *key= fk_list_it++)
|
||||
{
|
||||
if (key->type != Key::FOREIGN_KEY)
|
||||
if (key->type != Key::FOREIGN_KEY || key->old)
|
||||
continue;
|
||||
|
||||
Foreign_key *fk= static_cast<Foreign_key*>(key);
|
||||
|
@ -12196,7 +12196,7 @@ create_table_info_t::create_foreign_keys()
|
||||
}
|
||||
|
||||
while (Key* key = key_it++) {
|
||||
if (key->type != Key::FOREIGN_KEY)
|
||||
if (key->type != Key::FOREIGN_KEY || key->old)
|
||||
continue;
|
||||
|
||||
if (tmp_table) {
|
||||
|
@ -3020,7 +3020,7 @@ innobase_get_foreign_key_info(
|
||||
*n_add_fk = 0;
|
||||
|
||||
for (Key& key : alter_info->key_list) {
|
||||
if (key.type != Key::FOREIGN_KEY) {
|
||||
if (key.type != Key::FOREIGN_KEY || key.old) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user