diff options
author | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-05-04 13:42:38 +0530 |
---|---|---|
committer | Thirunarayanan Balathandayuthapani <thiru@mariadb.com> | 2020-05-04 14:33:45 +0530 |
commit | 2748c4993c68aa4b03049a97f3657de42dd01c52 (patch) | |
tree | d0f0d5566a40626cc296a4200ccbad665233dce3 /storage | |
parent | d233fd14a39f9c583b85ffb03e42b5ea52e2f4c2 (diff) | |
download | mariadb-git-2748c4993c68aa4b03049a97f3657de42dd01c52.tar.gz |
MDEV-19092 Server crash when renaming the column whenbb-10.1-MDEV-19092
FOREIGN_KEY_CHECKS is disabled
- Referenced index can be null While renaming the referenced column name.
In that case, rename the referenced column name in dict_foreign_t and
find the equivalent referenced index.
Diffstat (limited to 'storage')
-rw-r--r-- | storage/innobase/dict/dict0mem.cc | 46 | ||||
-rw-r--r-- | storage/xtradb/dict/dict0mem.cc | 46 |
2 files changed, 78 insertions, 14 deletions
diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index bc955fb13b9..6ace0ee9a75 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -415,17 +415,15 @@ dict_mem_table_col_rename_low( } } - dict_index_t* new_index = dict_foreign_find_index( + /* New index can be null if InnoDB already dropped + the foreign index when FOREIGN_KEY_CHECKS is + disabled */ + foreign->foreign_index = dict_foreign_find_index( foreign->foreign_table, NULL, foreign->foreign_col_names, foreign->n_fields, NULL, true, false, NULL, NULL, NULL); - /* New index can be null if InnoDB already dropped - the foreign index when FOREIGN_KEY_CHECKS is - disabled */ - foreign->foreign_index = new_index; - } else { for (unsigned f = 0; f < foreign->n_fields; f++) { @@ -447,7 +445,41 @@ dict_mem_table_col_rename_low( foreign = *it; - ut_ad(foreign->referenced_index != NULL); + if (!foreign->referenced_index) { + /* Referenced index could have been dropped + when foreign_key_checks is disabled. In that case, + rename the corresponding referenced_col_names and + find the equivalent referenced index also */ + for (unsigned f = 0; f < foreign->n_fields; f++) { + + const char*& rc = + foreign->referenced_col_names[f]; + if (strcmp(rc, from)) { + continue; + } + + if (to_len <= strlen(rc)) { + memcpy(const_cast<char*>(rc), to, + to_len + 1); + } else { + rc = static_cast<char*>( + mem_heap_dup( + foreign->heap, + to, to_len + 1)); + } + } + + /* New index can be null if InnoDB already dropped + the referenced index when FOREIGN_KEY_CHECKS is + disabled */ + foreign->referenced_index = dict_foreign_find_index( + foreign->referenced_table, NULL, + foreign->referenced_col_names, + foreign->n_fields, NULL, true, false, + NULL, NULL, NULL); + return; + } + for (unsigned f = 0; f < foreign->n_fields; f++) { /* foreign->referenced_col_names[] need to be diff --git a/storage/xtradb/dict/dict0mem.cc b/storage/xtradb/dict/dict0mem.cc index 51ca6de8cd2..89b9bd9aead 100644 --- a/storage/xtradb/dict/dict0mem.cc +++ b/storage/xtradb/dict/dict0mem.cc @@ -416,17 +416,15 @@ dict_mem_table_col_rename_low( } } - dict_index_t* new_index = dict_foreign_find_index( + /* New index can be null if XtraDB already dropped + the foreign index when FOREIGN_KEY_CHECKS is + disabled */ + foreign->foreign_index = dict_foreign_find_index( foreign->foreign_table, NULL, foreign->foreign_col_names, foreign->n_fields, NULL, true, false, NULL, NULL, NULL); - /* New index can be null if XtraDB already dropped - the foreign index when FOREIGN_KEY_CHECKS is - disabled */ - foreign->foreign_index = new_index; - } else { for (unsigned f = 0; f < foreign->n_fields; f++) { @@ -448,7 +446,41 @@ dict_mem_table_col_rename_low( foreign = *it; - ut_ad(foreign->referenced_index != NULL); + if (!foreign->referenced_index) { + /* Referenced index could have been dropped + when foreign_key_checks is disabled. In that case, + rename the corresponding referenced_col_names and + find the equivalent referenced index also */ + for (unsigned f = 0; f < foreign->n_fields; f++) { + + const char*& rc = + foreign->referenced_col_names[f]; + + if (strcmp(rc, from)) { + continue; + } + + if (to_len <= strlen(rc)) { + memcpy(const_cast<char*>(rc), to, + to_len + 1); + } else { + rc = static_cast<char*>( + mem_heap_dup( + foreign->heap, + to, to_len + 1)); + } + } + + /* New index can be null if InnoDB already dropped + the referenced index when FOREIGN_KEY_CHECKS is + disabled */ + foreign->referenced_index = dict_foreign_find_index( + foreign->referenced_table, NULL, + foreign->referenced_col_names, + foreign->n_fields, NULL, true, false, + NULL, NULL, NULL); + return; + } for (unsigned f = 0; f < foreign->n_fields; f++) { /* foreign->referenced_col_names[] need to be |