summaryrefslogtreecommitdiff
path: root/storage/innobase
diff options
context:
space:
mode:
authorDebarun Banerjee <debarun.banerjee@oracle.com>2016-11-25 11:04:23 +0530
committerMarko Mäkelä <marko.makela@mariadb.com>2017-04-26 23:03:30 +0300
commit49edf2d47636865e35d4916f72fe345f7d3d970e (patch)
treee4c56c722552a686301569b5b9c3de22df596125 /storage/innobase
parent07e88be5b7c6720fc95598c604274f2bdd2b8a6e (diff)
downloadmariadb-git-49edf2d47636865e35d4916f72fe345f7d3d970e.tar.gz
BUG#25126722 FOREIGN KEY CONSTRAINT NAME IS NULL IN INFORMATION_SCHEMA AFTER RESTART
Problem : --------- Information_Schema.referential_constraints (UNIQUE_CONSTRAINT_NAME) shows NULL for a foreign key constraint after restarting the server. If any dml or query (select/insert/update/delete) is done on referenced table, then the constraint name is correctly shown. Solution : ---------- UNIQUE_CONSTRAINT_NAME column is the key name of the referenced table. In innodb, FK reference is stored as a list of columns in referenced table in INNODB_SYS_FOREIGN and INNODB_SYS_FOREIGN_COLS. The referenced column must have at least one index/key with the referenced column as prefix but the key name itself is not included in FK metadata. For this reason, the UNIQUE_CONSTRAINT_NAME is only filled up when the referenced table is actually loaded in innodb dictionary cache. The information_schema view calls handler::get_foreign_key_list() on foreign key table to read the FK metadata. The UNIQUE_CONSTRAINT_NAME information shows NULL based on whether the referenced table is already loaded or not. One way to fix this issue is to load the referenced table while reading the FK metadata information, if needed. Reviewed-by: Sunny Bains <sunny.bains@oracle.com> RB: 14654
Diffstat (limited to 'storage/innobase')
-rw-r--r--storage/innobase/handler/ha_innodb.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index e039722deba..af1793d1920 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -15863,6 +15863,28 @@ get_foreign_key_info(
f_key_info.update_method = FK_OPTION_RESTRICT;
}
+ /* Load referenced table to update FK referenced key name. */
+ if (foreign->referenced_table == NULL) {
+
+ dict_table_t* ref_table;
+
+ ut_ad(mutex_own(&dict_sys->mutex));
+ ref_table = dict_table_open_on_name(
+ foreign->referenced_table_name_lookup,
+ TRUE, FALSE, DICT_ERR_IGNORE_NONE);
+
+ if (ref_table == NULL) {
+
+ ib::info() << "Foreign Key referenced table "
+ << foreign->referenced_table_name
+ << " not found for foreign table "
+ << foreign->foreign_table_name;
+ } else {
+
+ dict_table_close(ref_table, TRUE, FALSE);
+ }
+ }
+
if (foreign->referenced_index
&& foreign->referenced_index->name != NULL) {
referenced_key_name = thd_make_lex_string(