diff options
author | Aleksey Midenkov <midenok@gmail.com> | 2019-12-25 12:40:48 +0300 |
---|---|---|
committer | Aleksey Midenkov <midenok@gmail.com> | 2019-12-25 12:40:48 +0300 |
commit | 414e5f7f5544a9baf1bf1fc31b01b387a73ef3b4 (patch) | |
tree | 609408ecdbcc29c52c2c6e0c1c349b87cdabb7f6 | |
parent | b3cfde8c764da4816f940c99c86fa3d64780aba1 (diff) | |
download | mariadb-git-414e5f7f5544a9baf1bf1fc31b01b387a73ef3b4.tar.gz |
MDEV-20865 foreign_keys and referenced_keys objects in TABLE_SHARE
-rw-r--r-- | mysql-test/main/foreign_key.result | 6 | ||||
-rw-r--r-- | mysql-test/main/foreign_key.test | 5 | ||||
-rw-r--r-- | sql/sql_base.cc | 2 | ||||
-rw-r--r-- | sql/sql_list.h | 6 | ||||
-rw-r--r-- | sql/sql_show.cc | 12 | ||||
-rw-r--r-- | sql/sql_table.cc | 37 | ||||
-rw-r--r-- | sql/sql_truncate.cc | 3 | ||||
-rw-r--r-- | sql/table.cc | 53 | ||||
-rw-r--r-- | sql/table.h | 6 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 52 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.h | 5 | ||||
-rw-r--r-- | storage/mroonga/ha_mroonga.cpp | 49 | ||||
-rw-r--r-- | storage/mroonga/ha_mroonga.hpp | 2 |
13 files changed, 87 insertions, 151 deletions
diff --git a/mysql-test/main/foreign_key.result b/mysql-test/main/foreign_key.result index 21716737db7..d34602ee242 100644 --- a/mysql-test/main/foreign_key.result +++ b/mysql-test/main/foreign_key.result @@ -121,6 +121,12 @@ flush tables t1, t2; Warnings: Note 1105 Referenced table test.t1 is not opened drop table t2, t1; +create table t1 (id int primary key); +create table t2 (id int references t1(id)) select id from t1; +flush tables; +Warnings: +Note 1105 Referenced table test.t1 is not opened +drop table t2, t1; # Check rename column, lock tables create or replace table t1 (id int primary key); create or replace table t2 (id int primary key); diff --git a/mysql-test/main/foreign_key.test b/mysql-test/main/foreign_key.test index 3d3fe54aafe..5c710edf651 100644 --- a/mysql-test/main/foreign_key.test +++ b/mysql-test/main/foreign_key.test @@ -153,6 +153,11 @@ select * from t1, t2; flush tables t1, t2; drop table t2, t1; +create table t1 (id int primary key); +create table t2 (id int references t1(id)) select id from t1; +flush tables; +drop table t2, t1; + --echo # Check rename column, lock tables create or replace table t1 (id int primary key); create or replace table t2 (id int primary key); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 25b48c7ab98..766c5ec0d04 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4672,7 +4672,7 @@ handle_table(THD *thd, Query_tables_list *prelocking_ctx, if (table->s->referenced_by_foreign_key()) { - List_iterator<FOREIGN_KEY_INFO> fk_list_it(*table->s->referenced_keys); + List_iterator<FOREIGN_KEY_INFO> fk_list_it(table->s->referenced_keys); FOREIGN_KEY_INFO *fk; Query_arena *arena, backup; diff --git a/sql/sql_list.h b/sql/sql_list.h index 9d1c01a484d..53e442c5ad0 100644 --- a/sql/sql_list.h +++ b/sql/sql_list.h @@ -299,7 +299,7 @@ public: inline list_node* first_node() { return first;} inline void *head() { return first->info; } inline void **head_ref() { return first != &end_of_list ? &first->info : 0; } - inline bool is_empty() { return first == &end_of_list ; } + inline bool is_empty() const { return first == &end_of_list ; } inline list_node *last_ref() { return &end_of_list; } inline bool add_unique(void *info, List_eq *eq) { @@ -739,7 +739,7 @@ class base_ilist public: inline void empty() { first= &last; last.prev= &first; } base_ilist() { empty(); } - inline bool is_empty() { return first == &last; } + inline bool is_empty() const { return first == &last; } // Returns true if p is the last "real" object in the list, // i.e. p->next points to the sentinel. inline bool is_last(ilink *p) { return p->next == NULL || p->next == &last; } @@ -820,7 +820,7 @@ public: I_List() :base_ilist() {} inline bool is_last(T *p) { return base_ilist::is_last(p); } inline void empty() { base_ilist::empty(); } - inline bool is_empty() { return base_ilist::is_empty(); } + inline bool is_empty() const { return base_ilist::is_empty(); } inline void append(T* a) { base_ilist::append(a); } inline void push_back(T* a) { base_ilist::push_back(a); } inline T* get() { return (T*) base_ilist::get(); } diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 8eae74d27b7..c4a721bfa38 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -6874,10 +6874,10 @@ static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables, } } - if (show_table->s->foreign_keys) + if (!show_table->s->foreign_keys.is_empty()) { FOREIGN_KEY_INFO *f_key_info; - List_iterator_fast<FOREIGN_KEY_INFO> it(*show_table->s->foreign_keys); + List_iterator_fast<FOREIGN_KEY_INFO> it(show_table->s->foreign_keys); while ((f_key_info=it++)) { if (store_constraints(thd, table, db_name, table_name, @@ -7062,10 +7062,10 @@ static int get_schema_key_column_usage_record(THD *thd, } } - if (show_table->s->foreign_keys) + if (!show_table->s->foreign_keys.is_empty()) { FOREIGN_KEY_INFO *f_key_info; - List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(*show_table->s->foreign_keys); + List_iterator_fast<FOREIGN_KEY_INFO> fkey_it(show_table->s->foreign_keys); while ((f_key_info= fkey_it++)) { LEX_CSTRING *f_info; @@ -7806,7 +7806,7 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables, thd->clear_error(); DBUG_RETURN(0); } - if (!tables->view && tables->table->s->foreign_keys) + if (!tables->view && !tables->table->s->foreign_keys.is_empty()) { TABLE *show_table= tables->table; show_table->file->info(HA_STATUS_VARIABLE | @@ -7814,7 +7814,7 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables, HA_STATUS_TIME); FOREIGN_KEY_INFO *f_key_info; - List_iterator_fast<FOREIGN_KEY_INFO> it(*show_table->s->foreign_keys); + List_iterator_fast<FOREIGN_KEY_INFO> it(show_table->s->foreign_keys); while ((f_key_info= it++)) { restore_record(table, s->default_values); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 937af3ae0cf..5105891a457 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6260,10 +6260,10 @@ drop_create_field: } } } - else if (table->s->foreign_keys) + else if (!table->s->foreign_keys.is_empty()) { FOREIGN_KEY_INFO *f_key; - List_iterator<FOREIGN_KEY_INFO> fk_key_it(*table->s->foreign_keys); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(table->s->foreign_keys); while ((f_key= fk_key_it++)) { if (my_strcasecmp(system_charset_info, f_key->foreign_id->str, @@ -6361,10 +6361,10 @@ drop_create_field: } } } - else if (table->s->foreign_keys) + else if (!table->s->foreign_keys.is_empty()) { FOREIGN_KEY_INFO *f_key; - List_iterator<FOREIGN_KEY_INFO> fk_key_it(*table->s->foreign_keys); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(table->s->foreign_keys); while ((f_key= fk_key_it++)) { if (my_strcasecmp(system_charset_info, f_key->foreign_id->str, @@ -8166,14 +8166,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, 0 != my_strcasecmp(system_charset_info, def->change.str, def->field_name.str)) { - if (table->s->foreign_keys && - table->s->foreign_keys->get(thd, refs_to_close, def->change, true)) + if (!table->s->foreign_keys.is_empty() && + table->s->foreign_keys.get(thd, refs_to_close, def->change, true)) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); DBUG_RETURN(1); } - if (table->s->referenced_keys && - table->s->referenced_keys->get(thd, refs_to_close, def->change, false)) + if (!table->s->referenced_keys.is_empty() && + table->s->referenced_keys.get(thd, refs_to_close, def->change, false)) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); DBUG_RETURN(1); @@ -8721,11 +8721,12 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, } } - if (!alter_info->check_constraint_list.is_empty() && table->s->foreign_keys) + if (!alter_info->check_constraint_list.is_empty() && + !table->s->foreign_keys.is_empty()) { /* Check the table FOREIGN KEYs for name duplications. */ FOREIGN_KEY_INFO *f_key; - List_iterator<FOREIGN_KEY_INFO> fk_key_it(*table->s->foreign_keys); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(table->s->foreign_keys); while ((f_key= fk_key_it++)) { List_iterator_fast<Virtual_column_info> @@ -8992,14 +8993,14 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, DBUG_ENTER("fk_prepare_copy_alter_table"); - if (table->s->referenced_keys) + if (!table->s->referenced_keys.is_empty()) { /* Remove from the list all foreign keys in which table participates as parent which are to be dropped by this ALTER TABLE. This is possible when a foreign key has the same table as child and parent. */ - List_iterator<FOREIGN_KEY_INFO> fk_parent_key_it(*table->s->referenced_keys); + List_iterator<FOREIGN_KEY_INFO> fk_parent_key_it(table->s->referenced_keys); while ((f_key= fk_parent_key_it++)) { @@ -9032,9 +9033,9 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, as it might break referential integrity. OTOH it is OK to do so if foreign_key_checks are disabled. */ - if (!table->s->referenced_keys->is_empty() && + if (!table->s->referenced_keys.is_empty() && !(thd->variables.option_bits & OPTION_NO_FOREIGN_KEY_CHECKS)) - alter_ctx->set_fk_error_if_delete_row(table->s->referenced_keys->head()); + alter_ctx->set_fk_error_if_delete_row(table->s->referenced_keys.head()); fk_parent_key_it.rewind(); while ((f_key= fk_parent_key_it++)) @@ -9084,13 +9085,13 @@ static bool fk_prepare_copy_alter_table(THD *thd, TABLE *table, } } - if (table->s->foreign_keys) + if (!table->s->foreign_keys.is_empty()) { /* Remove from the list all foreign keys which are to be dropped by this ALTER TABLE. */ - List_iterator<FOREIGN_KEY_INFO> fk_key_it(*table->s->foreign_keys); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(table->s->foreign_keys); while ((f_key= fk_key_it++)) { @@ -9745,11 +9746,11 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, { if (drop->type == Alter_drop::CHECK_CONSTRAINT) { - if (table->s->foreign_keys) + if (!table->s->foreign_keys.is_empty()) { /* Test if there is a FOREIGN KEY with this name. */ FOREIGN_KEY_INFO *f_key; - List_iterator<FOREIGN_KEY_INFO> fk_key_it(*table->s->foreign_keys); + List_iterator<FOREIGN_KEY_INFO> fk_key_it(table->s->foreign_keys); while ((f_key= fk_key_it++)) { diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index b29623557b7..a2c837248ec 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -135,8 +135,7 @@ fk_truncate_illegal_if_parent(THD *thd, TABLE *table) of foreign keys referencing this table in order to check the name of the child (dependent) tables. */ - DBUG_ASSERT(table->s->referenced_keys); - it.init(*table->s->referenced_keys); + it.init(table->s->referenced_keys); /* Loop over the set of foreign keys for which this table is a parent. */ while ((fk_info= it++)) diff --git a/sql/table.cc b/sql/table.cc index b1cd2ab2943..761c0bf2b35 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -341,6 +341,8 @@ TABLE_SHARE *alloc_table_share(const char *db, const char *table_name, share->normalized_path.length= path_length; share->table_category= get_table_category(& share->db, & share->table_name); share->open_errno= ENOENT; + share->foreign_keys.empty(); + share->referenced_keys.empty(); /* The following will be updated in open_table_from_share */ share->can_do_row_logging= 1; if (share->table_category == TABLE_CATEGORY_LOG) @@ -428,6 +430,8 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, share->frm_version= FRM_VER_CURRENT; share->not_usable_by_query_cache= 1; share->can_do_row_logging= 0; // No row logging + share->foreign_keys.empty(); + share->referenced_keys.empty(); /* table_map_id is also used for MERGE tables to suppress repeated @@ -9341,21 +9345,9 @@ bool TABLE_SHARE::update_foreign_keys(THD *thd, Alter_info *alter_info, Foreign_key *src= static_cast<Foreign_key*>(key); - if (!foreign_keys) - { - foreign_keys= (FK_list *) alloc_root( - &mem_root, sizeof(FK_list)); - if (unlikely(!foreign_keys)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); - return true; - } - foreign_keys->empty(); - } - FOREIGN_KEY_INFO *dst= (FOREIGN_KEY_INFO *) alloc_root( &mem_root, sizeof(FOREIGN_KEY_INFO)); - if (unlikely(foreign_keys->push_back(dst, &mem_root))) + if (unlikely(foreign_keys.push_back(dst, &mem_root))) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); return true; @@ -9396,10 +9388,10 @@ bool TABLE_SHARE::update_foreign_keys(THD *thd, Alter_info *alter_info, } } - if (!foreign_keys) + if (foreign_keys.is_empty()) return false; - List_iterator_fast<FOREIGN_KEY_INFO> fk_it(*foreign_keys); + List_iterator_fast<FOREIGN_KEY_INFO> fk_it(foreign_keys); while (FOREIGN_KEY_INFO *fk= fk_it++) { if (!cmp(fk->referenced_db, &db) && !cmp(fk->referenced_table, &table_name)) @@ -9447,17 +9439,6 @@ bool TABLE_SHARE::update_foreign_keys(THD *thd, Alter_info *alter_info, if (!el) continue; Mutex_lock share_mutex(&el->share->LOCK_share); - if (!el->share->referenced_keys) - { - FK_list* list= (FK_list*)alloc_root(&el->share->mem_root, sizeof(FK_list)); - if (unlikely(!list)) - { - my_error(ER_OUT_OF_RESOURCES, MYF(0)); - return true; - } - list->empty(); - el->share->referenced_keys= list; - } key_it.rewind(); while (Key* key= key_it++) { @@ -9472,7 +9453,7 @@ bool TABLE_SHARE::update_foreign_keys(THD *thd, Alter_info *alter_info, FOREIGN_KEY_INFO *dst= (FOREIGN_KEY_INFO *) alloc_root( &el->share->mem_root, sizeof(FOREIGN_KEY_INFO)); - if (unlikely(el->share->referenced_keys->push_back(dst, &el->share->mem_root))) + if (unlikely(el->share->referenced_keys.push_back(dst, &el->share->mem_root))) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); return true; @@ -9527,9 +9508,9 @@ void TABLE_SHARE::revert_referenced_shares(THD *thd, Table_ident_set &ref_tables { Share_lock share_lock(thd, it->db.str, it->table.str); TDC_element *el= share_lock.element; - if (!el || !el->share->referenced_keys) + if (!el || el->share->referenced_keys.is_empty()) continue; - List_iterator<FOREIGN_KEY_INFO> fk_it(*el->share->referenced_keys); + List_iterator<FOREIGN_KEY_INFO> fk_it(el->share->referenced_keys); while (FOREIGN_KEY_INFO* fk= fk_it++) { if (!cmp(fk->foreign_db, &db) && !cmp(fk->foreign_table, &table_name)) @@ -9595,14 +9576,14 @@ bool release_ref_shares(THD *thd, TABLE_LIST *t) Table_ident_set tables; - if (share->foreign_keys && share->foreign_keys->get(thd, tables, false)) + if (!share->foreign_keys.is_empty() && share->foreign_keys.get(thd, tables, false)) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); tdc_release_share(share); return true; } - if (share->referenced_keys && share->referenced_keys->get(thd, tables, true)) + if (!share->referenced_keys.is_empty() && share->referenced_keys.get(thd, tables, true)) { my_error(ER_OUT_OF_RESOURCES, MYF(0)); tdc_release_share(share); @@ -9650,7 +9631,7 @@ bool TABLE_SHARE::check_foreign_keys(THD *thd) List_iterator_fast<FOREIGN_KEY_INFO> ref_it; List_iterator_fast<FOREIGN_KEY_INFO> fk_it; if (referenced_by_foreign_key()) { - ref_it.init(*referenced_keys); + ref_it.init(referenced_keys); while (FOREIGN_KEY_INFO *rk= ref_it++) { TDC_element *el= tdc_lock_share(thd, rk->foreign_db->str, rk->foreign_table->str); @@ -9677,7 +9658,7 @@ bool TABLE_SHARE::check_foreign_keys(THD *thd) my_error(ER_OUT_OF_RESOURCES, MYF(0)); return true; } - fk_it.init(*el->share->foreign_keys); + fk_it.init(el->share->foreign_keys); FOREIGN_KEY_INFO *fk; bool found_table= false; while ((fk= fk_it++)) @@ -9720,8 +9701,8 @@ bool TABLE_SHARE::check_foreign_keys(THD *thd) } } } - if (foreign_keys) { - fk_it.init(*foreign_keys); + if (!foreign_keys.is_empty()) { + fk_it.init(foreign_keys); while (FOREIGN_KEY_INFO *fk= fk_it++) { TDC_element *el= tdc_lock_share(thd, fk->referenced_db->str, fk->referenced_table->str); @@ -9748,7 +9729,7 @@ bool TABLE_SHARE::check_foreign_keys(THD *thd) my_error(ER_OUT_OF_RESOURCES, MYF(0)); return true; } - ref_it.init(*el->share->referenced_keys); + ref_it.init(el->share->referenced_keys); FOREIGN_KEY_INFO *rk; bool found_table= false; while ((rk= ref_it++)) diff --git a/sql/table.h b/sql/table.h index 8a602c09767..cfb5fc77d47 100644 --- a/sql/table.h +++ b/sql/table.h @@ -643,15 +643,15 @@ struct TABLE_SHARE Field **field; Field **found_next_number_field; KEY *key_info; /* data of keys in database */ - FK_list *foreign_keys; - FK_list *referenced_keys; + FK_list foreign_keys; + FK_list referenced_keys; bool update_foreign_keys(THD *thd, Alter_info *alter_info, Table_ident_set &ref_tables); void revert_referenced_shares(THD *thd, Table_ident_set &ref_tables); bool check_foreign_keys(THD *thd); bool referenced_by_foreign_key() const { - return referenced_keys && !referenced_keys->is_empty(); + return !referenced_keys.is_empty(); } Virtual_column_info **check_constraints; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 3a46c467e4a..6c3d5e3fb38 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -5845,19 +5845,11 @@ static FOREIGN_KEY_INFO* get_foreign_key_info(THD* thd, TABLE_SHARE* s, dict_foreign_t* foreign); /* TODO: Temporary until MDEV-21051 Store FK info in FRM files */ -FK_list* -ha_innobase::build_foreign_list(THD* thd, dict_foreign_set& foreign_set, +void +ha_innobase::build_foreign_list(FK_list& result_list, + THD* thd, dict_foreign_set& foreign_set, bool& err) const { - FK_list* result_list - = (FK_list*)alloc_root( - &table->s->mem_root, sizeof(FK_list)); - if (unlikely(!result_list)) { - err = true; - return NULL; - } - result_list->empty(); - m_prebuilt->trx->op_info = "getting list of foreign keys"; mutex_enter(&dict_sys.mutex); @@ -5872,15 +5864,13 @@ ha_innobase::build_foreign_list(THD* thd, dict_foreign_set& foreign_set, break; } - err = result_list->push_back(key_info, &table->s->mem_root); + err = result_list.push_back(key_info, &table->s->mem_root); if (err) break; } mutex_exit(&dict_sys.mutex); m_prebuilt->trx->op_info = ""; - - return result_list; } /** Open an InnoDB table @@ -6154,40 +6144,33 @@ no_such_table: /* TODO: Temporary until MDEV-21051 Store FK info in FRM files */ /* Non-null s->referenced_keys now temporarily serves as indicator of initialized FK structures. This will change when FK info will be loaded from FRM */ - if (!table->s->referenced_keys + if (table->s->referenced_keys.is_empty() + && table->s->foreign_keys.is_empty() && table->s->tmp_table == NO_TMP_TABLE) { bool err = false; mysql_mutex_lock(&table->s->LOCK_share); - if (!table->s->referenced_keys) { - DBUG_ASSERT(!table->s->foreign_keys); + if (table->s->foreign_keys.is_empty()) { + DBUG_ASSERT(table->s->foreign_keys.is_empty()); if (!m_prebuilt->table->foreign_set.empty()) { - table->s->foreign_keys = build_foreign_list( + build_foreign_list( + table->s->foreign_keys, thd, m_prebuilt->table->foreign_set, err); } - if (!err - && !m_prebuilt->table->referenced_set.empty()) { - table->s->referenced_keys = build_foreign_list( + } + if (!err && table->s->referenced_keys.is_empty()) { + if (!m_prebuilt->table->referenced_set.empty()) { + build_foreign_list( + table->s->referenced_keys, thd, m_prebuilt->table->referenced_set, err); } - if (!err && !table->s->referenced_keys) { - FK_list* list = (FK_list*)alloc_root( - &table->s->mem_root, sizeof(FK_list)); - if (unlikely(!list)) { - set_my_errno(ENOMEM); - DBUG_RETURN(HA_ERR_OUT_OF_MEM); - } - list->empty(); - table->s->referenced_keys = list; - } } mysql_mutex_unlock(&table->s->LOCK_share); if (unlikely(err)) { set_my_errno(ENOMEM); DBUG_RETURN(HA_ERR_OUT_OF_MEM); } - DBUG_ASSERT(table->s->referenced_keys); } DBUG_RETURN(0); @@ -12372,7 +12355,7 @@ create_table_info_t::create_foreign_keys() create_name[bufend - create_name] = '\0'; } - List_iterator_fast<FOREIGN_KEY_INFO> key_it(*m_form->s->foreign_keys); + List_iterator_fast<FOREIGN_KEY_INFO> key_it(m_form->s->foreign_keys); dict_table_t* table = dict_table_get_low(name); if (!table) { @@ -12844,8 +12827,7 @@ int create_table_info_t::create_table(bool create_fk) dict_table_get_all_fts_indexes(m_table, fts->indexes); } - dberr_t err = create_fk && m_form->s->foreign_keys - && !m_form->s->foreign_keys->is_empty() + dberr_t err = create_fk && !m_form->s->foreign_keys.is_empty() ? create_foreign_keys() : DB_SUCCESS; if (err == DB_SUCCESS) { diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 1b5b0e3be6e..0fe7a852632 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -501,8 +501,9 @@ protected: bool m_mysql_has_locked; private: - FK_list* - build_foreign_list(THD* thd, dict_foreign_set& foreign_set, + void + build_foreign_list(FK_list& result_list, + THD* thd, dict_foreign_set& foreign_set, bool& err) const; }; diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp index a2123e4300e..fc469bb1d49 100644 --- a/storage/mroonga/ha_mroonga.cpp +++ b/storage/mroonga/ha_mroonga.cpp @@ -4905,35 +4905,13 @@ error: } /* TODO: Temporary until MDEV-21051 Store FK info in FRM files */ -FK_list *ha_mroonga::build_foreign_list(bool &err, bool referenced) +void ha_mroonga::build_foreign_list(FK_list &fk_list, bool &err) { - FK_list fk_list; THD *thd= ha_thd(); MEM_ROOT *old_root= thd->mem_root; thd->mem_root= &table->s->mem_root; - if (referenced) - { - err= storage_get_foreign_key_list(thd, &fk_list); - } - else - { - err= storage_get_foreign_key_list(thd, &fk_list); - } + err= storage_get_foreign_key_list(thd, &fk_list); thd->mem_root= old_root; - - if (fk_list.is_empty()) - return NULL; - - FK_list *result_list= (FK_list *) alloc_root( - &table->s->mem_root, sizeof(FK_list)); - if (unlikely(!result_list)) - { - err= true; - return NULL; - } - result_list->empty(); - result_list->copy(&fk_list, &table->s->mem_root); - return result_list; } int ha_mroonga::open(const char *name, @@ -4965,37 +4943,20 @@ int ha_mroonga::open(const char *name, } else { error = storage_open(name, mode, open_options); /* TODO: Temporary until MDEV-21051 Store FK info in FRM files */ - if (!error && !table->s->referenced_keys && + if (!error && table->s->foreign_keys.is_empty() && table->s->tmp_table == NO_TMP_TABLE) { bool err= false; mysql_mutex_lock(&table->s->LOCK_share); - if (!table->s->referenced_keys) + if (table->s->foreign_keys.is_empty()) { - DBUG_ASSERT(!table->s->foreign_keys); - table->s->foreign_keys= build_foreign_list(err, false); - if (!err) - { - table->s->referenced_keys= build_foreign_list(err, true); - } + build_foreign_list(table->s->foreign_keys, err); } mysql_mutex_unlock(&table->s->LOCK_share); - if (!table->s->referenced_keys) - { - /* Assign some empty list to indicate that we don't need to initialize - * this TABLE_SHARE anymore. */ - static FK_list empty_list; - DBUG_ASSERT(empty_list.is_empty()); - table->s->referenced_keys= &empty_list; - } if (unlikely(err)) { error= HA_ERR_OUT_OF_MEM; } - else - { - DBUG_ASSERT(table->s->referenced_keys); - } } } diff --git a/storage/mroonga/ha_mroonga.hpp b/storage/mroonga/ha_mroonga.hpp index 5bac14290f5..ef49ebe8775 100644 --- a/storage/mroonga/ha_mroonga.hpp +++ b/storage/mroonga/ha_mroonga.hpp @@ -1297,7 +1297,7 @@ private: qc_engine_callback *engine_callback, ulonglong *engine_data); - FK_list *build_foreign_list(bool &err, bool referenced); + void build_foreign_list(FK_list &, bool &err); }; #ifdef __cplusplus |