diff options
-rw-r--r-- | mysql-test/r/information_schema_inno.result | 22 | ||||
-rw-r--r-- | mysql-test/t/information_schema_inno.test | 24 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 22 |
3 files changed, 63 insertions, 5 deletions
diff --git a/mysql-test/r/information_schema_inno.result b/mysql-test/r/information_schema_inno.result index 9bb3185c6fb..b9c0cae5efb 100644 --- a/mysql-test/r/information_schema_inno.result +++ b/mysql-test/r/information_schema_inno.result @@ -56,3 +56,25 @@ test t3 FOREIGN KEY A2 test t2 NONE SET NULL RESTRICT test t4 FOREIGN KEY A3 test t3 NONE NO ACTION SET NULL test t5 FOREIGN KEY A4 test t4 NONE RESTRICT CASCADE drop tables t5, t4, t3, t2, t1; +create database `db-1`; +use `db-1`; +create table `t-2` ( +id int(10) unsigned not null auto_increment, +primary key (id) +) engine=innodb; +create table `t-1` ( +id int(10) unsigned not null auto_increment, +idtype int(10) unsigned not null, +primary key (id), +key fk_t1_1 (idtype), +constraint fk_t1_1 foreign key (idtype) references `t-2` (id) +) engine=innodb; +use test; +select referenced_table_schema, referenced_table_name +from information_schema.key_column_usage +where constraint_schema = 'db-1'; +referenced_table_schema referenced_table_name +NULL NULL +db-1 t-2 +NULL NULL +drop database `db-1`; diff --git a/mysql-test/t/information_schema_inno.test b/mysql-test/t/information_schema_inno.test index 195bf57a880..014bdacfeea 100644 --- a/mysql-test/t/information_schema_inno.test +++ b/mysql-test/t/information_schema_inno.test @@ -1,3 +1,4 @@ +-- source include/testdb_only.inc -- source include/have_innodb.inc --disable_warnings DROP TABLE IF EXISTS t1,t2,t3; @@ -53,3 +54,26 @@ from information_schema.TABLE_CONSTRAINTS a, where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and a.CONSTRAINT_NAME = b.CONSTRAINT_NAME; drop tables t5, t4, t3, t2, t1; + +# +# Bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage +# +create database `db-1`; +use `db-1`; +create table `t-2` ( + id int(10) unsigned not null auto_increment, + primary key (id) +) engine=innodb; + +create table `t-1` ( + id int(10) unsigned not null auto_increment, + idtype int(10) unsigned not null, + primary key (id), + key fk_t1_1 (idtype), + constraint fk_t1_1 foreign key (idtype) references `t-2` (id) +) engine=innodb; +use test; +select referenced_table_schema, referenced_table_name +from information_schema.key_column_usage +where constraint_schema = 'db-1'; +drop database `db-1`; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 4d835b41863..f8facb40a89 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -5933,6 +5933,9 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list) uint i; FOREIGN_KEY_INFO f_key_info; LEX_STRING *name= 0; + uint ulen; + char uname[NAME_LEN*3+1]; /* Unencoded name */ + char db_name[NAME_LEN*3+1]; const char *tmp_buff; tmp_buff= foreign->id; @@ -5943,14 +5946,23 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list) f_key_info.forein_id= make_lex_string(thd, 0, tmp_buff, (uint) strlen(tmp_buff), 1); tmp_buff= foreign->referenced_table_name; + + /* Database name */ i= 0; while (tmp_buff[i] != '/') - i++; - f_key_info.referenced_db= make_lex_string(thd, 0, - tmp_buff, i, 1); + { + db_name[i]= tmp_buff[i]; + i++; + } + db_name[i]= 0; + ulen= filename_to_tablename(db_name, uname, sizeof(uname)); + f_key_info.referenced_db= make_lex_string(thd, 0, uname, ulen, 1); + + /* Table name */ tmp_buff+= i + 1; - f_key_info.referenced_table= make_lex_string(thd, 0, tmp_buff, - (uint) strlen(tmp_buff), 1); + ulen= filename_to_tablename(tmp_buff, uname, sizeof(uname)); + f_key_info.referenced_table= make_lex_string(thd, 0, uname, + ulen, 1); for (i= 0;;) { tmp_buff= foreign->foreign_col_names[i]; |