Bug#21713 incorrect value for the REFERENTIAL_CONSTRAINTS.UNIQUE_CONSTRAINT_NAME column

added new field 'REFERENCED_TABLE_NAME' to 'referential_constraints' table
field 'UNIQUE_CONSTRAINT_NAME' contains the name of the referenced index
parent 9a97420c
...@@ -31,11 +31,11 @@ CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2), ...@@ -31,11 +31,11 @@ CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A1 CONSTRAINT A1
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2) FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB; ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
CREATE TABLE t3(b1 INT, b2 INT, INDEX (b1, b2), CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
CONSTRAINT A2 CONSTRAINT A2
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2) FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB; ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
CREATE TABLE t4(b1 INT, b2 INT, INDEX (b1, b2), CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
CONSTRAINT A3 CONSTRAINT A3
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2) FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB; ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
...@@ -45,16 +45,16 @@ FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2) ...@@ -45,16 +45,16 @@ FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB; ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE, select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME, b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
MATCH_OPTION, UPDATE_RULE, DELETE_RULE MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
from information_schema.TABLE_CONSTRAINTS a, from information_schema.TABLE_CONSTRAINTS a,
information_schema.REFERENTIAL_CONSTRAINTS b information_schema.REFERENTIAL_CONSTRAINTS b
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME; a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_NAME UNIQUE_CONSTRAINT_SCHEMA UNIQUE_CONSTRAINT_NAME MATCH_OPTION UPDATE_RULE DELETE_RULE CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_TYPE CONSTRAINT_NAME UNIQUE_CONSTRAINT_SCHEMA UNIQUE_CONSTRAINT_NAME MATCH_OPTION UPDATE_RULE DELETE_RULE REFERENCED_TABLE_NAME
test t2 FOREIGN KEY A1 test t1 NONE CASCADE NO ACTION test t2 FOREIGN KEY A1 test PRIMARY NONE CASCADE NO ACTION t1
test t3 FOREIGN KEY A2 test t2 NONE SET NULL RESTRICT test t3 FOREIGN KEY A2 test b1 NONE SET NULL RESTRICT t2
test t4 FOREIGN KEY A3 test t3 NONE NO ACTION SET NULL test t4 FOREIGN KEY A3 test t3_indx NONE NO ACTION SET NULL t3
test t5 FOREIGN KEY A4 test t4 NONE RESTRICT CASCADE test t5 FOREIGN KEY A4 test t4_ukey NONE RESTRICT CASCADE t4
drop tables t5, t4, t3, t2, t1; drop tables t5, t4, t3, t2, t1;
create database `db-1`; create database `db-1`;
use `db-1`; use `db-1`;
......
...@@ -32,11 +32,11 @@ CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2), ...@@ -32,11 +32,11 @@ CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
CONSTRAINT A1 CONSTRAINT A1
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2) FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB; ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
CREATE TABLE t3(b1 INT, b2 INT, INDEX (b1, b2), CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
CONSTRAINT A2 CONSTRAINT A2
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2) FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB; ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
CREATE TABLE t4(b1 INT, b2 INT, INDEX (b1, b2), CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
CONSTRAINT A3 CONSTRAINT A3
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2) FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB; ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
...@@ -45,10 +45,9 @@ CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2), ...@@ -45,10 +45,9 @@ CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2) FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB; ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE, select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME, b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
MATCH_OPTION, UPDATE_RULE, DELETE_RULE MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
from information_schema.TABLE_CONSTRAINTS a, from information_schema.TABLE_CONSTRAINTS a,
information_schema.REFERENTIAL_CONSTRAINTS b information_schema.REFERENTIAL_CONSTRAINTS b
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
......
...@@ -4497,8 +4497,10 @@ get_referential_constraints_record(THD *thd, struct st_table_list *tables, ...@@ -4497,8 +4497,10 @@ get_referential_constraints_record(THD *thd, struct st_table_list *tables,
f_key_info->forein_id->length, cs); f_key_info->forein_id->length, cs);
table->field[4]->store(f_key_info->referenced_db->str, table->field[4]->store(f_key_info->referenced_db->str,
f_key_info->referenced_db->length, cs); f_key_info->referenced_db->length, cs);
table->field[5]->store(f_key_info->referenced_table->str, table->field[10]->store(f_key_info->referenced_table->str,
f_key_info->referenced_table->length, cs); 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);
table->field[6]->store(STRING_WITH_LEN("NONE"), cs); table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
table->field[7]->store(f_key_info->update_method->str, table->field[7]->store(f_key_info->update_method->str,
f_key_info->update_method->length, cs); f_key_info->update_method->length, cs);
...@@ -5668,6 +5670,7 @@ ST_FIELD_INFO referential_constraints_fields_info[]= ...@@ -5668,6 +5670,7 @@ ST_FIELD_INFO referential_constraints_fields_info[]=
{"UPDATE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"UPDATE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
{"DELETE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"DELETE_RULE", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
{"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0}, {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
{"REFERENCED_TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0},
{0, 0, MYSQL_TYPE_STRING, 0, 0, 0} {0, 0, MYSQL_TYPE_STRING, 0, 0, 0}
}; };
......
...@@ -460,6 +460,7 @@ typedef struct st_foreign_key_info ...@@ -460,6 +460,7 @@ typedef struct st_foreign_key_info
LEX_STRING *referenced_table; LEX_STRING *referenced_table;
LEX_STRING *update_method; LEX_STRING *update_method;
LEX_STRING *delete_method; LEX_STRING *delete_method;
LEX_STRING *referenced_key_name;
List<LEX_STRING> foreign_fields; List<LEX_STRING> foreign_fields;
List<LEX_STRING> referenced_fields; List<LEX_STRING> referenced_fields;
} FOREIGN_KEY_INFO; } FOREIGN_KEY_INFO;
......
...@@ -6003,8 +6003,14 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list) ...@@ -6003,8 +6003,14 @@ ha_innobase::get_foreign_key_list(THD *thd, List<FOREIGN_KEY_INFO> *f_key_list)
} }
f_key_info.update_method= make_lex_string(thd, f_key_info.update_method, f_key_info.update_method= make_lex_string(thd, f_key_info.update_method,
tmp_buff, length, 1); tmp_buff, length, 1);
if (foreign->referenced_index &&
foreign->referenced_index->name)
{
f_key_info.referenced_key_name=
make_lex_string(thd, f_key_info.referenced_key_name,
foreign->referenced_index->name,
strlen(foreign->referenced_index->name), 1);
}
FOREIGN_KEY_INFO *pf_key_info= ((FOREIGN_KEY_INFO *) FOREIGN_KEY_INFO *pf_key_info= ((FOREIGN_KEY_INFO *)
thd->memdup((gptr) &f_key_info, thd->memdup((gptr) &f_key_info,
......
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