diff --git a/mysql-test/main/alter_table.result b/mysql-test/main/alter_table.result index 3b20879637a..ba949496a51 100644 --- a/mysql-test/main/alter_table.result +++ b/mysql-test/main/alter_table.result @@ -1539,13 +1539,13 @@ t2 CREATE TABLE `t2` ( KEY `fk` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id); -ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS t2_ibfk_1(id) REFERENCES t1(id); +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS `1`(id) REFERENCES t1(id); Warnings: -Note 1061 Duplicate key name 't2_ibfk_1' -ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; -ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +Note 1061 Duplicate key name '1' +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`; Warnings: -Note 1091 Can't DROP FOREIGN KEY `t2_ibfk_1`; check that it exists +Note 1091 Can't DROP FOREIGN KEY `1`; check that it exists SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( diff --git a/mysql-test/main/alter_table.test b/mysql-test/main/alter_table.test index e44e14e6933..6385cb6945f 100644 --- a/mysql-test/main/alter_table.test +++ b/mysql-test/main/alter_table.test @@ -1384,9 +1384,9 @@ ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk; SHOW CREATE TABLE t2; ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id); -ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS t2_ibfk_1(id) REFERENCES t1(id); -ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; -ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1; +ALTER TABLE t2 ADD FOREIGN KEY IF NOT EXISTS `1`(id) REFERENCES t1(id); +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`; +ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`; SHOW CREATE TABLE t2; DROP TABLE t2; diff --git a/mysql-test/main/alter_table_combinations,aria.rdiff b/mysql-test/main/alter_table_combinations,aria.rdiff index 6564dbb44a6..f5f05cf9543 100644 --- a/mysql-test/main/alter_table_combinations,aria.rdiff +++ b/mysql-test/main/alter_table_combinations,aria.rdiff @@ -5,7 +5,7 @@ `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, - KEY `b` (`b`), -- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) +- CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) + KEY `b` (`b`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ALTER TABLE t1 RENAME COLUMN bb TO b; @@ -15,7 +15,7 @@ `a` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, - KEY `b` (`c`), -- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) +- CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) + KEY `b` (`c`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci CREATE TABLE t4(a int); diff --git a/mysql-test/main/alter_table_combinations,heap.rdiff b/mysql-test/main/alter_table_combinations,heap.rdiff index 81633a8255f..c9c7907f7d6 100644 --- a/mysql-test/main/alter_table_combinations,heap.rdiff +++ b/mysql-test/main/alter_table_combinations,heap.rdiff @@ -14,7 +14,7 @@ `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, - KEY `b` (`b`), -- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) +- CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) + KEY `b` (`b`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ALTER TABLE t1 RENAME COLUMN bb TO b; @@ -24,7 +24,7 @@ `a` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, - KEY `b` (`c`), -- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) +- CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) + KEY `b` (`c`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci CREATE TABLE t4(a int); diff --git a/mysql-test/main/alter_table_combinations.result b/mysql-test/main/alter_table_combinations.result index 1e8d1ee599b..d14aaaac8f7 100644 --- a/mysql-test/main/alter_table_combinations.result +++ b/mysql-test/main/alter_table_combinations.result @@ -174,7 +174,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `b` int(11) DEFAULT NULL, KEY `b` (`b`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) + CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ALTER TABLE t1 RENAME COLUMN bb TO b; SHOW CREATE TABLE t1; @@ -191,7 +191,7 @@ t3 CREATE TABLE `t3` ( `a` int(11) DEFAULT NULL, `c` int(11) DEFAULT NULL, KEY `b` (`c`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) + CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`) ) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci CREATE TABLE t4(a int); ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE; diff --git a/mysql-test/main/analyze.result b/mysql-test/main/analyze.result index 4af950ddc00..43da87403a1 100644 --- a/mysql-test/main/analyze.result +++ b/mysql-test/main/analyze.result @@ -364,7 +364,7 @@ t1 CREATE TABLE `t1` ( `b` int(11) DEFAULT NULL, KEY `b` (`b`), KEY `idx` (`aaaa`), - CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`aaaa`) REFERENCES `t1` (`b`) + CONSTRAINT `1` FOREIGN KEY (`aaaa`) REFERENCES `t1` (`b`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT index_name FROM mysql.index_stats WHERE table_name = 't1' order by index_name; index_name diff --git a/mysql-test/main/foreign_key.result b/mysql-test/main/foreign_key.result index 82bef2b23de..04067cb824c 100644 --- a/mysql-test/main/foreign_key.result +++ b/mysql-test/main/foreign_key.result @@ -18,7 +18,7 @@ create table t2 (id int PRIMARY KEY, FOREIGN KEY (id) REFERENCES t1(id)) engine= insert into t1 values (1), (2), (3), (4), (5), (6); insert into t2 values (3), (5); delete from t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) select * from t1; id 1 @@ -29,8 +29,8 @@ id 6 delete ignore from t1; Warnings: -Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) -Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) +Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) +Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`)) select row_count(); row_count() -1 diff --git a/mysql-test/main/func_rollback.result b/mysql-test/main/func_rollback.result index 91151302a06..ccc6f2b2ecf 100644 --- a/mysql-test/main/func_rollback.result +++ b/mysql-test/main/func_rollback.result @@ -446,7 +446,7 @@ INSERT INTO t1_child SET f1 = 2, f2 = 2; RETURN 1; END// SELECT f1_two_inserts(); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1_child`, CONSTRAINT `t1_child_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1_parent` (`f1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1_child`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1_parent` (`f1`)) SELECT * FROM t1_child; f1 f2 DROP TABLE t1_child; diff --git a/mysql-test/main/information_schema_db.result b/mysql-test/main/information_schema_db.result index 5a4c3c3ec3c..869455a8708 100644 --- a/mysql-test/main/information_schema_db.result +++ b/mysql-test/main/information_schema_db.result @@ -367,9 +367,9 @@ select table_name, constraint_name, constraint_type from information_schema.tabl table_name constraint_name constraint_type t3 e UNIQUE t3 CONSTRAINT_1 CHECK -t3 t3_ibfk_1 FOREIGN KEY -t3 t3_ibfk_2 FOREIGN KEY -t3 t3_ibfk_3 FOREIGN KEY +t3 1 FOREIGN KEY +t3 2 FOREIGN KEY +t3 3 FOREIGN KEY show index in t2; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored show index in t3; diff --git a/mysql-test/main/information_schema_inno.result b/mysql-test/main/information_schema_inno.result index c81631728f0..520e9a4c8ce 100644 --- a/mysql-test/main/information_schema_inno.result +++ b/mysql-test/main/information_schema_inno.result @@ -7,22 +7,22 @@ FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNO select * from information_schema.TABLE_CONSTRAINTS where TABLE_SCHEMA= "test"; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE +def test 1 test t2 FOREIGN KEY +def test 1 test t3 FOREIGN KEY +def test 2 test t2 FOREIGN KEY def test PRIMARY test t1 PRIMARY KEY def test PRIMARY test t2 PRIMARY KEY def test PRIMARY test t3 PRIMARY KEY -def test t2_ibfk_1 test t2 FOREIGN KEY -def test t2_ibfk_2 test t2 FOREIGN KEY -def test t3_ibfk_1 test t3 FOREIGN KEY select * from information_schema.KEY_COLUMN_USAGE where TABLE_SCHEMA= "test"; CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME +def test 1 def test t2 t1_id 1 1 test t1 id +def test 1 def test t3 id 1 1 test t2 t1_id +def test 1 def test t3 t2_id 2 2 test t2 id +def test 2 def test t2 t1_id 1 1 test t1 id def test PRIMARY def test t1 id 1 NULL NULL NULL NULL def test PRIMARY def test t2 id 1 NULL NULL NULL NULL def test PRIMARY def test t3 id 1 NULL NULL NULL NULL -def test t2_ibfk_1 def test t2 t1_id 1 1 test t1 id -def test t2_ibfk_2 def test t2 t1_id 1 1 test t1 id -def test t3_ibfk_1 def test t3 id 1 1 test t2 t1_id -def test t3_ibfk_1 def test t3 t2_id 2 2 test t2 id drop table t3, t2, t1; CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL, PRIMARY KEY(a1, a2)) ENGINE=INNODB; diff --git a/mysql-test/main/insert_innodb.result b/mysql-test/main/insert_innodb.result index 174a749a504..0ce0a625de7 100644 --- a/mysql-test/main/insert_innodb.result +++ b/mysql-test/main/insert_innodb.result @@ -10,7 +10,7 @@ INSERT INTO t2 VALUES(0); # Without fix, an error is reported. INSERT IGNORE INTO t2 VALUES(1); Warnings: -Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) UPDATE IGNORE t2 SET fld2=20 WHERE fld2=0; UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0; # Test for multi update. @@ -18,15 +18,15 @@ UPDATE IGNORE t1, t2 SET t2.fld2= t2.fld2 + 3; UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3; # Reports an error since IGNORE is not used. INSERT INTO t2 VALUES(1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) UPDATE t2 SET fld2=20 WHERE fld2=0; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) UPDATE t1 SET fld1=20 WHERE fld1=0; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) UPDATE t1, t2 SET t2.fld2= t2.fld2 + 3; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) UPDATE t1, t2 SET t1.fld1= t1.fld1 + 3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fld2`) REFERENCES `t1` (`fld1`)) DROP TABLE t2, t1; # # BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN diff --git a/mysql-test/main/lowercase_table4.result b/mysql-test/main/lowercase_table4.result index 422c2744af8..8ff0c07783f 100644 --- a/mysql-test/main/lowercase_table4.result +++ b/mysql-test/main/lowercase_table4.result @@ -73,8 +73,8 @@ Create Table CREATE TABLE `Product_Order` ( PRIMARY KEY (`No`), KEY `Product_Category` (`Product_Category`,`Product_Id`), KEY `Customer_Id` (`Customer_Id`), - CONSTRAINT `product_order_ibfk_1` FOREIGN KEY (`Product_Category`, `Product_Id`) REFERENCES `Product` (`Category`, `Id`) ON UPDATE CASCADE, - CONSTRAINT `product_order_ibfk_2` FOREIGN KEY (`Customer_Id`) REFERENCES `Customer` (`Id`) + CONSTRAINT `1` FOREIGN KEY (`Product_Category`, `Product_Id`) REFERENCES `Product` (`Category`, `Id`) ON UPDATE CASCADE, + CONSTRAINT `2` FOREIGN KEY (`Customer_Id`) REFERENCES `Customer` (`Id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SHOW CREATE TABLE Product; Table Product @@ -93,7 +93,7 @@ Create Table CREATE TABLE `Customer` ( SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='test'; CONSTRAINT_CATALOG def CONSTRAINT_SCHEMA test -CONSTRAINT_NAME product_order_ibfk_1 +CONSTRAINT_NAME 1 UNIQUE_CONSTRAINT_CATALOG def UNIQUE_CONSTRAINT_SCHEMA test UNIQUE_CONSTRAINT_NAME PRIMARY @@ -104,7 +104,7 @@ TABLE_NAME Product_Order REFERENCED_TABLE_NAME Product CONSTRAINT_CATALOG def CONSTRAINT_SCHEMA test -CONSTRAINT_NAME product_order_ibfk_2 +CONSTRAINT_NAME 2 UNIQUE_CONSTRAINT_CATALOG def UNIQUE_CONSTRAINT_SCHEMA test UNIQUE_CONSTRAINT_NAME PRIMARY diff --git a/mysql-test/main/mariadb-import.result b/mysql-test/main/mariadb-import.result index 5d1dda07591..d95da8c6ca6 100644 --- a/mysql-test/main/mariadb-import.result +++ b/mysql-test/main/mariadb-import.result @@ -225,7 +225,7 @@ child CREATE TABLE `child` ( `c` char(4) DEFAULT NULL, UNIQUE KEY `c` (`c`), KEY `par_ind` (`parent_id`), - CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE, + CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`) ON DELETE CASCADE, CONSTRAINT `CONSTRAINT_1` CHECK (`c` >= 'a') ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop database db2; diff --git a/mysql-test/main/trigger-trans.result b/mysql-test/main/trigger-trans.result index 2113377b1ab..16cb1d0bcfa 100644 --- a/mysql-test/main/trigger-trans.result +++ b/mysql-test/main/trigger-trans.result @@ -160,7 +160,7 @@ CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1; SET @a = 0; SET @b = 0; TRUNCATE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `test`.`t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `test`.`t1` (`a`)) SELECT @a, @b; @a @b 0 0 diff --git a/mysql-test/suite/binlog/r/start_alter_mysqlbinlog_replay.result b/mysql-test/suite/binlog/r/start_alter_mysqlbinlog_replay.result index 14bc2d3bf78..a2520e2fd44 100644 --- a/mysql-test/suite/binlog/r/start_alter_mysqlbinlog_replay.result +++ b/mysql-test/suite/binlog/r/start_alter_mysqlbinlog_replay.result @@ -11,7 +11,7 @@ set binlog_alter_two_phase = ON; create table t1 (f1 int primary key) engine=InnoDB; create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; alter table t2 add constraint c1 foreign key (f1) references t1(f1); -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") +ERROR HY000: Duplicate FOREIGN KEY constraint name '' drop table t2, t1; select @@gtid_binlog_state; @@gtid_binlog_state diff --git a/mysql-test/suite/binlog/t/start_alter_mysqlbinlog_replay.test b/mysql-test/suite/binlog/t/start_alter_mysqlbinlog_replay.test index d59456d72f6..1307c2921a1 100644 --- a/mysql-test/suite/binlog/t/start_alter_mysqlbinlog_replay.test +++ b/mysql-test/suite/binlog/t/start_alter_mysqlbinlog_replay.test @@ -21,7 +21,7 @@ set binlog_alter_two_phase = ON; create table t1 (f1 int primary key) engine=InnoDB; create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; ---error ER_CANT_CREATE_TABLE +--error ER_DUP_CONSTRAINT_NAME alter table t2 add constraint c1 foreign key (f1) references t1(f1); drop table t2, t1; diff --git a/mysql-test/suite/funcs_1/r/innodb_trig_frkey.result b/mysql-test/suite/funcs_1/r/innodb_trig_frkey.result index 333e9533608..6171bc16ed3 100644 --- a/mysql-test/suite/funcs_1/r/innodb_trig_frkey.result +++ b/mysql-test/suite/funcs_1/r/innodb_trig_frkey.result @@ -49,7 +49,7 @@ INSERT INTO t1 VALUES (3,'Department C'); INSERT INTO t2 VALUES (1,2,'Emp 1'); INSERT INTO t2 VALUES (2,3,'Emp 2'); insert into t2 VALUES (3,4,'Emp 3'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f_id`) REFERENCES `t1` (`id`) ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f_id`) REFERENCES `t1` (`id`) ON UPDATE CASCADE) CREATE TRIGGER tr_t2 BEFORE INSERT ON t2 FOR EACH ROW INSERT INTO t1 VALUES(new.f_id, CONCAT('New Department ', new.f_id)); LOCK TABLES t1 WRITE, t2 WRITE; diff --git a/mysql-test/suite/galera/r/galera_multirow_rollback.result b/mysql-test/suite/galera/r/galera_multirow_rollback.result index 13502d0d3dc..7e78c763885 100644 --- a/mysql-test/suite/galera/r/galera_multirow_rollback.result +++ b/mysql-test/suite/galera/r/galera_multirow_rollback.result @@ -54,7 +54,7 @@ INSERT INTO p VALUES(1, 0); START TRANSACTION; INSERT INTO c VALUES (3,1); INSERT INTO c VALUES (1,1), (2,2); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`c`, CONSTRAINT `c_ibfk_1` FOREIGN KEY (`fk1`) REFERENCES `p` (`id`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`c`, CONSTRAINT `1` FOREIGN KEY (`fk1`) REFERENCES `p` (`id`)) COMMIT; SELECT * FROM p; id j diff --git a/mysql-test/suite/galera/r/galera_var_fkchecks.result b/mysql-test/suite/galera/r/galera_var_fkchecks.result index 42f8085ee1a..e2faefff764 100644 --- a/mysql-test/suite/galera/r/galera_var_fkchecks.result +++ b/mysql-test/suite/galera/r/galera_var_fkchecks.result @@ -19,7 +19,7 @@ SELECT COUNT(*) = 1 FROM child WHERE id = 2; COUNT(*) = 1 1 INSERT INTO child VALUES (3,3); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) SET SESSION foreign_key_checks = 0; DELETE FROM parent; connection node_1; diff --git a/mysql-test/suite/gcol/inc/gcol_ins_upd.inc b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc index 68c0a0e30c9..555e1300db2 100644 --- a/mysql-test/suite/gcol/inc/gcol_ins_upd.inc +++ b/mysql-test/suite/gcol/inc/gcol_ins_upd.inc @@ -245,7 +245,7 @@ if ($innodb_engine) --error 1451 update t2 set a=4 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; --echo # - ON DELETE RESTRICT alter table t1 add foreign key (b) references t2(a) on delete restrict; @@ -253,14 +253,14 @@ if ($innodb_engine) delete from t2 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; --echo # - ON DELETE CASCADE alter table t1 add foreign key (b) references t2(a) on delete cascade; delete from t2 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; drop table t1; drop table t2; diff --git a/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result index bc3b5493dbd..291a983a7dd 100644 --- a/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result +++ b/mysql-test/suite/gcol/r/gcol_ins_upd_innodb.result @@ -357,19 +357,19 @@ a b name # - ON UPDATE RESTRICT alter table t1 add foreign key (b) references t2(a) on update restrict; insert into t1 (a) values (4); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) update t2 set a=4 where a=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; a b name 1 1 value1 2 2 value2 3 3 value3 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; # - ON DELETE RESTRICT alter table t1 add foreign key (b) references t2(a) on delete restrict; delete from t2 where a=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; a b name 1 1 value1 @@ -380,7 +380,7 @@ a b name 1 1 value1 2 2 value2 3 3 value3 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; # - ON DELETE CASCADE alter table t1 add foreign key (b) references t2(a) on delete cascade; delete from t2 where a=3; @@ -392,7 +392,7 @@ select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); a b name 1 1 value1 2 2 value2 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; drop table t1; drop table t2; # diff --git a/mysql-test/suite/gcol/r/innodb_virtual_basic.result b/mysql-test/suite/gcol/r/innodb_virtual_basic.result index dbdd1b62fc7..0caf1768b40 100644 --- a/mysql-test/suite/gcol/r/innodb_virtual_basic.result +++ b/mysql-test/suite/gcol/r/innodb_virtual_basic.result @@ -212,7 +212,7 @@ CREATE TABLE t1(a INT); CREATE INDEX idx ON t1(a); CREATE TABLE t3(a INT, b INT , INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a)); CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a)); -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") +DROP TABLE t2; CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b)); DROP TABLE t3; DROP TABLE t2; diff --git a/mysql-test/suite/gcol/t/innodb_virtual_basic.test b/mysql-test/suite/gcol/t/innodb_virtual_basic.test index 6e86aaad855..89dbf96b610 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_basic.test +++ b/mysql-test/suite/gcol/t/innodb_virtual_basic.test @@ -246,8 +246,8 @@ DROP TABLE t1; CREATE TABLE t1(a INT); CREATE INDEX idx ON t1(a); CREATE TABLE t3(a INT, b INT , INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a)); ---error ER_CANT_CREATE_TABLE CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b), CONSTRAINT x FOREIGN KEY(b) REFERENCES t1(a)); +DROP TABLE t2; CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b)); DROP TABLE t3; DROP TABLE t2; diff --git a/mysql-test/suite/innodb/r/add_constraint.result b/mysql-test/suite/innodb/r/add_constraint.result index 9d894e530c3..5bfe08e6041 100644 --- a/mysql-test/suite/innodb/r/add_constraint.result +++ b/mysql-test/suite/innodb/r/add_constraint.result @@ -6,7 +6,7 @@ create table t2(a int, b int, key(a),key(b))engine=innodb; alter table t2 add constraint b foreign key (b) references t1(a); alter table t1 add constraint b1 foreign key (b) references t2(a); alter table t2 add constraint b1 foreign key (b) references t1(a); -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") +alter table t2 drop foreign key b1; alter table t2 drop foreign key b; alter table t1 drop foreign key b1; drop table t2; diff --git a/mysql-test/suite/innodb/r/alter_copy_bulk.result b/mysql-test/suite/innodb/r/alter_copy_bulk.result index ea9687e9325..dbb76540416 100644 --- a/mysql-test/suite/innodb/r/alter_copy_bulk.result +++ b/mysql-test/suite/innodb/r/alter_copy_bulk.result @@ -37,7 +37,7 @@ info: Records: 0 Duplicates: 0 Warnings: 0 INSERT INTO t1 VALUES (1, 1); INSERT INTO t2 VALUES (1, 2); ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-alter`, CONSTRAINT `#sql-alter_ibfk_2` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-alter`, CONSTRAINT `2` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) INSERT INTO t1 VALUES(3, 1); SET STATEMENT foreign_key_checks=0 FOR ALTER TABLE t2 ALGORITHM=COPY, ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1); diff --git a/mysql-test/suite/innodb/r/alter_table.result b/mysql-test/suite/innodb/r/alter_table.result index 1e818bd0ff4..a2e81346b3b 100644 --- a/mysql-test/suite/innodb/r/alter_table.result +++ b/mysql-test/suite/innodb/r/alter_table.result @@ -46,7 +46,7 @@ CREATE TABLE tx (pk INT PRIMARY KEY) ENGINE=InnoDB; CREATE TABLE t1 (pk INT, a INT, PRIMARY KEY (pk), KEY (a), FOREIGN KEY (a) REFERENCES tx (pk)) ENGINE=InnoDB; SET FOREIGN_KEY_CHECKS=OFF; ALTER TABLE t1 DROP a; -ERROR HY000: Cannot drop column 'a': needed in a foreign key constraint 'test/t1_ibfk_1' +ERROR HY000: Cannot drop column 'a': needed in a foreign key constraint '1' SET FOREIGN_KEY_CHECKS=ON; ALTER TABLE t1 ADD b INT; ALTER TABLE t1 DROP a; diff --git a/mysql-test/suite/innodb/r/fk_col_alter.result b/mysql-test/suite/innodb/r/fk_col_alter.result index c6fdc3231e0..885bd0ba42b 100644 --- a/mysql-test/suite/innodb/r/fk_col_alter.result +++ b/mysql-test/suite/innodb/r/fk_col_alter.result @@ -23,22 +23,22 @@ SET FOREIGN_KEY_CHECKS=1; ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' SET FOREIGN_KEY_CHECKS=0; ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(400) character set utf8mb3, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' SET FOREIGN_KEY_CHECKS=1; ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' SET FOREIGN_KEY_CHECKS=0; ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' SET FOREIGN_KEY_CHECKS=1; ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY; ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") @@ -48,27 +48,27 @@ SET FOREIGN_KEY_CHECKS=0; ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY; ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg_1': used in a foreign key constraint 'test/t2_ibfk_0' +ERROR HY000: Cannot change column 'msg_1': used in a foreign key constraint '0' ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(msg_1) REFERENCES t1(msg),MODIFY COLUMN msg_1 VARCHAR(200) CHARACTER SET utf8mb3, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg_1': used in a foreign key constraint 'test/t2_ibfk_0' +ERROR HY000: Cannot change column 'msg_1': used in a foreign key constraint '0' SET FOREIGN_KEY_CHECKS=1; ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test.t2' ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' of table 'test/t2' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test/t2' ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test.t2' ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' of table 'test/t2' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test/t2' SET FOREIGN_KEY_CHECKS=0; ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test.t2' ALTER TABLE t1 MODIFY msg VARCHAR(400) CHARSET utf8mb3, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' of table 'test/t2' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test/t2' ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY; ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test.t2' ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=INPLACE; -ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'test/fk_t1' of table 'test/t2' +ERROR HY000: Cannot change column 'msg': used in a foreign key constraint 'fk_t1' of table 'test/t2' SET FOREIGN_KEY_CHECKS=0; ALTER TABLE t2 DROP FOREIGN KEY fk_t1, MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY; ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY; diff --git a/mysql-test/suite/innodb/r/fk_drop_alter.result b/mysql-test/suite/innodb/r/fk_drop_alter.result index 1205074bd69..9bcf6381d4d 100644 --- a/mysql-test/suite/innodb/r/fk_drop_alter.result +++ b/mysql-test/suite/innodb/r/fk_drop_alter.result @@ -39,6 +39,6 @@ t2 CREATE TABLE `t2` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -best/foo best/t2 best/t1 1 0 +foo best/t2 best/t1 1 0 DROP TABLE best.t2, best.t1, t2, t1; DROP DATABASE best; diff --git a/mysql-test/suite/innodb/r/foreign-keys.result b/mysql-test/suite/innodb/r/foreign-keys.result index d609efb1fd4..a02bd0c8235 100644 --- a/mysql-test/suite/innodb/r/foreign-keys.result +++ b/mysql-test/suite/innodb/r/foreign-keys.result @@ -22,7 +22,7 @@ insert t2 values (4,1),(5,2),(6,3); flush table t2 with read lock; connect con1,localhost,root; delete from t1 where a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) update t1 set a=10 where a=1; connection default; unlock tables; @@ -34,7 +34,7 @@ delete from t1 where a=2; connection default; unlock tables; connection con1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) connection default; unlock tables; disconnect con1; @@ -75,7 +75,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `f2` int(11) NOT NULL, PRIMARY KEY (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci disconnect con1; connection default; @@ -132,7 +132,7 @@ insert t2 values (4,1),(5,2),(6,3); flush table t2 with read lock; connect con1,localhost,root; delete from t1 where a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) update t1 set a=10 where a=1; connection default; unlock tables; @@ -144,7 +144,7 @@ delete from t1 where a=2; connection default; unlock tables; connection con1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) connection default; unlock tables; disconnect con1; @@ -233,7 +233,7 @@ SET FOREIGN_KEY_CHECKS=0; DROP INDEX f2 ON t2; SET FOREIGN_KEY_CHECKS=1; INSERT INTO t2 VALUES('G', 3); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) DROP TABLE t2, t1; SET FOREIGN_KEY_CHECKS=DEFAULT; CREATE TABLE t1(a SERIAL) ENGINE=InnoDB ROW_FORMAT=COMPRESSED PAGE_COMPRESSED=1; @@ -261,7 +261,15 @@ index i2яяяяяяяяяяььььььььььззззззззззшшшшшш insert t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш values(99, 2); alter table t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш add foreign key(f2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш) references t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш(f1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш); insert t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш values('g', 3); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш`, CONSTRAINT `t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш_ibfk_1` FOREIGN KEY (`f2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш`) REFERENCES `t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш` (`f1яяяяяяяяяяььььььььььззззз +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш`, CONSTRAINT `1` FOREIGN KEY (`f2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш`) REFERENCES `t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш` (`f1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш`)) drop table t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш, t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш; # End of 10.6 tests +# +# MDEV-37077 Crash in innobase_get_foreign_key_info() +# +CREATE TABLE t (id INT PRIMARY KEY, f INT NOT NULL, KEY(f)) ENGINE=InnoDB; +SET STATEMENT FOREIGN_KEY_CHECKS = OFF FOR +ALTER TABLE t ADD FOREIGN KEY (f) REFERENCES t (id) ON UPDATE SET NULL; +ERROR HY000: Failed to add the foreign key constraint on table 't'. Incorrect options in FOREIGN KEY constraint '(null)' +DROP TABLE t; diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result index 90440a2da31..d98da3242f8 100644 --- a/mysql-test/suite/innodb/r/foreign_key.result +++ b/mysql-test/suite/innodb/r/foreign_key.result @@ -11,10 +11,10 @@ ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; alter table t2 add constraint c1 foreign key (f1) references t1(f1); -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") -set foreign_key_checks = 0; +ERROR HY000: Duplicate FOREIGN KEY constraint name '' +set statement foreign_key_checks = 0 for alter table t2 add constraint c1 foreign key (f1) references t1(f1); -ERROR HY000: Duplicate FOREIGN KEY constraint name 'test/c1' +ERROR HY000: Duplicate FOREIGN KEY constraint name 'c1' drop table t2, t1; # # Bug #20031243 CREATE TABLE FAILS TO CHECK IF FOREIGN KEY COLUMN @@ -48,7 +48,7 @@ t2 CREATE TABLE `t2` ( `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), KEY `ind` (`b`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci INSERT INTO t1 VALUES (1, 80); INSERT INTO t1 VALUES (2, 81); @@ -75,7 +75,7 @@ a b 54 4 55 5 INSERT INTO t2 VALUES (56, 6); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) ALTER TABLE t1 CHANGE a id INT; SELECT id, b FROM t1 ORDER BY id; id b @@ -93,9 +93,9 @@ a b 55 5 # Operations on child table INSERT INTO t2 VALUES (56, 6); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) UPDATE t2 SET b = 99 WHERE a = 51; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) DELETE FROM t2 WHERE a = 53; SELECT id, b FROM t1 ORDER BY id; id b @@ -158,9 +158,9 @@ disconnect incomplete; SET GLOBAL innodb_stats_persistent = 0; INSERT INTO child SET a=0; INSERT INTO child SET a=1; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON DELETE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON DELETE CASCADE) DELETE FROM parent; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON DELETE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON DELETE CASCADE) ALTER TABLE child ADD INDEX(a); DELETE FROM parent; DROP TABLE child,parent; @@ -206,7 +206,16 @@ CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB; CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b), FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB; RENAME TABLE best.t2 TO test.t2; -ERROR 42S01: Table 't2' already exists +SHOW CREATE TABLE test.t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` int(11) NOT NULL, + `b` text DEFAULT NULL, + PRIMARY KEY (`a`), + FULLTEXT KEY `b` (`b`), + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +RENAME TABLE test.t2 TO best.t2; SHOW CREATE TABLE best.t2; Table Create Table t2 CREATE TABLE `t2` ( @@ -214,7 +223,7 @@ t2 CREATE TABLE `t2` ( `b` text DEFAULT NULL, PRIMARY KEY (`a`), FULLTEXT KEY `b` (`b`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP DATABASE best; # @@ -243,11 +252,21 @@ CREATE TABLE t1 (a INT, UNIQUE(a), KEY(a)) ENGINE=InnoDB; ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a); SET SESSION FOREIGN_KEY_CHECKS = OFF; ALTER TABLE t1 CHANGE COLUMN a a TIME NOT NULL; -ERROR HY000: Cannot change column 'a': used in a foreign key constraint 't1_ibfk_1' of table 'test.t1' +ERROR HY000: Cannot change column 'a': used in a foreign key constraint '1' of table 'test.t1' ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY; ALTER TABLE t1 CHANGE COLUMN a b TIME; ERROR 0A000: ALGORITHM=COPY is not supported. Reason: Columns participating in a foreign key are renamed. Try ALGORITHM=INPLACE -ALTER TABLE t1 CHANGE COLUMN a b TIME, DROP FOREIGN KEY t1_ibfk_1; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL, + `pk` int(11) NOT NULL AUTO_INCREMENT, + PRIMARY KEY (`pk`), + UNIQUE KEY `a` (`a`), + KEY `a_2` (`a`), + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +ALTER TABLE t1 CHANGE COLUMN a b TIME, DROP FOREIGN KEY `1`; SET SESSION FOREIGN_KEY_CHECKS = ON; DROP TABLE t1; # @@ -342,7 +361,7 @@ insert t2 values (4,1),(5,2),(6,3); flush table t2 with read lock; connect con1,localhost,root; delete from t1 where a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) update t1 set a=10 where a=1; connection default; unlock tables; @@ -354,7 +373,7 @@ delete from t1 where a=2; connection default; unlock tables; connection con1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`d`) REFERENCES `t1` (`a`) ON UPDATE CASCADE) connection default; unlock tables; disconnect con1; @@ -389,7 +408,7 @@ insert t1 values (1,1),(2,2),(3,3); create table t2 (t1_pk int, foreign key (t1_pk) references t1 (pk)) engine=innodb; insert t2 values (1),(2); insert t2 values (10); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_pk`) REFERENCES `t1` (`pk`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`t1_pk`) REFERENCES `t1` (`pk`)) flush tables; flush status; update t1 set data=10 where pk+1>10; @@ -478,10 +497,10 @@ pk f1 f2 f3 f4 f5 f6 f7 f8 ROLLBACK; ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; UPDATE t1 SET f6='update'; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; UPDATE t1 SET f6='cascade'; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) DROP TABLE t1; # Start of 10.2 tests # @@ -556,7 +575,7 @@ t2 CREATE TABLE `t2` ( `f` int(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `ref_id` (`ref_id`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`ref_id`) REFERENCES `t1` (`id`) ON DELETE CASCADE + CONSTRAINT `1` FOREIGN KEY (`ref_id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci connection con1; BEGIN; @@ -688,9 +707,9 @@ connection default; DELETE IGNORE FROM t1 WHERE b = 1; Warnings: Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again -Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB +Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again -Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB +Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB SELECT a FROM t1 FORCE INDEX(a); a 0 @@ -737,7 +756,7 @@ DROP TABLE t1; # MDEV-17187 table doesn't exist in engine after ALTER other tables # with CONSTRAINTs # -call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`\\.`t2` has or is referenced in foreign key constraints which are not compatible with the new table definition."); +call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`\\.`t[12]` has or is referenced in foreign key constraints which are not compatible with the new table definition."); set foreign_key_checks=on; create table t1 (id int not null primary key) engine=innodb; create table t2 (id int not null primary key, fid int not null, @@ -853,11 +872,11 @@ INSERT INTO t1 (a,b) VALUES (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0), (0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,1),(1,0); DELETE FROM t1 WHERE b = 1; -ERROR HY000: Got error 193 '`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB +ERROR HY000: Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB SHOW WARNINGS; Level Code Message Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again -Error 1296 Got error 193 '`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB +Error 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB DROP TABLE t1; FOUND 1 /InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15.*/ in mysqld.1.err # End of 10.2 tests @@ -941,8 +960,8 @@ t2 CREATE TABLE `t2` ( `y` int(11) DEFAULT NULL, KEY `x` (`x`), KEY `fk` (`y`), - CONSTRAINT `fk` FOREIGN KEY (`y`) REFERENCES `t1` (`y`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`) + CONSTRAINT `1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`), + CONSTRAINT `fk` FOREIGN KEY (`y`) REFERENCES `t1` (`y`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci create table t3 (z int); alter table t3 add x int references t1(x), add y int constraint fk2 references t1(y); @@ -954,8 +973,8 @@ t3 CREATE TABLE `t3` ( `y` int(11) DEFAULT NULL, KEY `x` (`x`), KEY `fk2` (`y`), - CONSTRAINT `fk2` FOREIGN KEY (`y`) REFERENCES `t1` (`y`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`) + CONSTRAINT `1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`), + CONSTRAINT `fk2` FOREIGN KEY (`y`) REFERENCES `t1` (`y`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop tables t3, t2, t1; create table t1 (id int primary key); @@ -967,7 +986,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `id` int(11) DEFAULT NULL, KEY `id` (`id`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) + CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop tables t2, t1; set default_storage_engine= default; @@ -1020,7 +1039,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `a` int(11) NOT NULL, PRIMARY KEY (`a`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop tables t2, t1; # @@ -1050,10 +1069,10 @@ CREATE TABLE child(a INT PRIMARY KEY REFERENCES parent(a)) ENGINE=InnoDB; connect con1, localhost, root,,; BEGIN; INSERT INTO child SET a=1; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`)) connection default; TRUNCATE TABLE parent; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) DROP TABLE parent; ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails SET innodb_lock_wait_timeout=0; @@ -1084,7 +1103,7 @@ ALTER TABLE parent FORCE, ALGORITHM=INPLACE; ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT; SET foreign_key_checks=ON; TRUNCATE TABLE parent; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) ALTER TABLE parent FORCE, ALGORITHM=COPY; ALTER TABLE parent FORCE, ALGORITHM=INPLACE; RENAME TABLE parent TO transparent; @@ -1148,13 +1167,13 @@ t2 CREATE TABLE `t2` ( `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`), - CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) + CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`), + CONSTRAINT `2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci INSERT INTO t1 SET a=1; INSERT INTO t2 SET a=1; DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`#mysql50#d-b`.`t2`, CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`#mysql50#d-b`.`t2`, CONSTRAINT `2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) DELETE FROM t2; DELETE FROM t1; DROP DATABASE `#mysql50##mysql50#d-b`; @@ -1172,7 +1191,7 @@ SET STATEMENT foreign_key_checks=0 FOR CREATE TABLE t1 (a INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1); INSERT INTO t2 VALUES (1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) ALTER TABLE t1 ADD KEY(a), ALGORITHM=NOCOPY; INSERT INTO t2 VALUES (1); DROP INDEX b ON t2; @@ -1181,7 +1200,7 @@ SET STATEMENT foreign_key_checks=0 FOR DROP INDEX b ON t2; DELETE FROM t2; DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) ALTER TABLE t2 ADD KEY(b), ALGORITHM=NOCOPY; DELETE FROM t1; DROP TABLE t2, t1; @@ -1224,6 +1243,6 @@ INSERT INTO t2 VALUES('MySQL', 'MySQL', 1), ALTER TABLE t1 ADD FOREIGN KEY (f1) REFERENCES t2 (f2); ALTER TABLE t2 ADD FOREIGN KEY (f2) REFERENCES t2 (f2), ADD UNIQUE INDEX(f3); -ERROR HY000: Cannot delete rows from table which is parent in a foreign key constraint 't1_ibfk_1' of table 't1' +ERROR HY000: Cannot delete rows from table which is parent in a foreign key constraint '1' of table 't1' drop table t1, t2; # End of 10.11 tests diff --git a/mysql-test/suite/innodb/r/foreign_key_debug.result b/mysql-test/suite/innodb/r/foreign_key_debug.result index f72598ddf1e..6a9ee0b8dd1 100644 --- a/mysql-test/suite/innodb/r/foreign_key_debug.result +++ b/mysql-test/suite/innodb/r/foreign_key_debug.result @@ -22,7 +22,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `f2` int(11) NOT NULL, PRIMARY KEY (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci disconnect con1; connection default; diff --git a/mysql-test/suite/innodb/r/foreign_null.result b/mysql-test/suite/innodb/r/foreign_null.result index a5d1afc7e0c..425b9bc0fe3 100644 --- a/mysql-test/suite/innodb/r/foreign_null.result +++ b/mysql-test/suite/innodb/r/foreign_null.result @@ -3,7 +3,7 @@ call mtr.add_suppression("InnoDB: In ALTER TABLE .* has or is referenced in fore CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, FOREIGN KEY(f1) REFERENCES t1(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; -ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL DROP TABLE t2, t1; # modify child column NOT NULL ON DELETE CASCADE..parent column NULL CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; @@ -14,13 +14,13 @@ DROP TABLE t2, t1; CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY(f1) REFERENCES t1(f1) ON UPDATE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; -ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL DROP TABLE t2, t1; # modify child column NOT NULL ON DELETE SET NULL CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY (f2) REFERENCES t1(f2) ON DELETE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL; -ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL DROP TABLE t2, t1; # modify child column NOT NULL ON UPDATE RESTRICT..parent column NULL CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; @@ -48,7 +48,7 @@ CREATE TABLE `t#2`(f1 INT NOT NULL, FOREIGN KEY(f1) REFERENCES `t#1`(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE `t#1` MODIFY COLUMN f2 INT; -ERROR HY000: Cannot change column 'f2': used in a foreign key constraint 't#2_ibfk_1' of table 'test.t#2' +ERROR HY000: Cannot change column 'f2': used in a foreign key constraint '1' of table 'test.t#2' DROP TABLE `t#2`, `t#1`; # modify parent column NULL ON DELETE CASCADE child column NOT NULL CREATE TABLE t1(f1 INT, f2 INT NOT NULL, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; @@ -94,7 +94,7 @@ INDEX(f1, f2), FOREIGN KEY(f1, f2) REFERENCES t1(f1, f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t1 MODIFY COLUMN f1 INT; -ERROR HY000: Cannot change column 'f1': used in a foreign key constraint 't2_ibfk_1' of table 'test.t2' +ERROR HY000: Cannot change column 'f1': used in a foreign key constraint '1' of table 'test.t2' DROP TABLE t2, t1; # modify child column NOT NULL ON UPDATE CASCADE parent column NULL CREATE TABLE t1(f1 INT, f2 INT, INDEX(f1, f2))ENGINE=InnoDB; @@ -102,7 +102,7 @@ CREATE TABLE t2(f1 INT, f2 INT, INDEX(f1, f2), FOREIGN KEY(f1, f2) REFERENCES t1(f1, f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL; -ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL DROP TABLE t2, t1; # allow foreign key constraints when parent table created later SET FOREIGN_KEY_CHECKS=0; @@ -113,7 +113,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1); UPDATE t1 SET f2= NULL; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) SELECT * FROM t2; f1 1 diff --git a/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NON-STRICT.rdiff b/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NON-STRICT.rdiff index 66e39ca633e..c02097d6355 100644 --- a/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NON-STRICT.rdiff +++ b/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NON-STRICT.rdiff @@ -4,11 +4,11 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, FOREIGN KEY(f1) REFERENCES t1(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; --ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1); UPDATE t1 SET f2= NULL; -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) DELETE FROM t2; SELECT * FROM t1; f1 f2 @@ -21,7 +21,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY(f1) REFERENCES t1(f1) ON UPDATE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; --ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL +ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 150 "Foreign key constraint is incorrectly formed") INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1, 1); @@ -30,7 +30,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY (f2) REFERENCES t1(f2) ON DELETE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL; --ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL +ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 150 "Foreign key constraint is incorrectly formed") DROP TABLE t2, t1; # modify parent column NULL ON UPDATE CASCADE child column NOT NULL @@ -39,12 +39,12 @@ FOREIGN KEY(f1) REFERENCES `t#1`(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE `t#1` MODIFY COLUMN f2 INT; --ERROR HY000: Cannot change column 'f2': used in a foreign key constraint 't#2_ibfk_1' of table 'test.t#2' +-ERROR HY000: Cannot change column 'f2': used in a foreign key constraint '1' of table 'test.t#2' INSERT INTO `t#1` VALUES(1, 1); INSERT INTO `t#2` VALUES(1); UPDATE `t#1` SET f2= NULL; -ERROR 23000: Column 'f2' cannot be null -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `t#2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) DELETE FROM `t#2`; SELECT * FROM `t#1`; f1 f2 diff --git a/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NOSTRICT.rdiff b/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NOSTRICT.rdiff index 95df1bfa7d3..d00f48b907c 100644 --- a/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NOSTRICT.rdiff +++ b/mysql-test/suite/innodb/r/foreign_sql_mode,COPY,NOSTRICT.rdiff @@ -4,11 +4,11 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, FOREIGN KEY(f1) REFERENCES t1(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; --ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1); UPDATE t1 SET f2= NULL; -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) DELETE FROM t2; SELECT * FROM t1; f1 f2 @@ -19,7 +19,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY(f1) REFERENCES t1(f1) ON UPDATE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; --ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL +ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 150 "Foreign key constraint is incorrectly formed") INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1, 1); @@ -28,7 +28,7 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY (f2) REFERENCES t1(f2) ON DELETE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL; --ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL +ERROR HY000: Error on rename of 'OLD_FILE_NAME' to 'NEW_FILE_NAME' (errno: 150 "Foreign key constraint is incorrectly formed") DROP TABLE t2, t1; # modify parent column NULL ON UPDATE CASCADE child column NOT NULL @@ -37,12 +37,12 @@ FOREIGN KEY(f1) REFERENCES `t#1`(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE `t#1` MODIFY COLUMN f2 INT; --ERROR HY000: Cannot change column 'f2': used in a foreign key constraint 't#2_ibfk_1' of table 'test.t#2' +-ERROR HY000: Cannot change column 'f2': used in a foreign key constraint '1' of table 'test.t#2' INSERT INTO `t#1` VALUES(1, 1); INSERT INTO `t#2` VALUES(1); UPDATE `t#1` SET f2= NULL; -ERROR 23000: Column 'f2' cannot be null -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `t#2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) DELETE FROM `t#2`; SELECT * FROM `t#1`; f1 f2 diff --git a/mysql-test/suite/innodb/r/foreign_sql_mode,INPLACE,NON-STRICT.rdiff b/mysql-test/suite/innodb/r/foreign_sql_mode,INPLACE,NON-STRICT.rdiff index 8919244e810..3638a899a1a 100644 --- a/mysql-test/suite/innodb/r/foreign_sql_mode,INPLACE,NON-STRICT.rdiff +++ b/mysql-test/suite/innodb/r/foreign_sql_mode,INPLACE,NON-STRICT.rdiff @@ -4,11 +4,11 @@ CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, FOREIGN KEY(f1) REFERENCES t1(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; --ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +-ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1); UPDATE t1 SET f2= NULL; -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE) DELETE FROM t2; SELECT * FROM t1; f1 f2 @@ -21,12 +21,12 @@ FOREIGN KEY(f1) REFERENCES `t#1`(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE `t#1` MODIFY COLUMN f2 INT; --ERROR HY000: Cannot change column 'f2': used in a foreign key constraint 't#2_ibfk_1' of table 'test.t#2' +-ERROR HY000: Cannot change column 'f2': used in a foreign key constraint '1' of table 'test.t#2' INSERT INTO `t#1` VALUES(1, 1); INSERT INTO `t#2` VALUES(1); UPDATE `t#1` SET f2= NULL; -ERROR 23000: Column 'f2' cannot be null -+ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `t#2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) ++ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t#2`, CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t#1` (`f2`) ON UPDATE CASCADE) DELETE FROM `t#2`; SELECT * FROM `t#1`; f1 f2 diff --git a/mysql-test/suite/innodb/r/foreign_sql_mode.result b/mysql-test/suite/innodb/r/foreign_sql_mode.result index 7044e402745..7cc6859d71d 100644 --- a/mysql-test/suite/innodb/r/foreign_sql_mode.result +++ b/mysql-test/suite/innodb/r/foreign_sql_mode.result @@ -3,7 +3,7 @@ call mtr.add_suppression("InnoDB: In ALTER TABLE .* has or is referenced in fore CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, FOREIGN KEY(f1) REFERENCES t1(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; -ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1); UPDATE t1 SET f2= NULL; @@ -20,7 +20,7 @@ DROP TABLE t2, t1; CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY(f1) REFERENCES t1(f1) ON UPDATE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f1 INT NOT NULL; -ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f1' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL INSERT INTO t1 VALUES(1, 1); INSERT INTO t2 VALUES(1, 1); UPDATE t1 SET f1= 2; @@ -32,7 +32,7 @@ DROP TABLE t2, t1; CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; CREATE TABLE t2(f1 INT, f2 INT, FOREIGN KEY (f2) REFERENCES t1(f2) ON DELETE SET NULL)ENGINE=InnoDB; ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL; -ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'f2' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL DROP TABLE t2, t1; # modify parent column NULL ON UPDATE CASCADE child column NOT NULL CREATE TABLE `t#1`(f1 INT, f2 INT NOT NULL, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB; @@ -40,7 +40,7 @@ CREATE TABLE `t#2`(f1 INT NOT NULL, FOREIGN KEY(f1) REFERENCES `t#1`(f2) ON UPDATE CASCADE)ENGINE=InnoDB; ALTER TABLE `t#1` MODIFY COLUMN f2 INT; -ERROR HY000: Cannot change column 'f2': used in a foreign key constraint 't#2_ibfk_1' of table 'test.t#2' +ERROR HY000: Cannot change column 'f2': used in a foreign key constraint '1' of table 'test.t#2' INSERT INTO `t#1` VALUES(1, 1); INSERT INTO `t#2` VALUES(1); UPDATE `t#1` SET f2= NULL; diff --git a/mysql-test/suite/innodb/r/innodb-alter-table.result b/mysql-test/suite/innodb/r/innodb-alter-table.result index 8467c84dbad..291764030f3 100644 --- a/mysql-test/suite/innodb/r/innodb-alter-table.result +++ b/mysql-test/suite/innodb/r/innodb-alter-table.result @@ -132,7 +132,7 @@ child CREATE TABLE `child` ( `c` int(11) NOT NULL, PRIMARY KEY (`a`), KEY `c` (`c`), - CONSTRAINT `child_ibfk_1` FOREIGN KEY (`c`) REFERENCES `parent` (`a`) + CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `parent` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE child, parent; CREATE TABLE IF NOT EXISTS ticket ( diff --git a/mysql-test/suite/innodb/r/innodb-alter.result b/mysql-test/suite/innodb/r/innodb-alter.result index 8ea757e0244..97af366a8f6 100644 --- a/mysql-test/suite/innodb/r/innodb-alter.result +++ b/mysql-test/suite/innodb/r/innodb-alter.result @@ -20,8 +20,8 @@ WHERE FOR_NAME LIKE 'test/t%'; SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID; @@ -37,8 +37,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -73,8 +73,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1; ALTER TABLE t1 CHANGE c1 c1 INT FIRST; SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN @@ -92,8 +92,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE C2 c3 INT; SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i @@ -110,8 +110,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE c3 C INT; SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i @@ -128,14 +128,14 @@ c2 0 C SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 C 0 -test/t1c3 c3 c2 0 +t1c2 c2 C 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT; SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 Cöŀumň_TWO 0 -test/t1c3 c3 c2 0 +t1c2 c2 Cöŀumň_TWO 0 +t1c3 c3 c2 0 SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID; @@ -151,8 +151,8 @@ c2 0 Cöŀumň_TWO SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 Cöŀumň_TWO 0 -test/t1c3 c3 c2 0 +t1c2 c2 Cöŀumň_TWO 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT; ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1' ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3; @@ -250,8 +250,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1 DROP INDEX c2; ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint ALTER TABLE t1 DROP INDEX c4; @@ -308,8 +308,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE=InnoDB; ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3; ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint @@ -344,8 +344,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1c DROP FOREIGN KEY t1C3; SHOW CREATE TABLE t1c; Table Create Table @@ -372,7 +372,7 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 +t1c2 c2 c3 0 ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2; SHOW CREATE TABLE t1c; Table Create Table @@ -726,7 +726,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `c2` int(11) NOT NULL, KEY `c2` (`c2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c1`) + CONSTRAINT `1` FOREIGN KEY (`c2`) REFERENCES `t1` (`c1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ALTER TABLE t1 CHANGE COLUMN c1 C1 INT; ALTER TABLE t2 CHANGE COLUMN c2 C2 INT; @@ -741,7 +741,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `C2` int(11) DEFAULT NULL, KEY `c2` (`C2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`C2`) REFERENCES `t1` (`C1`) + CONSTRAINT `1` FOREIGN KEY (`C2`) REFERENCES `t1` (`C1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ALTER TABLE t1 CHANGE COLUMN C1 c5 INT; ALTER TABLE t2 CHANGE COLUMN C2 c6 INT; @@ -756,7 +756,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `c6` int(11) DEFAULT NULL, KEY `c2` (`c6`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c6`) REFERENCES `t1` (`c5`) + CONSTRAINT `1` FOREIGN KEY (`c6`) REFERENCES `t1` (`c5`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES T ON C.TABLE_ID=T.TABLE_ID @@ -845,27 +845,27 @@ t2 CREATE TABLE `t2` ( KEY `bb` (`BB`), KEY `CC` (`CC`), KEY `DD` (`DD`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`), - CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`BB`) REFERENCES `t1` (`B`), - CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`CC`) REFERENCES `t1` (`C`), - CONSTRAINT `t2_ibfk_4` FOREIGN KEY (`DD`) REFERENCES `t1` (`D`) + CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`), + CONSTRAINT `2` FOREIGN KEY (`BB`) REFERENCES `t1` (`B`), + CONSTRAINT `3` FOREIGN KEY (`CC`) REFERENCES `t1` (`C`), + CONSTRAINT `4` FOREIGN KEY (`DD`) REFERENCES `t1` (`D`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DELETE FROM t1 WHERE a=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE A=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE b=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE B=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE c=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE C=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE d=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DELETE FROM t1 WHERE D=1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`)) DROP TABLE t2, t1; # virtual columns case too CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB; diff --git a/mysql-test/suite/innodb/r/innodb-fk-warnings.result b/mysql-test/suite/innodb/r/innodb-fk-warnings.result index b58d21b0914..d81f707a6fb 100644 --- a/mysql-test/suite/innodb/r/innodb-fk-warnings.result +++ b/mysql-test/suite/innodb/r/innodb-fk-warnings.result @@ -13,13 +13,9 @@ c int not null, CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id), CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") show warnings; Level Code Message -Warning 121 CREATE or ALTER TABLE `test`.`t2` failed: duplicate name, CONSTRAINT `test` FOREIGN KEY (`b`) REFERENCES `t2` (`id`) -Error 1005 Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") -Warning 1022 Can't write; duplicate key in table 't2' -drop table t1; +drop table t2,t1; create table t1(a int) engine=innodb; create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=innodb; ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") diff --git a/mysql-test/suite/innodb/r/innodb-fk.result b/mysql-test/suite/innodb/r/innodb-fk.result index 945484d5dc7..7dac31c4544 100644 --- a/mysql-test/suite/innodb/r/innodb-fk.result +++ b/mysql-test/suite/innodb/r/innodb-fk.result @@ -135,7 +135,7 @@ Table Create Table PRIMARY KEY (`id_depart`,`id_depart_in`), KEY `id_depart_in` (`id_depart_in`), CONSTRAINT `#departaments_tree_ibfk_1` FOREIGN KEY (`id_depart`) REFERENCES `#departaments` (`id_depart`), - CONSTRAINT `#departaments_tree_ibfk_2` FOREIGN KEY (`id_depart_in`) REFERENCES `#departaments` (`id_depart`) + CONSTRAINT `1` FOREIGN KEY (`id_depart_in`) REFERENCES `#departaments` (`id_depart`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci DROP TABLE `#departaments_tree`; DROP TABLE `#departaments`; @@ -145,11 +145,11 @@ CREATE TABLE `boroda` ( `b` INT(11) UNSIGNED DEFAULT NULL, PRIMARY KEY (`id`), KEY `a` (`a`), -CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) +CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; ALTER TABLE `boroda` ADD FOREIGN KEY (`b`) REFERENCES `boroda`(`id`); -ALTER TABLE `boroda` DROP FOREIGN KEY `boroda_ibfk_2`; +ALTER TABLE `boroda` DROP FOREIGN KEY `2`; RENAME TABLE `boroda` TO `#boroda`; ALTER TABLE `#boroda` ADD FOREIGN KEY (`b`) REFERENCES `#boroda`(`id`); @@ -162,8 +162,8 @@ Table Create Table PRIMARY KEY (`id`), KEY `a` (`a`), KEY `b` (`b`), - CONSTRAINT `#boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `#boroda` (`id`), - CONSTRAINT `#boroda_ibfk_2` FOREIGN KEY (`b`) REFERENCES `#boroda` (`id`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `#boroda` (`id`), + CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `#boroda` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci DROP TABLE `#boroda`; CREATE TABLE `boroda` ( @@ -172,7 +172,7 @@ CREATE TABLE `boroda` ( `b` INT(11) UNSIGNED DEFAULT NULL, PRIMARY KEY (`id`), KEY `a` (`a`), -CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) +CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; RENAME TABLE `boroda` TO `bor#oda`; ALTER TABLE `bor#oda` @@ -186,8 +186,8 @@ bor#oda CREATE TABLE `bor#oda` ( PRIMARY KEY (`id`), KEY `a` (`a`), KEY `b` (`b`), - CONSTRAINT `bor#oda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `bor#oda` (`id`), - CONSTRAINT `bor#oda_ibfk_2` FOREIGN KEY (`b`) REFERENCES `bor#oda` (`id`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `bor#oda` (`id`), + CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `bor#oda` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci DROP TABLE `bor#oda`; # @@ -216,7 +216,7 @@ CREATE TABLE t1_fk (a VARCHAR(40), KEY a (a), FULLTEXT KEY(a), CONSTRAINT fk FOR ALTER TABLE t1 RENAME TO tm1, ALGORITHM=COPY; SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk test/t1_fk test/t1 1 4 +fk test/t1_fk test/t1 1 4 SET FOREIGN_KEY_CHECKS=0; CREATE TABLE t1 (c1 BIGINT NOT NULL, c2 BIGINT NOT NULL, PRIMARY KEY(c1), UNIQUE KEY(c2)) ENGINE=MEMORY; ALTER TABLE t1 ENGINE=InnoDB, ALGORITHM=COPY; diff --git a/mysql-test/suite/innodb/r/innodb-index-online-fk.result b/mysql-test/suite/innodb/r/innodb-index-online-fk.result index 2b5b3c91c68..369e71a64c9 100644 --- a/mysql-test/suite/innodb/r/innodb-index-online-fk.result +++ b/mysql-test/suite/innodb/r/innodb-index-online-fk.result @@ -14,14 +14,14 @@ REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 +fk_1 test/child test/parent 1 6 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 +fk_1 a2 b 0 ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; -ERROR HY000: Duplicate FOREIGN KEY constraint name 'test/fk_1' +ERROR HY000: Duplicate FOREIGN KEY constraint name 'fk_1' SET foreign_key_checks = 1; INSERT INTO child VALUES(1,2),(2,3); INSERT INTO child VALUES(4,4); @@ -54,19 +54,19 @@ ALTER TABLE child ADD CONSTRAINT fk_3 FOREIGN KEY (a1, a2) REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE; SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 -test/fk_10 test/child test/parent 2 5 -test/fk_2 test/child test/parent 2 5 -test/fk_3 test/child test/parent 2 5 +fk_1 test/child test/parent 1 6 +fk_10 test/child test/parent 2 5 +fk_2 test/child test/parent 2 5 +fk_3 test/child test/parent 2 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 -test/fk_10 a1 a 0 -test/fk_10 a2 b 1 -test/fk_2 a1 a 0 -test/fk_2 a2 b 1 -test/fk_3 a1 a 0 -test/fk_3 a2 b 1 +fk_1 a2 b 0 +fk_10 a1 a 0 +fk_10 a2 b 1 +fk_2 a1 a 0 +fk_2 a2 b 1 +fk_3 a1 a 0 +fk_3 a2 b 1 SET foreign_key_checks = 1; INSERT INTO child VALUES(5,4); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `fk_1` FOREIGN KEY (`a2`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE) @@ -98,22 +98,22 @@ ALGORITHM = INPLACE; SET DEBUG_DBUG = @saved_debug_dbug; SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 -test/fk_10 test/child test/parent 2 5 -test/fk_2 test/child test/parent 2 5 -test/fk_3 test/child test/parent 2 5 -test/fk_4 test/child test/parent 2 5 +fk_1 test/child test/parent 1 6 +fk_10 test/child test/parent 2 5 +fk_2 test/child test/parent 2 5 +fk_3 test/child test/parent 2 5 +fk_4 test/child test/parent 2 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 -test/fk_10 a1 a 0 -test/fk_10 a2 b 1 -test/fk_2 a1 a 0 -test/fk_2 a2 b 1 -test/fk_3 a1 a 0 -test/fk_3 a2 b 1 -test/fk_4 a1 a 0 -test/fk_4 a2 b 1 +fk_1 a2 b 0 +fk_10 a1 a 0 +fk_10 a2 b 1 +fk_2 a1 a 0 +fk_2 a2 b 1 +fk_3 a1 a 0 +fk_3 a2 b 1 +fk_4 a1 a 0 +fk_4 a2 b 1 SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name; name name test/child a1 @@ -148,22 +148,22 @@ Level Code Message Error 1821 Failed to add the foreign key constraint. Missing index for constraint 'fk_40' in the foreign table '#child' SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 -test/fk_10 test/child test/parent 2 5 -test/fk_2 test/child test/parent 2 5 -test/fk_3 test/child test/parent 2 5 -test/fk_4 test/child test/parent 2 5 +fk_1 test/child test/parent 1 6 +fk_10 test/child test/parent 2 5 +fk_2 test/child test/parent 2 5 +fk_3 test/child test/parent 2 5 +fk_4 test/child test/parent 2 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 -test/fk_10 a1 a 0 -test/fk_10 a2 b 1 -test/fk_2 a1 a 0 -test/fk_2 a2 b 1 -test/fk_3 a1 a 0 -test/fk_3 a2 b 1 -test/fk_4 a1 a 0 -test/fk_4 a2 b 1 +fk_1 a2 b 0 +fk_10 a1 a 0 +fk_10 a2 b 1 +fk_2 a1 a 0 +fk_2 a2 b 1 +fk_3 a1 a 0 +fk_3 a2 b 1 +fk_4 a1 a 0 +fk_4 a2 b 1 SET DEBUG_DBUG = '+d,innodb_test_no_reference_idx'; ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2) REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, @@ -177,35 +177,35 @@ SET DEBUG_DBUG = '+d,innodb_test_wrong_fk_option'; ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2) REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, ALGORITHM = INPLACE; -ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'test/fk_42' +ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'fk_42' SET DEBUG_DBUG = @saved_debug_dbug; SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 -test/fk_10 test/child test/parent 2 5 -test/fk_2 test/child test/parent 2 5 -test/fk_3 test/child test/parent 2 5 -test/fk_4 test/child test/parent 2 5 +fk_1 test/child test/parent 1 6 +fk_10 test/child test/parent 2 5 +fk_2 test/child test/parent 2 5 +fk_3 test/child test/parent 2 5 +fk_4 test/child test/parent 2 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 -test/fk_10 a1 a 0 -test/fk_10 a2 b 1 -test/fk_2 a1 a 0 -test/fk_2 a2 b 1 -test/fk_3 a1 a 0 -test/fk_3 a2 b 1 -test/fk_4 a1 a 0 -test/fk_4 a2 b 1 +fk_1 a2 b 0 +fk_10 a1 a 0 +fk_10 a2 b 1 +fk_2 a1 a 0 +fk_2 a2 b 1 +fk_3 a1 a 0 +fk_3 a2 b 1 +fk_4 a1 a 0 +fk_4 a2 b 1 SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system'; ALTER TABLE `#child` ADD CONSTRAINT fk_43 FOREIGN KEY (a1, a2) REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE, ALGORITHM = INPLACE; -ERROR HY000: Failed to add the foreign key constraint 'test/fk_43' to system tables +ERROR HY000: Failed to add the foreign key constraint 'test/@0023child' to system tables SET DEBUG_DBUG = @saved_debug_dbug; SHOW ERRORS; Level Code Message -Error 1823 Failed to add the foreign key constraint 'test/fk_43' to system tables +Error 1823 Failed to add the foreign key constraint 'test/@0023child' to system tables DROP TABLE `#child`; DROP TABLE `#parent`; SET foreign_key_checks = 0; @@ -216,27 +216,27 @@ REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, ALGORITHM = INPLACE; SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 -test/fk_10 test/child test/parent 2 5 -test/fk_2 test/child test/parent 2 5 -test/fk_3 test/child test/parent 2 5 -test/fk_4 test/child test/parent 2 5 -test/fk_5 test/child test/parent 1 6 -test/fk_6 test/child test/parent 2 5 +fk_1 test/child test/parent 1 6 +fk_10 test/child test/parent 2 5 +fk_2 test/child test/parent 2 5 +fk_3 test/child test/parent 2 5 +fk_4 test/child test/parent 2 5 +fk_5 test/child test/parent 1 6 +fk_6 test/child test/parent 2 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 -test/fk_10 a1 a 0 -test/fk_10 a2 b 1 -test/fk_2 a1 a 0 -test/fk_2 a2 b 1 -test/fk_3 a1 a 0 -test/fk_3 a2 b 1 -test/fk_4 a1 a 0 -test/fk_4 a2 b 1 -test/fk_5 a2 b 0 -test/fk_6 a1 a 0 -test/fk_6 a2 b 1 +fk_1 a2 b 0 +fk_10 a1 a 0 +fk_10 a2 b 1 +fk_2 a1 a 0 +fk_2 a2 b 1 +fk_3 a1 a 0 +fk_3 a2 b 1 +fk_4 a1 a 0 +fk_4 a2 b 1 +fk_5 a2 b 0 +fk_6 a1 a 0 +fk_6 a2 b 1 DROP TABLE child; DROP TABLE parent; CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; @@ -261,10 +261,10 @@ child CREATE TABLE `child` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * FROM information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_4 test/child test/parent 1 5 +fk_4 test/child test/parent 1 5 SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_4 a2 b 0 +fk_4 a2 b 0 SET foreign_key_checks = 1; DROP TABLE child; DROP TABLE parent; @@ -298,7 +298,7 @@ ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; -ERROR HY000: Failed to add the foreign key constraint 'test/fk_1' to system tables +ERROR HY000: Failed to add the foreign key constraint 'test/child' to system tables SET DEBUG_DBUG = @saved_debug_dbug; SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE @@ -326,10 +326,10 @@ Warnings: Warning 1280 Name 'idx' ignored for PRIMARY key. SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 +fk_1 test/child test/parent 1 6 SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 +fk_1 a2 b 0 SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name; name name test/child a2 @@ -363,10 +363,10 @@ Warnings: Warning 1280 Name 'idx' ignored for PRIMARY key. SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 +fk_1 test/child test/parent 1 6 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a2 b 0 +fk_1 a2 b 0 SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name; name name test/child a1 @@ -398,10 +398,10 @@ ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_1 test/child test/parent 1 6 +fk_1 test/child test/parent 1 6 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_1 a3 b 0 +fk_1 a3 b 0 SELECT t2.name, t1.name FROM information_schema.innodb_sys_columns t1, information_schema.innodb_sys_tables t2 WHERE t1.table_id = t2.table_id AND t2.name LIKE "%child" ORDER BY t1.name; name name test/child a2 @@ -430,7 +430,7 @@ ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; -ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'test/fk_1' +ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'fk_1' DROP TABLE parent; DROP TABLE child; CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL, c INT) ENGINE = InnoDB; @@ -459,12 +459,12 @@ child CREATE TABLE `child` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_a test/child test/parent 1 6 -test/fk_b test/child test/parent 1 0 +fk_a test/child test/parent 1 6 +fk_b test/child test/parent 1 0 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_a a2_new b 0 -test/fk_b a1_new a 0 +fk_a a2_new b 0 +fk_b a1_new a 0 ALTER TABLE child ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b), ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a), @@ -484,12 +484,12 @@ child CREATE TABLE `child` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_a test/child test/parent 1 6 -test/fk_b test/child test/parent 1 0 +fk_a test/child test/parent 1 6 +fk_b test/child test/parent 1 0 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_a a2_new b 0 -test/fk_b a1_new a 0 +fk_a a2_new b 0 +fk_b a1_new a 0 ALTER TABLE child ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b), ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a), @@ -512,18 +512,18 @@ child CREATE TABLE `child` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_a test/child test/parent 1 6 -test/fk_b test/child test/parent 1 0 -test/fk_new_1 test/child test/parent 1 0 -test/fk_new_2 test/child test/parent 1 0 -test/fk_new_3 test/child test/parent 1 0 +fk_a test/child test/parent 1 6 +fk_b test/child test/parent 1 0 +fk_new_1 test/child test/parent 1 0 +fk_new_2 test/child test/parent 1 0 +fk_new_3 test/child test/parent 1 0 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_a a2_new b 0 -test/fk_b a1_new a 0 -test/fk_new_1 a1_new b 0 -test/fk_new_2 a2_new a 0 -test/fk_new_3 a3 a 0 +fk_a a2_new b 0 +fk_b a1_new a 0 +fk_new_1 a1_new b 0 +fk_new_2 a2_new a 0 +fk_new_3 a3 a 0 DROP TABLE child; CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB; CREATE INDEX tb ON child(a2); @@ -567,14 +567,14 @@ child CREATE TABLE `child` ( ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/fk_new_1 test/child test/parent 1 0 -test/fk_new_2 test/child test/parent 1 0 -test/fk_new_3 test/child test/parent 1 0 +fk_new_1 test/child test/parent 1 0 +fk_new_2 test/child test/parent 1 0 +fk_new_3 test/child test/parent 1 0 SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/fk_new_1 a1 b 0 -test/fk_new_2 a2 a 0 -test/fk_new_3 a3 a 0 +fk_new_1 a1 b 0 +fk_new_2 a2 a 0 +fk_new_3 a3 a 0 SET foreign_key_checks = 1; DROP TABLE child; DROP TABLE parent; @@ -597,15 +597,16 @@ CREATE INDEX idx ON t3(a); ALTER TABLE `t2` ADD CONSTRAINT `fw` FOREIGN KEY (`c`) REFERENCES t3 (a); ALTER TABLE `t2` ADD CONSTRAINT `e` foreign key (`d`) REFERENCES t3(a); ALTER TABLE `t3` ADD CONSTRAINT `e` foreign key (`c`) REFERENCES `t2`(`c`) ON UPDATE SET NULL; -ERROR HY000: Failed to add the foreign key constraint 'test/e' to system tables SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/e test/t2 test/t3 1 0 -test/fw test/t2 test/t3 1 0 +e test/t2 test/t3 1 0 +fw test/t2 test/t3 1 0 +e test/t3 test/t2 1 8 SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/e d a 0 -test/fw c a 0 +e d a 0 +fw c a 0 +e c c 0 DROP TABLE t2; DROP TABLE t3; # Bug #17449901 TABLE DISAPPEARS WHEN ALTERING @@ -625,7 +626,7 @@ Table Create Table t2 CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, `f3` int(11) DEFAULT NULL, - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t2; drop table t1; @@ -640,7 +641,7 @@ t2 CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, `f3` int(11) DEFAULT NULL, KEY `t1` (`f2`,`f3`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t2; drop table t1; @@ -655,7 +656,7 @@ Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, KEY `f1` (`f1`), - CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; CREATE TABLE t1(f1 INT, KEY(f1), @@ -665,13 +666,13 @@ Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, KEY `f1` (`f1`), - CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ALTER TABLE t1 DROP KEY f1; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) DEFAULT NULL, - CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/innodb-index.result b/mysql-test/suite/innodb/r/innodb-index.result index 27733c5165d..211f28d9f6e 100644 --- a/mysql-test/suite/innodb/r/innodb-index.result +++ b/mysql-test/suite/innodb/r/innodb-index.result @@ -456,21 +456,21 @@ ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint alter table t2 drop index b, drop index c, drop index d; ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint alter table t2 MODIFY b INT NOT NULL, ALGORITHM=COPY; -ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL set @old_sql_mode = @@sql_mode; set @@sql_mode = 'STRICT_TRANS_TABLES'; alter table t2 MODIFY b INT NOT NULL, ALGORITHM=INPLACE; -ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL set @@sql_mode = @old_sql_mode; SET FOREIGN_KEY_CHECKS=0; alter table t2 DROP COLUMN b, ALGORITHM=COPY; -ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint 't2_ibfk_1' +ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint '1' alter table t2 DROP COLUMN b; -ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint 'test/t2_ibfk_1' +ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint '1' alter table t1 DROP COLUMN b, ALGORITHM=COPY; -ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint 't2_ibfk_1' of table `test`.`t2` +ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint '1' of table `test`.`t2` alter table t1 DROP COLUMN b; -ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint 'test/t2_ibfk_1' of table `test`.`t2` +ERROR HY000: Cannot drop column 'b': needed in a foreign key constraint 'test/t2' of table `test`.`t2` SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; create unique index dc on t2 (d,c); affected rows: 0 @@ -481,10 +481,10 @@ info: Records: 0 Duplicates: 0 Warnings: 0 set @@sql_mode = 'STRICT_TRANS_TABLES'; alter table t2 add primary key (alpha), change a alpha int, change b beta int not null, change c charlie int not null; -ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'b' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL alter table t2 add primary key (alpha), change a alpha int, change c charlie int not null, change d delta int not null; -ERROR HY000: Column 'd' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_3' SET NULL +ERROR HY000: Column 'd' cannot be NOT NULL: needed in a foreign key constraint '3' SET NULL alter table t2 add primary key (alpha), change a alpha int, change b beta int, modify c int not null; affected rows: 0 @@ -509,11 +509,8 @@ t4 CREATE TABLE `t4` ( CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci alter table t3 add constraint dc foreign key (a) references t1(a); -ERROR HY000: Can't create table `test`.`t3` (errno: 121 "Duplicate key on write or update") -SET FOREIGN_KEY_CHECKS=0; +alter table t3 drop foreign key dc; alter table t3 add constraint dc foreign key (a) references t1(a); -ERROR HY000: Failed to add the foreign key constraint 'test/dc' to system tables -SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; show create table t3; Table Create Table t3 CREATE TABLE `t3` ( @@ -521,7 +518,8 @@ t3 CREATE TABLE `t3` ( `c` int(11) NOT NULL, `d` int(11) DEFAULT NULL, PRIMARY KEY (`a`), - KEY `c` (`c`) + KEY `c` (`c`), + CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci alter table t2 drop index b, add index (beta); affected rows: 0 @@ -538,16 +536,17 @@ t2 CREATE TABLE `t2` ( UNIQUE KEY `dc` (`d`,`c`), KEY `c` (`c`), KEY `beta` (`beta`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`beta`) REFERENCES `t1` (`b`) ON DELETE SET NULL, - CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`), - CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`) ON UPDATE SET NULL + CONSTRAINT `1` FOREIGN KEY (`beta`) REFERENCES `t1` (`b`) ON DELETE SET NULL, + CONSTRAINT `2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`), + CONSTRAINT `3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`) ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci delete from t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) drop index dc on t4; ERROR 42000: Can't DROP INDEX `dc`; check that it exists alter table t3 drop foreign key dc; -ERROR 42000: Can't DROP FOREIGN KEY `dc`; check that it exists +affected rows: 0 +info: Records: 0 Duplicates: 0 Warnings: 0 alter table t4 drop foreign key dc; affected rows: 0 info: Records: 0 Duplicates: 0 Warnings: 0 @@ -968,7 +967,7 @@ FOREIGN KEY (c3,c2) REFERENCES t1(c1,c2); ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_t2_ca' in the referenced table 't1' ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=INPLACE; -ERROR HY000: Failed to add the foreign key constraint on table 't2'. Incorrect options in FOREIGN KEY constraint 'test/fk_t2_ca' +ERROR HY000: Failed to add the foreign key constraint on table 't2'. Incorrect options in FOREIGN KEY constraint 'fk_t2_ca' ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=COPY; ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed") diff --git a/mysql-test/suite/innodb/r/innodb-system-table-view.result b/mysql-test/suite/innodb/r/innodb-system-table-view.result index ab1d6bc89db..907e898cb28 100644 --- a/mysql-test/suite/innodb/r/innodb-system-table-view.result +++ b/mysql-test/suite/innodb/r/innodb-system-table-view.result @@ -98,10 +98,10 @@ FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE) ENGINE=INNODB; SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/constraint_test test/child test/parent 1 1 +constraint_test test/child test/parent 1 1 SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/constraint_test parent_id id 0 +constraint_test parent_id id 0 INSERT INTO parent VALUES(1); InnoDB 0 transactions not purged SELECT name, num_rows, ref_count @@ -154,11 +154,11 @@ FOREIGN KEY (id, parent_id) REFERENCES parent(id, newid) ON DELETE CASCADE) ENGINE=INNODB; SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE -test/constraint_test test/child test/parent 2 1 +constraint_test test/child test/parent 2 1 SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; ID FOR_COL_NAME REF_COL_NAME POS -test/constraint_test id id 0 -test/constraint_test parent_id newid 1 +constraint_test id id 0 +constraint_test parent_id newid 1 INSERT INTO parent VALUES(1, 9); SELECT * FROM parent WHERE id IN (SELECT id FROM parent); id newid diff --git a/mysql-test/suite/innodb/r/innodb-truncate.result b/mysql-test/suite/innodb/r/innodb-truncate.result index 5b7d052bca3..7c9d099fe7b 100644 --- a/mysql-test/suite/innodb/r/innodb-truncate.result +++ b/mysql-test/suite/innodb/r/innodb-truncate.result @@ -7,7 +7,7 @@ CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB; CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) # Truncation of child should succeed. TRUNCATE TABLE t2; DROP TABLE t2; @@ -32,7 +32,7 @@ TRUNCATE TABLE t2; TRUNCATE TABLE t3; SET @@SESSION.foreign_key_checks = 1; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) TRUNCATE TABLE t2; TRUNCATE TABLE t3; LOCK TABLES t1 WRITE; @@ -40,7 +40,7 @@ SET @@SESSION.foreign_key_checks = 0; TRUNCATE TABLE t1; SET @@SESSION.foreign_key_checks = 1; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) UNLOCK TABLES; DROP TABLE t3,t2,t1; SET @@SESSION.foreign_key_checks = @old_foreign_key_checks; @@ -88,7 +88,7 @@ ERROR HY000: Can't create table `test`.`t3` (errno: 150 "Foreign key constraint ALTER TABLE t1 RENAME TO t3; ALTER TABLE t3 FORCE; TRUNCATE TABLE t3; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `test`.`t3` (`f2`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `test`.`t3` (`f2`)) DROP TABLE t2, t3; # # MDEV-24861 Assertion `trx->rsegs.m_redo.rseg' failed diff --git a/mysql-test/suite/innodb/r/innodb-wl5522-1.result b/mysql-test/suite/innodb/r/innodb-wl5522-1.result index 72d7268244f..9d5a68a4e8b 100644 --- a/mysql-test/suite/innodb/r/innodb-wl5522-1.result +++ b/mysql-test/suite/innodb/r/innodb-wl5522-1.result @@ -279,7 +279,7 @@ col_1_int col_2_varchar 2 a2 3 a3 INSERT INTO testdb_wl5522.t1_fk VALUES (100,'a100'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`testdb_wl5522`.`t1_fk`, CONSTRAINT `t1_fk_ibfk_1` FOREIGN KEY (`col_2_varchar`) REFERENCES `t1` (`col_2_varchar`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`testdb_wl5522`.`t1_fk`, CONSTRAINT `1` FOREIGN KEY (`col_2_varchar`) REFERENCES `t1` (`col_2_varchar`)) SET AUTOCOMMIT = 0; INSERT INTO testdb_wl5522.t1_fk VALUES (4,'a4'),(5,'a5'); ROLLBACK; diff --git a/mysql-test/suite/innodb/r/innodb-wl5980-alter.result b/mysql-test/suite/innodb/r/innodb-wl5980-alter.result index 70ba67cff07..a0e23ad9809 100644 --- a/mysql-test/suite/innodb/r/innodb-wl5980-alter.result +++ b/mysql-test/suite/innodb/r/innodb-wl5980-alter.result @@ -25,8 +25,8 @@ WHERE FOR_NAME LIKE 'test/t%'; SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID; @@ -42,8 +42,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -95,8 +95,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1; ALTER TABLE t1 CHANGE c1 c1 INT FIRST; ### files in MYSQL_DATA_DIR/test @@ -131,8 +131,8 @@ c2 0 c2 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c2 0 -test/t1c3 c3 c2 0 +t1c2 c2 c2 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE C2 c3 INT; ### files in MYSQL_DATA_DIR/test db.opt @@ -166,8 +166,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE c3 C INT; ### files in MYSQL_DATA_DIR/test db.opt @@ -201,8 +201,8 @@ c2 0 C SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 C 0 -test/t1c3 c3 c2 0 +t1c2 c2 C 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT; ### files in MYSQL_DATA_DIR/test db.opt @@ -224,8 +224,8 @@ t1c.ibd SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 Cöŀumň_TWO 0 -test/t1c3 c3 c2 0 +t1c2 c2 Cöŀumň_TWO 0 +t1c3 c3 c2 0 SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID; @@ -241,8 +241,8 @@ c2 0 Cöŀumň_TWO SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 Cöŀumň_TWO 0 -test/t1c3 c3 c2 0 +t1c2 c2 Cöŀumň_TWO 0 +t1c3 c3 c2 0 ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT; ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1' ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3; @@ -442,8 +442,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1 DROP INDEX c2; ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint ALTER TABLE t1 DROP INDEX c4; @@ -515,8 +515,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE=InnoDB DATA DIRECTORY='MYSQL_TMP_DIR/alt_dir'; ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3; @@ -570,8 +570,8 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 -test/t1c3 c3 c2 0 +t1c2 c2 c3 0 +t1c3 c3 c2 0 ALTER TABLE t1c DROP FOREIGN KEY t1C3; ### files in MYSQL_DATA_DIR/test db.opt @@ -616,7 +616,7 @@ c2 0 c3 SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i INNER JOIN sys_foreign sf ON i.ID = sf.ID; ID FOR_COL_NAME REF_COL_NAME POS -test/t1c2 c2 c3 0 +t1c2 c2 c3 0 ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2; ### files in MYSQL_DATA_DIR/test db.opt diff --git a/mysql-test/suite/innodb/r/innodb.result b/mysql-test/suite/innodb/r/innodb.result index d2cdcdf9752..7b91a41c2d2 100644 --- a/mysql-test/suite/innodb/r/innodb.result +++ b/mysql-test/suite/innodb/r/innodb.result @@ -1580,7 +1580,7 @@ t2 CREATE TABLE `t2` ( PRIMARY KEY (`a`), UNIQUE KEY `b_2` (`b`), KEY `b` (`b`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) + CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t2; create table t2 (a int auto_increment primary key, b int, foreign key (b) references t1(id), foreign key (b) references t1(id), unique(b)) engine=innodb; @@ -1591,8 +1591,8 @@ t2 CREATE TABLE `t2` ( `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b` (`b`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`), - CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) + CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`), + CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci drop table t2, t1; create table t1 (c char(10), index (c,c)) engine=innodb; @@ -2413,7 +2413,7 @@ SELECT * FROM t1; id 1 TRUNCATE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `test`.`t1` (`id`)) INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; id @@ -2421,7 +2421,7 @@ id 2 DELETE FROM t1; TRUNCATE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`id`) REFERENCES `test`.`t1` (`id`)) INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; id @@ -2539,12 +2539,12 @@ create table t2 (a int primary key, b int, foreign key (b) references t1(a)) eng create table t1(a char(10) primary key, b varchar(20)) engine = innodb; set foreign_key_checks=1; insert into t2 values (1,1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) set foreign_key_checks=0; drop table t1; set foreign_key_checks=1; insert into t2 values (1,1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) create table t1(a char(10) primary key, b varchar(20)) engine = innodb; ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed") drop table t2; @@ -2560,14 +2560,14 @@ set foreign_key_checks=0; create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb; create table t1(a varchar(10) primary key) engine = innodb; alter table t1 modify column a int; -ERROR HY000: Cannot change column 'a': used in a foreign key constraint 't2_ibfk_1' of table 'test.t2' +ERROR HY000: Cannot change column 'a': used in a foreign key constraint '1' of table 'test.t2' set foreign_key_checks=1; drop table t2,t1; set foreign_key_checks=0; create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1; create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1; alter table t1 convert to character set utf8; -ERROR HY000: Cannot change column 'a': used in a foreign key constraint 't2_ibfk_1' of table 'test.t2' +ERROR HY000: Cannot change column 'a': used in a foreign key constraint '1' of table 'test.t2' set foreign_key_checks=1; drop table t2,t1; call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`.`t1` has or is referenced in foreign key constraints which are not compatible with the new table definition."); @@ -2585,29 +2585,29 @@ create table t4(a int primary key,constraint foreign key(a)references t3(a)) row insert into t1 values(1); insert into t3 values(1); insert into t2 values(2); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) insert into t4 values(2); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) insert into t2 values(1); insert into t4 values(1); update t1 set a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t2 set a=2; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) update t3 set a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) update t4 set a=2; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) truncate t3; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) truncate t2; truncate t4; truncate t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) truncate t3; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) drop table t4,t3,t2,t1; create table t1 (a varchar(255) character set utf8, b varchar(255) character set utf8, @@ -2728,14 +2728,14 @@ drop table t2,t1; CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB; CREATE TABLE t2(a INT) ENGINE=InnoDB; ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a); -ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1; -ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a); -ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0; +ALTER TABLE t2 DROP FOREIGN KEY `1`; +ALTER TABLE t2 ADD CONSTRAINT `0` FOREIGN KEY (a) REFERENCES t1(a); +ALTER TABLE t2 DROP FOREIGN KEY `0`; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, - KEY `t2_ibfk_0` (`a`) + KEY `0` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t2,t1; SET sql_mode = default; @@ -3061,7 +3061,7 @@ t2 CREATE TABLE `t2` ( `f` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `f` (`f`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `1` FOREIGN KEY (`f`) REFERENCES `t1` (`f`) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t2, t1; @@ -3073,7 +3073,7 @@ ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1 (a) ON DELETE SET NULL; set @old_sql_mode = @@sql_mode; set @@sql_mode = 'STRICT_TRANS_TABLES'; ALTER TABLE t2 MODIFY a INT NOT NULL; -ERROR HY000: Column 'a' cannot be NOT NULL: needed in a foreign key constraint 't2_ibfk_1' SET NULL +ERROR HY000: Column 'a' cannot be NOT NULL: needed in a foreign key constraint '1' SET NULL set @@sql_mode = @old_sql_mode; DELETE FROM t1; DROP TABLE t2,t1; diff --git a/mysql-test/suite/innodb/r/innodb_bug21704.result b/mysql-test/suite/innodb/r/innodb_bug21704.result index 7a880be2646..8853817bd67 100644 --- a/mysql-test/suite/innodb/r/innodb_bug21704.result +++ b/mysql-test/suite/innodb/r/innodb_bug21704.result @@ -82,8 +82,8 @@ INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FOREIGN f ON c.ID=f.ID WHERE FOR_NAME LIKE 'test/t%'; ID FOR_NAME REF_NAME N_COLS TYPE ID FOR_COL_NAME REF_COL_NAME POS -test/fk1 test/t2 test/t1 1 0 test/fk1 z e 0 -test/fk2 test/t3 test/t3 1 0 test/fk2 g f 0 +fk1 test/t2 test/t1 1 0 fk1 z e 0 +fk2 test/t3 test/t3 1 0 fk2 g f 0 DROP TABLE t3; DROP TABLE t2; DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/innodb_bug57904.result b/mysql-test/suite/innodb/r/innodb_bug57904.result index 909f77b25d4..1167bcfd869 100644 --- a/mysql-test/suite/innodb/r/innodb_bug57904.result +++ b/mysql-test/suite/innodb/r/innodb_bug57904.result @@ -17,7 +17,7 @@ SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE table_name = 'product_order'; CONSTRAINT_CATALOG def CONSTRAINT_SCHEMA test -CONSTRAINT_NAME product_order_ibfk_1 +CONSTRAINT_NAME 1 UNIQUE_CONSTRAINT_CATALOG def UNIQUE_CONSTRAINT_SCHEMA test UNIQUE_CONSTRAINT_NAME PRIMARY @@ -28,7 +28,7 @@ TABLE_NAME product_order REFERENCED_TABLE_NAME product CONSTRAINT_CATALOG def CONSTRAINT_SCHEMA test -CONSTRAINT_NAME product_order_ibfk_2 +CONSTRAINT_NAME 2 UNIQUE_CONSTRAINT_CATALOG def UNIQUE_CONSTRAINT_SCHEMA test UNIQUE_CONSTRAINT_NAME PRIMARY diff --git a/mysql-test/suite/innodb/r/innodb_mysql.result b/mysql-test/suite/innodb/r/innodb_mysql.result index b4130769725..106b3a994e1 100644 --- a/mysql-test/suite/innodb/r/innodb_mysql.result +++ b/mysql-test/suite/innodb/r/innodb_mysql.result @@ -322,7 +322,7 @@ INSERT INTO t1 VALUES (1); INSERT INTO t2 VALUES (1); DELETE IGNORE FROM t1 WHERE i = 1; Warnings: -Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`i`) REFERENCES `t1` (`i`) ON DELETE NO ACTION) +Warning 1451 Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`i`) REFERENCES `t1` (`i`) ON DELETE NO ACTION) SELECT * FROM t1, t2; i i 1 1 @@ -2126,10 +2126,10 @@ t2 CREATE TABLE `t2` ( `c` int(11) NOT NULL, `d` int(11) NOT NULL, PRIMARY KEY (`c`,`d`), + CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION, CONSTRAINT `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION, CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION, - CONSTRAINT `f3` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION, - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION + CONSTRAINT `f3` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t2; DROP TABLE t1; @@ -2445,7 +2445,7 @@ INSERT INTO t2 VALUES (3,2); SET AUTOCOMMIT = 0; START TRANSACTION; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -2457,7 +2457,7 @@ id 2 START TRANSACTION; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -2475,7 +2475,7 @@ id 2 COMMIT; TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -2487,7 +2487,7 @@ id 1 2 TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) ROLLBACK; SELECT * FROM t1; id @@ -2526,9 +2526,9 @@ INSERT INTO t4 VALUES (1),(2),(3),(4),(5); INSERT INTO t5 VALUES (1); DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a; DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`)) DELETE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `1` FOREIGN KEY (`bid`) REFERENCES `t2` (`id`)) DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1; DROP TABLE t3; DROP TABLE t2; @@ -2627,7 +2627,7 @@ END|| SET @a:=0; ** Errors in the trigger causes the statement to abort. DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`t1i`) REFERENCES `t1` (`i`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `1` FOREIGN KEY (`t1i`) REFERENCES `t1` (`i`)) SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i; i i 1 1 diff --git a/mysql-test/suite/innodb/r/instant_alter.result b/mysql-test/suite/innodb/r/instant_alter.result index 6c21056b46d..def1fecb96a 100644 --- a/mysql-test/suite/innodb/r/instant_alter.result +++ b/mysql-test/suite/innodb/r/instant_alter.result @@ -468,7 +468,7 @@ CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=InnoDB ROW_FORMAT=REDUNDANT; INSERT INTO t1 SET a=1; INSERT INTO t2 SET b=1; -ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY t2_ibfk_1; +ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY `1`; ALTER TABLE t2 ADD INDEX(a); ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a), ALGORITHM=INSTANT; @@ -480,7 +480,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a), ALGORITHM=INSTANT; SET foreign_key_checks=1; ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk; -ALTER TABLE t1 DROP FOREIGN KEY t1_ibfk_1; +ALTER TABLE t1 DROP FOREIGN KEY `1`; ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75); CHECK TABLE t2, t1; @@ -1402,7 +1402,7 @@ CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=InnoDB ROW_FORMAT=COMPACT; INSERT INTO t1 SET a=1; INSERT INTO t2 SET b=1; -ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY t2_ibfk_1; +ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY `1`; ALTER TABLE t2 ADD INDEX(a); ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a), ALGORITHM=INSTANT; @@ -1414,7 +1414,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a), ALGORITHM=INSTANT; SET foreign_key_checks=1; ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk; -ALTER TABLE t1 DROP FOREIGN KEY t1_ibfk_1; +ALTER TABLE t1 DROP FOREIGN KEY `1`; ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75); CHECK TABLE t2, t1; @@ -2336,7 +2336,7 @@ CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a)) ENGINE=InnoDB ROW_FORMAT=DYNAMIC; INSERT INTO t1 SET a=1; INSERT INTO t2 SET b=1; -ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY t2_ibfk_1; +ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY `1`; ALTER TABLE t2 ADD INDEX(a); ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a), ALGORITHM=INSTANT; @@ -2348,7 +2348,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a), ALGORITHM=INSTANT; SET foreign_key_checks=1; ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk; -ALTER TABLE t1 DROP FOREIGN KEY t1_ibfk_1; +ALTER TABLE t1 DROP FOREIGN KEY `1`; ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75); CHECK TABLE t2, t1; @@ -2913,20 +2913,19 @@ CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1), FOREIGN KEY fk (f2) REFERENCES t2(f1) )ENGINE=InnoDB; ALTER TABLE t1 ADD f5 INT; -SET FOREIGN_KEY_CHECKS=0; +SET STATEMENT FOREIGN_KEY_CHECKS=0 FOR ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1) REFERENCES x(x); -ERROR HY000: Failed to add the foreign key constraint 'test/fk' to system tables ALTER TABLE t1 DROP COLUMN f5; SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( `f1` int(11) NOT NULL, `f2` int(11) DEFAULT NULL, - `f3` int(11) DEFAULT NULL, `f4` int(11) NOT NULL, PRIMARY KEY (`f1`,`f4`), - KEY `f2` (`f2`) + KEY `f2` (`f2`), + CONSTRAINT `fk` FOREIGN KEY (`f1`) REFERENCES `x` (`x`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci DROP TABLE t1, t2; # diff --git a/mysql-test/suite/innodb/r/instant_alter_bugs.result b/mysql-test/suite/innodb/r/instant_alter_bugs.result index bd4e2316bc4..dc91465c40c 100644 --- a/mysql-test/suite/innodb/r/instant_alter_bugs.result +++ b/mysql-test/suite/innodb/r/instant_alter_bugs.result @@ -157,7 +157,7 @@ t2 CREATE TABLE `t2` ( `status` enum('a','b','c') DEFAULT NULL, PRIMARY KEY (`f1`), KEY `idx1` (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci ALTER TABLE t2 CHANGE status status VARCHAR(20) DEFAULT NULL; DROP TABLE t2, t1; diff --git a/mysql-test/suite/innodb/r/lock_insert_into_empty.result b/mysql-test/suite/innodb/r/lock_insert_into_empty.result index 97369b58aef..e9a721364e7 100644 --- a/mysql-test/suite/innodb/r/lock_insert_into_empty.result +++ b/mysql-test/suite/innodb/r/lock_insert_into_empty.result @@ -35,9 +35,9 @@ SET FOREIGN_KEY_CHECKS=ON; BEGIN; INSERT IGNORE INTO t1 VALUES (1,11); Warnings: -Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f`) REFERENCES `nonexistent` (`x`)) +Warning 1452 Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`f`) REFERENCES `nonexistent` (`x`)) REPLACE INTO t1 VALUES (1,12); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f`) REFERENCES `nonexistent` (`x`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`f`) REFERENCES `nonexistent` (`x`)) COMMIT; DROP TABLE t1; # diff --git a/mysql-test/suite/innodb/r/stored_fk.result b/mysql-test/suite/innodb/r/stored_fk.result index 588bbdcd106..a18d02e1c85 100644 --- a/mysql-test/suite/innodb/r/stored_fk.result +++ b/mysql-test/suite/innodb/r/stored_fk.result @@ -17,7 +17,7 @@ t2 CREATE TABLE `t2` ( `f1` int(11) NOT NULL, `f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL, KEY `f1` (`f1`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t2; # adding foreign key constraint for base columns during alter copy. diff --git a/mysql-test/suite/innodb/r/truncate_foreign.result b/mysql-test/suite/innodb/r/truncate_foreign.result index e001e3ba507..2114142fef7 100644 --- a/mysql-test/suite/innodb/r/truncate_foreign.result +++ b/mysql-test/suite/innodb/r/truncate_foreign.result @@ -5,7 +5,7 @@ ON UPDATE CASCADE) ENGINE=InnoDB; INSERT INTO child SET a=1; TRUNCATE TABLE parent; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`parent` (`a`)) TRUNCATE TABLE child; INSERT INTO child SET a=1; UPDATE parent SET a=2; @@ -34,7 +34,7 @@ TRUNCATE TABLE child; ERROR HY000: Lock wait timeout exceeded; try restarting transaction SET DEBUG_SYNC='now SIGNAL go'; connection dml; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `parent` (`a`) ON UPDATE CASCADE) SELECT * FROM child; a 3 @@ -85,13 +85,13 @@ SET FOREIGN_KEY_CHECKS=1; TRUNCATE t1; ERROR HY000: Cannot add foreign key constraint for `t1` INSERT INTO t1 VALUES (2,2); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t2` (`a`)) SELECT * FROM t1; pk a 1 1 UNLOCK TABLES; INSERT INTO t1 VALUES (2,2); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t2` (`a`)) SET FOREIGN_KEY_CHECKS=0; INSERT INTO t1 VALUES (2,2); SELECT * FROM t1; diff --git a/mysql-test/suite/innodb/r/update-cascade.result b/mysql-test/suite/innodb/r/update-cascade.result index 1240155e3dd..17d024382b7 100644 --- a/mysql-test/suite/innodb/r/update-cascade.result +++ b/mysql-test/suite/innodb/r/update-cascade.result @@ -18,7 +18,7 @@ t2 CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, PRIMARY KEY (`f1`), KEY `f2` (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (1, repeat('+', 20000)); insert into t1 values (2, repeat('-', 20000)); @@ -81,7 +81,7 @@ t2 CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, PRIMARY KEY (`f1`), KEY `f2` (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (1, 91); insert into t2 values (1, 91); @@ -136,7 +136,7 @@ t2 CREATE TABLE `t2` ( `f1` int(11) NOT NULL, `f2` blob DEFAULT NULL, PRIMARY KEY (`f1`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci show create table t3; Table Create Table @@ -144,7 +144,7 @@ t3 CREATE TABLE `t3` ( `f1` int(11) NOT NULL, `f2` blob DEFAULT NULL, PRIMARY KEY (`f1`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t2` (`f1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t2` (`f1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (2, repeat('-', 20000)); insert into t2 values (2, repeat('%', 20000)); @@ -224,7 +224,7 @@ t2 CREATE TABLE `t2` ( `f2` int(11) DEFAULT NULL, PRIMARY KEY (`f1`), KEY `f2` (`f2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci show create table t3; Table Create Table @@ -233,7 +233,7 @@ t3 CREATE TABLE `t3` ( `f2` int(11) DEFAULT NULL, PRIMARY KEY (`f1`), KEY `f2` (`f2`), - CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t2` (`f2`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t2` (`f2`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (2, 91); insert into t2 values (2, 91); diff --git a/mysql-test/suite/innodb/r/xa_recovery.result b/mysql-test/suite/innodb/r/xa_recovery.result index 0caa501c1e1..a77b42e3256 100644 --- a/mysql-test/suite/innodb/r/xa_recovery.result +++ b/mysql-test/suite/innodb/r/xa_recovery.result @@ -38,7 +38,7 @@ CREATE TABLE t3(a INT PRIMARY KEY REFERENCES t1(a)) ENGINE=InnoDB; XA START 'a'; INSERT INTO t3 SET a=1; INSERT INTO t3 SET a=42; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t3`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) XA END 'a'; XA PREPARE 'a'; SET GLOBAL innodb_fast_shutdown=0; diff --git a/mysql-test/suite/innodb/t/add_constraint.test b/mysql-test/suite/innodb/t/add_constraint.test index f43f2977020..70f3669ee33 100644 --- a/mysql-test/suite/innodb/t/add_constraint.test +++ b/mysql-test/suite/innodb/t/add_constraint.test @@ -10,9 +10,9 @@ create table t2(a int, b int, key(a),key(b))engine=innodb; alter table t2 add constraint b foreign key (b) references t1(a); alter table t1 add constraint b1 foreign key (b) references t2(a); ---error ER_CANT_CREATE_TABLE alter table t2 add constraint b1 foreign key (b) references t1(a); +alter table t2 drop foreign key b1; alter table t2 drop foreign key b; alter table t1 drop foreign key b1; diff --git a/mysql-test/suite/innodb/t/foreign-keys.test b/mysql-test/suite/innodb/t/foreign-keys.test index 6010ff0e3fc..fc0cdfd1570 100644 --- a/mysql-test/suite/innodb/t/foreign-keys.test +++ b/mysql-test/suite/innodb/t/foreign-keys.test @@ -299,3 +299,13 @@ drop table t2яяяяяяяяяяььььььььььззззззззззшшш t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш; --echo # End of 10.6 tests + +--echo # +--echo # MDEV-37077 Crash in innobase_get_foreign_key_info() +--echo # + +CREATE TABLE t (id INT PRIMARY KEY, f INT NOT NULL, KEY(f)) ENGINE=InnoDB; +--error ER_FK_INCORRECT_OPTION +SET STATEMENT FOREIGN_KEY_CHECKS = OFF FOR +ALTER TABLE t ADD FOREIGN KEY (f) REFERENCES t (id) ON UPDATE SET NULL; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test index d09d48e3fdb..497585d74f4 100644 --- a/mysql-test/suite/innodb/t/foreign_key.test +++ b/mysql-test/suite/innodb/t/foreign_key.test @@ -22,11 +22,11 @@ constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB; create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; ---error ER_CANT_CREATE_TABLE +--error ER_DUP_CONSTRAINT_NAME alter table t2 add constraint c1 foreign key (f1) references t1(f1); -set foreign_key_checks = 0; --error ER_DUP_CONSTRAINT_NAME +set statement foreign_key_checks = 0 for alter table t2 add constraint c1 foreign key (f1) references t1(f1); drop table t2, t1; @@ -195,9 +195,9 @@ CREATE TABLE t3 (a INT PRIMARY KEY, CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB; CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b), FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB; ---replace_regex /Table '.*t2'/Table 't2'/ ---error ER_TABLE_EXISTS_ERROR RENAME TABLE best.t2 TO test.t2; +SHOW CREATE TABLE test.t2; +RENAME TABLE test.t2 TO best.t2; SHOW CREATE TABLE best.t2; DROP DATABASE best; @@ -245,7 +245,8 @@ ALTER TABLE t1 CHANGE COLUMN a a TIME NOT NULL; ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY; --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON ALTER TABLE t1 CHANGE COLUMN a b TIME; -ALTER TABLE t1 CHANGE COLUMN a b TIME, DROP FOREIGN KEY t1_ibfk_1; +SHOW CREATE TABLE t1; +ALTER TABLE t1 CHANGE COLUMN a b TIME, DROP FOREIGN KEY `1`; SET SESSION FOREIGN_KEY_CHECKS = ON; DROP TABLE t1; @@ -748,7 +749,7 @@ DROP TABLE t1; --echo # with CONSTRAINTs --echo # -call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`\\.`t2` has or is referenced in foreign key constraints which are not compatible with the new table definition."); +call mtr.add_suppression("\\[Warning\\] InnoDB: In ALTER TABLE `test`\\.`t[12]` has or is referenced in foreign key constraints which are not compatible with the new table definition."); set foreign_key_checks=on; create table t1 (id int not null primary key) engine=innodb; diff --git a/mysql-test/suite/innodb/t/innodb-fk-warnings.test b/mysql-test/suite/innodb/t/innodb-fk-warnings.test index 2732df35614..7d1f39591dc 100644 --- a/mysql-test/suite/innodb/t/innodb-fk-warnings.test +++ b/mysql-test/suite/innodb/t/innodb-fk-warnings.test @@ -11,11 +11,6 @@ CREATE TABLE t1 ( CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -# -# Below create table fails because constraint name test -# is reserved for above table. -# ---error ER_CANT_CREATE_TABLE CREATE TABLE t2 ( id int(11) NOT NULL PRIMARY KEY, a int(11) NOT NULL, @@ -27,7 +22,7 @@ CREATE TABLE t2 ( show warnings; -drop table t1; +drop table t2,t1; # # MDEV-6697: Improve foreign keys warnings/errors diff --git a/mysql-test/suite/innodb/t/innodb-fk.test b/mysql-test/suite/innodb/t/innodb-fk.test index 6d5307a1f84..28dc4a28ce1 100644 --- a/mysql-test/suite/innodb/t/innodb-fk.test +++ b/mysql-test/suite/innodb/t/innodb-fk.test @@ -194,13 +194,13 @@ CREATE TABLE `boroda` ( `b` INT(11) UNSIGNED DEFAULT NULL, PRIMARY KEY (`id`), KEY `a` (`a`), - CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; ALTER TABLE `boroda` ADD FOREIGN KEY (`b`) REFERENCES `boroda`(`id`); -ALTER TABLE `boroda` DROP FOREIGN KEY `boroda_ibfk_2`; +ALTER TABLE `boroda` DROP FOREIGN KEY `2`; RENAME TABLE `boroda` TO `#boroda`; @@ -216,7 +216,7 @@ CREATE TABLE `boroda` ( `b` INT(11) UNSIGNED DEFAULT NULL, PRIMARY KEY (`id`), KEY `a` (`a`), - CONSTRAINT `boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `boroda` (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8; RENAME TABLE `boroda` TO `bor#oda`; diff --git a/mysql-test/suite/innodb/t/innodb-index-online-fk.test b/mysql-test/suite/innodb/t/innodb-index-online-fk.test index 64cea29e7d9..349c6480e8c 100644 --- a/mysql-test/suite/innodb/t/innodb-index-online-fk.test +++ b/mysql-test/suite/innodb/t/innodb-index-online-fk.test @@ -473,7 +473,6 @@ ALTER TABLE `t2` ADD CONSTRAINT `fw` FOREIGN KEY (`c`) REFERENCES t3 (a); ALTER TABLE `t2` ADD CONSTRAINT `e` foreign key (`d`) REFERENCES t3(a); ---error ER_FK_FAIL_ADD_SYSTEM ALTER TABLE `t3` ADD CONSTRAINT `e` foreign key (`c`) REFERENCES `t2`(`c`) ON UPDATE SET NULL; SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; diff --git a/mysql-test/suite/innodb/t/innodb-index.test b/mysql-test/suite/innodb/t/innodb-index.test index c70352a49f3..5ee4c9cddf4 100644 --- a/mysql-test/suite/innodb/t/innodb-index.test +++ b/mysql-test/suite/innodb/t/innodb-index.test @@ -220,13 +220,9 @@ show create table t4; # mysqltest first does replace_regex, then replace_result # Embedded server doesn't chdir to data directory --replace_result $MYSQLD_DATADIR ./ master-data/ '' -# a foreign key 'test/dc' already exists ---error ER_CANT_CREATE_TABLE alter table t3 add constraint dc foreign key (a) references t1(a); -SET FOREIGN_KEY_CHECKS=0; ---error ER_FK_FAIL_ADD_SYSTEM +alter table t3 drop foreign key dc; alter table t3 add constraint dc foreign key (a) references t1(a); -SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; show create table t3; --enable_info alter table t2 drop index b, add index (beta); @@ -237,7 +233,6 @@ delete from t1; --error ER_CANT_DROP_FIELD_OR_KEY drop index dc on t4; --enable_info ---error ER_CANT_DROP_FIELD_OR_KEY alter table t3 drop foreign key dc; alter table t4 drop foreign key dc; --disable_info diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test index d1c37b7fd98..01fa0d84934 100644 --- a/mysql-test/suite/innodb/t/innodb.test +++ b/mysql-test/suite/innodb/t/innodb.test @@ -1797,9 +1797,9 @@ drop table t2,t1; CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB; CREATE TABLE t2(a INT) ENGINE=InnoDB; ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a); -ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1; -ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a); -ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0; +ALTER TABLE t2 DROP FOREIGN KEY `1`; +ALTER TABLE t2 ADD CONSTRAINT `0` FOREIGN KEY (a) REFERENCES t1(a); +ALTER TABLE t2 DROP FOREIGN KEY `0`; SHOW CREATE TABLE t2; DROP TABLE t2,t1; SET sql_mode = default; diff --git a/mysql-test/suite/innodb/t/instant_alter.test b/mysql-test/suite/innodb/t/instant_alter.test index a4eded01931..277df0d9be3 100644 --- a/mysql-test/suite/innodb/t/instant_alter.test +++ b/mysql-test/suite/innodb/t/instant_alter.test @@ -354,7 +354,7 @@ eval CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a)) $engine; INSERT INTO t1 SET a=1; INSERT INTO t2 SET b=1; -ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY t2_ibfk_1; +ALTER TABLE t2 ADD COLUMN a INT, DROP FOREIGN KEY `1`; ALTER TABLE t2 ADD INDEX(a); --error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a), @@ -366,7 +366,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a), ALGORITHM=INSTANT; SET foreign_key_checks=1; ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk; -ALTER TABLE t1 DROP FOREIGN KEY t1_ibfk_1; +ALTER TABLE t1 DROP FOREIGN KEY `1`; ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75); CHECK TABLE t2, t1; @@ -951,8 +951,7 @@ CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1), )ENGINE=InnoDB; ALTER TABLE t1 ADD f5 INT; -SET FOREIGN_KEY_CHECKS=0; ---error ER_FK_FAIL_ADD_SYSTEM +SET STATEMENT FOREIGN_KEY_CHECKS=0 FOR ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1) REFERENCES x(x); ALTER TABLE t1 DROP COLUMN f5; diff --git a/mysql-test/suite/innodb_fts/r/foreign_key_update.result b/mysql-test/suite/innodb_fts/r/foreign_key_update.result index 87c21c0bfc5..25eca0a6932 100644 --- a/mysql-test/suite/innodb_fts/r/foreign_key_update.result +++ b/mysql-test/suite/innodb_fts/r/foreign_key_update.result @@ -42,5 +42,5 @@ FULLTEXT (b))ENGINE=InnoDB; INSERT INTO t1 SET a=1; ALTER TABLE t2 DISCARD TABLESPACE; UPDATE t1 SET a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) DROP TABLE t2,t1; diff --git a/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result b/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result index 93fce5a42b1..7b670b3bca2 100644 --- a/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result +++ b/mysql-test/suite/innodb_fts/r/innodb_fts_misc_1.result @@ -32,9 +32,9 @@ INSERT INTO t2 (a2,b2) VALUES ('MySQL Security','When configured properly, MySQL ...'); INSERT INTO t2 (a2,b2) VALUES ('MySQL Tricks','1. Never run mysqld as root. 2. ...'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected @@ -184,7 +184,7 @@ t2 CREATE TABLE `t2` ( `s2` varchar(200) DEFAULT NULL, KEY `FTS_DOC_ID` (`FTS_DOC_ID`), FULLTEXT KEY `idx` (`s2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (1,'Sunshine'),(2,'Lollipops'); insert into t2 values (1,'Sunshine'),(2,'Lollipops'); @@ -193,7 +193,7 @@ select * from t2 where match(s2) against ('sunshine'); FTS_DOC_ID s2 3 Sunshine update t1 set s1 = 1 where s1=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) DROP TABLE t2 , t1; CREATE TABLE t1 ( id1 INT , @@ -265,9 +265,9 @@ INSERT INTO t2 (a2,b2) VALUES ('MySQL Security','When configured properly, MySQL ...'); INSERT INTO t2 (a2,b2) VALUES ('MySQL Tricks','1. Never run mysqld as root. 2. ...'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1; id1 a1 b1 1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... @@ -957,10 +957,10 @@ pk f1 f2 f3 f4 f5 f6 f7 f8 ROLLBACK; ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL; UPDATE t1 SET f6='update'; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE; UPDATE t1 SET f6='cascade'; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `3` FOREIGN KEY (`f5`) REFERENCES `t1` (`f6`) ON UPDATE SET NULL) DROP TABLE t1; SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; # diff --git a/mysql-test/suite/innodb_fts/r/misc_1.result b/mysql-test/suite/innodb_fts/r/misc_1.result index e9f87c7e7c0..f1dcadb041c 100644 --- a/mysql-test/suite/innodb_fts/r/misc_1.result +++ b/mysql-test/suite/innodb_fts/r/misc_1.result @@ -32,9 +32,9 @@ INSERT INTO t2 (a2,b2) VALUES ('MySQL Security','When configured properly, MySQL ...'); INSERT INTO t2 (a2,b2) VALUES ('MySQL Tricks','1. Never run mysqld as root. 2. ...'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) ANALYZE TABLE t1; Table Op Msg_type Msg_text test.t1 analyze status Engine-independent statistics collected @@ -184,7 +184,7 @@ t2 CREATE TABLE `t2` ( `s2` varchar(200) DEFAULT NULL, KEY `FTS_DOC_ID` (`FTS_DOC_ID`), FULLTEXT KEY `idx` (`s2`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE + CONSTRAINT `1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci insert into t1 values (1,'Sunshine'),(2,'Lollipops'); insert into t2 values (1,'Sunshine'),(2,'Lollipops'); @@ -193,7 +193,7 @@ select * from t2 where match(s2) against ('sunshine'); FTS_DOC_ID s2 3 Sunshine update t1 set s1 = 1 where s1=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`FTS_DOC_ID`) REFERENCES `t1` (`s1`) ON UPDATE CASCADE) DROP TABLE t2 , t1; CREATE TABLE t1 ( id1 INT , @@ -265,9 +265,9 @@ INSERT INTO t2 (a2,b2) VALUES ('MySQL Security','When configured properly, MySQL ...'); INSERT INTO t2 (a2,b2) VALUES ('MySQL Tricks','1. Never run mysqld as root. 2. ...'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) DELETE FROM t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a2`) REFERENCES `t1` (`a1`) ON UPDATE CASCADE) SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1; id1 a1 b1 1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ... diff --git a/mysql-test/suite/rpl/r/rpl_alter_rollback.result b/mysql-test/suite/rpl/r/rpl_alter_rollback.result index 3bd91a516c4..0df3d4abac9 100644 --- a/mysql-test/suite/rpl/r/rpl_alter_rollback.result +++ b/mysql-test/suite/rpl/r/rpl_alter_rollback.result @@ -15,7 +15,7 @@ ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; alter table t2 add constraint c1 foreign key (f1) references t1(f1); -ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update") +ERROR HY000: Duplicate FOREIGN KEY constraint name '' include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# @@ -27,9 +27,9 @@ master-bin.000001 # Gtid # # GTID #-#-# START ALTER master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 foreign key (f1) references t1(f1) master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=# master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 foreign key (f1) references t1(f1) -set foreign_key_checks = 0; +set statement foreign_key_checks = 0 for alter table t2 add constraint c1 foreign key (f1) references t1(f1); -ERROR HY000: Duplicate FOREIGN KEY constraint name 'test/c1' +ERROR HY000: Duplicate FOREIGN KEY constraint name 'c1' include/show_binlog_events.inc Log_name Pos Event_type Server_id End_log_pos Info master-bin.000001 # Gtid # # GTID #-#-# @@ -42,9 +42,11 @@ master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 forei master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=# master-bin.000001 # Query # # use `test`; alter table t2 add constraint c1 foreign key (f1) references t1(f1) master-bin.000001 # Gtid # # GTID #-#-# START ALTER -master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1) +master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; set statement foreign_key_checks = 0 for +alter table t2 add constraint c1 foreign key (f1) references t1(f1) master-bin.000001 # Gtid # # GTID #-#-# ROLLBACK ALTER id=# -master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; alter table t2 add constraint c1 foreign key (f1) references t1(f1) +master-bin.000001 # Query # # use `test`; set foreign_key_checks=1; set statement foreign_key_checks = 0 for +alter table t2 add constraint c1 foreign key (f1) references t1(f1) connection slave; connection master; drop table t2, t1; diff --git a/mysql-test/suite/rpl/t/rpl_alter_rollback.test b/mysql-test/suite/rpl/t/rpl_alter_rollback.test index c24f01ff007..64928fe0035 100644 --- a/mysql-test/suite/rpl/t/rpl_alter_rollback.test +++ b/mysql-test/suite/rpl/t/rpl_alter_rollback.test @@ -22,12 +22,12 @@ constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB; create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; ---error ER_CANT_CREATE_TABLE +--error ER_DUP_CONSTRAINT_NAME alter table t2 add constraint c1 foreign key (f1) references t1(f1); --source include/show_binlog_events.inc -set foreign_key_checks = 0; --error ER_DUP_CONSTRAINT_NAME +set statement foreign_key_checks = 0 for alter table t2 add constraint c1 foreign key (f1) references t1(f1); --source include/show_binlog_events.inc --sync_slave_with_master diff --git a/mysql-test/suite/storage_engine/foreign_keys.result b/mysql-test/suite/storage_engine/foreign_keys.result index 6c4a3406811..b5fe617c00e 100644 --- a/mysql-test/suite/storage_engine/foreign_keys.result +++ b/mysql-test/suite/storage_engine/foreign_keys.result @@ -13,18 +13,18 @@ t2 CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, KEY `a` (`a`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) -) ENGINE= DEFAULT CHARSET=latin1 + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d'); INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); UPDATE t2 SET a=a+1; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) UPDATE t1 SET a=3 WHERE a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) DELETE FROM t1 WHERE a=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) DELETE FROM t2 WHERE a=2; SELECT a,b FROM t1; a b @@ -47,10 +47,10 @@ t2 CREATE TABLE `t2` ( `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, KEY `a` (`a`), - CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE -) ENGINE= DEFAULT CHARSET=latin1 + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a'); INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(4,'e'),(3,'a'); UPDATE t1 SET a=a+1; @@ -66,6 +66,6 @@ DELETE FROM t1 WHERE b='a' LIMIT 2; SELECT a,b FROM t2; a b TRUNCATE TABLE t1; -ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) DROP TABLE t2; DROP TABLE t1; diff --git a/mysql-test/suite/vcol/inc/vcol_ins_upd.inc b/mysql-test/suite/vcol/inc/vcol_ins_upd.inc index c523083d370..62e6f7b20e3 100644 --- a/mysql-test/suite/vcol/inc/vcol_ins_upd.inc +++ b/mysql-test/suite/vcol/inc/vcol_ins_upd.inc @@ -248,7 +248,7 @@ if ($innodb_engine) --error ER_ROW_IS_REFERENCED_2 update t2 set a=4 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; --echo # - ON DELETE RESTRICT alter table t1 add foreign key (b) references t2(a) on delete restrict; @@ -256,14 +256,14 @@ if ($innodb_engine) delete from t2 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; --echo # - ON DELETE CASCADE alter table t1 add foreign key (b) references t2(a) on delete cascade; delete from t2 where a=3; select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); - alter table t1 drop foreign key t1_ibfk_1; + alter table t1 drop foreign key `1`; drop table t1; drop table t2; diff --git a/mysql-test/suite/vcol/r/innodb_virtual_fk.result b/mysql-test/suite/vcol/r/innodb_virtual_fk.result index 0b9386bf7e8..43767c897d1 100644 --- a/mysql-test/suite/vcol/r/innodb_virtual_fk.result +++ b/mysql-test/suite/vcol/r/innodb_virtual_fk.result @@ -93,7 +93,7 @@ t CREATE TABLE `t` ( KEY `b` (`b`), KEY `c` (`c`), KEY `a` (`a`), - CONSTRAINT `t_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t` (`b`) + CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t` (`b`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t; # diff --git a/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result b/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result index 624477d20f0..5244450c9e4 100644 --- a/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result +++ b/mysql-test/suite/vcol/r/vcol_ins_upd_innodb.result @@ -364,19 +364,19 @@ a b name # - ON UPDATE RESTRICT alter table t1 add foreign key (b) references t2(a) on update restrict; insert into t1 (a) values (4); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) update t2 set a=4 where a=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; a b name 1 1 value1 2 2 value2 3 3 value3 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; # - ON DELETE RESTRICT alter table t1 add foreign key (b) references t2(a) on delete restrict; delete from t2 where a=3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t2` (`a`)) select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a; a b name 1 1 value1 @@ -387,7 +387,7 @@ a b name 1 1 value1 2 2 value2 3 3 value3 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; # - ON DELETE CASCADE alter table t1 add foreign key (b) references t2(a) on delete cascade; delete from t2 where a=3; @@ -399,7 +399,7 @@ select t1.a, t1.b, t2.name from t1 left outer join t2 on (t1.b=t2.a); a b name 1 1 value1 2 2 value2 -alter table t1 drop foreign key t1_ibfk_1; +alter table t1 drop foreign key `1`; drop table t1; drop table t2; # diff --git a/mysql-test/suite/versioning/r/foreign.result b/mysql-test/suite/versioning/r/foreign.result index 7c8d9577096..fcd41111c51 100644 --- a/mysql-test/suite/versioning/r/foreign.result +++ b/mysql-test/suite/versioning/r/foreign.result @@ -17,13 +17,13 @@ on update restrict insert into parent values(1); insert into child values(1); delete from parent where id = 1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) delete from child where parent_id = 1; delete from parent where id = 1; insert into parent values(1); insert into child values(1); update parent set id=id+1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) delete from child; update parent set id=id+1; select * from child for system_time all; @@ -49,7 +49,7 @@ foreign key(parent_id) references parent(id) insert into parent values(1); insert into child values(1); delete from parent where id = 1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) drop table child; drop table parent; ################ @@ -202,19 +202,19 @@ foreign key(parent_id) references parent(id) insert into parent values(1); insert into child values(1); delete from parent; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) update parent set id=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) delete from child; delete from parent; insert into child values(1); -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) insert into parent values(1); insert into child values(1); delete from parent; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) update parent set id=2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `child_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`child`, CONSTRAINT `1` FOREIGN KEY (`parent_id`) REFERENCES `parent` (`id`)) drop table child; drop table parent; ################### @@ -307,7 +307,7 @@ set foreign_key_checks= off; insert ignore into t2 values (1); set foreign_key_checks= on; update t2 set f2= 2; -ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) +ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`)) delete from t2; drop table t2, t1; # @@ -409,7 +409,7 @@ insert into t1 values (1),(2); insert into t2 values (1); # DELETE from referenced table is not allowed delete from t1 where a = 1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) drop tables t2, t1; # # MDEV-20812 Unexpected ER_ROW_IS_REFERENCED_2 or server crash in row_ins_foreign_report_err upon DELETE from versioned table with FK @@ -506,14 +506,14 @@ insert into t0 (pk) values (1); insert into t1 (pk) values (1); insert into t2 (pk) values (1); delete from t0; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) replace t0 values (1); -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) select * into outfile 'load_t0' from t0 ; load data infile 'load_t0' replace into table t0; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) delete t0, t2 from t0 join t2; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) +ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`pk`) REFERENCES `t0` (`pk`) ON UPDATE CASCADE) select pk from t0; pk 1 diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index 84b8a4435a4..96ebc629a74 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -107,9 +107,6 @@ ulong zip_pad_max = 50; #define DICT_POOL_PER_VARYING 4 /*!< buffer pool max size per data dictionary varying size in bytes */ -/** Identifies generated InnoDB foreign key names */ -static char dict_ibfk[] = "_ibfk_"; - /*******************************************************************//** Tries to find column names for the index and sets the col field of the index. @@ -1488,26 +1485,6 @@ dict_table_t::rename_tablespace(span new_name, bool replace) const return err; } -/********************************************************************** -Converts an identifier from my_charset_filename to UTF-8 charset. -@return result string length, as returned by strconvert() */ -static -uint -innobase_convert_to_filename_charset( -/*=================================*/ - char* to, /* out: converted identifier */ - const char* from, /* in: identifier to convert */ - ulint len) /* in: length of 'to', in bytes */ -{ - uint errors; - CHARSET_INFO* cs_to = &my_charset_filename; - CHARSET_INFO* cs_from = system_charset_info; - - return(static_cast(strconvert( - cs_from, from, uint(strlen(from)), - cs_to, to, static_cast(len), &errors))); -} - /**********************************************************************//** Renames a table object. @return TRUE if success */ @@ -1647,150 +1624,17 @@ dict_table_rename_in_cache( foreign->heap, table->name.m_name); foreign->foreign_table_name_lookup_set(); - if (strchr(foreign->id, '/')) { - /* This is a >= 4.0.18 format id */ - - ulint db_len; - char* old_id; - char old_name_cs_filename[MAX_FULL_NAME_LEN+1]; - uint errors = 0; - - /* All table names are internally stored in charset - my_charset_filename (except the temp tables and the - partition identifier suffix in partition tables). The - foreign key constraint names are internally stored - in UTF-8 charset. The variable fkid here is used - to store foreign key constraint name in charset - my_charset_filename for comparison further below. */ - char fkid[MAX_TABLE_NAME_LEN * 2 + 20]; - - /* The old table name in my_charset_filename is stored - in old_name_cs_filename */ - - strcpy(old_name_cs_filename, old_name); - old_name_cs_filename[MAX_FULL_NAME_LEN] = '\0'; - if (!dict_table_t::is_temporary_name(old_name)) { - innobase_convert_to_system_charset( - strchr(old_name_cs_filename, '/') + 1, - strchr(old_name, '/') + 1, - MAX_TABLE_NAME_LEN, &errors); - - if (errors) { - /* There has been an error to convert - old table into UTF-8. This probably - means that the old table name is - actually in UTF-8. */ - innobase_convert_to_filename_charset( - strchr(old_name_cs_filename, - '/') + 1, - strchr(old_name, '/') + 1, - MAX_TABLE_NAME_LEN); - } else { - /* Old name already in - my_charset_filename */ - strcpy(old_name_cs_filename, old_name); - old_name_cs_filename[MAX_FULL_NAME_LEN] - = '\0'; - } - } - - strncpy(fkid, foreign->id, (sizeof fkid) - 1); - fkid[(sizeof fkid) - 1] = '\0'; - - const bool on_tmp = dict_table_t::is_temporary_name( - fkid); - - if (!on_tmp) { - innobase_convert_to_filename_charset( - strchr(fkid, '/') + 1, - strchr(foreign->id, '/') + 1, - MAX_TABLE_NAME_LEN+20); - } - - old_id = mem_strdup(foreign->id); - - if (strlen(fkid) > strlen(old_name_cs_filename) - + ((sizeof dict_ibfk) - 1) - && !memcmp(fkid, old_name_cs_filename, - strlen(old_name_cs_filename)) - && !memcmp(fkid + strlen(old_name_cs_filename), - dict_ibfk, (sizeof dict_ibfk) - 1)) { - - /* This is a generated >= 4.0.18 format id */ - - char table_name[MAX_TABLE_NAME_LEN + 1]; - uint errors = 0; - - if (strlen(table->name.m_name) - > strlen(old_name)) { - foreign->id = static_cast( - mem_heap_alloc( - foreign->heap, - strlen(table->name.m_name) - + strlen(old_id) + 1)); - } - - /* Convert the table name to UTF-8 */ - strncpy(table_name, table->name.m_name, - MAX_TABLE_NAME_LEN); - table_name[MAX_TABLE_NAME_LEN] = '\0'; - innobase_convert_to_system_charset( - strchr(table_name, '/') + 1, - strchr(table->name.m_name, '/') + 1, - MAX_TABLE_NAME_LEN, &errors); - - if (errors) { - /* Table name could not be converted - from charset my_charset_filename to - UTF-8. This means that the table name - is already in UTF-8 (#mysql50#). */ - strncpy(table_name, table->name.m_name, - MAX_TABLE_NAME_LEN); - table_name[MAX_TABLE_NAME_LEN] = '\0'; - } - - /* Replace the prefix 'databasename/tablename' - with the new names */ - strcpy(foreign->id, table_name); - if (on_tmp) { - strcat(foreign->id, - old_id + strlen(old_name)); - } else { - sprintf(strchr(foreign->id, '/') + 1, - "%s%s", - strchr(table_name, '/') +1, - strstr(old_id, "_ibfk_") ); - } - - } else { - /* This is a >= 4.0.18 format id where the user - gave the id name */ - db_len = dict_get_db_name_len( - table->name.m_name) + 1; - - if (db_len - 1 - > dict_get_db_name_len(foreign->id)) { - - foreign->id = static_cast( - mem_heap_alloc( - foreign->heap, - db_len + strlen(old_id) + 1)); - } - - /* Replace the database prefix in id with the - one from table->name */ - - memcpy(foreign->id, - table->name.m_name, db_len); - - strcpy(foreign->id + db_len, - dict_remove_db_name(old_id)); - } - - ut_free(old_id); + const char* sql_id = foreign->sql_id(); + size_t fklen = snprintf(nullptr, 0, "%s\377%s", + table->name.m_name, sql_id); + char* id = foreign->id; + if (fklen++ > strlen(id)) { + id = static_cast( + mem_heap_alloc(foreign->heap, fklen)); } - table->foreign_set.erase(it); + foreign->id = id; + snprintf(id, fklen, "%s\377%s", table->name.m_name, sql_id); fk_set.insert(foreign); if (foreign->referenced_table) { @@ -3302,69 +3146,6 @@ end_of_string: } } -/*********************************************************************//** -Finds the highest [number] for foreign key constraints of the table. Looks -only at the >= 4.0.18-format id's, which are of the form -databasename/tablename_ibfk_[number]. -@return highest number, 0 if table has no new format foreign key constraints */ -ulint -dict_table_get_highest_foreign_id( -/*==============================*/ - dict_table_t* table) /*!< in: table in the dictionary memory cache */ -{ - dict_foreign_t* foreign; - char* endp; - ulint biggest_id = 0; - ulint id; - ulint len; - - DBUG_ENTER("dict_table_get_highest_foreign_id"); - - ut_a(table); - - len = strlen(table->name.m_name); - - for (dict_foreign_set::iterator it = table->foreign_set.begin(); - it != table->foreign_set.end(); - ++it) { - char fkid[MAX_TABLE_NAME_LEN * 2 + 20]; - foreign = *it; - - strncpy(fkid, foreign->id, (sizeof fkid) - 1); - fkid[(sizeof fkid) - 1] = '\0'; - /* Convert foreign key identifier on dictionary memory - cache to filename charset. */ - innobase_convert_to_filename_charset( - strchr(fkid, '/') + 1, - strchr(foreign->id, '/') + 1, - MAX_TABLE_NAME_LEN); - - if (strlen(fkid) > ((sizeof dict_ibfk) - 1) + len - && 0 == memcmp(fkid, table->name.m_name, len) - && 0 == memcmp(fkid + len, - dict_ibfk, (sizeof dict_ibfk) - 1) - && fkid[len + ((sizeof dict_ibfk) - 1)] != '0') { - /* It is of the >= 4.0.18 format */ - - id = strtoul(fkid + len - + ((sizeof dict_ibfk) - 1), - &endp, 10); - if (*endp == '\0') { - ut_a(id != biggest_id); - - if (id > biggest_id) { - biggest_id = id; - } - } - } - } - - DBUG_PRINT("dict_table_get_highest_foreign_id", - ("id: " ULINTPF, biggest_id)); - - DBUG_RETURN(biggest_id); -} - /**********************************************************************//** Parses the CONSTRAINT id's to be dropped in an ALTER TABLE statement. @return DB_SUCCESS or DB_CANNOT_DROP_CONSTRAINT if syntax error or the @@ -3432,8 +3213,25 @@ loop: ptr = dict_accept(cs, ptr, "KEY", &success); if (!success) { +syntax_error: + if (!srv_read_only_mode) { + FILE* ef = dict_foreign_err_file; - goto syntax_error; + mysql_mutex_lock(&dict_foreign_err_mutex); + rewind(ef); + ut_print_timestamp(ef); + fputs(" Syntax error in dropping of a" + " foreign key constraint of table ", ef); + ut_print_name(ef, NULL, table->name.m_name); + fprintf(ef, ",\n" + "close to:\n%s\n in SQL command\n%s\n", + ptr, str); + mysql_mutex_unlock(&dict_foreign_err_mutex); + } + + ut_free(str); + + return DB_CANNOT_DROP_CONSTRAINT; } ptr1 = dict_accept(cs, ptr, "IF", &success); @@ -3448,16 +3246,16 @@ loop: ptr = dict_scan_id(cs, ptr, heap, &id); - if (id == NULL) { - + if (!id) { goto syntax_error; } - if (std::find_if(table->foreign_set.begin(), - table->foreign_set.end(), - dict_foreign_matches_id(id)) - == table->foreign_set.end()) { + const Lex_ident_column i{Lex_cstring_strlen(id)}; + if (std::find_if(table->foreign_set.begin(), table->foreign_set.end(), + [&i](const dict_foreign_t *fk) + {return i.streq(Lex_cstring_strlen(fk->sql_id()));}) + == table->foreign_set.end()) { if (if_exists) { goto loop; } @@ -3486,25 +3284,6 @@ loop: (*constraints_to_drop)[*n] = id; (*n)++; goto loop; - -syntax_error: - if (!srv_read_only_mode) { - FILE* ef = dict_foreign_err_file; - - mysql_mutex_lock(&dict_foreign_err_mutex); - rewind(ef); - ut_print_timestamp(ef); - fputs(" Syntax error in dropping of a" - " foreign key constraint of table ", ef); - ut_print_name(ef, NULL, table->name.m_name); - fprintf(ef, ",\n" - "close to:\n%s\n in SQL command\n%s\n", ptr, str); - mysql_mutex_unlock(&dict_foreign_err_mutex); - } - - ut_free(str); - - return(DB_CANNOT_DROP_CONSTRAINT); } /*==================== END OF FOREIGN KEY PROCESSING ====================*/ @@ -3710,18 +3489,10 @@ dict_print_info_on_foreign_key_in_create_format(const trx_t *trx, const dict_foreign_t *foreign, bool add_newline) { - const char* stripped_id; + const char* id = foreign->sql_id(); ulint i; std::string str; - if (strchr(foreign->id, '/')) { - /* Strip the preceding database name from the constraint id */ - stripped_id = foreign->id + 1 - + dict_get_db_name_len(foreign->id); - } else { - stripped_id = foreign->id; - } - str.append(","); if (add_newline) { @@ -3733,7 +3504,7 @@ dict_print_info_on_foreign_key_in_create_format(const trx_t *trx, str.append(" CONSTRAINT "); - str.append(innobase_quote_identifier(trx, stripped_id)); + str.append(innobase_quote_identifier(trx, id)); str.append(" FOREIGN KEY ("); for (i = 0;;) { diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index 4e2b23a4e87..0210bf4f73f 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -1504,10 +1504,6 @@ fts_rename_aux_tables( err = fts_rename_one_aux_table( new_name, old_table_name, trx); - DBUG_EXECUTE_IF("fts_rename_failure", - err = DB_DEADLOCK; - fts_sql_rollback(trx);); - if (err != DB_SUCCESS) { return(err); } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 835eab4980c..a2d8e81c425 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -2354,30 +2354,6 @@ dtype_get_mblen( } } -/********************************************************************** -Check if the length of the identifier exceeds the maximum allowed. -return true when length of identifier is too long. */ -my_bool -innobase_check_identifier_length( -/*=============================*/ - const char* id) /* in: FK identifier to check excluding the - database portion. */ -{ - int well_formed_error = 0; - CHARSET_INFO *cs = system_charset_info; - DBUG_ENTER("innobase_check_identifier_length"); - - size_t len = my_well_formed_length( - cs, id, id + strlen(id), - NAME_CHAR_LEN, &well_formed_error); - - if (well_formed_error || len == NAME_CHAR_LEN) { - my_error(ER_TOO_LONG_IDENT, MYF(0), id); - DBUG_RETURN(true); - } - DBUG_RETURN(false); -} - /******************************************************************//** Converts an identifier to UTF-8. */ void @@ -12315,6 +12291,40 @@ LEX_CSTRING innodb_convert_name(CHARSET_INFO *cs, LEX_CSTRING name, char *buf) buf, MAX_TABLE_NAME_LEN, &errors)}; } +/** Find an auto-generated foreign key constraint identifier. +@param table InnoDB table +@return the next number to assign to a constraint */ +ulint dict_table_get_foreign_id(const dict_table_t &table) noexcept +{ + ulint id= 0; + + for (const dict_foreign_t *foreign : table.foreign_set) + { + const char *s= foreign->sql_id(); + char *endp; + ulint f= strtoul(s, &endp, 10); + if (!*endp && f > id) + id= f; + } + + return id + 1; +} + +/** Generate a foreign key constraint name for an anonymous constraint. +@param id_nr sequence to allocate identifiers from +@param name table name +@param foreign foreign key */ +void dict_create_add_foreign_id(ulint *id_nr, const char *name, + dict_foreign_t *foreign) noexcept +{ + if (!foreign->id) + { + size_t len= snprintf(nullptr, 0, "%s\377%zu", name, *id_nr); + foreign->id= static_cast(mem_heap_alloc(foreign->heap, len + 1)); + snprintf(foreign->id, len + 1, "%s\377%zu", name, (*id_nr)++); + } +} + /** Create InnoDB foreign keys from MySQL alter_info. Collect all dict_foreign_t items into local_fk_set and then add into system table. @return DB_SUCCESS or specific error code */ @@ -12352,12 +12362,6 @@ create_table_info_t::create_foreign_keys() dict_table_t* alter_table; char* n = dict_table_lookup(d, t, &alter_table, heap); - /* Starting from 4.0.18 and 4.1.2, we generate foreign key id's - in the format databasename/tablename_ibfk_[number], where - [number] is local to the table; look for the highest [number] - for alter_table, so that we can assign to new constraints - higher numbers. */ - /* If we are altering a temporary table, the table name after ALTER TABLE does not correspond to the internal table name, and alter_table=nullptr. But, we do not support FOREIGN KEY @@ -12365,8 +12369,7 @@ create_table_info_t::create_foreign_keys() if (alter_table) { n = alter_table->name.m_name; - number = 1 + dict_table_get_highest_foreign_id( - alter_table); + number = dict_table_get_foreign_id(*alter_table); } char* bufend = innobase_convert_name( @@ -12478,33 +12481,17 @@ create_table_info_t::create_foreign_keys() return (DB_CANNOT_ADD_CONSTRAINT); } - if (fk->constraint_name.str) { - ulint db_len; - - /* Catenate 'databasename/' to the constraint name - specified by the user: we conceive the constraint as - belonging to the same MySQL 'database' as the table - itself. We store the name to foreign->id. */ - - db_len = dict_get_db_name_len(table->name.m_name); - - foreign->id = static_cast(mem_heap_alloc( - foreign->heap, - db_len + fk->constraint_name.length + 2)); - - memcpy(foreign->id, table->name.m_name, db_len); - foreign->id[db_len] = '/'; - strcpy(foreign->id + db_len + 1, - fk->constraint_name.str); - } - - if (foreign->id == NULL) { - error = dict_create_add_foreign_id( - &number, table->name.m_name, foreign); - if (error != DB_SUCCESS) { - dict_foreign_free(foreign); - return (error); - } + if (size_t fk_len = fk->constraint_name.length) { + /* Prepend the table name to the constraint name. */ + size_t s = strlen(table->name.m_name) + 2 + fk_len; + foreign->id = static_cast( + mem_heap_alloc(foreign->heap, s)); + snprintf(foreign->id, s, "%s\377%.*s", + table->name.m_name, int(fk_len), + fk->constraint_name.str); + } else { + dict_create_add_foreign_id(&number, table->name.m_name, + foreign); } std::pair ret @@ -14286,18 +14273,24 @@ ha_innobase::rename_table( stats.close(); } - if (error == DB_DUPLICATE_KEY) { + switch (error) { + case DB_SUCCESS: + DBUG_RETURN(0); + case DB_DUPLICATE_KEY: /* We are not able to deal with handler::get_dup_key() during DDL operations, because the duplicate key would exist in metadata tables, not in the user table. */ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to); DBUG_RETURN(HA_ERR_GENERIC); - } else if (error == DB_LOCK_WAIT_TIMEOUT) { + case DB_LOCK_WAIT_TIMEOUT: my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0)); DBUG_RETURN(HA_ERR_GENERIC); + case DB_FOREIGN_DUPLICATE_KEY: + my_error(ER_DUP_CONSTRAINT_NAME, MYF(0), "FOREIGN KEY", ""); + DBUG_RETURN(HA_ERR_GENERIC); + default: + DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL)); } - - DBUG_RETURN(convert_error_code_to_mysql(error, 0, NULL)); } /*********************************************************************//** @@ -15653,14 +15646,13 @@ get_foreign_key_info( size_t len; char tmp_buff[NAME_LEN+1]; char name_buff[NAME_LEN+1]; - const char* ptr; + const char* ptr = foreign->sql_id(); LEX_CSTRING* name = NULL; if (dict_table_t::is_temporary_name(foreign->foreign_table_name)) { - return NULL; - } + return NULL; + } - ptr = dict_remove_db_name(foreign->id); f_key_info.foreign_id = thd_make_lex_string( thd, 0, ptr, strlen(ptr), 1); diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index c58906b746a..9003d9827d3 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -946,3 +946,15 @@ ib_push_frm_error( @return true if index column length exceeds limit */ MY_ATTRIBUTE((warn_unused_result)) bool too_big_key_part_length(size_t max_field_len, const KEY& key); + +/** Find an auto-generated foreign key constraint identifier. +@param table InnoDB table +@return the next number to assign to a constraint */ +ulint dict_table_get_foreign_id(const dict_table_t &table) noexcept; + +/** Generate a foreign key constraint name for an anonymous constraint. +@param id_nr sequence to allocate identifiers from +@param name table name +@param foreign foreign key */ +void dict_create_add_foreign_id(ulint *id_nr, const char *name, + dict_foreign_t *foreign) noexcept; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 487fc0f44a9..aa2664e17f3 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -2889,21 +2889,13 @@ innobase_init_foreign( ut_ad(dict_sys.locked()); if (constraint_name) { - ulint db_len; - - /* Catenate 'databasename/' to the constraint name specified - by the user: we conceive the constraint as belonging to the - same MySQL 'database' as the table itself. We store the name - to foreign->id. */ - - db_len = dict_get_db_name_len(table->name.m_name); - - foreign->id = static_cast(mem_heap_alloc( - foreign->heap, db_len + strlen(constraint_name) + 2)); - - memcpy(foreign->id, table->name.m_name, db_len); - foreign->id[db_len] = '/'; - strcpy(foreign->id + db_len + 1, constraint_name); + /* Prepend the table name to the constraint name. */ + size_t s = 1 + snprintf(nullptr, 0, "%s\377%s", + table->name.m_name, constraint_name); + foreign->id = static_cast( + mem_heap_alloc(foreign->heap, s)); + snprintf(foreign->id, s, "%s\377%s", + table->name.m_name, constraint_name); /* Check if any existing foreign key has the same id, this is needed only if user supplies the constraint name */ @@ -3298,7 +3290,8 @@ innobase_get_foreign_key_info( num_col = i; } - add_fk[num_fk] = dict_mem_foreign_create(); + dict_foreign_t* const fk = add_fk[num_fk] + = dict_mem_foreign_create(); LEX_CSTRING t = innodb_convert_name(cs, fk_key->ref_table, t_name); @@ -3308,7 +3301,7 @@ innobase_get_foreign_key_info( dict_sys.lock(SRW_LOCK_CALL); referenced_table_name = dict_table_lookup( - d, t, &referenced_table, add_fk[num_fk]->heap); + d, t, &referenced_table, fk->heap); /* Test the case when referenced_table failed to open, if trx->check_foreigns is not set, we should @@ -3367,8 +3360,19 @@ innobase_get_foreign_key_info( goto err_exit_unlock; } + /* If fk_key->name.str==nullptr, we will end up with + fk->id=nullptr. In the calls to my_error() below, + passing nullptr to "%s" is fine; process_str_arg() + will display "(null)". + + Anonymous constraints (fk->id=nullptr) will be + assigned a name in dict_create_add_foreign_id(), which + is invoked by innobase_update_foreing_try(). + + In check_col_is_in_fk_indexes(), errors in anonymous + contraints will be attributed to a constraint name "0". */ if (!innobase_init_foreign( - add_fk[num_fk], fk_key->name.str, + fk, fk_key->name.str, table, index, column_names, num_col, referenced_table_name, referenced_table, referenced_index, @@ -3376,14 +3380,13 @@ innobase_get_foreign_key_info( my_error( ER_DUP_CONSTRAINT_NAME, MYF(0), - "FOREIGN KEY", add_fk[num_fk]->id); + "FOREIGN KEY", fk_key->name.str); goto err_exit_unlock; } dict_sys.unlock(); - correct_option = innobase_set_foreign_key_option( - add_fk[num_fk], fk_key); + correct_option = innobase_set_foreign_key_option(fk, fk_key); DBUG_EXECUTE_IF("innodb_test_wrong_fk_option", correct_option = false;); @@ -3392,12 +3395,11 @@ innobase_get_foreign_key_info( my_error(ER_FK_INCORRECT_OPTION, MYF(0), table_share->table_name.str, - add_fk[num_fk]->id); + fk_key->name.str); goto err_exit; } - if (innobase_check_fk_stored( - add_fk[num_fk], table, s_cols)) { + if (innobase_check_fk_stored(fk, table, s_cols)) { my_printf_error( HA_ERR_UNSUPPORTED, "Cannot add foreign key on the base column " @@ -3415,8 +3417,8 @@ err_exit_unlock: dict_sys.unlock(); err_exit: for (ulint i = 0; i <= num_fk; i++) { - if (add_fk[i]) { - dict_foreign_free(add_fk[i]); + if (dict_foreign_t* fk = add_fk[i]) { + dict_foreign_free(fk); } } @@ -4484,9 +4486,7 @@ bool check_foreigns_nullability(const dict_table_t *user_table, && foreign->col_fk_exists(col_name) != UINT_MAX) { non_null_error: - const char* fid = strchr(foreign->id, '/'); - fid= fid ? fid + 1 : foreign->id; - my_error(ER_FK_COLUMN_NOT_NULL, MYF(0), col_name, fid); + my_error(ER_FK_COLUMN_NOT_NULL, MYF(0), col_name, foreign->sql_id()); return true; } } @@ -4522,10 +4522,8 @@ non_null_error: dblen, foreign->foreign_table_name, tbl_name); display_name[FN_REFLEN - 1]= '\0'; - const char* fid = strchr(foreign->id, '/'); - fid= fid ? fid + 1 : foreign->id; my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0), col_name, - fid, display_name); + foreign->sql_id(), display_name); return true; } } @@ -4560,7 +4558,7 @@ bool check_foreign_drop_col(const dict_table_t *user_table, if (!strcmp(foreign->foreign_col_names[f], col_name)) { my_error(ER_FK_COLUMN_CANNOT_DROP, MYF(0), - col_name, foreign->id); + col_name, foreign->sql_id()); return true; } } @@ -7883,9 +7881,9 @@ bool check_col_is_in_fk_indexes( span drop_fk, span add_fk) { - char *fk_id= nullptr; + const dict_foreign_t *fk; - for (const auto &f : table->foreign_set) + for (const auto f : table->foreign_set) { if (!f->foreign_index || std::find(drop_fk.begin(), drop_fk.end(), f) != drop_fk.end()) @@ -7893,25 +7891,25 @@ bool check_col_is_in_fk_indexes( for (ulint i= 0; i < f->n_fields; i++) if (f->foreign_index->fields[i].col == col) { - fk_id= f->id; + fk= f; goto err_exit; } } - for (const auto &a : add_fk) + for (const auto a : add_fk) { if (!a->foreign_index) continue; for (ulint i= 0; i < a->n_fields; i++) { if (a->foreign_index->fields[i].col == col) { - fk_id= a->id; + fk= a; goto err_exit; } } } - for (const auto &f : table->referenced_set) + for (const auto f : table->referenced_set) { if (!f->referenced_index) continue; for (ulint i= 0; i < f->n_fields; i++) @@ -7919,7 +7917,7 @@ bool check_col_is_in_fk_indexes( if (f->referenced_index->fields[i].col == col) { my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0), - col_name, f->id, f->foreign_table_name); + col_name, f->sql_id(), f->foreign_table_name); return true; } } @@ -7927,8 +7925,7 @@ bool check_col_is_in_fk_indexes( return false; err_exit: my_error(ER_FK_COLUMN_CANNOT_CHANGE, MYF(0), col_name, - fk_id ? fk_id : - (std::string(table->name.m_name) + "_ibfk_0").c_str()); + fk->id ? fk->sql_id() : "0"); return true; } @@ -8289,22 +8286,11 @@ check_if_ok_to_rename: dict_foreign_t* foreign; - for (dict_foreign_set::iterator it - = m_prebuilt->table->foreign_set.begin(); - it != m_prebuilt->table->foreign_set.end(); - ++it) { - - foreign = *it; - const char* fid = strchr(foreign->id, '/'); - - DBUG_ASSERT(fid); - /* If no database/ prefix was present in - the FOREIGN KEY constraint name, compare - to the full constraint name. */ - fid = fid ? fid + 1 : foreign->id; - - if (Lex_ident_column(Lex_cstring_strlen(fid)). - streq(drop.name)) { + for (dict_foreign_t* fk : m_prebuilt->table->foreign_set) { + if (Lex_ident_column(Lex_cstring_strlen + (fk->sql_id())). + streq(drop.name)) { + foreign = fk; goto found_fk; } } @@ -10051,14 +10037,11 @@ innobase_update_foreign_try( trx_t* trx, const char* table_name) { - ulint foreign_id; ulint i; DBUG_ENTER("innobase_update_foreign_try"); - foreign_id = dict_table_get_highest_foreign_id(ctx->new_table); - - foreign_id++; + ulint foreign_id = dict_table_get_foreign_id(*ctx->new_table); for (i = 0; i < ctx->num_to_add_fk; i++) { dict_foreign_t* fk = ctx->add_fk[i]; @@ -10066,14 +10049,9 @@ innobase_update_foreign_try( ut_ad(fk->foreign_table == ctx->new_table || fk->foreign_table == ctx->old_table); - dberr_t error = dict_create_add_foreign_id( + dict_create_add_foreign_id( &foreign_id, ctx->old_table->name.m_name, fk); - - if (error != DB_SUCCESS) { - my_error(ER_TOO_LONG_IDENT, MYF(0), - fk->id); - DBUG_RETURN(true); - } + /* After this point, it is safe to call fk->sql_id(). */ if (!fk->foreign_index) { fk->foreign_index = dict_foreign_find_index( @@ -10086,7 +10064,7 @@ innobase_update_foreign_try( NULL, NULL, NULL); if (!fk->foreign_index) { my_error(ER_FK_INCORRECT_OPTION, - MYF(0), table_name, fk->id); + MYF(0), table_name, fk->sql_id()); DBUG_RETURN(true); } } @@ -10094,7 +10072,7 @@ innobase_update_foreign_try( /* The fk->foreign_col_names[] uses renamed column names, while the columns in ctx->old_table have not been renamed yet. */ - error = dict_create_add_foreign_to_dictionary( + dberr_t error = dict_create_add_foreign_to_dictionary( ctx->old_table->name.m_name, fk, trx); DBUG_EXECUTE_IF( diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index ad74f80b044..fa4ce4bab17 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -5742,7 +5742,7 @@ i_s_dict_fill_sys_foreign( fields = table_to_fill->field; - OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->id)); + OK(field_store_string(fields[SYS_FOREIGN_ID], foreign->sql_id())); OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME], foreign->foreign_table_name)); @@ -5934,8 +5934,11 @@ i_s_dict_fill_sys_foreign_cols( DBUG_ENTER("i_s_dict_fill_sys_foreign_cols"); fields = table_to_fill->field; + const char* id = strchr(name, '\377'); + if (!id) id = strchr(name, '/'); + id = id ? id + 1 : name; - OK(field_store_string(fields[SYS_FOREIGN_COL_ID], name)); + OK(field_store_string(fields[SYS_FOREIGN_COL_ID], id)); OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name)); diff --git a/storage/innobase/include/dict0crea.h b/storage/innobase/include/dict0crea.h index c40df12babe..7857cc60485 100644 --- a/storage/innobase/include/dict0crea.h +++ b/storage/innobase/include/dict0crea.h @@ -117,20 +117,6 @@ dict_create_index_tree_in_mem( dict_index_t* index, /*!< in/out: index */ const trx_t* trx); /*!< in: InnoDB transaction handle */ -/********************************************************************//** -Generate a foreign key constraint name when it was not named by the user. -A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER, -where the numbers start from 1, and are given locally for this table, that is, -the number is not global, as it used to be before MySQL 4.0.18. */ -UNIV_INLINE -dberr_t -dict_create_add_foreign_id( -/*=======================*/ - ulint* id_nr, /*!< in/out: number to use in id - generation; incremented if used */ - const char* name, /*!< in: table name */ - dict_foreign_t* foreign); /*!< in/out: foreign key */ - /** Adds the given set of foreign key objects to the dictionary tables in the database. This function does not modify the dictionary cache. The caller must ensure that all foreign key objects contain a valid constraint diff --git a/storage/innobase/include/dict0crea.inl b/storage/innobase/include/dict0crea.inl index 5641206d313..986810f18ae 100644 --- a/storage/innobase/include/dict0crea.inl +++ b/storage/innobase/include/dict0crea.inl @@ -24,75 +24,6 @@ Database object creation Created 1/8/1996 Heikki Tuuri *******************************************************/ -#include "ha_prototypes.h" - -#include "mem0mem.h" - -/********************************************************************//** -Generate a foreign key constraint name when it was not named by the user. -A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER, -where the numbers start from 1, and are given locally for this table, that is, -the number is not global, as it used to be before MySQL 4.0.18. */ -UNIV_INLINE -dberr_t -dict_create_add_foreign_id( -/*=======================*/ - ulint* id_nr, /*!< in/out: number to use in id generation; - incremented if used */ - const char* name, /*!< in: table name */ - dict_foreign_t* foreign)/*!< in/out: foreign key */ -{ - DBUG_ENTER("dict_create_add_foreign_id"); - - if (foreign->id == NULL) { - /* Generate a new constraint id */ - ulint namelen = strlen(name); - char* id = static_cast( - mem_heap_alloc(foreign->heap, - namelen + 20)); - - if (dict_table_t::is_temporary_name(name)) { - - /* no overflow if number < 1e13 */ - sprintf(id, "%s_ibfk_%lu", name, - (ulong) (*id_nr)++); - } else { - char table_name[MAX_TABLE_NAME_LEN + 21]; - uint errors = 0; - - strncpy(table_name, name, (sizeof table_name) - 1); - table_name[(sizeof table_name) - 1] = '\0'; - - innobase_convert_to_system_charset( - strchr(table_name, '/') + 1, - strchr(name, '/') + 1, - MAX_TABLE_NAME_LEN, &errors); - - if (errors) { - strncpy(table_name, name, - (sizeof table_name) - 1); - table_name[(sizeof table_name) - 1] = '\0'; - } - - /* no overflow if number < 1e13 */ - sprintf(id, "%s_ibfk_%lu", table_name, - (ulong) (*id_nr)++); - - if (innobase_check_identifier_length( - strchr(id,'/') + 1)) { - DBUG_RETURN(DB_IDENTIFIER_TOO_LONG); - } - } - foreign->id = id; - - DBUG_PRINT("dict_create_add_foreign_id", - ("generated foreign id: %s", id)); - } - - - DBUG_RETURN(DB_SUCCESS); -} - /** Compose a column number for a virtual column, stored in the "POS" field of Sys_columns. The column number includes both its virtual column sequence (the "nth" virtual column) and its actual column position in original table diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index cdb181d557a..9007c698513 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -61,16 +61,6 @@ void dict_foreign_free( /*==============*/ dict_foreign_t* foreign); /*!< in, own: foreign key struct */ -/*********************************************************************//** -Finds the highest [number] for foreign key constraints of the table. Looks -only at the >= 4.0.18-format id's, which are of the form -databasename/tablename_ibfk_[number]. -@return highest number, 0 if table has no new format foreign key constraints */ -ulint -dict_table_get_highest_foreign_id( -/*==============================*/ - dict_table_t* table); /*!< in: table in the dictionary - memory cache */ /** Check whether the dict_table_t is a partition. A partitioned table on the SQL level is composed of InnoDB tables, where each InnoDB table is a [sub]partition including its secondary indexes diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index d3ece2f8b58..ab7161995da 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -1671,6 +1671,18 @@ public: } return true; } + + /** @return the SQL visible constraint name */ + const char *sql_id() const noexcept + { + /* Before MySQL 4.0.18, constraint names were auto-generated (%lu_%lu) + and unique among all InnoDB tables. Starting with MySQL 4.0.18, the + constraint names were prepended with the schema name and /. + Starting with MariaDB 12, constraint names are prepended with the + dict_table_t::name and the invalid UTF-8 sequence 0xff. */ + const char *s; + return ((s= strchr(id, '\377')) || (s= strchr(id, '/'))) ? ++s : id; + } }; std::ostream& @@ -1730,33 +1742,6 @@ struct dict_foreign_different_tables { } }; -/** A function object to check if the foreign key constraint has the same -name as given. If the full name of the foreign key constraint doesn't match, -then, check if removing the database name from the foreign key constraint -matches. Return true if it matches, false otherwise. */ -struct dict_foreign_matches_id { - - dict_foreign_matches_id(const char* id) - : m_id(id) - {} - - bool operator()(const dict_foreign_t* foreign) const - { - const Lex_ident_column ident = Lex_cstring_strlen(m_id); - if (ident.streq(Lex_cstring_strlen(foreign->id))) { - return(true); - } - if (const char* pos = strchr(foreign->id, '/')) { - if (ident.streq(Lex_cstring_strlen(pos + 1))) { - return(true); - } - } - return(false); - } - - const char* m_id; -}; - typedef std::set< dict_foreign_t*, dict_foreign_compare, diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h index 61d4afd8025..6a965ea50e8 100644 --- a/storage/innobase/include/ha_prototypes.h +++ b/storage/innobase/include/ha_prototypes.h @@ -347,16 +347,6 @@ innobase_next_autoinc( ulonglong max_value) /*!< in: max value for type */ MY_ATTRIBUTE((pure, warn_unused_result)); -/********************************************************************** -Check if the length of the identifier exceeds the maximum allowed. -The input to this function is an identifier in charset my_charset_filename. -return true when length of identifier is too long. */ -my_bool -innobase_check_identifier_length( -/*=============================*/ - const char* id); /* in: identifier to check. it must belong - to charset my_charset_filename */ - /********************************************************************** Converts an identifier from my_charset_filename to UTF-8 charset. */ uint diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index e08267b690a..572fc66a632 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -2502,29 +2502,28 @@ dberr_t row_delete_constraint( /*==================*/ const char* id, /*!< in: constraint id */ - const char* database_name, /*!< in: database name, with the - trailing '/' */ + const char* name, /*!< in: table name */ mem_heap_t* heap, /*!< in: memory heap */ trx_t* trx) /*!< in: transaction handle */ { - dberr_t err; + const size_t s= strlen(id) + strlen(name) + 2; + char *fk= static_cast(mem_heap_alloc(heap, s)); + snprintf(fk, s, "%s\377%s", name, id); + dberr_t err= row_delete_constraint_low(fk, trx); + if (err == DB_SUCCESS) + { + /* Also try dropping the MySQL 4.0.18 or 4.1.2 constraints, + with schemaname/constraintname. */ + snprintf(fk, s, "%.*s%s", int(dict_get_db_name_len(name) + 1), name, id); + err= row_delete_constraint_low(fk, trx); + } + if (err == DB_SUCCESS && !strchr(id, '/')) + /* Before MySQL 4.0.18 or 4.1.2, constraints were of the form + %lu_%lu (a 64-bit global identifier split into two 32-bit + parts). Let them be dropped. */ + err= row_delete_constraint_low(id, trx); - /* New format constraints have ids /. */ - err = row_delete_constraint_low( - mem_heap_strcat(heap, database_name, id), trx); - - if ((err == DB_SUCCESS) && !strchr(id, '/')) { - /* Old format < 4.0.18 constraints have constraint ids - NUMBER_NUMBER. We only try deleting them if the - constraint name does not contain a '/' character, otherwise - deleting a new format constraint named 'foo/bar' from - database 'baz' would remove constraint 'bar' from database - 'foo', if it existed. */ - - err = row_delete_constraint_low(id, trx); - } - - return(err); + return err; } /*********************************************************************//** @@ -2664,132 +2663,49 @@ row_rename_table_for_mysql( if (err != DB_SUCCESS) { // Assume the caller guarantees destination name doesn't exist. ut_ad(err != DB_DUPLICATE_KEY); - goto rollback_and_exit; - } - - if (/* fk == RENAME_IGNORE_FK || */ !new_is_tmp) { + } else if (/* fk == RENAME_IGNORE_FK || */ !new_is_tmp) { /* Rename all constraints. */ - char new_table_name[MAX_TABLE_NAME_LEN + 1]; - char old_table_utf8[MAX_TABLE_NAME_LEN + 1]; - uint errors = 0; - - strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); - old_table_utf8[MAX_TABLE_NAME_LEN] = '\0'; - innobase_convert_to_system_charset( - strchr(old_table_utf8, '/') + 1, - strchr(old_name, '/') +1, - MAX_TABLE_NAME_LEN, &errors); - - if (errors) { - /* Table name could not be converted from charset - my_charset_filename to UTF-8. This means that the - table name is already in UTF-8 (#mysql#50). */ - strncpy(old_table_utf8, old_name, MAX_TABLE_NAME_LEN); - old_table_utf8[MAX_TABLE_NAME_LEN] = '\0'; - } - info = pars_info_create(); - pars_info_add_str_literal(info, "new_table_name", new_name); - pars_info_add_str_literal(info, "old_table_name", old_name); - pars_info_add_str_literal(info, "old_table_name_utf8", - old_table_utf8); - - strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN); - new_table_name[MAX_TABLE_NAME_LEN] = '\0'; - innobase_convert_to_system_charset( - strchr(new_table_name, '/') + 1, - strchr(new_name, '/') +1, - MAX_TABLE_NAME_LEN, &errors); - - if (errors) { - /* Table name could not be converted from charset - my_charset_filename to UTF-8. This means that the - table name is already in UTF-8 (#mysql#50). */ - strncpy(new_table_name, new_name, MAX_TABLE_NAME_LEN); - new_table_name[MAX_TABLE_NAME_LEN] = '\0'; - } - - pars_info_add_str_literal(info, "new_table_utf8", new_table_name); + pars_info_add_str_literal(info, "new_name", new_name); + pars_info_add_str_literal(info, "old_name", old_name); err = que_eval_sql( info, "PROCEDURE RENAME_CONSTRAINT_IDS () IS\n" - "gen_constr_prefix CHAR;\n" - "new_db_name CHAR;\n" - "foreign_id CHAR;\n" - "new_foreign_id CHAR;\n" - "old_db_name_len INT;\n" - "old_t_name_len INT;\n" - "new_db_name_len INT;\n" - "id_len INT;\n" - "offset INT;\n" - "found INT;\n" + "old CHAR; new CHAR; found INT; p INT;\n" "BEGIN\n" "found := 1;\n" - "old_db_name_len := INSTR(:old_table_name, '/')-1;\n" - "new_db_name_len := INSTR(:new_table_name, '/')-1;\n" - "new_db_name := SUBSTR(:new_table_name, 0,\n" - " new_db_name_len);\n" - "old_t_name_len := LENGTH(:old_table_name);\n" - "gen_constr_prefix := CONCAT(:old_table_name_utf8,\n" - " '_ibfk_');\n" "WHILE found = 1 LOOP\n" - " SELECT ID INTO foreign_id\n" - " FROM SYS_FOREIGN\n" - " WHERE FOR_NAME = :old_table_name\n" - " AND TO_BINARY(FOR_NAME)\n" - " = TO_BINARY(:old_table_name)\n" - " LOCK IN SHARE MODE;\n" - " IF (SQL % NOTFOUND) THEN\n" - " found := 0;\n" - " ELSE\n" - " UPDATE SYS_FOREIGN\n" - " SET FOR_NAME = :new_table_name\n" - " WHERE ID = foreign_id;\n" - " id_len := LENGTH(foreign_id);\n" - " IF (INSTR(foreign_id, '/') > 0) THEN\n" - " IF (INSTR(foreign_id,\n" - " gen_constr_prefix) > 0)\n" - " THEN\n" - " offset := INSTR(foreign_id, '_ibfk_') - 1;\n" - " new_foreign_id :=\n" - " CONCAT(:new_table_utf8,\n" - " SUBSTR(foreign_id, offset,\n" - " id_len - offset));\n" - " ELSE\n" - " new_foreign_id :=\n" - " CONCAT(new_db_name,\n" - " SUBSTR(foreign_id,\n" - " old_db_name_len,\n" - " id_len - old_db_name_len));\n" - " END IF;\n" - " UPDATE SYS_FOREIGN\n" - " SET ID = new_foreign_id\n" - " WHERE ID = foreign_id;\n" - " UPDATE SYS_FOREIGN_COLS\n" - " SET ID = new_foreign_id\n" - " WHERE ID = foreign_id;\n" - " END IF;\n" - " END IF;\n" + " SELECT ID INTO old FROM SYS_FOREIGN\n" + " WHERE FOR_NAME = :old_name\n" + " AND TO_BINARY(FOR_NAME)=TO_BINARY(:old_name)\n" + " LOCK IN SHARE MODE;\n" + " IF (SQL % NOTFOUND) THEN\n" + " found := 0;\n" + " ELSE\n" + " p := INSTR(old, '\377');\n" + " IF p = 0 THEN p := INSTR(old, '/'); END IF;\n" + " new:=CONCAT(:new_name,'\377',\n" + " SUBSTR(old,p,LENGTH(old)-1));\n" + " UPDATE SYS_FOREIGN\n" + " SET ID=new, FOR_NAME=:new_name WHERE ID=old;\n" + " UPDATE SYS_FOREIGN_COLS\n" + " SET ID=new WHERE ID=old;\n" + " END IF;\n" "END LOOP;\n" - "UPDATE SYS_FOREIGN SET REF_NAME = :new_table_name\n" - "WHERE REF_NAME = :old_table_name\n" - " AND TO_BINARY(REF_NAME)\n" - " = TO_BINARY(:old_table_name);\n" + "UPDATE SYS_FOREIGN SET REF_NAME = :new_name\n" + "WHERE REF_NAME = :old_name\n" + "AND TO_BINARY(REF_NAME)=TO_BINARY(:old_name);\n" "END;\n", trx); - + if (err == DB_DUPLICATE_KEY) { + err = DB_FOREIGN_DUPLICATE_KEY; + } } else if (n_constraints_to_drop > 0) { /* Drop some constraints of tmp tables. */ - - ulint db_name_len = dict_get_db_name_len(old_name) + 1; - char* db_name = mem_heap_strdupl(heap, old_name, - db_name_len); - ulint i; - - for (i = 0; i < n_constraints_to_drop; i++) { + for (auto i = n_constraints_to_drop; i--; ) { err = row_delete_constraint(constraints_to_drop[i], - db_name, heap, trx); + old_name, heap, trx); if (err != DB_SUCCESS) { break; @@ -2799,34 +2715,20 @@ row_rename_table_for_mysql( if (err == DB_SUCCESS && (dict_table_has_fts_index(table) - || DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) - && !dict_tables_have_same_db(old_name, new_name)) { + || DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID)) + && !dict_tables_have_same_db(old_name, new_name)) { err = fts_rename_aux_tables(table, new_name, trx); } - switch (err) { - case DB_DUPLICATE_KEY: - ib::error() << "Table rename might cause two" - " FOREIGN KEY constraints to have the same" - " internal name in case-insensitive comparison."; - ib::info() << TROUBLESHOOTING_MSG; - /* fall through */ - rollback_and_exit: - default: - trx->error_state = DB_SUCCESS; - trx->rollback(); - trx->error_state = DB_SUCCESS; - break; - case DB_SUCCESS: + if (err == DB_SUCCESS) { DEBUG_SYNC_C("innodb_rename_in_cache"); /* The following call will also rename the .ibd file */ err = dict_table_rename_in_cache( table, span{new_name,strlen(new_name)}, false); - if (err != DB_SUCCESS) { - goto rollback_and_exit; - } + } + if (err == DB_SUCCESS) { /* In case of copy alter, template db_name and table_name should be renamed only for newly created table. */ @@ -2860,7 +2762,7 @@ row_rename_table_for_mysql( " definition."; if (!trx->check_foreigns) { err = DB_SUCCESS; - break; + goto funct_exit; } } else { ib::error() << "In RENAME TABLE table " @@ -2869,29 +2771,23 @@ row_rename_table_for_mysql( " constraints which are not compatible" " with the new table definition."; } - - goto rollback_and_exit; - } - - /* Check whether virtual column or stored column affects - the foreign key constraint of the table. */ - if (dict_foreigns_has_s_base_col(table->foreign_set, table)) { + } else if (dict_foreigns_has_s_base_col(table->foreign_set, + table)) { err = DB_NO_FK_ON_S_BASE_COL; - goto rollback_and_exit; + } else { + /* Fill the virtual column set in foreign when + the table undergoes copy alter operation. */ + dict_mem_table_free_foreign_vcol_set(table); + dict_mem_table_fill_foreign_vcol_set(table); + + while (!fk_tables.empty()) { + const char *f = fk_tables.front(); + dict_sys.load_table({f, strlen(f)}); + fk_tables.pop_front(); + } + + table->data_dir_path= NULL; } - - /* Fill the virtual column set in foreign when - the table undergoes copy alter operation. */ - dict_mem_table_free_foreign_vcol_set(table); - dict_mem_table_fill_foreign_vcol_set(table); - - while (!fk_tables.empty()) { - const char *f = fk_tables.front(); - dict_sys.load_table({f, strlen(f)}); - fk_tables.pop_front(); - } - - table->data_dir_path= NULL; } funct_exit: diff --git a/storage/myisam/mysql-test/storage_engine/foreign_keys.rdiff b/storage/myisam/mysql-test/storage_engine/foreign_keys.rdiff index 65d11557c86..1d55aaa135e 100644 --- a/storage/myisam/mysql-test/storage_engine/foreign_keys.rdiff +++ b/storage/myisam/mysql-test/storage_engine/foreign_keys.rdiff @@ -5,11 +5,11 @@ `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, - KEY `a` (`a`), -- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) + KEY `a` (`a`) - ) ENGINE= DEFAULT CHARSET=latin1 + ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -21,7 +21,7 @@ INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d'); INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); UPDATE t2 SET a=a+1; --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -31,10 +31,10 @@ +# Also, this problem may cause a chain effect (more errors of different kinds in the test). +# ------------------------------------------- UPDATE t1 SET a=3 WHERE a=2; --ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2) DELETE FROM t1 WHERE a=2; --ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -72,11 +72,11 @@ `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, - KEY `a` (`a`), -- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE +- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE + KEY `a` (`a`) - ) ENGINE= DEFAULT CHARSET=latin1 + ) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'); --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a'); +ERROR 42S02: Table 'test.t1' doesn't exist @@ -130,7 +130,7 @@ +4 d +4 e TRUNCATE TABLE t1; --ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +-ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +ERROR 42S02: Table 'test.t1' doesn't exist +# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK) +# ------------ UNEXPECTED RESULT ------------ diff --git a/storage/myisammrg/mysql-test/storage_engine/foreign_keys.rdiff b/storage/myisammrg/mysql-test/storage_engine/foreign_keys.rdiff index 4af98e0d3b4..29f748d4706 100644 --- a/storage/myisammrg/mysql-test/storage_engine/foreign_keys.rdiff +++ b/storage/myisammrg/mysql-test/storage_engine/foreign_keys.rdiff @@ -5,12 +5,12 @@ `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, - KEY `a` (`a`), -- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) --) ENGINE= DEFAULT CHARSET=latin1 +- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) +-) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci + KEY `a` (`a`) -+) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t2`) ++) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT_METHOD=LAST UNION=(`mrg`.`t2`) INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -22,7 +22,7 @@ INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d'); INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'); UPDATE t2 SET a=a+1; --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -32,10 +32,10 @@ +# Also, this problem may cause a chain effect (more errors of different kinds in the test). +# ------------------------------------------- UPDATE t1 SET a=3 WHERE a=2; --ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2) DELETE FROM t1 WHERE a=2; --ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +-ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2) +# ------------ UNEXPECTED RESULT ------------ +# The statement|command succeeded unexpectedly. @@ -73,12 +73,12 @@ `a` int(11) DEFAULT NULL, `b` char(8) DEFAULT NULL, - KEY `a` (`a`), -- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE --) ENGINE= DEFAULT CHARSET=latin1 +- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE +-) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci + KEY `a` (`a`) -+) ENGINE= DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t2`) ++) ENGINE= DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT_METHOD=LAST UNION=(`mrg`.`t2`) INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'); --ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +-ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) +# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2) INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a'); +ERROR 42S02: Table 'test.t1' doesn't exist @@ -132,7 +132,7 @@ +4 d +4 e TRUNCATE TABLE t1; --ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +-ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) +ERROR 42S02: Table 'test.t1' doesn't exist +# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK) +# ------------ UNEXPECTED RESULT ------------