Commit ed70e034 authored by Aleksey Midenkov's avatar Aleksey Midenkov

MDEV-20865 FIXMEs

parent e0145df6
...@@ -241,46 +241,52 @@ test.t3 check status OK ...@@ -241,46 +241,52 @@ test.t3 check status OK
drop tables ch1, t2, t1, t3; drop tables ch1, t2, t1, t3;
# Rename column on referenced table # Rename column on referenced table
create or replace table t1 (id int primary key); create or replace table t1 (id int primary key);
create or replace table t2 (id int references t1); create or replace table t2 (id int references t1, id2 int references t1(id));
select * from t2; select * from t2;
id id id2
alter table t1 change id xid int; alter table t1 change id xid int;
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`id` int(11) DEFAULT NULL, `id` int(11) DEFAULT NULL,
`id2` int(11) DEFAULT NULL,
KEY `fk_t2` (`id`), KEY `fk_t2` (`id`),
CONSTRAINT `fk_t2` FOREIGN KEY (`id`) REFERENCES `t1` (`xid`) KEY `fk_t2_2` (`id2`),
CONSTRAINT `fk_t2` FOREIGN KEY (`id`) REFERENCES `t1` (`xid`),
CONSTRAINT `fk_t2_2` FOREIGN KEY (`id2`) REFERENCES `t1` (`xid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
select * from t1; select * from t1;
xid xid
check table t2; check table t2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 check Note Found 1 foreign keys test.t2 check Note Found 2 foreign keys
test.t2 check status OK test.t2 check status OK
flush table t2; flush table t2;
check table t2; check table t2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 check Note Found 1 foreign keys test.t2 check Note Found 2 foreign keys
test.t2 check status OK test.t2 check status OK
alter table t1 rename column xid to yid; alter table t1 rename column xid to yid;
show create table t2; show create table t2;
Table Create Table Table Create Table
t2 CREATE TABLE `t2` ( t2 CREATE TABLE `t2` (
`id` int(11) DEFAULT NULL, `id` int(11) DEFAULT NULL,
`id2` int(11) DEFAULT NULL,
KEY `fk_t2` (`id`), KEY `fk_t2` (`id`),
CONSTRAINT `fk_t2` FOREIGN KEY (`id`) REFERENCES `t1` (`yid`) KEY `fk_t2_2` (`id2`),
CONSTRAINT `fk_t2` FOREIGN KEY (`id`) REFERENCES `t1` (`yid`),
CONSTRAINT `fk_t2_2` FOREIGN KEY (`id2`) REFERENCES `t1` (`yid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ) ENGINE=InnoDB DEFAULT CHARSET=latin1
select * from t1; select * from t1;
yid yid
check table t2; check table t2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 check Note Found 1 foreign keys test.t2 check Note Found 2 foreign keys
test.t2 check status OK test.t2 check status OK
flush table t2; flush table t2;
check table t2; check table t2;
Table Op Msg_type Msg_text Table Op Msg_type Msg_text
test.t2 check Note Found 1 foreign keys test.t2 check Note Found 2 foreign keys
test.t2 check status OK test.t2 check status OK
drop tables t2, t1; drop tables t2, t1;
# Check rename table # Check rename table
......
...@@ -242,7 +242,7 @@ drop tables ch1, t2, t1, t3; ...@@ -242,7 +242,7 @@ drop tables ch1, t2, t1, t3;
--echo # Rename column on referenced table --echo # Rename column on referenced table
create or replace table t1 (id int primary key); create or replace table t1 (id int primary key);
create or replace table t2 (id int references t1); create or replace table t2 (id int references t1, id2 int references t1(id));
select * from t2; select * from t2;
alter table t1 change id xid int; alter table t1 change id xid int;
show create table t2; show create table t2;
......
...@@ -416,7 +416,7 @@ class Alter_table_ctx ...@@ -416,7 +416,7 @@ class Alter_table_ctx
Table_name ref; Table_name ref;
const FK_info *fk; const FK_info *fk;
}; };
// FIXME: why this stored in std::set? // NB: multiple foreign keys can utilize same column (see fk_prepare_rename())
mbd::set<FK_rename_col> fk_renamed_cols; mbd::set<FK_rename_col> fk_renamed_cols;
mbd::set<FK_rename_col> rk_renamed_cols; mbd::set<FK_rename_col> rk_renamed_cols;
mbd::vector<FK_add_new> fk_added; mbd::vector<FK_add_new> fk_added;
......
...@@ -1546,11 +1546,7 @@ bool TABLE_SHARE::fk_resolve_referenced_keys(THD *thd, TABLE_SHARE *from) ...@@ -1546,11 +1546,7 @@ bool TABLE_SHARE::fk_resolve_referenced_keys(THD *thd, TABLE_SHARE *from)
if (!ids.insert(rk.foreign_id, &inserted)) if (!ids.insert(rk.foreign_id, &inserted))
return true; return true;
if (!inserted) // FIXME: assert instead error DBUG_ASSERT(inserted);
{
my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "FOREIGN KEY", rk.foreign_id.str);
return true;
}
} }
for (FK_info &fk: from->foreign_keys) for (FK_info &fk: from->foreign_keys)
...@@ -1564,8 +1560,9 @@ bool TABLE_SHARE::fk_resolve_referenced_keys(THD *thd, TABLE_SHARE *from) ...@@ -1564,8 +1560,9 @@ bool TABLE_SHARE::fk_resolve_referenced_keys(THD *thd, TABLE_SHARE *from)
if (!inserted) if (!inserted)
{ {
my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "FOREIGN KEY", fk.foreign_id.str); push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_DUP_CONSTRAINT_NAME,
return true; // FIXME: warn instead fail "Foreign ID already exists `%s`", fk.foreign_id.str);
continue;
} }
for (Lex_cstring &fld: fk.referenced_fields) for (Lex_cstring &fld: fk.referenced_fields)
......
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