Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes

referenced_key_name field can be uninitialized in the case when
referenced table is dropped.
Added codition which allows to handle this situation.
parent eac3a26e
......@@ -78,3 +78,14 @@ NULL NULL
db-1 t-2
NULL NULL
drop database `db-1`;
create table t1(id int primary key) engine = Innodb;
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
set foreign_key_checks = 0;
drop table t1;
select UNIQUE_CONSTRAINT_NAME
from information_schema.referential_constraints
where constraint_schema = schema();
UNIQUE_CONSTRAINT_NAME
NULL
drop table t2;
set foreign_key_checks = 1;
......@@ -76,3 +76,16 @@ select referenced_table_schema, referenced_table_name
from information_schema.key_column_usage
where constraint_schema = 'db-1';
drop database `db-1`;
#
# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes
#
create table t1(id int primary key) engine = Innodb;
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
set foreign_key_checks = 0;
drop table t1;
select UNIQUE_CONSTRAINT_NAME
from information_schema.referential_constraints
where constraint_schema = schema();
drop table t2;
set foreign_key_checks = 1;
......@@ -5276,8 +5276,14 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
f_key_info->referenced_db->length, cs);
table->field[10]->store(f_key_info->referenced_table->str,
f_key_info->referenced_table->length, cs);
table->field[5]->store(f_key_info->referenced_key_name->str,
f_key_info->referenced_key_name->length, cs);
if (f_key_info->referenced_key_name)
{
table->field[5]->store(f_key_info->referenced_key_name->str,
f_key_info->referenced_key_name->length, cs);
table->field[5]->set_notnull();
}
else
table->field[5]->set_null();
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
table->field[7]->store(f_key_info->update_method->str,
f_key_info->update_method->length, cs);
......@@ -6480,8 +6486,8 @@ ST_FIELD_INFO referential_constraints_fields_info[]=
OPEN_FULL_TABLE},
{"UNIQUE_CONSTRAINT_SCHEMA", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE},
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0,
OPEN_FULL_TABLE},
{"UNIQUE_CONSTRAINT_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0,
MY_I_S_MAYBE_NULL, 0, OPEN_FULL_TABLE},
{"MATCH_OPTION", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"UPDATE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
{"DELETE_RULE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, OPEN_FULL_TABLE},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment