From ab1191c0394ae687cba5aeaf5348a8534d64f191 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 13 Jul 2023 10:23:11 +0200 Subject: [PATCH] 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. --- sql/handler.cc | 2 +- sql/handler.h | 6 ------ sql/sql_class.cc | 4 +++- sql/sql_class.h | 9 ++++----- sql/sql_table.cc | 11 +++-------- storage/innobase/handler/ha_innodb.cc | 2 +- storage/innobase/handler/handler0alter.cc | 2 +- 7 files changed, 13 insertions(+), 23 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 49bc20976a3..bc54b7e1a3e 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -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; diff --git a/sql/handler.h b/sql/handler.h index 09b6cf08fab..e28cb871fbd 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -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; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 6fb034b00ce..d53887bd8f8 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -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 &table_fields) List_iterator cols(columns); List_iterator it(table_fields); DBUG_ENTER("Foreign_key::validate"); + if (old) + DBUG_RETURN(FALSE); // must be good while ((column= cols++)) { it.rewind(); diff --git a/sql/sql_class.h b/sql/sql_class.h index 65185b7f4b3..98c0f04a5c5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -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); /** diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 144ea9fe8a8..327d2bad3ac 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -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(key); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 15f7f842a78..f783b875295 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -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) { diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 2389c056245..5c8629733d6 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -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; }