diff options
Diffstat (limited to 'storage/innobase/handler/ha_innodb.cc')
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 7d555bfec51..a747038aed4 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -71,6 +71,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "buf0flu.h" #include "buf0lru.h" #include "dict0boot.h" +#include "dict0load.h" #include "btr0defragment.h" #include "dict0crea.h" #include "dict0dict.h" @@ -85,10 +86,8 @@ this program; if not, write to the Free Software Foundation, Inc., #include "ibuf0ibuf.h" #include "lock0lock.h" #include "log0crypt.h" -#include "mem0mem.h" #include "mtr0mtr.h" #include "os0file.h" -#include "os0thread.h" #include "page0zip.h" #include "pars0pars.h" #include "rem0types.h" @@ -12265,8 +12264,6 @@ int create_table_info_t::create_table(bool create_fk) int error; int primary_key_no; uint i; - const char* stmt; - size_t stmt_len; DBUG_ENTER("create_table"); @@ -12345,9 +12342,7 @@ int create_table_info_t::create_table(bool create_fk) my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), FTS_DOC_ID_INDEX_NAME); - m_drop_before_rollback = false; - error = -1; - DBUG_RETURN(error); + DBUG_RETURN(-1); case FTS_EXIST_DOC_ID_INDEX: case FTS_NOT_EXIST_DOC_ID_INDEX: break; @@ -12381,15 +12376,28 @@ int create_table_info_t::create_table(bool create_fk) dict_table_get_all_fts_indexes(m_table, fts->indexes); } - stmt = innobase_get_stmt_unsafe(m_thd, &stmt_len); - - if (stmt) { - dberr_t err = row_table_add_foreign_constraints( - create_fk ? m_trx : NULL, stmt, stmt_len, m_table_name, - m_create_info->options & HA_LEX_CREATE_TMP_TABLE); + size_t stmt_len; + if (const char* stmt = innobase_get_stmt_unsafe(m_thd, &stmt_len)) { + dberr_t err = create_fk + ? dict_create_foreign_constraints( + m_trx, stmt, stmt_len, m_table_name, + m_flags2 & DICT_TF2_TEMPORARY) + : DB_SUCCESS; + if (err == DB_SUCCESS) { + /* Check that also referencing constraints are ok */ + dict_names_t fk_tables; + err = dict_load_foreigns(m_table_name, NULL, + false, true, + DICT_ERR_IGNORE_NONE, + fk_tables); + while (err == DB_SUCCESS && !fk_tables.empty()) { + dict_load_table(fk_tables.front(), true, + DICT_ERR_IGNORE_NONE); + fk_tables.pop_front(); + } + } switch (err) { - case DB_PARENT_NO_INDEX: push_warning_printf( m_thd, Sql_condition::WARN_LEVEL_WARN, @@ -12422,13 +12430,9 @@ int create_table_info_t::create_table(bool create_fk) break; } - error = convert_error_code_to_mysql(err, m_flags, NULL); - - if (error) { - /* row_table_add_foreign_constraints() dropped - the table */ - m_drop_before_rollback = false; - DBUG_RETURN(error); + if (err != DB_SUCCESS) { + DBUG_RETURN(convert_error_code_to_mysql( + err, m_flags, NULL)); } } |