mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
MDEV-28933: Per-table unique FOREIGN KEY constraint names
Before MySQL 4.0.18, user-specified constraint names were ignored. Starting with MySQL 4.0.18, the specified constraint name was prepended with the schema name and '/'. Now we are transforming into a format where the constraint name is prepended with the dict_table_t::name and the impossible UTF-8 sequence 0xff. Generated constraint names will be ASCII decimal numbers. On upgrade, old FOREIGN KEY constraint names will be displayed without any schema name prefix. They will be updated to the new format on DDL operations. dict_foreign_t::sql_id(): Return the SQL constraint name without any schemaname/tablename\377 or schemaname/ prefix. row_rename_table_for_mysql(), dict_table_rename_in_cache(): Simplify the logic: Just rename constraints to the new format. dict_table_get_foreign_id(): Replaces dict_table_get_highest_foreign_id(). innobase_get_foreign_key_info(): Let my_error() refer to erroneous anonymous constraints as "(null)". row_delete_constraint(): Try to drop all 3 constraint name variants. Reviewed by: Thirunarayanan Balathandayuthapani Tested by: Matthias Leich
This commit is contained in:
@@ -1539,13 +1539,13 @@ t2 CREATE TABLE `t2` (
|
|||||||
KEY `fk` (`id`)
|
KEY `fk` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) 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 (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:
|
Warnings:
|
||||||
Note 1061 Duplicate key name 't2_ibfk_1'
|
Note 1061 Duplicate key name '1'
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`;
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`;
|
||||||
Warnings:
|
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;
|
SHOW CREATE TABLE t2;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
|
@@ -1384,9 +1384,9 @@ ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk;
|
|||||||
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk;
|
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS fk;
|
||||||
SHOW CREATE TABLE t2;
|
SHOW CREATE TABLE t2;
|
||||||
ALTER TABLE t2 ADD FOREIGN KEY (id) REFERENCES t1(id);
|
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);
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`;
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY IF EXISTS `1`;
|
||||||
SHOW CREATE TABLE t2;
|
SHOW CREATE TABLE t2;
|
||||||
|
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
- KEY `b` (`b`),
|
- KEY `b` (`b`),
|
||||||
- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`)
|
- CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`)
|
||||||
+ KEY `b` (`b`)
|
+ KEY `b` (`b`)
|
||||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`c` int(11) DEFAULT NULL,
|
`c` int(11) DEFAULT NULL,
|
||||||
- KEY `b` (`c`),
|
- KEY `b` (`c`),
|
||||||
- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`)
|
- CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`)
|
||||||
+ KEY `b` (`c`)
|
+ KEY `b` (`c`)
|
||||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
CREATE TABLE t4(a int);
|
CREATE TABLE t4(a int);
|
||||||
|
@@ -14,7 +14,7 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
- KEY `b` (`b`),
|
- KEY `b` (`b`),
|
||||||
- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`)
|
- CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`bb`)
|
||||||
+ KEY `b` (`b`)
|
+ KEY `b` (`b`)
|
||||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`c` int(11) DEFAULT NULL,
|
`c` int(11) DEFAULT NULL,
|
||||||
- KEY `b` (`c`),
|
- KEY `b` (`c`),
|
||||||
- CONSTRAINT `t3_ibfk_1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`)
|
- CONSTRAINT `1` FOREIGN KEY (`c`) REFERENCES `t1` (`b`)
|
||||||
+ KEY `b` (`c`)
|
+ KEY `b` (`c`)
|
||||||
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
CREATE TABLE t4(a int);
|
CREATE TABLE t4(a int);
|
||||||
|
@@ -174,7 +174,7 @@ t3 CREATE TABLE `t3` (
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
KEY `b` (`b`),
|
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
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
ALTER TABLE t1 RENAME COLUMN bb TO b;
|
||||||
SHOW CREATE TABLE t1;
|
SHOW CREATE TABLE t1;
|
||||||
@@ -191,7 +191,7 @@ t3 CREATE TABLE `t3` (
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`c` int(11) DEFAULT NULL,
|
`c` int(11) DEFAULT NULL,
|
||||||
KEY `b` (`c`),
|
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
|
) ENGINE=DEFAULT_ENGINE DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
CREATE TABLE t4(a int);
|
CREATE TABLE t4(a int);
|
||||||
ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE;
|
ALTER TABLE t4 RENAME COLUMN a TO aa, ALGORITHM = INPLACE;
|
||||||
|
@@ -364,7 +364,7 @@ t1 CREATE TABLE `t1` (
|
|||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
KEY `b` (`b`),
|
KEY `b` (`b`),
|
||||||
KEY `idx` (`aaaa`),
|
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
|
) 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;
|
SELECT index_name FROM mysql.index_stats WHERE table_name = 't1' order by index_name;
|
||||||
index_name
|
index_name
|
||||||
|
@@ -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 t1 values (1), (2), (3), (4), (5), (6);
|
||||||
insert into t2 values (3), (5);
|
insert into t2 values (3), (5);
|
||||||
delete from t1;
|
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;
|
select * from t1;
|
||||||
id
|
id
|
||||||
1
|
1
|
||||||
@@ -29,8 +29,8 @@ id
|
|||||||
6
|
6
|
||||||
delete ignore from t1;
|
delete ignore from t1;
|
||||||
Warnings:
|
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 `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`))
|
||||||
select row_count();
|
select row_count();
|
||||||
row_count()
|
row_count()
|
||||||
-1
|
-1
|
||||||
|
@@ -446,7 +446,7 @@ INSERT INTO t1_child SET f1 = 2, f2 = 2;
|
|||||||
RETURN 1;
|
RETURN 1;
|
||||||
END//
|
END//
|
||||||
SELECT f1_two_inserts();
|
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;
|
SELECT * FROM t1_child;
|
||||||
f1 f2
|
f1 f2
|
||||||
DROP TABLE t1_child;
|
DROP TABLE t1_child;
|
||||||
|
@@ -367,9 +367,9 @@ select table_name, constraint_name, constraint_type from information_schema.tabl
|
|||||||
table_name constraint_name constraint_type
|
table_name constraint_name constraint_type
|
||||||
t3 e UNIQUE
|
t3 e UNIQUE
|
||||||
t3 CONSTRAINT_1 CHECK
|
t3 CONSTRAINT_1 CHECK
|
||||||
t3 t3_ibfk_1 FOREIGN KEY
|
t3 1 FOREIGN KEY
|
||||||
t3 t3_ibfk_2 FOREIGN KEY
|
t3 2 FOREIGN KEY
|
||||||
t3 t3_ibfk_3 FOREIGN KEY
|
t3 3 FOREIGN KEY
|
||||||
show index in t2;
|
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
|
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;
|
show index in t3;
|
||||||
|
@@ -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
|
select * from information_schema.TABLE_CONSTRAINTS where
|
||||||
TABLE_SCHEMA= "test";
|
TABLE_SCHEMA= "test";
|
||||||
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
|
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 t1 PRIMARY KEY
|
||||||
def test PRIMARY test t2 PRIMARY KEY
|
def test PRIMARY test t2 PRIMARY KEY
|
||||||
def test PRIMARY test t3 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
|
select * from information_schema.KEY_COLUMN_USAGE where
|
||||||
TABLE_SCHEMA= "test";
|
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
|
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 t1 id 1 NULL NULL NULL NULL
|
||||||
def test PRIMARY def test t2 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 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;
|
drop table t3, t2, t1;
|
||||||
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
|
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
|
||||||
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
|
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
|
||||||
|
@@ -10,7 +10,7 @@ INSERT INTO t2 VALUES(0);
|
|||||||
# Without fix, an error is reported.
|
# Without fix, an error is reported.
|
||||||
INSERT IGNORE INTO t2 VALUES(1);
|
INSERT IGNORE INTO t2 VALUES(1);
|
||||||
Warnings:
|
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 t2 SET fld2=20 WHERE fld2=0;
|
||||||
UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0;
|
UPDATE IGNORE t1 SET fld1=20 WHERE fld1=0;
|
||||||
# Test for multi update.
|
# 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;
|
UPDATE IGNORE t1, t2 SET t1.fld1= t1.fld1 + 3;
|
||||||
# Reports an error since IGNORE is not used.
|
# Reports an error since IGNORE is not used.
|
||||||
INSERT INTO t2 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 (`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;
|
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;
|
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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
#
|
#
|
||||||
# BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN
|
# BUG#22037930: INSERT IGNORE FAILS TO IGNORE FOREIGN
|
||||||
|
@@ -73,8 +73,8 @@ Create Table CREATE TABLE `Product_Order` (
|
|||||||
PRIMARY KEY (`No`),
|
PRIMARY KEY (`No`),
|
||||||
KEY `Product_Category` (`Product_Category`,`Product_Id`),
|
KEY `Product_Category` (`Product_Category`,`Product_Id`),
|
||||||
KEY `Customer_Id` (`Customer_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 `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 `2` FOREIGN KEY (`Customer_Id`) REFERENCES `Customer` (`Id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SHOW CREATE TABLE Product;
|
SHOW CREATE TABLE Product;
|
||||||
Table Product
|
Table Product
|
||||||
@@ -93,7 +93,7 @@ Create Table CREATE TABLE `Customer` (
|
|||||||
SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='test';
|
SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_SCHEMA='test';
|
||||||
CONSTRAINT_CATALOG def
|
CONSTRAINT_CATALOG def
|
||||||
CONSTRAINT_SCHEMA test
|
CONSTRAINT_SCHEMA test
|
||||||
CONSTRAINT_NAME product_order_ibfk_1
|
CONSTRAINT_NAME 1
|
||||||
UNIQUE_CONSTRAINT_CATALOG def
|
UNIQUE_CONSTRAINT_CATALOG def
|
||||||
UNIQUE_CONSTRAINT_SCHEMA test
|
UNIQUE_CONSTRAINT_SCHEMA test
|
||||||
UNIQUE_CONSTRAINT_NAME PRIMARY
|
UNIQUE_CONSTRAINT_NAME PRIMARY
|
||||||
@@ -104,7 +104,7 @@ TABLE_NAME Product_Order
|
|||||||
REFERENCED_TABLE_NAME Product
|
REFERENCED_TABLE_NAME Product
|
||||||
CONSTRAINT_CATALOG def
|
CONSTRAINT_CATALOG def
|
||||||
CONSTRAINT_SCHEMA test
|
CONSTRAINT_SCHEMA test
|
||||||
CONSTRAINT_NAME product_order_ibfk_2
|
CONSTRAINT_NAME 2
|
||||||
UNIQUE_CONSTRAINT_CATALOG def
|
UNIQUE_CONSTRAINT_CATALOG def
|
||||||
UNIQUE_CONSTRAINT_SCHEMA test
|
UNIQUE_CONSTRAINT_SCHEMA test
|
||||||
UNIQUE_CONSTRAINT_NAME PRIMARY
|
UNIQUE_CONSTRAINT_NAME PRIMARY
|
||||||
|
@@ -225,7 +225,7 @@ child CREATE TABLE `child` (
|
|||||||
`c` char(4) DEFAULT NULL,
|
`c` char(4) DEFAULT NULL,
|
||||||
UNIQUE KEY `c` (`c`),
|
UNIQUE KEY `c` (`c`),
|
||||||
KEY `par_ind` (`parent_id`),
|
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')
|
CONSTRAINT `CONSTRAINT_1` CHECK (`c` >= 'a')
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop database db2;
|
drop database db2;
|
||||||
|
@@ -160,7 +160,7 @@ CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1;
|
|||||||
SET @a = 0;
|
SET @a = 0;
|
||||||
SET @b = 0;
|
SET @b = 0;
|
||||||
TRUNCATE t1;
|
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;
|
SELECT @a, @b;
|
||||||
@a @b
|
@a @b
|
||||||
0 0
|
0 0
|
||||||
|
@@ -11,7 +11,7 @@ set binlog_alter_two_phase = ON;
|
|||||||
create table t1 (f1 int primary key) engine=InnoDB;
|
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;
|
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);
|
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;
|
drop table t2, t1;
|
||||||
select @@gtid_binlog_state;
|
select @@gtid_binlog_state;
|
||||||
@@gtid_binlog_state
|
@@gtid_binlog_state
|
||||||
|
@@ -21,7 +21,7 @@ set binlog_alter_two_phase = ON;
|
|||||||
create table t1 (f1 int primary key) engine=InnoDB;
|
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;
|
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);
|
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
||||||
|
|
||||||
drop table t2, t1;
|
drop table t2, t1;
|
||||||
|
@@ -49,7 +49,7 @@ INSERT INTO t1 VALUES (3,'Department C');
|
|||||||
INSERT INTO t2 VALUES (1,2,'Emp 1');
|
INSERT INTO t2 VALUES (1,2,'Emp 1');
|
||||||
INSERT INTO t2 VALUES (2,3,'Emp 2');
|
INSERT INTO t2 VALUES (2,3,'Emp 2');
|
||||||
insert into t2 VALUES (3,4,'Emp 3');
|
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
|
CREATE TRIGGER tr_t2 BEFORE INSERT ON t2 FOR EACH ROW
|
||||||
INSERT INTO t1 VALUES(new.f_id, CONCAT('New Department ', new.f_id));
|
INSERT INTO t1 VALUES(new.f_id, CONCAT('New Department ', new.f_id));
|
||||||
LOCK TABLES t1 WRITE, t2 WRITE;
|
LOCK TABLES t1 WRITE, t2 WRITE;
|
||||||
|
@@ -54,7 +54,7 @@ INSERT INTO p VALUES(1, 0);
|
|||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
INSERT INTO c VALUES (3,1);
|
INSERT INTO c VALUES (3,1);
|
||||||
INSERT INTO c VALUES (1,1), (2,2);
|
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;
|
COMMIT;
|
||||||
SELECT * FROM p;
|
SELECT * FROM p;
|
||||||
id j
|
id j
|
||||||
|
@@ -19,7 +19,7 @@ SELECT COUNT(*) = 1 FROM child WHERE id = 2;
|
|||||||
COUNT(*) = 1
|
COUNT(*) = 1
|
||||||
1
|
1
|
||||||
INSERT INTO child VALUES (3,3);
|
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;
|
SET SESSION foreign_key_checks = 0;
|
||||||
DELETE FROM parent;
|
DELETE FROM parent;
|
||||||
connection node_1;
|
connection node_1;
|
||||||
|
@@ -245,7 +245,7 @@ if ($innodb_engine)
|
|||||||
--error 1451
|
--error 1451
|
||||||
update t2 set a=4 where a=3;
|
update t2 set a=4 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,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
|
--echo # - ON DELETE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) 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;
|
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,t2 where t1.b=t2.a;
|
||||||
select t1.a, t1.b, t2.name from t1 left outer join t2 on (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
|
--echo # - ON DELETE CASCADE
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
||||||
delete from t2 where a=3;
|
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,t2 where t1.b=t2.a;
|
||||||
select t1.a, t1.b, t2.name from t1 left outer join t2 on (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 t1;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
|
@@ -357,19 +357,19 @@ a b name
|
|||||||
# - ON UPDATE RESTRICT
|
# - ON UPDATE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) on update restrict;
|
alter table t1 add foreign key (b) references t2(a) on update restrict;
|
||||||
insert into t1 (a) values (4);
|
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;
|
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;
|
select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
|
||||||
a b name
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
3 3 value3
|
3 3 value3
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
# - ON DELETE RESTRICT
|
# - ON DELETE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete restrict;
|
alter table t1 add foreign key (b) references t2(a) on delete restrict;
|
||||||
delete from t2 where a=3;
|
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;
|
select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
|
||||||
a b name
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
@@ -380,7 +380,7 @@ a b name
|
|||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
3 3 value3
|
3 3 value3
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
# - ON DELETE CASCADE
|
# - ON DELETE CASCADE
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
||||||
delete from t2 where a=3;
|
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
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
#
|
#
|
||||||
|
@@ -212,7 +212,7 @@ CREATE TABLE t1(a INT);
|
|||||||
CREATE INDEX idx ON t1(a);
|
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 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));
|
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));
|
CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b));
|
||||||
DROP TABLE t3;
|
DROP TABLE t3;
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
|
@@ -246,8 +246,8 @@ DROP TABLE t1;
|
|||||||
CREATE TABLE t1(a INT);
|
CREATE TABLE t1(a INT);
|
||||||
CREATE INDEX idx ON t1(a);
|
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 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));
|
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));
|
CREATE TABLE t2(a INT, b INT generated always as (a+1) virtual, INDEX(b));
|
||||||
DROP TABLE t3;
|
DROP TABLE t3;
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
|
@@ -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 t2 add constraint b foreign key (b) references t1(a);
|
||||||
alter table t1 add constraint b1 foreign key (b) references t2(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);
|
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 t2 drop foreign key b;
|
||||||
alter table t1 drop foreign key b1;
|
alter table t1 drop foreign key b1;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
|
@@ -37,7 +37,7 @@ info: Records: 0 Duplicates: 0 Warnings: 0
|
|||||||
INSERT INTO t1 VALUES (1, 1);
|
INSERT INTO t1 VALUES (1, 1);
|
||||||
INSERT INTO t2 VALUES (1, 2);
|
INSERT INTO t2 VALUES (1, 2);
|
||||||
ALTER TABLE t2 ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1);
|
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);
|
INSERT INTO t1 VALUES(3, 1);
|
||||||
SET STATEMENT foreign_key_checks=0 FOR
|
SET STATEMENT foreign_key_checks=0 FOR
|
||||||
ALTER TABLE t2 ALGORITHM=COPY, ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1);
|
ALTER TABLE t2 ALGORITHM=COPY, ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1);
|
||||||
|
@@ -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;
|
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;
|
SET FOREIGN_KEY_CHECKS=OFF;
|
||||||
ALTER TABLE t1 DROP a;
|
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;
|
SET FOREIGN_KEY_CHECKS=ON;
|
||||||
ALTER TABLE t1 ADD b INT;
|
ALTER TABLE t1 ADD b INT;
|
||||||
ALTER TABLE t1 DROP a;
|
ALTER TABLE t1 DROP a;
|
||||||
|
@@ -23,22 +23,22 @@ SET FOREIGN_KEY_CHECKS=1;
|
|||||||
ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(200) character set utf8mb3, ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=1;
|
||||||
ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4, ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
ALTER TABLE t2 MODIFY COLUMN msg VARCHAR(100) CHARACTER SET utf8mb4,ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
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;
|
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")
|
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;
|
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")
|
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;
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=1;
|
||||||
ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
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'
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb3, ALGORITHM=COPY;
|
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'
|
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;
|
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;
|
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'
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY fk_t1, MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
|
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;
|
ALTER TABLE t1 MODIFY msg VARCHAR(200) CHARSET utf8mb4, ALGORITHM=COPY;
|
||||||
|
@@ -39,6 +39,6 @@ t2 CREATE TABLE `t2` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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 TABLE best.t2, best.t1, t2, t1;
|
||||||
DROP DATABASE best;
|
DROP DATABASE best;
|
||||||
|
@@ -22,7 +22,7 @@ insert t2 values (4,1),(5,2),(6,3);
|
|||||||
flush table t2 with read lock;
|
flush table t2 with read lock;
|
||||||
connect con1,localhost,root;
|
connect con1,localhost,root;
|
||||||
delete from t1 where a=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 (`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;
|
update t1 set a=10 where a=1;
|
||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
@@ -34,7 +34,7 @@ delete from t1 where a=2;
|
|||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
connection con1;
|
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;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
disconnect con1;
|
disconnect con1;
|
||||||
@@ -75,7 +75,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`f2` int(11) NOT NULL,
|
`f2` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
disconnect con1;
|
disconnect con1;
|
||||||
connection default;
|
connection default;
|
||||||
@@ -132,7 +132,7 @@ insert t2 values (4,1),(5,2),(6,3);
|
|||||||
flush table t2 with read lock;
|
flush table t2 with read lock;
|
||||||
connect con1,localhost,root;
|
connect con1,localhost,root;
|
||||||
delete from t1 where a=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 (`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;
|
update t1 set a=10 where a=1;
|
||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
@@ -144,7 +144,7 @@ delete from t1 where a=2;
|
|||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
connection con1;
|
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;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
disconnect con1;
|
disconnect con1;
|
||||||
@@ -233,7 +233,7 @@ SET FOREIGN_KEY_CHECKS=0;
|
|||||||
DROP INDEX f2 ON t2;
|
DROP INDEX f2 ON t2;
|
||||||
SET FOREIGN_KEY_CHECKS=1;
|
SET FOREIGN_KEY_CHECKS=1;
|
||||||
INSERT INTO t2 VALUES('G', 3);
|
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;
|
DROP TABLE t2, t1;
|
||||||
SET FOREIGN_KEY_CHECKS=DEFAULT;
|
SET FOREIGN_KEY_CHECKS=DEFAULT;
|
||||||
CREATE TABLE t1(a SERIAL) ENGINE=InnoDB ROW_FORMAT=COMPRESSED PAGE_COMPRESSED=1;
|
CREATE TABLE t1(a SERIAL) ENGINE=InnoDB ROW_FORMAT=COMPRESSED PAGE_COMPRESSED=1;
|
||||||
@@ -261,7 +261,15 @@ index i2яяяяяяяяяяььььььььььззззззззззшшшшшш
|
|||||||
insert t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш values(99, 2);
|
insert t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш values(99, 2);
|
||||||
alter table t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш add foreign key(f2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш) references t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш(f1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш);
|
alter table t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш add foreign key(f2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш) references t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш(f1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш);
|
||||||
insert t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш values('g', 3);
|
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яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш,
|
drop table t2яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш,
|
||||||
t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш;
|
t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш;
|
||||||
# End of 10.6 tests
|
# 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;
|
||||||
|
@@ -11,10 +11,10 @@ ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint
|
|||||||
create table t2 (f1 int primary key,
|
create table t2 (f1 int primary key,
|
||||||
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
||||||
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
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 ''
|
||||||
set foreign_key_checks = 0;
|
set statement foreign_key_checks = 0 for
|
||||||
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
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;
|
drop table t2, t1;
|
||||||
#
|
#
|
||||||
# Bug #20031243 CREATE TABLE FAILS TO CHECK IF FOREIGN KEY COLUMN
|
# Bug #20031243 CREATE TABLE FAILS TO CHECK IF FOREIGN KEY COLUMN
|
||||||
@@ -48,7 +48,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
KEY `ind` (`b`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
INSERT INTO t1 VALUES (1, 80);
|
INSERT INTO t1 VALUES (1, 80);
|
||||||
INSERT INTO t1 VALUES (2, 81);
|
INSERT INTO t1 VALUES (2, 81);
|
||||||
@@ -75,7 +75,7 @@ a b
|
|||||||
54 4
|
54 4
|
||||||
55 5
|
55 5
|
||||||
INSERT INTO t2 VALUES (56, 6);
|
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;
|
ALTER TABLE t1 CHANGE a id INT;
|
||||||
SELECT id, b FROM t1 ORDER BY id;
|
SELECT id, b FROM t1 ORDER BY id;
|
||||||
id b
|
id b
|
||||||
@@ -93,9 +93,9 @@ a b
|
|||||||
55 5
|
55 5
|
||||||
# Operations on child table
|
# Operations on child table
|
||||||
INSERT INTO t2 VALUES (56, 6);
|
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;
|
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;
|
DELETE FROM t2 WHERE a = 53;
|
||||||
SELECT id, b FROM t1 ORDER BY id;
|
SELECT id, b FROM t1 ORDER BY id;
|
||||||
id b
|
id b
|
||||||
@@ -158,9 +158,9 @@ disconnect incomplete;
|
|||||||
SET GLOBAL innodb_stats_persistent = 0;
|
SET GLOBAL innodb_stats_persistent = 0;
|
||||||
INSERT INTO child SET a=0;
|
INSERT INTO child SET a=0;
|
||||||
INSERT INTO child SET a=1;
|
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;
|
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);
|
ALTER TABLE child ADD INDEX(a);
|
||||||
DELETE FROM parent;
|
DELETE FROM parent;
|
||||||
DROP TABLE child,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),
|
CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
|
||||||
FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
|
FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
|
||||||
RENAME TABLE best.t2 TO test.t2;
|
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;
|
SHOW CREATE TABLE best.t2;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
@@ -214,7 +223,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`b` text DEFAULT NULL,
|
`b` text DEFAULT NULL,
|
||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
FULLTEXT KEY `b` (`b`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
DROP DATABASE best;
|
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);
|
ALTER TABLE t1 ADD FOREIGN KEY (a) REFERENCES t1 (a);
|
||||||
SET SESSION FOREIGN_KEY_CHECKS = OFF;
|
SET SESSION FOREIGN_KEY_CHECKS = OFF;
|
||||||
ALTER TABLE t1 CHANGE COLUMN a a TIME NOT NULL;
|
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 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
|
||||||
ALTER TABLE t1 CHANGE COLUMN a b TIME;
|
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
|
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;
|
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
#
|
#
|
||||||
@@ -342,7 +361,7 @@ insert t2 values (4,1),(5,2),(6,3);
|
|||||||
flush table t2 with read lock;
|
flush table t2 with read lock;
|
||||||
connect con1,localhost,root;
|
connect con1,localhost,root;
|
||||||
delete from t1 where a=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 (`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;
|
update t1 set a=10 where a=1;
|
||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
@@ -354,7 +373,7 @@ delete from t1 where a=2;
|
|||||||
connection default;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
connection con1;
|
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;
|
connection default;
|
||||||
unlock tables;
|
unlock tables;
|
||||||
disconnect con1;
|
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;
|
create table t2 (t1_pk int, foreign key (t1_pk) references t1 (pk)) engine=innodb;
|
||||||
insert t2 values (1),(2);
|
insert t2 values (1),(2);
|
||||||
insert t2 values (10);
|
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 tables;
|
||||||
flush status;
|
flush status;
|
||||||
update t1 set data=10 where pk+1>10;
|
update t1 set data=10 where pk+1>10;
|
||||||
@@ -478,10 +497,10 @@ pk f1 f2 f3 f4 f5 f6 f7 f8
|
|||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL;
|
ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL;
|
||||||
UPDATE t1 SET f6='update';
|
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;
|
ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE;
|
||||||
UPDATE t1 SET f6='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;
|
DROP TABLE t1;
|
||||||
# Start of 10.2 tests
|
# Start of 10.2 tests
|
||||||
#
|
#
|
||||||
@@ -556,7 +575,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f` int(11) DEFAULT NULL,
|
`f` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `ref_id` (`ref_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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
connection con1;
|
connection con1;
|
||||||
BEGIN;
|
BEGIN;
|
||||||
@@ -688,9 +707,9 @@ connection default;
|
|||||||
DELETE IGNORE FROM t1 WHERE b = 1;
|
DELETE IGNORE FROM t1 WHERE b = 1;
|
||||||
Warnings:
|
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 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 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);
|
SELECT a FROM t1 FORCE INDEX(a);
|
||||||
a
|
a
|
||||||
0
|
0
|
||||||
@@ -737,7 +756,7 @@ DROP TABLE t1;
|
|||||||
# MDEV-17187 table doesn't exist in engine after ALTER other tables
|
# MDEV-17187 table doesn't exist in engine after ALTER other tables
|
||||||
# with CONSTRAINTs
|
# 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;
|
set foreign_key_checks=on;
|
||||||
create table t1 (id int not null primary key) engine=innodb;
|
create table t1 (id int not null primary key) engine=innodb;
|
||||||
create table t2 (id int not null primary key, fid int not null,
|
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,0),(0,0),
|
||||||
(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,1),(1,0);
|
(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,1),(1,0);
|
||||||
DELETE FROM t1 WHERE b = 1;
|
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;
|
SHOW WARNINGS;
|
||||||
Level Code Message
|
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
|
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;
|
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
|
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
|
# End of 10.2 tests
|
||||||
@@ -941,8 +960,8 @@ t2 CREATE TABLE `t2` (
|
|||||||
`y` int(11) DEFAULT NULL,
|
`y` int(11) DEFAULT NULL,
|
||||||
KEY `x` (`x`),
|
KEY `x` (`x`),
|
||||||
KEY `fk` (`y`),
|
KEY `fk` (`y`),
|
||||||
CONSTRAINT `fk` FOREIGN KEY (`y`) REFERENCES `t1` (`y`),
|
CONSTRAINT `1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`),
|
||||||
CONSTRAINT `t2_ibfk_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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
create table t3 (z int);
|
create table t3 (z int);
|
||||||
alter table t3 add x int references t1(x), add y int constraint fk2 references t1(y);
|
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,
|
`y` int(11) DEFAULT NULL,
|
||||||
KEY `x` (`x`),
|
KEY `x` (`x`),
|
||||||
KEY `fk2` (`y`),
|
KEY `fk2` (`y`),
|
||||||
CONSTRAINT `fk2` FOREIGN KEY (`y`) REFERENCES `t1` (`y`),
|
CONSTRAINT `1` FOREIGN KEY (`x`) REFERENCES `t1` (`x`),
|
||||||
CONSTRAINT `t3_ibfk_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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop tables t3, t2, t1;
|
drop tables t3, t2, t1;
|
||||||
create table t1 (id int primary key);
|
create table t1 (id int primary key);
|
||||||
@@ -967,7 +986,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`id` int(11) DEFAULT NULL,
|
`id` int(11) DEFAULT NULL,
|
||||||
KEY `id` (`id`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop tables t2, t1;
|
drop tables t2, t1;
|
||||||
set default_storage_engine= default;
|
set default_storage_engine= default;
|
||||||
@@ -1020,7 +1039,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`a` int(11) NOT NULL,
|
`a` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`a`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop tables t2, t1;
|
drop tables t2, t1;
|
||||||
#
|
#
|
||||||
@@ -1050,10 +1069,10 @@ CREATE TABLE child(a INT PRIMARY KEY REFERENCES parent(a)) ENGINE=InnoDB;
|
|||||||
connect con1, localhost, root,,;
|
connect con1, localhost, root,,;
|
||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT INTO child SET a=1;
|
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;
|
connection default;
|
||||||
TRUNCATE TABLE parent;
|
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;
|
DROP TABLE parent;
|
||||||
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
|
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
|
||||||
SET innodb_lock_wait_timeout=0;
|
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;
|
ALTER TABLE parent ADD COLUMN b INT, ALGORITHM=INSTANT;
|
||||||
SET foreign_key_checks=ON;
|
SET foreign_key_checks=ON;
|
||||||
TRUNCATE TABLE parent;
|
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=COPY;
|
||||||
ALTER TABLE parent FORCE, ALGORITHM=INPLACE;
|
ALTER TABLE parent FORCE, ALGORITHM=INPLACE;
|
||||||
RENAME TABLE parent TO transparent;
|
RENAME TABLE parent TO transparent;
|
||||||
@@ -1148,13 +1167,13 @@ t2 CREATE TABLE `t2` (
|
|||||||
`b` int(11) DEFAULT NULL,
|
`b` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
UNIQUE KEY `b` (`b`),
|
UNIQUE KEY `b` (`b`),
|
||||||
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`),
|
CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`b`),
|
||||||
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
CONSTRAINT `2` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
INSERT INTO t2 SET a=1;
|
INSERT INTO t2 SET a=1;
|
||||||
DELETE FROM t1;
|
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 t2;
|
||||||
DELETE FROM t1;
|
DELETE FROM t1;
|
||||||
DROP DATABASE `#mysql50##mysql50#d-b`;
|
DROP DATABASE `#mysql50##mysql50#d-b`;
|
||||||
@@ -1172,7 +1191,7 @@ SET STATEMENT foreign_key_checks=0 FOR
|
|||||||
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
|
CREATE TABLE t1 (a INT) ENGINE=InnoDB;
|
||||||
INSERT INTO t1 VALUES (1);
|
INSERT INTO t1 VALUES (1);
|
||||||
INSERT INTO t2 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;
|
ALTER TABLE t1 ADD KEY(a), ALGORITHM=NOCOPY;
|
||||||
INSERT INTO t2 VALUES (1);
|
INSERT INTO t2 VALUES (1);
|
||||||
DROP INDEX b ON t2;
|
DROP INDEX b ON t2;
|
||||||
@@ -1181,7 +1200,7 @@ SET STATEMENT foreign_key_checks=0 FOR
|
|||||||
DROP INDEX b ON t2;
|
DROP INDEX b ON t2;
|
||||||
DELETE FROM t2;
|
DELETE FROM t2;
|
||||||
DELETE FROM t1;
|
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;
|
ALTER TABLE t2 ADD KEY(b), ALGORITHM=NOCOPY;
|
||||||
DELETE FROM t1;
|
DELETE FROM t1;
|
||||||
DROP TABLE t2, 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 t1 ADD FOREIGN KEY (f1) REFERENCES t2 (f2);
|
||||||
ALTER TABLE t2 ADD FOREIGN KEY (f2) REFERENCES t2 (f2),
|
ALTER TABLE t2 ADD FOREIGN KEY (f2) REFERENCES t2 (f2),
|
||||||
ADD UNIQUE INDEX(f3);
|
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;
|
drop table t1, t2;
|
||||||
# End of 10.11 tests
|
# End of 10.11 tests
|
||||||
|
@@ -22,7 +22,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`f2` int(11) NOT NULL,
|
`f2` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
disconnect con1;
|
disconnect con1;
|
||||||
connection default;
|
connection default;
|
||||||
|
@@ -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 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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# modify child column NOT NULL ON DELETE CASCADE..parent column NULL
|
# 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;
|
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 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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# modify child column NOT NULL ON DELETE SET NULL
|
# 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 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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# modify child column NOT NULL ON UPDATE RESTRICT..parent column NULL
|
# 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;
|
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)
|
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
||||||
ON UPDATE CASCADE)ENGINE=InnoDB;
|
ON UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE `t#1` MODIFY COLUMN f2 INT;
|
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`;
|
DROP TABLE `t#2`, `t#1`;
|
||||||
# modify parent column NULL ON DELETE CASCADE child column NOT NULL
|
# 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;
|
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
|
FOREIGN KEY(f1, f2) REFERENCES t1(f1, f2) ON
|
||||||
UPDATE CASCADE)ENGINE=InnoDB;
|
UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE t1 MODIFY COLUMN f1 INT;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# modify child column NOT NULL ON UPDATE CASCADE parent column NULL
|
# modify child column NOT NULL ON UPDATE CASCADE parent column NULL
|
||||||
CREATE TABLE t1(f1 INT, f2 INT, INDEX(f1, f2))ENGINE=InnoDB;
|
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
|
FOREIGN KEY(f1, f2) REFERENCES t1(f1, f2) ON
|
||||||
UPDATE CASCADE)ENGINE=InnoDB;
|
UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE t2 MODIFY COLUMN f2 INT NOT NULL;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# allow foreign key constraints when parent table created later
|
# allow foreign key constraints when parent table created later
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1);
|
INSERT INTO t2 VALUES(1);
|
||||||
UPDATE t1 SET f2= NULL;
|
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;
|
SELECT * FROM t2;
|
||||||
f1
|
f1
|
||||||
1
|
1
|
||||||
|
@@ -4,11 +4,11 @@
|
|||||||
CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB;
|
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;
|
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;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1);
|
INSERT INTO t2 VALUES(1);
|
||||||
UPDATE t1 SET f2= NULL;
|
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;
|
DELETE FROM t2;
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
f1 f2
|
f1 f2
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB;
|
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;
|
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;
|
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")
|
+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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 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 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;
|
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;
|
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")
|
+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;
|
DROP TABLE t2, t1;
|
||||||
# modify parent column NULL ON UPDATE CASCADE child column NOT NULL
|
# modify parent column NULL ON UPDATE CASCADE child column NOT NULL
|
||||||
@@ -39,12 +39,12 @@
|
|||||||
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
||||||
ON UPDATE CASCADE)ENGINE=InnoDB;
|
ON UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE `t#1` MODIFY COLUMN f2 INT;
|
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#1` VALUES(1, 1);
|
||||||
INSERT INTO `t#2` VALUES(1);
|
INSERT INTO `t#2` VALUES(1);
|
||||||
UPDATE `t#1` SET f2= NULL;
|
UPDATE `t#1` SET f2= NULL;
|
||||||
-ERROR 23000: Column 'f2' cannot be 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`;
|
DELETE FROM `t#2`;
|
||||||
SELECT * FROM `t#1`;
|
SELECT * FROM `t#1`;
|
||||||
f1 f2
|
f1 f2
|
||||||
|
@@ -4,11 +4,11 @@
|
|||||||
CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB;
|
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;
|
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;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1);
|
INSERT INTO t2 VALUES(1);
|
||||||
UPDATE t1 SET f2= NULL;
|
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;
|
DELETE FROM t2;
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
f1 f2
|
f1 f2
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB;
|
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;
|
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;
|
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")
|
+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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 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 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;
|
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;
|
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")
|
+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;
|
DROP TABLE t2, t1;
|
||||||
# modify parent column NULL ON UPDATE CASCADE child column NOT NULL
|
# modify parent column NULL ON UPDATE CASCADE child column NOT NULL
|
||||||
@@ -37,12 +37,12 @@
|
|||||||
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
||||||
ON UPDATE CASCADE)ENGINE=InnoDB;
|
ON UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE `t#1` MODIFY COLUMN f2 INT;
|
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#1` VALUES(1, 1);
|
||||||
INSERT INTO `t#2` VALUES(1);
|
INSERT INTO `t#2` VALUES(1);
|
||||||
UPDATE `t#1` SET f2= NULL;
|
UPDATE `t#1` SET f2= NULL;
|
||||||
-ERROR 23000: Column 'f2' cannot be 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`;
|
DELETE FROM `t#2`;
|
||||||
SELECT * FROM `t#1`;
|
SELECT * FROM `t#1`;
|
||||||
f1 f2
|
f1 f2
|
||||||
|
@@ -4,11 +4,11 @@
|
|||||||
CREATE TABLE t1(f1 INT, f2 INT, PRIMARY KEY(f1), KEY(f2))ENGINE=InnoDB;
|
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;
|
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;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1);
|
INSERT INTO t2 VALUES(1);
|
||||||
UPDATE t1 SET f2= NULL;
|
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;
|
DELETE FROM t2;
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
f1 f2
|
f1 f2
|
||||||
@@ -21,12 +21,12 @@
|
|||||||
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
||||||
ON UPDATE CASCADE)ENGINE=InnoDB;
|
ON UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE `t#1` MODIFY COLUMN f2 INT;
|
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#1` VALUES(1, 1);
|
||||||
INSERT INTO `t#2` VALUES(1);
|
INSERT INTO `t#2` VALUES(1);
|
||||||
UPDATE `t#1` SET f2= NULL;
|
UPDATE `t#1` SET f2= NULL;
|
||||||
-ERROR 23000: Column 'f2' cannot be 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`;
|
DELETE FROM `t#2`;
|
||||||
SELECT * FROM `t#1`;
|
SELECT * FROM `t#1`;
|
||||||
f1 f2
|
f1 f2
|
||||||
|
@@ -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 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;
|
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;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1);
|
INSERT INTO t2 VALUES(1);
|
||||||
UPDATE t1 SET f2= NULL;
|
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 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;
|
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;
|
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 t1 VALUES(1, 1);
|
||||||
INSERT INTO t2 VALUES(1, 1);
|
INSERT INTO t2 VALUES(1, 1);
|
||||||
UPDATE t1 SET f1= 2;
|
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 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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# modify parent column NULL ON UPDATE CASCADE child column NOT NULL
|
# 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;
|
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)
|
FOREIGN KEY(f1) REFERENCES `t#1`(f2)
|
||||||
ON UPDATE CASCADE)ENGINE=InnoDB;
|
ON UPDATE CASCADE)ENGINE=InnoDB;
|
||||||
ALTER TABLE `t#1` MODIFY COLUMN f2 INT;
|
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#1` VALUES(1, 1);
|
||||||
INSERT INTO `t#2` VALUES(1);
|
INSERT INTO `t#2` VALUES(1);
|
||||||
UPDATE `t#1` SET f2= NULL;
|
UPDATE `t#1` SET f2= NULL;
|
||||||
|
@@ -132,7 +132,7 @@ child CREATE TABLE `child` (
|
|||||||
`c` int(11) NOT NULL,
|
`c` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
KEY `c` (`c`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
DROP TABLE child, parent;
|
DROP TABLE child, parent;
|
||||||
CREATE TABLE IF NOT EXISTS ticket (
|
CREATE TABLE IF NOT EXISTS ticket (
|
||||||
|
@@ -20,8 +20,8 @@ WHERE FOR_NAME LIKE 'test/t%';
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SHOW CREATE TABLE t1;
|
SHOW CREATE TABLE t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
@@ -73,8 +73,8 @@ c2 0 c2
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
|
ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
|
||||||
ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
|
ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE C2 c3 INT;
|
ALTER TABLE t1 CHANGE C2 c3 INT;
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
@@ -110,8 +110,8 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE c3 C INT;
|
ALTER TABLE t1 CHANGE c3 C INT;
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
@@ -128,14 +128,14 @@ c2 0 C
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 C 0
|
t1c2 c2 C 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
|
ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
|
||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 Cöŀumň_TWO 0
|
t1c2 c2 Cöŀumň_TWO 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 Cöŀumň_TWO 0
|
t1c2 c2 Cöŀumň_TWO 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
|
ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
|
||||||
ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1'
|
ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1'
|
||||||
ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 DROP INDEX c2;
|
ALTER TABLE t1 DROP INDEX c2;
|
||||||
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint
|
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint
|
||||||
ALTER TABLE t1 DROP INDEX c4;
|
ALTER TABLE t1 DROP INDEX c4;
|
||||||
@@ -308,8 +308,8 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE=InnoDB;
|
CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2)) ENGINE=InnoDB;
|
||||||
ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3;
|
ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3;
|
||||||
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1c DROP FOREIGN KEY t1C3;
|
ALTER TABLE t1c DROP FOREIGN KEY t1C3;
|
||||||
SHOW CREATE TABLE t1c;
|
SHOW CREATE TABLE t1c;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
@@ -372,7 +372,7 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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;
|
ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2;
|
||||||
SHOW CREATE TABLE t1c;
|
SHOW CREATE TABLE t1c;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
@@ -726,7 +726,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`c2` int(11) NOT NULL,
|
`c2` int(11) NOT NULL,
|
||||||
KEY `c2` (`c2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
ALTER TABLE t1 CHANGE COLUMN c1 C1 INT;
|
ALTER TABLE t1 CHANGE COLUMN c1 C1 INT;
|
||||||
ALTER TABLE t2 CHANGE COLUMN c2 C2 INT;
|
ALTER TABLE t2 CHANGE COLUMN c2 C2 INT;
|
||||||
@@ -741,7 +741,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`C2` int(11) DEFAULT NULL,
|
`C2` int(11) DEFAULT NULL,
|
||||||
KEY `c2` (`C2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
|
ALTER TABLE t1 CHANGE COLUMN C1 c5 INT;
|
||||||
ALTER TABLE t2 CHANGE COLUMN C2 c6 INT;
|
ALTER TABLE t2 CHANGE COLUMN C2 c6 INT;
|
||||||
@@ -756,7 +756,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`c6` int(11) DEFAULT NULL,
|
`c6` int(11) DEFAULT NULL,
|
||||||
KEY `c2` (`c6`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
SELECT C.NAME FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS C INNER JOIN
|
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
|
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 `bb` (`BB`),
|
||||||
KEY `CC` (`CC`),
|
KEY `CC` (`CC`),
|
||||||
KEY `DD` (`DD`),
|
KEY `DD` (`DD`),
|
||||||
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`),
|
CONSTRAINT `1` FOREIGN KEY (`AA`) REFERENCES `t1` (`A`),
|
||||||
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`BB`) REFERENCES `t1` (`B`),
|
CONSTRAINT `2` FOREIGN KEY (`BB`) REFERENCES `t1` (`B`),
|
||||||
CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`CC`) REFERENCES `t1` (`C`),
|
CONSTRAINT `3` FOREIGN KEY (`CC`) REFERENCES `t1` (`C`),
|
||||||
CONSTRAINT `t2_ibfk_4` FOREIGN KEY (`DD`) REFERENCES `t1` (`D`)
|
CONSTRAINT `4` FOREIGN KEY (`DD`) REFERENCES `t1` (`D`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
DELETE FROM t1 WHERE a=1;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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;
|
DROP TABLE t2, t1;
|
||||||
# virtual columns case too
|
# virtual columns case too
|
||||||
CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
|
CREATE TABLE t1 (a INT, b INT GENERATED ALWAYS AS (a) VIRTUAL) ENGINE = InnoDB;
|
||||||
|
@@ -13,13 +13,9 @@ c int not null,
|
|||||||
CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id),
|
CONSTRAINT mytest FOREIGN KEY (c) REFERENCES t1(id),
|
||||||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id)
|
CONSTRAINT test FOREIGN KEY (b) REFERENCES t2 (id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
|
|
||||||
show warnings;
|
show warnings;
|
||||||
Level Code Message
|
Level Code Message
|
||||||
Warning 121 CREATE or ALTER TABLE `test`.`t2` failed: duplicate name, CONSTRAINT `test` FOREIGN KEY (`b`) REFERENCES `t2` (`id`)
|
drop table t2,t1;
|
||||||
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;
|
|
||||||
create table t1(a int) engine=innodb;
|
create table t1(a int) engine=innodb;
|
||||||
create table t2(a int, constraint a foreign key a (a) references t1(a)) 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")
|
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
|
||||||
|
@@ -135,7 +135,7 @@ Table Create Table
|
|||||||
PRIMARY KEY (`id_depart`,`id_depart_in`),
|
PRIMARY KEY (`id_depart`,`id_depart_in`),
|
||||||
KEY `id_depart_in` (`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_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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci
|
||||||
DROP TABLE `#departaments_tree`;
|
DROP TABLE `#departaments_tree`;
|
||||||
DROP TABLE `#departaments`;
|
DROP TABLE `#departaments`;
|
||||||
@@ -145,11 +145,11 @@ CREATE TABLE `boroda` (
|
|||||||
`b` INT(11) UNSIGNED DEFAULT NULL,
|
`b` INT(11) UNSIGNED DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
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;
|
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
||||||
ALTER TABLE `boroda`
|
ALTER TABLE `boroda`
|
||||||
ADD FOREIGN KEY (`b`) REFERENCES `boroda`(`id`);
|
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`;
|
RENAME TABLE `boroda` TO `#boroda`;
|
||||||
ALTER TABLE `#boroda`
|
ALTER TABLE `#boroda`
|
||||||
ADD FOREIGN KEY (`b`) REFERENCES `#boroda`(`id`);
|
ADD FOREIGN KEY (`b`) REFERENCES `#boroda`(`id`);
|
||||||
@@ -162,8 +162,8 @@ Table Create Table
|
|||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
KEY `a` (`a`),
|
||||||
KEY `b` (`b`),
|
KEY `b` (`b`),
|
||||||
CONSTRAINT `#boroda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `#boroda` (`id`),
|
CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `#boroda` (`id`),
|
||||||
CONSTRAINT `#boroda_ibfk_2` FOREIGN KEY (`b`) REFERENCES `#boroda` (`id`)
|
CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `#boroda` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci
|
||||||
DROP TABLE `#boroda`;
|
DROP TABLE `#boroda`;
|
||||||
CREATE TABLE `boroda` (
|
CREATE TABLE `boroda` (
|
||||||
@@ -172,7 +172,7 @@ CREATE TABLE `boroda` (
|
|||||||
`b` INT(11) UNSIGNED DEFAULT NULL,
|
`b` INT(11) UNSIGNED DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
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;
|
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
||||||
RENAME TABLE `boroda` TO `bor#oda`;
|
RENAME TABLE `boroda` TO `bor#oda`;
|
||||||
ALTER TABLE `bor#oda`
|
ALTER TABLE `bor#oda`
|
||||||
@@ -186,8 +186,8 @@ bor#oda CREATE TABLE `bor#oda` (
|
|||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
KEY `a` (`a`),
|
||||||
KEY `b` (`b`),
|
KEY `b` (`b`),
|
||||||
CONSTRAINT `bor#oda_ibfk_1` FOREIGN KEY (`a`) REFERENCES `bor#oda` (`id`),
|
CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `bor#oda` (`id`),
|
||||||
CONSTRAINT `bor#oda_ibfk_2` FOREIGN KEY (`b`) REFERENCES `bor#oda` (`id`)
|
CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `bor#oda` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_uca1400_ai_ci
|
||||||
DROP TABLE `bor#oda`;
|
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;
|
ALTER TABLE t1 RENAME TO tm1, ALGORITHM=COPY;
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
CREATE TABLE t1 (c1 BIGINT NOT NULL, c2 BIGINT NOT NULL, PRIMARY KEY(c1), UNIQUE KEY(c2)) ENGINE=MEMORY;
|
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;
|
ALTER TABLE t1 ENGINE=InnoDB, ALGORITHM=COPY;
|
||||||
|
@@ -14,14 +14,14 @@ REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
|
|||||||
ALGORITHM = INPLACE;
|
ALGORITHM = INPLACE;
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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)
|
ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2)
|
||||||
REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
|
REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
ALGORITHM = INPLACE;
|
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;
|
SET foreign_key_checks = 1;
|
||||||
INSERT INTO child VALUES(1,2),(2,3);
|
INSERT INTO child VALUES(1,2),(2,3);
|
||||||
INSERT INTO child VALUES(4,4);
|
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;
|
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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
|
||||||
test/fk_10 test/child test/parent 2 5
|
fk_10 test/child test/parent 2 5
|
||||||
test/fk_2 test/child test/parent 2 5
|
fk_2 test/child test/parent 2 5
|
||||||
test/fk_3 test/child test/parent 2 5
|
fk_3 test/child test/parent 2 5
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_1 a2 b 0
|
fk_1 a2 b 0
|
||||||
test/fk_10 a1 a 0
|
fk_10 a1 a 0
|
||||||
test/fk_10 a2 b 1
|
fk_10 a2 b 1
|
||||||
test/fk_2 a1 a 0
|
fk_2 a1 a 0
|
||||||
test/fk_2 a2 b 1
|
fk_2 a2 b 1
|
||||||
test/fk_3 a1 a 0
|
fk_3 a1 a 0
|
||||||
test/fk_3 a2 b 1
|
fk_3 a2 b 1
|
||||||
SET foreign_key_checks = 1;
|
SET foreign_key_checks = 1;
|
||||||
INSERT INTO child VALUES(5,4);
|
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)
|
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;
|
SET DEBUG_DBUG = @saved_debug_dbug;
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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
|
||||||
test/fk_10 test/child test/parent 2 5
|
fk_10 test/child test/parent 2 5
|
||||||
test/fk_2 test/child test/parent 2 5
|
fk_2 test/child test/parent 2 5
|
||||||
test/fk_3 test/child test/parent 2 5
|
fk_3 test/child test/parent 2 5
|
||||||
test/fk_4 test/child test/parent 2 5
|
fk_4 test/child test/parent 2 5
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_1 a2 b 0
|
fk_1 a2 b 0
|
||||||
test/fk_10 a1 a 0
|
fk_10 a1 a 0
|
||||||
test/fk_10 a2 b 1
|
fk_10 a2 b 1
|
||||||
test/fk_2 a1 a 0
|
fk_2 a1 a 0
|
||||||
test/fk_2 a2 b 1
|
fk_2 a2 b 1
|
||||||
test/fk_3 a1 a 0
|
fk_3 a1 a 0
|
||||||
test/fk_3 a2 b 1
|
fk_3 a2 b 1
|
||||||
test/fk_4 a1 a 0
|
fk_4 a1 a 0
|
||||||
test/fk_4 a2 b 1
|
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;
|
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
|
name name
|
||||||
test/child a1
|
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'
|
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;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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
|
||||||
test/fk_10 test/child test/parent 2 5
|
fk_10 test/child test/parent 2 5
|
||||||
test/fk_2 test/child test/parent 2 5
|
fk_2 test/child test/parent 2 5
|
||||||
test/fk_3 test/child test/parent 2 5
|
fk_3 test/child test/parent 2 5
|
||||||
test/fk_4 test/child test/parent 2 5
|
fk_4 test/child test/parent 2 5
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_1 a2 b 0
|
fk_1 a2 b 0
|
||||||
test/fk_10 a1 a 0
|
fk_10 a1 a 0
|
||||||
test/fk_10 a2 b 1
|
fk_10 a2 b 1
|
||||||
test/fk_2 a1 a 0
|
fk_2 a1 a 0
|
||||||
test/fk_2 a2 b 1
|
fk_2 a2 b 1
|
||||||
test/fk_3 a1 a 0
|
fk_3 a1 a 0
|
||||||
test/fk_3 a2 b 1
|
fk_3 a2 b 1
|
||||||
test/fk_4 a1 a 0
|
fk_4 a1 a 0
|
||||||
test/fk_4 a2 b 1
|
fk_4 a2 b 1
|
||||||
SET DEBUG_DBUG = '+d,innodb_test_no_reference_idx';
|
SET DEBUG_DBUG = '+d,innodb_test_no_reference_idx';
|
||||||
ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2)
|
ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2)
|
||||||
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
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)
|
ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2)
|
||||||
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
ALGORITHM = INPLACE;
|
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;
|
SET DEBUG_DBUG = @saved_debug_dbug;
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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
|
||||||
test/fk_10 test/child test/parent 2 5
|
fk_10 test/child test/parent 2 5
|
||||||
test/fk_2 test/child test/parent 2 5
|
fk_2 test/child test/parent 2 5
|
||||||
test/fk_3 test/child test/parent 2 5
|
fk_3 test/child test/parent 2 5
|
||||||
test/fk_4 test/child test/parent 2 5
|
fk_4 test/child test/parent 2 5
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_1 a2 b 0
|
fk_1 a2 b 0
|
||||||
test/fk_10 a1 a 0
|
fk_10 a1 a 0
|
||||||
test/fk_10 a2 b 1
|
fk_10 a2 b 1
|
||||||
test/fk_2 a1 a 0
|
fk_2 a1 a 0
|
||||||
test/fk_2 a2 b 1
|
fk_2 a2 b 1
|
||||||
test/fk_3 a1 a 0
|
fk_3 a1 a 0
|
||||||
test/fk_3 a2 b 1
|
fk_3 a2 b 1
|
||||||
test/fk_4 a1 a 0
|
fk_4 a1 a 0
|
||||||
test/fk_4 a2 b 1
|
fk_4 a2 b 1
|
||||||
SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system';
|
SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system';
|
||||||
ALTER TABLE `#child` ADD CONSTRAINT fk_43 FOREIGN KEY (a1, a2)
|
ALTER TABLE `#child` ADD CONSTRAINT fk_43 FOREIGN KEY (a1, a2)
|
||||||
REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
ALGORITHM = INPLACE;
|
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;
|
SET DEBUG_DBUG = @saved_debug_dbug;
|
||||||
SHOW ERRORS;
|
SHOW ERRORS;
|
||||||
Level Code Message
|
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 `#child`;
|
||||||
DROP TABLE `#parent`;
|
DROP TABLE `#parent`;
|
||||||
SET foreign_key_checks = 0;
|
SET foreign_key_checks = 0;
|
||||||
@@ -216,27 +216,27 @@ REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE,
|
|||||||
ALGORITHM = INPLACE;
|
ALGORITHM = INPLACE;
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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
|
||||||
test/fk_10 test/child test/parent 2 5
|
fk_10 test/child test/parent 2 5
|
||||||
test/fk_2 test/child test/parent 2 5
|
fk_2 test/child test/parent 2 5
|
||||||
test/fk_3 test/child test/parent 2 5
|
fk_3 test/child test/parent 2 5
|
||||||
test/fk_4 test/child test/parent 2 5
|
fk_4 test/child test/parent 2 5
|
||||||
test/fk_5 test/child test/parent 1 6
|
fk_5 test/child test/parent 1 6
|
||||||
test/fk_6 test/child test/parent 2 5
|
fk_6 test/child test/parent 2 5
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_1 a2 b 0
|
fk_1 a2 b 0
|
||||||
test/fk_10 a1 a 0
|
fk_10 a1 a 0
|
||||||
test/fk_10 a2 b 1
|
fk_10 a2 b 1
|
||||||
test/fk_2 a1 a 0
|
fk_2 a1 a 0
|
||||||
test/fk_2 a2 b 1
|
fk_2 a2 b 1
|
||||||
test/fk_3 a1 a 0
|
fk_3 a1 a 0
|
||||||
test/fk_3 a2 b 1
|
fk_3 a2 b 1
|
||||||
test/fk_4 a1 a 0
|
fk_4 a1 a 0
|
||||||
test/fk_4 a2 b 1
|
fk_4 a2 b 1
|
||||||
test/fk_5 a2 b 0
|
fk_5 a2 b 0
|
||||||
test/fk_6 a1 a 0
|
fk_6 a1 a 0
|
||||||
test/fk_6 a2 b 1
|
fk_6 a2 b 1
|
||||||
DROP TABLE child;
|
DROP TABLE child;
|
||||||
DROP TABLE parent;
|
DROP TABLE parent;
|
||||||
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB;
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_4 a2 b 0
|
fk_4 a2 b 0
|
||||||
SET foreign_key_checks = 1;
|
SET foreign_key_checks = 1;
|
||||||
DROP TABLE child;
|
DROP TABLE child;
|
||||||
DROP TABLE parent;
|
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)
|
ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b)
|
||||||
ON DELETE SET NULL ON UPDATE CASCADE,
|
ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
ALGORITHM = INPLACE;
|
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;
|
SET DEBUG_DBUG = @saved_debug_dbug;
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
@@ -326,10 +326,10 @@ Warnings:
|
|||||||
Warning 1280 Name 'idx' ignored for PRIMARY key.
|
Warning 1280 Name 'idx' ignored for PRIMARY key.
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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;
|
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
|
name name
|
||||||
test/child a2
|
test/child a2
|
||||||
@@ -363,10 +363,10 @@ Warnings:
|
|||||||
Warning 1280 Name 'idx' ignored for PRIMARY key.
|
Warning 1280 Name 'idx' ignored for PRIMARY key.
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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;
|
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
|
name name
|
||||||
test/child a1
|
test/child a1
|
||||||
@@ -398,10 +398,10 @@ ON DELETE SET NULL ON UPDATE CASCADE,
|
|||||||
ALGORITHM = INPLACE;
|
ALGORITHM = INPLACE;
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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;
|
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
|
name name
|
||||||
test/child a2
|
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)
|
ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b)
|
||||||
ON DELETE SET NULL ON UPDATE CASCADE,
|
ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
ALGORITHM = INPLACE;
|
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 parent;
|
||||||
DROP TABLE child;
|
DROP TABLE child;
|
||||||
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL, c INT) ENGINE = InnoDB;
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
test/fk_a test/child test/parent 1 6
|
fk_a test/child test/parent 1 6
|
||||||
test/fk_b test/child test/parent 1 0
|
fk_b test/child test/parent 1 0
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_a a2_new b 0
|
fk_a a2_new b 0
|
||||||
test/fk_b a1_new a 0
|
fk_b a1_new a 0
|
||||||
ALTER TABLE child
|
ALTER TABLE child
|
||||||
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
|
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
|
||||||
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
test/fk_a test/child test/parent 1 6
|
fk_a test/child test/parent 1 6
|
||||||
test/fk_b test/child test/parent 1 0
|
fk_b test/child test/parent 1 0
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_a a2_new b 0
|
fk_a a2_new b 0
|
||||||
test/fk_b a1_new a 0
|
fk_b a1_new a 0
|
||||||
ALTER TABLE child
|
ALTER TABLE child
|
||||||
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
|
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b),
|
||||||
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
test/fk_a test/child test/parent 1 6
|
fk_a test/child test/parent 1 6
|
||||||
test/fk_b test/child test/parent 1 0
|
fk_b test/child test/parent 1 0
|
||||||
test/fk_new_1 test/child test/parent 1 0
|
fk_new_1 test/child test/parent 1 0
|
||||||
test/fk_new_2 test/child test/parent 1 0
|
fk_new_2 test/child test/parent 1 0
|
||||||
test/fk_new_3 test/child test/parent 1 0
|
fk_new_3 test/child test/parent 1 0
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_a a2_new b 0
|
fk_a a2_new b 0
|
||||||
test/fk_b a1_new a 0
|
fk_b a1_new a 0
|
||||||
test/fk_new_1 a1_new b 0
|
fk_new_1 a1_new b 0
|
||||||
test/fk_new_2 a2_new a 0
|
fk_new_2 a2_new a 0
|
||||||
test/fk_new_3 a3 a 0
|
fk_new_3 a3 a 0
|
||||||
DROP TABLE child;
|
DROP TABLE child;
|
||||||
CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB;
|
CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB;
|
||||||
CREATE INDEX tb ON child(a2);
|
CREATE INDEX tb ON child(a2);
|
||||||
@@ -567,14 +567,14 @@ child CREATE TABLE `child` (
|
|||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
test/fk_new_1 test/child test/parent 1 0
|
fk_new_1 test/child test/parent 1 0
|
||||||
test/fk_new_2 test/child test/parent 1 0
|
fk_new_2 test/child test/parent 1 0
|
||||||
test/fk_new_3 test/child test/parent 1 0
|
fk_new_3 test/child test/parent 1 0
|
||||||
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/fk_new_1 a1 b 0
|
fk_new_1 a1 b 0
|
||||||
test/fk_new_2 a2 a 0
|
fk_new_2 a2 a 0
|
||||||
test/fk_new_3 a3 a 0
|
fk_new_3 a3 a 0
|
||||||
SET foreign_key_checks = 1;
|
SET foreign_key_checks = 1;
|
||||||
DROP TABLE child;
|
DROP TABLE child;
|
||||||
DROP TABLE parent;
|
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 `fw` FOREIGN KEY (`c`) REFERENCES t3 (a);
|
||||||
ALTER TABLE `t2` ADD CONSTRAINT `e` foreign key (`d`) 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;
|
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;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
ID FOR_NAME REF_NAME N_COLS TYPE
|
||||||
test/e test/t2 test/t3 1 0
|
e test/t2 test/t3 1 0
|
||||||
test/fw 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;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/e d a 0
|
e d a 0
|
||||||
test/fw c a 0
|
fw c a 0
|
||||||
|
e c c 0
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
DROP TABLE t3;
|
DROP TABLE t3;
|
||||||
# Bug #17449901 TABLE DISAPPEARS WHEN ALTERING
|
# Bug #17449901 TABLE DISAPPEARS WHEN ALTERING
|
||||||
@@ -625,7 +626,7 @@ Table Create Table
|
|||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
`f3` 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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop table t2;
|
drop table t2;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
@@ -640,7 +641,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
`f3` int(11) DEFAULT NULL,
|
`f3` int(11) DEFAULT NULL,
|
||||||
KEY `t1` (`f2`,`f3`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop table t2;
|
drop table t2;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
@@ -655,7 +656,7 @@ Table Create Table
|
|||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`f1` int(11) DEFAULT NULL,
|
`f1` int(11) DEFAULT NULL,
|
||||||
KEY `f1` (`f1`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
CREATE TABLE t1(f1 INT, KEY(f1),
|
CREATE TABLE t1(f1 INT, KEY(f1),
|
||||||
@@ -665,13 +666,13 @@ Table Create Table
|
|||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`f1` int(11) DEFAULT NULL,
|
`f1` int(11) DEFAULT NULL,
|
||||||
KEY `f1` (`f1`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
ALTER TABLE t1 DROP KEY f1;
|
ALTER TABLE t1 DROP KEY f1;
|
||||||
SHOW CREATE TABLE t1;
|
SHOW CREATE TABLE t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`f1` int(11) DEFAULT NULL,
|
`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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
@@ -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;
|
alter table t2 drop index b, drop index c, drop index d;
|
||||||
ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
|
ERROR HY000: Cannot drop index 'b': needed in a foreign key constraint
|
||||||
alter table t2 MODIFY b INT NOT NULL, ALGORITHM=COPY;
|
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 @old_sql_mode = @@sql_mode;
|
||||||
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
||||||
alter table t2 MODIFY b INT NOT NULL, ALGORITHM=INPLACE;
|
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 @@sql_mode = @old_sql_mode;
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
alter table t2 DROP COLUMN b, ALGORITHM=COPY;
|
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;
|
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;
|
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;
|
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;
|
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||||
create unique index dc on t2 (d,c);
|
create unique index dc on t2 (d,c);
|
||||||
affected rows: 0
|
affected rows: 0
|
||||||
@@ -481,10 +481,10 @@ info: Records: 0 Duplicates: 0 Warnings: 0
|
|||||||
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
||||||
alter table t2 add primary key (alpha), change a alpha int,
|
alter table t2 add primary key (alpha), change a alpha int,
|
||||||
change b beta int not null, change c charlie int not null;
|
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,
|
alter table t2 add primary key (alpha), change a alpha int,
|
||||||
change c charlie int not null, change d delta int not null;
|
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,
|
alter table t2 add primary key (alpha), change a alpha int,
|
||||||
change b beta int, modify c int not null;
|
change b beta int, modify c int not null;
|
||||||
affected rows: 0
|
affected rows: 0
|
||||||
@@ -509,11 +509,8 @@ t4 CREATE TABLE `t4` (
|
|||||||
CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
alter table t3 add constraint dc foreign key (a) references t1(a);
|
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")
|
alter table t3 drop foreign key dc;
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
|
||||||
alter table t3 add constraint dc foreign key (a) references t1(a);
|
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;
|
show create table t3;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t3 CREATE TABLE `t3` (
|
t3 CREATE TABLE `t3` (
|
||||||
@@ -521,7 +518,8 @@ t3 CREATE TABLE `t3` (
|
|||||||
`c` int(11) NOT NULL,
|
`c` int(11) NOT NULL,
|
||||||
`d` int(11) DEFAULT NULL,
|
`d` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`a`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
alter table t2 drop index b, add index (beta);
|
alter table t2 drop index b, add index (beta);
|
||||||
affected rows: 0
|
affected rows: 0
|
||||||
@@ -538,16 +536,17 @@ t2 CREATE TABLE `t2` (
|
|||||||
UNIQUE KEY `dc` (`d`,`c`),
|
UNIQUE KEY `dc` (`d`,`c`),
|
||||||
KEY `c` (`c`),
|
KEY `c` (`c`),
|
||||||
KEY `beta` (`beta`),
|
KEY `beta` (`beta`),
|
||||||
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`beta`) REFERENCES `t1` (`b`) ON DELETE SET NULL,
|
CONSTRAINT `1` FOREIGN KEY (`beta`) REFERENCES `t1` (`b`) ON DELETE SET NULL,
|
||||||
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`),
|
CONSTRAINT `2` FOREIGN KEY (`c`) REFERENCES `t3` (`c`),
|
||||||
CONSTRAINT `t2_ibfk_3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`) ON UPDATE SET NULL
|
CONSTRAINT `3` FOREIGN KEY (`d`) REFERENCES `t4` (`d`) ON UPDATE SET NULL
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
delete from t1;
|
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;
|
drop index dc on t4;
|
||||||
ERROR 42000: Can't DROP INDEX `dc`; check that it exists
|
ERROR 42000: Can't DROP INDEX `dc`; check that it exists
|
||||||
alter table t3 drop foreign key dc;
|
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;
|
alter table t4 drop foreign key dc;
|
||||||
affected rows: 0
|
affected rows: 0
|
||||||
info: Records: 0 Duplicates: 0 Warnings: 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'
|
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
|
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
|
||||||
FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=INPLACE;
|
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
|
ALTER TABLE t2 ADD CONSTRAINT fk_t2_ca
|
||||||
FOREIGN KEY (c3,c2) REFERENCES t1(c2,c1), ALGORITHM=COPY;
|
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")
|
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
|
||||||
|
@@ -98,10 +98,10 @@ FOREIGN KEY (parent_id) REFERENCES parent(id)
|
|||||||
ON DELETE CASCADE) ENGINE=INNODB;
|
ON DELETE CASCADE) ENGINE=INNODB;
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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);
|
INSERT INTO parent VALUES(1);
|
||||||
InnoDB 0 transactions not purged
|
InnoDB 0 transactions not purged
|
||||||
SELECT name, num_rows, ref_count
|
SELECT name, num_rows, ref_count
|
||||||
@@ -154,11 +154,11 @@ FOREIGN KEY (id, parent_id) REFERENCES parent(id, newid)
|
|||||||
ON DELETE CASCADE) ENGINE=INNODB;
|
ON DELETE CASCADE) ENGINE=INNODB;
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE
|
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;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/constraint_test id id 0
|
constraint_test id id 0
|
||||||
test/constraint_test parent_id newid 1
|
constraint_test parent_id newid 1
|
||||||
INSERT INTO parent VALUES(1, 9);
|
INSERT INTO parent VALUES(1, 9);
|
||||||
SELECT * FROM parent WHERE id IN (SELECT id FROM parent);
|
SELECT * FROM parent WHERE id IN (SELECT id FROM parent);
|
||||||
id newid
|
id newid
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB;
|
CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB;
|
||||||
CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
|
CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB;
|
||||||
TRUNCATE TABLE t1;
|
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.
|
# Truncation of child should succeed.
|
||||||
TRUNCATE TABLE t2;
|
TRUNCATE TABLE t2;
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
@@ -32,7 +32,7 @@ TRUNCATE TABLE t2;
|
|||||||
TRUNCATE TABLE t3;
|
TRUNCATE TABLE t3;
|
||||||
SET @@SESSION.foreign_key_checks = 1;
|
SET @@SESSION.foreign_key_checks = 1;
|
||||||
TRUNCATE TABLE t1;
|
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 t2;
|
||||||
TRUNCATE TABLE t3;
|
TRUNCATE TABLE t3;
|
||||||
LOCK TABLES t1 WRITE;
|
LOCK TABLES t1 WRITE;
|
||||||
@@ -40,7 +40,7 @@ SET @@SESSION.foreign_key_checks = 0;
|
|||||||
TRUNCATE TABLE t1;
|
TRUNCATE TABLE t1;
|
||||||
SET @@SESSION.foreign_key_checks = 1;
|
SET @@SESSION.foreign_key_checks = 1;
|
||||||
TRUNCATE TABLE t1;
|
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;
|
UNLOCK TABLES;
|
||||||
DROP TABLE t3,t2,t1;
|
DROP TABLE t3,t2,t1;
|
||||||
SET @@SESSION.foreign_key_checks = @old_foreign_key_checks;
|
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 t1 RENAME TO t3;
|
||||||
ALTER TABLE t3 FORCE;
|
ALTER TABLE t3 FORCE;
|
||||||
TRUNCATE TABLE t3;
|
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;
|
DROP TABLE t2, t3;
|
||||||
#
|
#
|
||||||
# MDEV-24861 Assertion `trx->rsegs.m_redo.rseg' failed
|
# MDEV-24861 Assertion `trx->rsegs.m_redo.rseg' failed
|
||||||
|
@@ -279,7 +279,7 @@ col_1_int col_2_varchar
|
|||||||
2 a2
|
2 a2
|
||||||
3 a3
|
3 a3
|
||||||
INSERT INTO testdb_wl5522.t1_fk VALUES (100,'a100');
|
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;
|
SET AUTOCOMMIT = 0;
|
||||||
INSERT INTO testdb_wl5522.t1_fk VALUES (4,'a4'),(5,'a5');
|
INSERT INTO testdb_wl5522.t1_fk VALUES (4,'a4'),(5,'a5');
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
@@ -25,8 +25,8 @@ WHERE FOR_NAME LIKE 'test/t%';
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SHOW CREATE TABLE t1;
|
SHOW CREATE TABLE t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
@@ -95,8 +95,8 @@ c2 0 c2
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
|
ALTER TABLE t1 CHANGE c2 c2 INT AFTER c1;
|
||||||
ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
|
ALTER TABLE t1 CHANGE c1 c1 INT FIRST;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
@@ -131,8 +131,8 @@ c2 0 c2
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c2 0
|
t1c2 c2 c2 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE C2 c3 INT;
|
ALTER TABLE t1 CHANGE C2 c3 INT;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
db.opt
|
db.opt
|
||||||
@@ -166,8 +166,8 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE c3 C INT;
|
ALTER TABLE t1 CHANGE c3 C INT;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
db.opt
|
db.opt
|
||||||
@@ -201,8 +201,8 @@ c2 0 C
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 C 0
|
t1c2 c2 C 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
|
ALTER TABLE t1 CHANGE C Cöŀumň_TWO INT;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
db.opt
|
db.opt
|
||||||
@@ -224,8 +224,8 @@ t1c.ibd
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 Cöŀumň_TWO 0
|
t1c2 c2 Cöŀumň_TWO 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
SELECT i.NAME,i.POS,i.MTYPE,i.PRTYPE,i.LEN
|
||||||
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS i
|
||||||
INNER JOIN sys_tables st ON i.TABLE_ID=st.TABLE_ID;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 Cöŀumň_TWO 0
|
t1c2 c2 Cöŀumň_TWO 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
|
ALTER TABLE t1 CHANGE cöĿǖmň_two c3 INT;
|
||||||
ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1'
|
ERROR 42S22: Unknown column 'cöĿǖmň_two' in 't1'
|
||||||
ALTER TABLE t1 CHANGE cÖĿUMŇ_two c3 INT, RENAME TO t3;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1 DROP INDEX c2;
|
ALTER TABLE t1 DROP INDEX c2;
|
||||||
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint
|
ERROR HY000: Cannot drop index 'c2': needed in a foreign key constraint
|
||||||
ALTER TABLE t1 DROP INDEX c4;
|
ALTER TABLE t1 DROP INDEX c4;
|
||||||
@@ -515,8 +515,8 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2))
|
CREATE TABLE t1p (c1 INT PRIMARY KEY, c2 INT, INDEX(c2))
|
||||||
ENGINE=InnoDB DATA DIRECTORY='MYSQL_TMP_DIR/alt_dir';
|
ENGINE=InnoDB DATA DIRECTORY='MYSQL_TMP_DIR/alt_dir';
|
||||||
ALTER TABLE t1c DROP INDEX C2, DROP INDEX C3;
|
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
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
ID FOR_COL_NAME REF_COL_NAME POS
|
||||||
test/t1c2 c2 c3 0
|
t1c2 c2 c3 0
|
||||||
test/t1c3 c3 c2 0
|
t1c3 c3 c2 0
|
||||||
ALTER TABLE t1c DROP FOREIGN KEY t1C3;
|
ALTER TABLE t1c DROP FOREIGN KEY t1C3;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
db.opt
|
db.opt
|
||||||
@@ -616,7 +616,7 @@ c2 0 c3
|
|||||||
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
SELECT i.* FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS i
|
||||||
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
INNER JOIN sys_foreign sf ON i.ID = sf.ID;
|
||||||
ID FOR_COL_NAME REF_COL_NAME POS
|
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;
|
ALTER TABLE t1c DROP INDEX c2, DROP FOREIGN KEY t1C2;
|
||||||
### files in MYSQL_DATA_DIR/test
|
### files in MYSQL_DATA_DIR/test
|
||||||
db.opt
|
db.opt
|
||||||
|
@@ -1580,7 +1580,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
UNIQUE KEY `b_2` (`b`),
|
UNIQUE KEY `b_2` (`b`),
|
||||||
KEY `b` (`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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
drop table t2;
|
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;
|
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,
|
`b` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`a`),
|
PRIMARY KEY (`a`),
|
||||||
UNIQUE KEY `b` (`b`),
|
UNIQUE KEY `b` (`b`),
|
||||||
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
|
CONSTRAINT `1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`),
|
||||||
CONSTRAINT `t2_ibfk_2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
|
CONSTRAINT `2` FOREIGN KEY (`b`) REFERENCES `t1` (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
drop table t2, t1;
|
drop table t2, t1;
|
||||||
create table t1 (c char(10), index (c,c)) engine=innodb;
|
create table t1 (c char(10), index (c,c)) engine=innodb;
|
||||||
@@ -2413,7 +2413,7 @@ SELECT * FROM t1;
|
|||||||
id
|
id
|
||||||
1
|
1
|
||||||
TRUNCATE 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);
|
INSERT INTO t1 (id) VALUES (NULL);
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
id
|
id
|
||||||
@@ -2421,7 +2421,7 @@ id
|
|||||||
2
|
2
|
||||||
DELETE FROM t1;
|
DELETE FROM t1;
|
||||||
TRUNCATE 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);
|
INSERT INTO t1 (id) VALUES (NULL);
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
id
|
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;
|
create table t1(a char(10) primary key, b varchar(20)) engine = innodb;
|
||||||
set foreign_key_checks=1;
|
set foreign_key_checks=1;
|
||||||
insert into t2 values (1,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;
|
set foreign_key_checks=0;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
set foreign_key_checks=1;
|
set foreign_key_checks=1;
|
||||||
insert into t2 values (1,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;
|
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")
|
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
|
||||||
drop table t2;
|
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 t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb;
|
||||||
create table t1(a varchar(10) primary key) engine = innodb;
|
create table t1(a varchar(10) primary key) engine = innodb;
|
||||||
alter table t1 modify column a int;
|
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;
|
set foreign_key_checks=1;
|
||||||
drop table t2,t1;
|
drop table t2,t1;
|
||||||
set foreign_key_checks=0;
|
set foreign_key_checks=0;
|
||||||
create table t2 (a varchar(10), foreign key (a) references t1(a)) engine = innodb DEFAULT CHARSET=latin1;
|
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;
|
create table t1(a varchar(10) primary key) engine = innodb DEFAULT CHARSET=latin1;
|
||||||
alter table t1 convert to character set utf8;
|
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;
|
set foreign_key_checks=1;
|
||||||
drop table t2,t1;
|
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.");
|
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 t1 values(1);
|
||||||
insert into t3 values(1);
|
insert into t3 values(1);
|
||||||
insert into t2 values(2);
|
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);
|
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 t2 values(1);
|
||||||
insert into t4 values(1);
|
insert into t4 values(1);
|
||||||
update t1 set a=2;
|
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;
|
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;
|
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;
|
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;
|
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;
|
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 t2;
|
||||||
truncate t4;
|
truncate t4;
|
||||||
truncate t1;
|
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;
|
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;
|
drop table t4,t3,t2,t1;
|
||||||
create table t1 (a varchar(255) character set utf8,
|
create table t1 (a varchar(255) character set utf8,
|
||||||
b 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 t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
|
||||||
CREATE TABLE t2(a INT) ENGINE=InnoDB;
|
CREATE TABLE t2(a INT) ENGINE=InnoDB;
|
||||||
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
|
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY `1`;
|
||||||
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
|
ALTER TABLE t2 ADD CONSTRAINT `0` FOREIGN KEY (a) REFERENCES t1(a);
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
|
ALTER TABLE t2 DROP FOREIGN KEY `0`;
|
||||||
SHOW CREATE TABLE t2;
|
SHOW CREATE TABLE t2;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t2 CREATE TABLE `t2` (
|
t2 CREATE TABLE `t2` (
|
||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
KEY `t2_ibfk_0` (`a`)
|
KEY `0` (`a`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
DROP TABLE t2,t1;
|
DROP TABLE t2,t1;
|
||||||
SET sql_mode = default;
|
SET sql_mode = default;
|
||||||
@@ -3061,7 +3061,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f` int(11) NOT NULL,
|
`f` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `f` (`f`),
|
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
|
CONSTRAINT `t2_t1` FOREIGN KEY (`id`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
DROP TABLE t2, t1;
|
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 @old_sql_mode = @@sql_mode;
|
||||||
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
set @@sql_mode = 'STRICT_TRANS_TABLES';
|
||||||
ALTER TABLE t2 MODIFY a INT NOT NULL;
|
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;
|
set @@sql_mode = @old_sql_mode;
|
||||||
DELETE FROM t1;
|
DELETE FROM t1;
|
||||||
DROP TABLE t2,t1;
|
DROP TABLE t2,t1;
|
||||||
|
@@ -82,8 +82,8 @@ INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FOREIGN f
|
|||||||
ON c.ID=f.ID
|
ON c.ID=f.ID
|
||||||
WHERE FOR_NAME LIKE 'test/t%';
|
WHERE FOR_NAME LIKE 'test/t%';
|
||||||
ID FOR_NAME REF_NAME N_COLS TYPE ID FOR_COL_NAME REF_COL_NAME POS
|
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
|
fk1 test/t2 test/t1 1 0 fk1 z e 0
|
||||||
test/fk2 test/t3 test/t3 1 0 test/fk2 g f 0
|
fk2 test/t3 test/t3 1 0 fk2 g f 0
|
||||||
DROP TABLE t3;
|
DROP TABLE t3;
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
@@ -17,7 +17,7 @@ SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
|
|||||||
WHERE table_name = 'product_order';
|
WHERE table_name = 'product_order';
|
||||||
CONSTRAINT_CATALOG def
|
CONSTRAINT_CATALOG def
|
||||||
CONSTRAINT_SCHEMA test
|
CONSTRAINT_SCHEMA test
|
||||||
CONSTRAINT_NAME product_order_ibfk_1
|
CONSTRAINT_NAME 1
|
||||||
UNIQUE_CONSTRAINT_CATALOG def
|
UNIQUE_CONSTRAINT_CATALOG def
|
||||||
UNIQUE_CONSTRAINT_SCHEMA test
|
UNIQUE_CONSTRAINT_SCHEMA test
|
||||||
UNIQUE_CONSTRAINT_NAME PRIMARY
|
UNIQUE_CONSTRAINT_NAME PRIMARY
|
||||||
@@ -28,7 +28,7 @@ TABLE_NAME product_order
|
|||||||
REFERENCED_TABLE_NAME product
|
REFERENCED_TABLE_NAME product
|
||||||
CONSTRAINT_CATALOG def
|
CONSTRAINT_CATALOG def
|
||||||
CONSTRAINT_SCHEMA test
|
CONSTRAINT_SCHEMA test
|
||||||
CONSTRAINT_NAME product_order_ibfk_2
|
CONSTRAINT_NAME 2
|
||||||
UNIQUE_CONSTRAINT_CATALOG def
|
UNIQUE_CONSTRAINT_CATALOG def
|
||||||
UNIQUE_CONSTRAINT_SCHEMA test
|
UNIQUE_CONSTRAINT_SCHEMA test
|
||||||
UNIQUE_CONSTRAINT_NAME PRIMARY
|
UNIQUE_CONSTRAINT_NAME PRIMARY
|
||||||
|
@@ -322,7 +322,7 @@ INSERT INTO t1 VALUES (1);
|
|||||||
INSERT INTO t2 VALUES (1);
|
INSERT INTO t2 VALUES (1);
|
||||||
DELETE IGNORE FROM t1 WHERE i = 1;
|
DELETE IGNORE FROM t1 WHERE i = 1;
|
||||||
Warnings:
|
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;
|
SELECT * FROM t1, t2;
|
||||||
i i
|
i i
|
||||||
1 1
|
1 1
|
||||||
@@ -2126,10 +2126,10 @@ t2 CREATE TABLE `t2` (
|
|||||||
`c` int(11) NOT NULL,
|
`c` int(11) NOT NULL,
|
||||||
`d` int(11) NOT NULL,
|
`d` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`c`,`d`),
|
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 `c1` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON DELETE NO ACTION,
|
||||||
CONSTRAINT `c2` FOREIGN KEY (`c`) REFERENCES `t1` (`a`) ON UPDATE 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 `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
|
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
@@ -2445,7 +2445,7 @@ INSERT INTO t2 VALUES (3,2);
|
|||||||
SET AUTOCOMMIT = 0;
|
SET AUTOCOMMIT = 0;
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
TRUNCATE TABLE t1;
|
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;
|
SELECT * FROM t1;
|
||||||
id
|
id
|
||||||
1
|
1
|
||||||
@@ -2457,7 +2457,7 @@ id
|
|||||||
2
|
2
|
||||||
START TRANSACTION;
|
START TRANSACTION;
|
||||||
TRUNCATE TABLE t1;
|
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;
|
SELECT * FROM t1;
|
||||||
id
|
id
|
||||||
1
|
1
|
||||||
@@ -2475,7 +2475,7 @@ id
|
|||||||
2
|
2
|
||||||
COMMIT;
|
COMMIT;
|
||||||
TRUNCATE TABLE t1;
|
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;
|
SELECT * FROM t1;
|
||||||
id
|
id
|
||||||
1
|
1
|
||||||
@@ -2487,7 +2487,7 @@ id
|
|||||||
1
|
1
|
||||||
2
|
2
|
||||||
TRUNCATE TABLE t1;
|
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;
|
ROLLBACK;
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
id
|
id
|
||||||
@@ -2526,9 +2526,9 @@ INSERT INTO t4 VALUES (1),(2),(3),(4),(5);
|
|||||||
INSERT INTO t5 VALUES (1);
|
INSERT INTO t5 VALUES (1);
|
||||||
DELETE t5 FROM t4 LEFT JOIN t5 ON t4.a= t5.a;
|
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;
|
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;
|
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;
|
DELETE IGNORE t2, t1 FROM t2 INNER JOIN t1 ON (t2.aid = t1.id) WHERE t2.id = 1;
|
||||||
DROP TABLE t3;
|
DROP TABLE t3;
|
||||||
DROP TABLE t2;
|
DROP TABLE t2;
|
||||||
@@ -2627,7 +2627,7 @@ END||
|
|||||||
SET @a:=0;
|
SET @a:=0;
|
||||||
** Errors in the trigger causes the statement to abort.
|
** Errors in the trigger causes the statement to abort.
|
||||||
DELETE IGNORE t1 FROM t3 LEFT JOIN t1 ON t1.i=t3.i;
|
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;
|
SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i;
|
||||||
i i
|
i i
|
||||||
1 1
|
1 1
|
||||||
|
@@ -468,7 +468,7 @@ CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a))
|
|||||||
ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
|
ENGINE=InnoDB ROW_FORMAT=REDUNDANT;
|
||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
INSERT INTO t2 SET b=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 t2 ADD INDEX(a);
|
||||||
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
@@ -480,7 +480,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a),
|
|||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
SET foreign_key_checks=1;
|
SET foreign_key_checks=1;
|
||||||
ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk;
|
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
|
ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL
|
||||||
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
||||||
CHECK TABLE t2, t1;
|
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;
|
ENGINE=InnoDB ROW_FORMAT=COMPACT;
|
||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
INSERT INTO t2 SET b=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 t2 ADD INDEX(a);
|
||||||
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
@@ -1414,7 +1414,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a),
|
|||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
SET foreign_key_checks=1;
|
SET foreign_key_checks=1;
|
||||||
ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk;
|
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
|
ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL
|
||||||
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
||||||
CHECK TABLE t2, t1;
|
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;
|
ENGINE=InnoDB ROW_FORMAT=DYNAMIC;
|
||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
INSERT INTO t2 SET b=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 t2 ADD INDEX(a);
|
||||||
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
@@ -2348,7 +2348,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk FOREIGN KEY(b) REFERENCES t1(a),
|
|||||||
ALGORITHM=INSTANT;
|
ALGORITHM=INSTANT;
|
||||||
SET foreign_key_checks=1;
|
SET foreign_key_checks=1;
|
||||||
ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk;
|
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
|
ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL
|
||||||
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
||||||
CHECK TABLE t2, t1;
|
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)
|
FOREIGN KEY fk (f2) REFERENCES t2(f1)
|
||||||
)ENGINE=InnoDB;
|
)ENGINE=InnoDB;
|
||||||
ALTER TABLE t1 ADD f5 INT;
|
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)
|
ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1)
|
||||||
REFERENCES x(x);
|
REFERENCES x(x);
|
||||||
ERROR HY000: Failed to add the foreign key constraint 'test/fk' to system tables
|
|
||||||
ALTER TABLE t1 DROP COLUMN f5;
|
ALTER TABLE t1 DROP COLUMN f5;
|
||||||
SHOW CREATE TABLE t1;
|
SHOW CREATE TABLE t1;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
t1 CREATE TABLE `t1` (
|
t1 CREATE TABLE `t1` (
|
||||||
`f1` int(11) NOT NULL,
|
`f1` int(11) NOT NULL,
|
||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
`f3` int(11) DEFAULT NULL,
|
|
||||||
`f4` int(11) NOT NULL,
|
`f4` int(11) NOT NULL,
|
||||||
PRIMARY KEY (`f1`,`f4`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
DROP TABLE t1, t2;
|
DROP TABLE t1, t2;
|
||||||
#
|
#
|
||||||
|
@@ -157,7 +157,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`status` enum('a','b','c') DEFAULT NULL,
|
`status` enum('a','b','c') DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
PRIMARY KEY (`f1`),
|
||||||
KEY `idx1` (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
ALTER TABLE t2 CHANGE status status VARCHAR(20) DEFAULT NULL;
|
ALTER TABLE t2 CHANGE status status VARCHAR(20) DEFAULT NULL;
|
||||||
DROP TABLE t2, t1;
|
DROP TABLE t2, t1;
|
||||||
|
@@ -35,9 +35,9 @@ SET FOREIGN_KEY_CHECKS=ON;
|
|||||||
BEGIN;
|
BEGIN;
|
||||||
INSERT IGNORE INTO t1 VALUES (1,11);
|
INSERT IGNORE INTO t1 VALUES (1,11);
|
||||||
Warnings:
|
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);
|
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;
|
COMMIT;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
#
|
#
|
||||||
|
@@ -17,7 +17,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f1` int(11) NOT NULL,
|
`f1` int(11) NOT NULL,
|
||||||
`f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
|
`f2` int(11) GENERATED ALWAYS AS (`f1`) VIRTUAL,
|
||||||
KEY `f1` (`f1`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop table t2;
|
drop table t2;
|
||||||
# adding foreign key constraint for base columns during alter copy.
|
# adding foreign key constraint for base columns during alter copy.
|
||||||
|
@@ -5,7 +5,7 @@ ON UPDATE CASCADE)
|
|||||||
ENGINE=InnoDB;
|
ENGINE=InnoDB;
|
||||||
INSERT INTO child SET a=1;
|
INSERT INTO child SET a=1;
|
||||||
TRUNCATE TABLE parent;
|
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;
|
TRUNCATE TABLE child;
|
||||||
INSERT INTO child SET a=1;
|
INSERT INTO child SET a=1;
|
||||||
UPDATE parent SET a=2;
|
UPDATE parent SET a=2;
|
||||||
@@ -34,7 +34,7 @@ TRUNCATE TABLE child;
|
|||||||
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
ERROR HY000: Lock wait timeout exceeded; try restarting transaction
|
||||||
SET DEBUG_SYNC='now SIGNAL go';
|
SET DEBUG_SYNC='now SIGNAL go';
|
||||||
connection dml;
|
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;
|
SELECT * FROM child;
|
||||||
a
|
a
|
||||||
3
|
3
|
||||||
@@ -85,13 +85,13 @@ SET FOREIGN_KEY_CHECKS=1;
|
|||||||
TRUNCATE t1;
|
TRUNCATE t1;
|
||||||
ERROR HY000: Cannot add foreign key constraint for `t1`
|
ERROR HY000: Cannot add foreign key constraint for `t1`
|
||||||
INSERT INTO t1 VALUES (2,2);
|
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;
|
SELECT * FROM t1;
|
||||||
pk a
|
pk a
|
||||||
1 1
|
1 1
|
||||||
UNLOCK TABLES;
|
UNLOCK TABLES;
|
||||||
INSERT INTO t1 VALUES (2,2);
|
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;
|
SET FOREIGN_KEY_CHECKS=0;
|
||||||
INSERT INTO t1 VALUES (2,2);
|
INSERT INTO t1 VALUES (2,2);
|
||||||
SELECT * FROM t1;
|
SELECT * FROM t1;
|
||||||
|
@@ -18,7 +18,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
PRIMARY KEY (`f1`),
|
||||||
KEY `f2` (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (1, repeat('+', 20000));
|
insert into t1 values (1, repeat('+', 20000));
|
||||||
insert into t1 values (2, repeat('-', 20000));
|
insert into t1 values (2, repeat('-', 20000));
|
||||||
@@ -81,7 +81,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
PRIMARY KEY (`f1`),
|
||||||
KEY `f2` (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (1, 91);
|
insert into t1 values (1, 91);
|
||||||
insert into t2 values (1, 91);
|
insert into t2 values (1, 91);
|
||||||
@@ -136,7 +136,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f1` int(11) NOT NULL,
|
`f1` int(11) NOT NULL,
|
||||||
`f2` blob DEFAULT NULL,
|
`f2` blob DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
show create table t3;
|
show create table t3;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
@@ -144,7 +144,7 @@ t3 CREATE TABLE `t3` (
|
|||||||
`f1` int(11) NOT NULL,
|
`f1` int(11) NOT NULL,
|
||||||
`f2` blob DEFAULT NULL,
|
`f2` blob DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (2, repeat('-', 20000));
|
insert into t1 values (2, repeat('-', 20000));
|
||||||
insert into t2 values (2, repeat('%', 20000));
|
insert into t2 values (2, repeat('%', 20000));
|
||||||
@@ -224,7 +224,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
PRIMARY KEY (`f1`),
|
||||||
KEY `f2` (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
show create table t3;
|
show create table t3;
|
||||||
Table Create Table
|
Table Create Table
|
||||||
@@ -233,7 +233,7 @@ t3 CREATE TABLE `t3` (
|
|||||||
`f2` int(11) DEFAULT NULL,
|
`f2` int(11) DEFAULT NULL,
|
||||||
PRIMARY KEY (`f1`),
|
PRIMARY KEY (`f1`),
|
||||||
KEY `f2` (`f2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (2, 91);
|
insert into t1 values (2, 91);
|
||||||
insert into t2 values (2, 91);
|
insert into t2 values (2, 91);
|
||||||
|
@@ -38,7 +38,7 @@ CREATE TABLE t3(a INT PRIMARY KEY REFERENCES t1(a)) ENGINE=InnoDB;
|
|||||||
XA START 'a';
|
XA START 'a';
|
||||||
INSERT INTO t3 SET a=1;
|
INSERT INTO t3 SET a=1;
|
||||||
INSERT INTO t3 SET a=42;
|
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 END 'a';
|
||||||
XA PREPARE 'a';
|
XA PREPARE 'a';
|
||||||
SET GLOBAL innodb_fast_shutdown=0;
|
SET GLOBAL innodb_fast_shutdown=0;
|
||||||
|
@@ -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 t2 add constraint b foreign key (b) references t1(a);
|
||||||
alter table t1 add constraint b1 foreign key (b) references t2(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 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 t2 drop foreign key b;
|
||||||
alter table t1 drop foreign key b1;
|
alter table t1 drop foreign key b1;
|
||||||
|
|
||||||
|
@@ -299,3 +299,13 @@ drop table t2яяяяяяяяяяььььььььььззззззззззшшш
|
|||||||
t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш;
|
t1яяяяяяяяяяььььььььььззззззззззшшшшшшшшшш;
|
||||||
|
|
||||||
--echo # End of 10.6 tests
|
--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;
|
||||||
|
@@ -22,11 +22,11 @@ constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB;
|
|||||||
create table t2 (f1 int primary key,
|
create table t2 (f1 int primary key,
|
||||||
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
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);
|
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
||||||
|
|
||||||
set foreign_key_checks = 0;
|
|
||||||
--error ER_DUP_CONSTRAINT_NAME
|
--error ER_DUP_CONSTRAINT_NAME
|
||||||
|
set statement foreign_key_checks = 0 for
|
||||||
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
||||||
|
|
||||||
drop table t2, t1;
|
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;
|
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),
|
CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
|
||||||
FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
|
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;
|
RENAME TABLE best.t2 TO test.t2;
|
||||||
|
SHOW CREATE TABLE test.t2;
|
||||||
|
RENAME TABLE test.t2 TO best.t2;
|
||||||
SHOW CREATE TABLE best.t2;
|
SHOW CREATE TABLE best.t2;
|
||||||
DROP DATABASE best;
|
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;
|
ALTER TABLE t1 ADD pk INT NOT NULL AUTO_INCREMENT PRIMARY KEY;
|
||||||
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
||||||
ALTER TABLE t1 CHANGE COLUMN a b TIME;
|
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;
|
SET SESSION FOREIGN_KEY_CHECKS = ON;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
|
||||||
@@ -748,7 +749,7 @@ DROP TABLE t1;
|
|||||||
--echo # with CONSTRAINTs
|
--echo # with CONSTRAINTs
|
||||||
--echo #
|
--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;
|
set foreign_key_checks=on;
|
||||||
create table t1 (id int not null primary key) engine=innodb;
|
create table t1 (id int not null primary key) engine=innodb;
|
||||||
|
@@ -11,11 +11,6 @@ CREATE TABLE t1 (
|
|||||||
CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id)
|
CONSTRAINT test FOREIGN KEY (b) REFERENCES t1 (id)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
) 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 (
|
CREATE TABLE t2 (
|
||||||
id int(11) NOT NULL PRIMARY KEY,
|
id int(11) NOT NULL PRIMARY KEY,
|
||||||
a int(11) NOT NULL,
|
a int(11) NOT NULL,
|
||||||
@@ -27,7 +22,7 @@ CREATE TABLE t2 (
|
|||||||
|
|
||||||
show warnings;
|
show warnings;
|
||||||
|
|
||||||
drop table t1;
|
drop table t2,t1;
|
||||||
|
|
||||||
#
|
#
|
||||||
# MDEV-6697: Improve foreign keys warnings/errors
|
# MDEV-6697: Improve foreign keys warnings/errors
|
||||||
|
@@ -194,13 +194,13 @@ CREATE TABLE `boroda` (
|
|||||||
`b` INT(11) UNSIGNED DEFAULT NULL,
|
`b` INT(11) UNSIGNED DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
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;
|
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
ALTER TABLE `boroda`
|
ALTER TABLE `boroda`
|
||||||
ADD FOREIGN KEY (`b`) REFERENCES `boroda`(`id`);
|
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`;
|
RENAME TABLE `boroda` TO `#boroda`;
|
||||||
|
|
||||||
@@ -216,7 +216,7 @@ CREATE TABLE `boroda` (
|
|||||||
`b` INT(11) UNSIGNED DEFAULT NULL,
|
`b` INT(11) UNSIGNED DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `a` (`a`),
|
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;
|
) ENGINE=INNODB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
RENAME TABLE `boroda` TO `bor#oda`;
|
RENAME TABLE `boroda` TO `bor#oda`;
|
||||||
|
@@ -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);
|
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;
|
ALTER TABLE `t3` ADD CONSTRAINT `e` foreign key (`c`) REFERENCES `t2`(`c`) ON UPDATE SET NULL;
|
||||||
|
|
||||||
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN;
|
||||||
|
@@ -220,13 +220,9 @@ show create table t4;
|
|||||||
# mysqltest first does replace_regex, then replace_result
|
# mysqltest first does replace_regex, then replace_result
|
||||||
# Embedded server doesn't chdir to data directory
|
# Embedded server doesn't chdir to data directory
|
||||||
--replace_result $MYSQLD_DATADIR ./ master-data/ ''
|
--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);
|
alter table t3 add constraint dc foreign key (a) references t1(a);
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
alter table t3 drop foreign key dc;
|
||||||
--error ER_FK_FAIL_ADD_SYSTEM
|
|
||||||
alter table t3 add constraint dc foreign key (a) references t1(a);
|
alter table t3 add constraint dc foreign key (a) references t1(a);
|
||||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
|
||||||
show create table t3;
|
show create table t3;
|
||||||
--enable_info
|
--enable_info
|
||||||
alter table t2 drop index b, add index (beta);
|
alter table t2 drop index b, add index (beta);
|
||||||
@@ -237,7 +233,6 @@ delete from t1;
|
|||||||
--error ER_CANT_DROP_FIELD_OR_KEY
|
--error ER_CANT_DROP_FIELD_OR_KEY
|
||||||
drop index dc on t4;
|
drop index dc on t4;
|
||||||
--enable_info
|
--enable_info
|
||||||
--error ER_CANT_DROP_FIELD_OR_KEY
|
|
||||||
alter table t3 drop foreign key dc;
|
alter table t3 drop foreign key dc;
|
||||||
alter table t4 drop foreign key dc;
|
alter table t4 drop foreign key dc;
|
||||||
--disable_info
|
--disable_info
|
||||||
|
@@ -1797,9 +1797,9 @@ drop table t2,t1;
|
|||||||
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
|
CREATE TABLE t1(a INT, PRIMARY KEY(a)) ENGINE=InnoDB;
|
||||||
CREATE TABLE t2(a INT) ENGINE=InnoDB;
|
CREATE TABLE t2(a INT) ENGINE=InnoDB;
|
||||||
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
|
ALTER TABLE t2 ADD FOREIGN KEY (a) REFERENCES t1(a);
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_1;
|
ALTER TABLE t2 DROP FOREIGN KEY `1`;
|
||||||
ALTER TABLE t2 ADD CONSTRAINT t2_ibfk_0 FOREIGN KEY (a) REFERENCES t1(a);
|
ALTER TABLE t2 ADD CONSTRAINT `0` FOREIGN KEY (a) REFERENCES t1(a);
|
||||||
ALTER TABLE t2 DROP FOREIGN KEY t2_ibfk_0;
|
ALTER TABLE t2 DROP FOREIGN KEY `0`;
|
||||||
SHOW CREATE TABLE t2;
|
SHOW CREATE TABLE t2;
|
||||||
DROP TABLE t2,t1;
|
DROP TABLE t2,t1;
|
||||||
SET sql_mode = default;
|
SET sql_mode = default;
|
||||||
|
@@ -354,7 +354,7 @@ eval CREATE TABLE t2 (b INT PRIMARY KEY, FOREIGN KEY(b) REFERENCES t1(a))
|
|||||||
$engine;
|
$engine;
|
||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
INSERT INTO t2 SET b=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 t2 ADD INDEX(a);
|
||||||
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
|
||||||
ALTER TABLE t1 ADD COLUMN b INT, ADD FOREIGN KEY(a) REFERENCES t2(a),
|
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;
|
ALGORITHM=INSTANT;
|
||||||
SET foreign_key_checks=1;
|
SET foreign_key_checks=1;
|
||||||
ALTER TABLE t2 COMMENT 'domestic keys only', DROP FOREIGN KEY fk;
|
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
|
ALTER TABLE t1 ADD COLUMN big BLOB NOT NULL
|
||||||
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
DEFAULT REPEAT('a', @@GLOBAL.innodb_page_size * .75);
|
||||||
CHECK TABLE t2, t1;
|
CHECK TABLE t2, t1;
|
||||||
@@ -951,8 +951,7 @@ CREATE TABLE t2 (f1 INT, f2 INT, PRIMARY KEY(f1),
|
|||||||
)ENGINE=InnoDB;
|
)ENGINE=InnoDB;
|
||||||
|
|
||||||
ALTER TABLE t1 ADD f5 INT;
|
ALTER TABLE t1 ADD f5 INT;
|
||||||
SET FOREIGN_KEY_CHECKS=0;
|
SET STATEMENT FOREIGN_KEY_CHECKS=0 FOR
|
||||||
--error ER_FK_FAIL_ADD_SYSTEM
|
|
||||||
ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1)
|
ALTER TABLE t1 DROP COLUMN f3, ADD FOREIGN KEY fk (f1)
|
||||||
REFERENCES x(x);
|
REFERENCES x(x);
|
||||||
ALTER TABLE t1 DROP COLUMN f5;
|
ALTER TABLE t1 DROP COLUMN f5;
|
||||||
|
@@ -42,5 +42,5 @@ FULLTEXT (b))ENGINE=InnoDB;
|
|||||||
INSERT INTO t1 SET a=1;
|
INSERT INTO t1 SET a=1;
|
||||||
ALTER TABLE t2 DISCARD TABLESPACE;
|
ALTER TABLE t2 DISCARD TABLESPACE;
|
||||||
UPDATE t1 SET a=2;
|
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;
|
DROP TABLE t2,t1;
|
||||||
|
@@ -32,9 +32,9 @@ INSERT INTO t2 (a2,b2) VALUES
|
|||||||
('MySQL Security','When configured properly, MySQL ...');
|
('MySQL Security','When configured properly, MySQL ...');
|
||||||
INSERT INTO t2 (a2,b2) VALUES
|
INSERT INTO t2 (a2,b2) VALUES
|
||||||
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
|
('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;
|
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;
|
ANALYZE TABLE t1;
|
||||||
Table Op Msg_type Msg_text
|
Table Op Msg_type Msg_text
|
||||||
test.t1 analyze status Engine-independent statistics collected
|
test.t1 analyze status Engine-independent statistics collected
|
||||||
@@ -184,7 +184,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`s2` varchar(200) DEFAULT NULL,
|
`s2` varchar(200) DEFAULT NULL,
|
||||||
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
|
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
|
||||||
FULLTEXT KEY `idx` (`s2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
|
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
|
||||||
insert into t2 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
|
FTS_DOC_ID s2
|
||||||
3 Sunshine
|
3 Sunshine
|
||||||
update t1 set s1 = 1 where s1=3;
|
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;
|
DROP TABLE t2 , t1;
|
||||||
CREATE TABLE t1 (
|
CREATE TABLE t1 (
|
||||||
id1 INT ,
|
id1 INT ,
|
||||||
@@ -265,9 +265,9 @@ INSERT INTO t2 (a2,b2) VALUES
|
|||||||
('MySQL Security','When configured properly, MySQL ...');
|
('MySQL Security','When configured properly, MySQL ...');
|
||||||
INSERT INTO t2 (a2,b2) VALUES
|
INSERT INTO t2 (a2,b2) VALUES
|
||||||
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
|
('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;
|
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;
|
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
|
||||||
id1 a1 b1
|
id1 a1 b1
|
||||||
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
|
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
|
||||||
@@ -957,10 +957,10 @@ pk f1 f2 f3 f4 f5 f6 f7 f8
|
|||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL;
|
ALTER TABLE t1 ADD FOREIGN KEY (f5) REFERENCES t1 (f6) ON UPDATE SET NULL;
|
||||||
UPDATE t1 SET f6='update';
|
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;
|
ALTER TABLE t1 ADD FOREIGN KEY (f7) REFERENCES t1 (f8) ON UPDATE CASCADE;
|
||||||
UPDATE t1 SET f6='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;
|
DROP TABLE t1;
|
||||||
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
|
||||||
#
|
#
|
||||||
|
@@ -32,9 +32,9 @@ INSERT INTO t2 (a2,b2) VALUES
|
|||||||
('MySQL Security','When configured properly, MySQL ...');
|
('MySQL Security','When configured properly, MySQL ...');
|
||||||
INSERT INTO t2 (a2,b2) VALUES
|
INSERT INTO t2 (a2,b2) VALUES
|
||||||
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
|
('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;
|
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;
|
ANALYZE TABLE t1;
|
||||||
Table Op Msg_type Msg_text
|
Table Op Msg_type Msg_text
|
||||||
test.t1 analyze status Engine-independent statistics collected
|
test.t1 analyze status Engine-independent statistics collected
|
||||||
@@ -184,7 +184,7 @@ t2 CREATE TABLE `t2` (
|
|||||||
`s2` varchar(200) DEFAULT NULL,
|
`s2` varchar(200) DEFAULT NULL,
|
||||||
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
|
KEY `FTS_DOC_ID` (`FTS_DOC_ID`),
|
||||||
FULLTEXT KEY `idx` (`s2`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
|
insert into t1 values (1,'Sunshine'),(2,'Lollipops');
|
||||||
insert into t2 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
|
FTS_DOC_ID s2
|
||||||
3 Sunshine
|
3 Sunshine
|
||||||
update t1 set s1 = 1 where s1=3;
|
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;
|
DROP TABLE t2 , t1;
|
||||||
CREATE TABLE t1 (
|
CREATE TABLE t1 (
|
||||||
id1 INT ,
|
id1 INT ,
|
||||||
@@ -265,9 +265,9 @@ INSERT INTO t2 (a2,b2) VALUES
|
|||||||
('MySQL Security','When configured properly, MySQL ...');
|
('MySQL Security','When configured properly, MySQL ...');
|
||||||
INSERT INTO t2 (a2,b2) VALUES
|
INSERT INTO t2 (a2,b2) VALUES
|
||||||
('MySQL Tricks','1. Never run mysqld as root. 2. ...');
|
('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;
|
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;
|
SELECT * FROM t1 WHERE MATCH (a1,b1) AGAINST ('tutorial') ORDER BY id1;
|
||||||
id1 a1 b1
|
id1 a1 b1
|
||||||
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
|
1 MySQL Tutorial DBMS stands for DataBase VÐƷWİ...
|
||||||
|
@@ -15,7 +15,7 @@ ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint
|
|||||||
create table t2 (f1 int primary key,
|
create table t2 (f1 int primary key,
|
||||||
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
||||||
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
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
|
include/show_binlog_events.inc
|
||||||
Log_name Pos Event_type Server_id End_log_pos Info
|
Log_name Pos Event_type Server_id End_log_pos Info
|
||||||
master-bin.000001 # Gtid # # GTID #-#-#
|
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 # 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 # 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 # 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);
|
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
|
include/show_binlog_events.inc
|
||||||
Log_name Pos Event_type Server_id End_log_pos Info
|
Log_name Pos Event_type Server_id End_log_pos Info
|
||||||
master-bin.000001 # Gtid # # GTID #-#-#
|
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 # 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 # 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 # 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 # 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 slave;
|
||||||
connection master;
|
connection master;
|
||||||
drop table t2, t1;
|
drop table t2, t1;
|
||||||
|
@@ -22,12 +22,12 @@ constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB;
|
|||||||
create table t2 (f1 int primary key,
|
create table t2 (f1 int primary key,
|
||||||
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
|
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);
|
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
||||||
--source include/show_binlog_events.inc
|
--source include/show_binlog_events.inc
|
||||||
|
|
||||||
set foreign_key_checks = 0;
|
|
||||||
--error ER_DUP_CONSTRAINT_NAME
|
--error ER_DUP_CONSTRAINT_NAME
|
||||||
|
set statement foreign_key_checks = 0 for
|
||||||
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
|
||||||
--source include/show_binlog_events.inc
|
--source include/show_binlog_events.inc
|
||||||
--sync_slave_with_master
|
--sync_slave_with_master
|
||||||
|
@@ -13,18 +13,18 @@ t2 CREATE TABLE `t2` (
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
KEY `a` (`a`),
|
KEY `a` (`a`),
|
||||||
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
||||||
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
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 t1 (a,b) VALUES (1,'c'),(2,'d');
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
||||||
UPDATE t2 SET a=a+1;
|
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;
|
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;
|
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;
|
DELETE FROM t2 WHERE a=2;
|
||||||
SELECT a,b FROM t1;
|
SELECT a,b FROM t1;
|
||||||
a b
|
a b
|
||||||
@@ -47,10 +47,10 @@ t2 CREATE TABLE `t2` (
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
KEY `a` (`a`),
|
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
|
||||||
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d');
|
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 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');
|
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d'),(4,'e'),(3,'a');
|
||||||
UPDATE t1 SET a=a+1;
|
UPDATE t1 SET a=a+1;
|
||||||
@@ -66,6 +66,6 @@ DELETE FROM t1 WHERE b='a' LIMIT 2;
|
|||||||
SELECT a,b FROM t2;
|
SELECT a,b FROM t2;
|
||||||
a b
|
a b
|
||||||
TRUNCATE TABLE t1;
|
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 t2;
|
||||||
DROP TABLE t1;
|
DROP TABLE t1;
|
||||||
|
@@ -248,7 +248,7 @@ if ($innodb_engine)
|
|||||||
--error ER_ROW_IS_REFERENCED_2
|
--error ER_ROW_IS_REFERENCED_2
|
||||||
update t2 set a=4 where a=3;
|
update t2 set a=4 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,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
|
--echo # - ON DELETE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) 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;
|
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,t2 where t1.b=t2.a;
|
||||||
select t1.a, t1.b, t2.name from t1 left outer join t2 on (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
|
--echo # - ON DELETE CASCADE
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
||||||
delete from t2 where a=3;
|
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,t2 where t1.b=t2.a;
|
||||||
select t1.a, t1.b, t2.name from t1 left outer join t2 on (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 t1;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
|
@@ -93,7 +93,7 @@ t CREATE TABLE `t` (
|
|||||||
KEY `b` (`b`),
|
KEY `b` (`b`),
|
||||||
KEY `c` (`c`),
|
KEY `c` (`c`),
|
||||||
KEY `a` (`a`),
|
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
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
||||||
drop table t;
|
drop table t;
|
||||||
#
|
#
|
||||||
|
@@ -364,19 +364,19 @@ a b name
|
|||||||
# - ON UPDATE RESTRICT
|
# - ON UPDATE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) on update restrict;
|
alter table t1 add foreign key (b) references t2(a) on update restrict;
|
||||||
insert into t1 (a) values (4);
|
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;
|
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;
|
select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
|
||||||
a b name
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
3 3 value3
|
3 3 value3
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
# - ON DELETE RESTRICT
|
# - ON DELETE RESTRICT
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete restrict;
|
alter table t1 add foreign key (b) references t2(a) on delete restrict;
|
||||||
delete from t2 where a=3;
|
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;
|
select t1.a, t1.b, t2.name from t1,t2 where t1.b=t2.a;
|
||||||
a b name
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
@@ -387,7 +387,7 @@ a b name
|
|||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
3 3 value3
|
3 3 value3
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
# - ON DELETE CASCADE
|
# - ON DELETE CASCADE
|
||||||
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
alter table t1 add foreign key (b) references t2(a) on delete cascade;
|
||||||
delete from t2 where a=3;
|
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
|
a b name
|
||||||
1 1 value1
|
1 1 value1
|
||||||
2 2 value2
|
2 2 value2
|
||||||
alter table t1 drop foreign key t1_ibfk_1;
|
alter table t1 drop foreign key `1`;
|
||||||
drop table t1;
|
drop table t1;
|
||||||
drop table t2;
|
drop table t2;
|
||||||
#
|
#
|
||||||
|
@@ -17,13 +17,13 @@ on update restrict
|
|||||||
insert into parent values(1);
|
insert into parent values(1);
|
||||||
insert into child values(1);
|
insert into child values(1);
|
||||||
delete from parent where id = 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 child where parent_id = 1;
|
||||||
delete from parent where id = 1;
|
delete from parent where id = 1;
|
||||||
insert into parent values(1);
|
insert into parent values(1);
|
||||||
insert into child values(1);
|
insert into child values(1);
|
||||||
update parent set id=id+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;
|
delete from child;
|
||||||
update parent set id=id+1;
|
update parent set id=id+1;
|
||||||
select * from child for system_time all;
|
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 parent values(1);
|
||||||
insert into child values(1);
|
insert into child values(1);
|
||||||
delete from parent where id = 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 child;
|
||||||
drop table parent;
|
drop table parent;
|
||||||
################
|
################
|
||||||
@@ -202,19 +202,19 @@ foreign key(parent_id) references parent(id)
|
|||||||
insert into parent values(1);
|
insert into parent values(1);
|
||||||
insert into child values(1);
|
insert into child values(1);
|
||||||
delete from parent;
|
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;
|
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 child;
|
||||||
delete from parent;
|
delete from parent;
|
||||||
insert into child values(1);
|
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 parent values(1);
|
||||||
insert into child values(1);
|
insert into child values(1);
|
||||||
delete from parent;
|
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;
|
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 child;
|
||||||
drop table parent;
|
drop table parent;
|
||||||
###################
|
###################
|
||||||
@@ -307,7 +307,7 @@ set foreign_key_checks= off;
|
|||||||
insert ignore into t2 values (1);
|
insert ignore into t2 values (1);
|
||||||
set foreign_key_checks= on;
|
set foreign_key_checks= on;
|
||||||
update t2 set f2= 2;
|
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;
|
delete from t2;
|
||||||
drop table t2, t1;
|
drop table t2, t1;
|
||||||
#
|
#
|
||||||
@@ -409,7 +409,7 @@ insert into t1 values (1),(2);
|
|||||||
insert into t2 values (1);
|
insert into t2 values (1);
|
||||||
# DELETE from referenced table is not allowed
|
# DELETE from referenced table is not allowed
|
||||||
delete from t1 where a = 1;
|
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;
|
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
|
# 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 t1 (pk) values (1);
|
||||||
insert into t2 (pk) values (1);
|
insert into t2 (pk) values (1);
|
||||||
delete from t0;
|
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);
|
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 ;
|
select * into outfile 'load_t0' from t0 ;
|
||||||
load data infile 'load_t0' replace into table 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;
|
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;
|
select pk from t0;
|
||||||
pk
|
pk
|
||||||
1
|
1
|
||||||
|
@@ -107,9 +107,6 @@ ulong zip_pad_max = 50;
|
|||||||
#define DICT_POOL_PER_VARYING 4 /*!< buffer pool max size per data
|
#define DICT_POOL_PER_VARYING 4 /*!< buffer pool max size per data
|
||||||
dictionary varying size in bytes */
|
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
|
Tries to find column names for the index and sets the col field of the
|
||||||
index.
|
index.
|
||||||
@@ -1488,26 +1485,6 @@ dict_table_t::rename_tablespace(span<const char> new_name, bool replace) const
|
|||||||
return err;
|
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<uint>(strconvert(
|
|
||||||
cs_from, from, uint(strlen(from)),
|
|
||||||
cs_to, to, static_cast<uint>(len), &errors)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**********************************************************************//**
|
/**********************************************************************//**
|
||||||
Renames a table object.
|
Renames a table object.
|
||||||
@return TRUE if success */
|
@return TRUE if success */
|
||||||
@@ -1647,150 +1624,17 @@ dict_table_rename_in_cache(
|
|||||||
foreign->heap, table->name.m_name);
|
foreign->heap, table->name.m_name);
|
||||||
foreign->foreign_table_name_lookup_set();
|
foreign->foreign_table_name_lookup_set();
|
||||||
|
|
||||||
if (strchr(foreign->id, '/')) {
|
const char* sql_id = foreign->sql_id();
|
||||||
/* This is a >= 4.0.18 format id */
|
size_t fklen = snprintf(nullptr, 0, "%s\377%s",
|
||||||
|
table->name.m_name, sql_id);
|
||||||
ulint db_len;
|
char* id = foreign->id;
|
||||||
char* old_id;
|
if (fklen++ > strlen(id)) {
|
||||||
char old_name_cs_filename[MAX_FULL_NAME_LEN+1];
|
id = static_cast<char*>(
|
||||||
uint errors = 0;
|
mem_heap_alloc(foreign->heap, fklen));
|
||||||
|
|
||||||
/* 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<char*>(
|
|
||||||
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<char*>(
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
table->foreign_set.erase(it);
|
table->foreign_set.erase(it);
|
||||||
|
foreign->id = id;
|
||||||
|
snprintf(id, fklen, "%s\377%s", table->name.m_name, sql_id);
|
||||||
fk_set.insert(foreign);
|
fk_set.insert(foreign);
|
||||||
|
|
||||||
if (foreign->referenced_table) {
|
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.
|
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
|
@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);
|
ptr = dict_accept(cs, ptr, "KEY", &success);
|
||||||
|
|
||||||
if (!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);
|
ptr1 = dict_accept(cs, ptr, "IF", &success);
|
||||||
@@ -3448,16 +3246,16 @@ loop:
|
|||||||
|
|
||||||
ptr = dict_scan_id(cs, ptr, heap, &id);
|
ptr = dict_scan_id(cs, ptr, heap, &id);
|
||||||
|
|
||||||
if (id == NULL) {
|
if (!id) {
|
||||||
|
|
||||||
goto syntax_error;
|
goto syntax_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (std::find_if(table->foreign_set.begin(),
|
const Lex_ident_column i{Lex_cstring_strlen(id)};
|
||||||
table->foreign_set.end(),
|
|
||||||
dict_foreign_matches_id(id))
|
|
||||||
== table->foreign_set.end()) {
|
|
||||||
|
|
||||||
|
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) {
|
if (if_exists) {
|
||||||
goto loop;
|
goto loop;
|
||||||
}
|
}
|
||||||
@@ -3486,25 +3284,6 @@ loop:
|
|||||||
(*constraints_to_drop)[*n] = id;
|
(*constraints_to_drop)[*n] = id;
|
||||||
(*n)++;
|
(*n)++;
|
||||||
goto loop;
|
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 ====================*/
|
/*==================== 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,
|
const dict_foreign_t *foreign,
|
||||||
bool add_newline)
|
bool add_newline)
|
||||||
{
|
{
|
||||||
const char* stripped_id;
|
const char* id = foreign->sql_id();
|
||||||
ulint i;
|
ulint i;
|
||||||
std::string str;
|
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(",");
|
str.append(",");
|
||||||
|
|
||||||
if (add_newline) {
|
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(" CONSTRAINT ");
|
||||||
|
|
||||||
str.append(innobase_quote_identifier(trx, stripped_id));
|
str.append(innobase_quote_identifier(trx, id));
|
||||||
str.append(" FOREIGN KEY (");
|
str.append(" FOREIGN KEY (");
|
||||||
|
|
||||||
for (i = 0;;) {
|
for (i = 0;;) {
|
||||||
|
@@ -1504,10 +1504,6 @@ fts_rename_aux_tables(
|
|||||||
err = fts_rename_one_aux_table(
|
err = fts_rename_one_aux_table(
|
||||||
new_name, old_table_name, trx);
|
new_name, old_table_name, trx);
|
||||||
|
|
||||||
DBUG_EXECUTE_IF("fts_rename_failure",
|
|
||||||
err = DB_DEADLOCK;
|
|
||||||
fts_sql_rollback(trx););
|
|
||||||
|
|
||||||
if (err != DB_SUCCESS) {
|
if (err != DB_SUCCESS) {
|
||||||
return(err);
|
return(err);
|
||||||
}
|
}
|
||||||
|
@@ -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. */
|
Converts an identifier to UTF-8. */
|
||||||
void
|
void
|
||||||
@@ -12315,6 +12291,40 @@ LEX_CSTRING innodb_convert_name(CHARSET_INFO *cs, LEX_CSTRING name, char *buf)
|
|||||||
buf, MAX_TABLE_NAME_LEN, &errors)};
|
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<char*>(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
|
/** Create InnoDB foreign keys from MySQL alter_info. Collect all
|
||||||
dict_foreign_t items into local_fk_set and then add into system table.
|
dict_foreign_t items into local_fk_set and then add into system table.
|
||||||
@return DB_SUCCESS or specific error code */
|
@return DB_SUCCESS or specific error code */
|
||||||
@@ -12352,12 +12362,6 @@ create_table_info_t::create_foreign_keys()
|
|||||||
dict_table_t* alter_table;
|
dict_table_t* alter_table;
|
||||||
char* n = dict_table_lookup(d, t, &alter_table, heap);
|
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
|
/* If we are altering a temporary table, the table name after
|
||||||
ALTER TABLE does not correspond to the internal table name, and
|
ALTER TABLE does not correspond to the internal table name, and
|
||||||
alter_table=nullptr. But, we do not support FOREIGN KEY
|
alter_table=nullptr. But, we do not support FOREIGN KEY
|
||||||
@@ -12365,8 +12369,7 @@ create_table_info_t::create_foreign_keys()
|
|||||||
|
|
||||||
if (alter_table) {
|
if (alter_table) {
|
||||||
n = alter_table->name.m_name;
|
n = alter_table->name.m_name;
|
||||||
number = 1 + dict_table_get_highest_foreign_id(
|
number = dict_table_get_foreign_id(*alter_table);
|
||||||
alter_table);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
char* bufend = innobase_convert_name(
|
char* bufend = innobase_convert_name(
|
||||||
@@ -12478,33 +12481,17 @@ create_table_info_t::create_foreign_keys()
|
|||||||
return (DB_CANNOT_ADD_CONSTRAINT);
|
return (DB_CANNOT_ADD_CONSTRAINT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fk->constraint_name.str) {
|
if (size_t fk_len = fk->constraint_name.length) {
|
||||||
ulint db_len;
|
/* Prepend the table name to the constraint name. */
|
||||||
|
size_t s = strlen(table->name.m_name) + 2 + fk_len;
|
||||||
/* Catenate 'databasename/' to the constraint name
|
foreign->id = static_cast<char*>(
|
||||||
specified by the user: we conceive the constraint as
|
mem_heap_alloc(foreign->heap, s));
|
||||||
belonging to the same MySQL 'database' as the table
|
snprintf(foreign->id, s, "%s\377%.*s",
|
||||||
itself. We store the name to foreign->id. */
|
table->name.m_name, int(fk_len),
|
||||||
|
fk->constraint_name.str);
|
||||||
db_len = dict_get_db_name_len(table->name.m_name);
|
} else {
|
||||||
|
dict_create_add_foreign_id(&number, table->name.m_name,
|
||||||
foreign->id = static_cast<char*>(mem_heap_alloc(
|
foreign);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<dict_foreign_set::iterator, bool> ret
|
std::pair<dict_foreign_set::iterator, bool> ret
|
||||||
@@ -14286,18 +14273,24 @@ ha_innobase::rename_table(
|
|||||||
stats.close();
|
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()
|
/* We are not able to deal with handler::get_dup_key()
|
||||||
during DDL operations, because the duplicate key would
|
during DDL operations, because the duplicate key would
|
||||||
exist in metadata tables, not in the user table. */
|
exist in metadata tables, not in the user table. */
|
||||||
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to);
|
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), to);
|
||||||
DBUG_RETURN(HA_ERR_GENERIC);
|
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));
|
my_error(ER_LOCK_WAIT_TIMEOUT, MYF(0));
|
||||||
DBUG_RETURN(HA_ERR_GENERIC);
|
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;
|
size_t len;
|
||||||
char tmp_buff[NAME_LEN+1];
|
char tmp_buff[NAME_LEN+1];
|
||||||
char name_buff[NAME_LEN+1];
|
char name_buff[NAME_LEN+1];
|
||||||
const char* ptr;
|
const char* ptr = foreign->sql_id();
|
||||||
LEX_CSTRING* name = NULL;
|
LEX_CSTRING* name = NULL;
|
||||||
|
|
||||||
if (dict_table_t::is_temporary_name(foreign->foreign_table_name)) {
|
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(
|
f_key_info.foreign_id = thd_make_lex_string(
|
||||||
thd, 0, ptr, strlen(ptr), 1);
|
thd, 0, ptr, strlen(ptr), 1);
|
||||||
|
|
||||||
|
@@ -946,3 +946,15 @@ ib_push_frm_error(
|
|||||||
@return true if index column length exceeds limit */
|
@return true if index column length exceeds limit */
|
||||||
MY_ATTRIBUTE((warn_unused_result))
|
MY_ATTRIBUTE((warn_unused_result))
|
||||||
bool too_big_key_part_length(size_t max_field_len, const KEY& key);
|
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;
|
||||||
|
@@ -2889,21 +2889,13 @@ innobase_init_foreign(
|
|||||||
ut_ad(dict_sys.locked());
|
ut_ad(dict_sys.locked());
|
||||||
|
|
||||||
if (constraint_name) {
|
if (constraint_name) {
|
||||||
ulint db_len;
|
/* Prepend the table name to the constraint name. */
|
||||||
|
size_t s = 1 + snprintf(nullptr, 0, "%s\377%s",
|
||||||
/* Catenate 'databasename/' to the constraint name specified
|
table->name.m_name, constraint_name);
|
||||||
by the user: we conceive the constraint as belonging to the
|
foreign->id = static_cast<char*>(
|
||||||
same MySQL 'database' as the table itself. We store the name
|
mem_heap_alloc(foreign->heap, s));
|
||||||
to foreign->id. */
|
snprintf(foreign->id, s, "%s\377%s",
|
||||||
|
table->name.m_name, constraint_name);
|
||||||
db_len = dict_get_db_name_len(table->name.m_name);
|
|
||||||
|
|
||||||
foreign->id = static_cast<char*>(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);
|
|
||||||
|
|
||||||
/* Check if any existing foreign key has the same id,
|
/* Check if any existing foreign key has the same id,
|
||||||
this is needed only if user supplies the constraint name */
|
this is needed only if user supplies the constraint name */
|
||||||
@@ -3298,7 +3290,8 @@ innobase_get_foreign_key_info(
|
|||||||
num_col = i;
|
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,
|
LEX_CSTRING t = innodb_convert_name(cs, fk_key->ref_table,
|
||||||
t_name);
|
t_name);
|
||||||
@@ -3308,7 +3301,7 @@ innobase_get_foreign_key_info(
|
|||||||
dict_sys.lock(SRW_LOCK_CALL);
|
dict_sys.lock(SRW_LOCK_CALL);
|
||||||
|
|
||||||
referenced_table_name = dict_table_lookup(
|
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
|
/* Test the case when referenced_table failed to
|
||||||
open, if trx->check_foreigns is not set, we should
|
open, if trx->check_foreigns is not set, we should
|
||||||
@@ -3367,8 +3360,19 @@ innobase_get_foreign_key_info(
|
|||||||
goto err_exit_unlock;
|
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(
|
if (!innobase_init_foreign(
|
||||||
add_fk[num_fk], fk_key->name.str,
|
fk, fk_key->name.str,
|
||||||
table, index, column_names,
|
table, index, column_names,
|
||||||
num_col, referenced_table_name,
|
num_col, referenced_table_name,
|
||||||
referenced_table, referenced_index,
|
referenced_table, referenced_index,
|
||||||
@@ -3376,14 +3380,13 @@ innobase_get_foreign_key_info(
|
|||||||
my_error(
|
my_error(
|
||||||
ER_DUP_CONSTRAINT_NAME,
|
ER_DUP_CONSTRAINT_NAME,
|
||||||
MYF(0),
|
MYF(0),
|
||||||
"FOREIGN KEY", add_fk[num_fk]->id);
|
"FOREIGN KEY", fk_key->name.str);
|
||||||
goto err_exit_unlock;
|
goto err_exit_unlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
dict_sys.unlock();
|
dict_sys.unlock();
|
||||||
|
|
||||||
correct_option = innobase_set_foreign_key_option(
|
correct_option = innobase_set_foreign_key_option(fk, fk_key);
|
||||||
add_fk[num_fk], fk_key);
|
|
||||||
|
|
||||||
DBUG_EXECUTE_IF("innodb_test_wrong_fk_option",
|
DBUG_EXECUTE_IF("innodb_test_wrong_fk_option",
|
||||||
correct_option = false;);
|
correct_option = false;);
|
||||||
@@ -3392,12 +3395,11 @@ innobase_get_foreign_key_info(
|
|||||||
my_error(ER_FK_INCORRECT_OPTION,
|
my_error(ER_FK_INCORRECT_OPTION,
|
||||||
MYF(0),
|
MYF(0),
|
||||||
table_share->table_name.str,
|
table_share->table_name.str,
|
||||||
add_fk[num_fk]->id);
|
fk_key->name.str);
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (innobase_check_fk_stored(
|
if (innobase_check_fk_stored(fk, table, s_cols)) {
|
||||||
add_fk[num_fk], table, s_cols)) {
|
|
||||||
my_printf_error(
|
my_printf_error(
|
||||||
HA_ERR_UNSUPPORTED,
|
HA_ERR_UNSUPPORTED,
|
||||||
"Cannot add foreign key on the base column "
|
"Cannot add foreign key on the base column "
|
||||||
@@ -3415,8 +3417,8 @@ err_exit_unlock:
|
|||||||
dict_sys.unlock();
|
dict_sys.unlock();
|
||||||
err_exit:
|
err_exit:
|
||||||
for (ulint i = 0; i <= num_fk; i++) {
|
for (ulint i = 0; i <= num_fk; i++) {
|
||||||
if (add_fk[i]) {
|
if (dict_foreign_t* fk = add_fk[i]) {
|
||||||
dict_foreign_free(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)
|
&& foreign->col_fk_exists(col_name) != UINT_MAX)
|
||||||
{
|
{
|
||||||
non_null_error:
|
non_null_error:
|
||||||
const char* fid = strchr(foreign->id, '/');
|
my_error(ER_FK_COLUMN_NOT_NULL, MYF(0), col_name, foreign->sql_id());
|
||||||
fid= fid ? fid + 1 : foreign->id;
|
|
||||||
my_error(ER_FK_COLUMN_NOT_NULL, MYF(0), col_name, fid);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4522,10 +4522,8 @@ non_null_error:
|
|||||||
dblen, foreign->foreign_table_name, tbl_name);
|
dblen, foreign->foreign_table_name, tbl_name);
|
||||||
|
|
||||||
display_name[FN_REFLEN - 1]= '\0';
|
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,
|
my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0), col_name,
|
||||||
fid, display_name);
|
foreign->sql_id(), display_name);
|
||||||
return true;
|
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))
|
if (!strcmp(foreign->foreign_col_names[f], col_name))
|
||||||
{
|
{
|
||||||
my_error(ER_FK_COLUMN_CANNOT_DROP, MYF(0),
|
my_error(ER_FK_COLUMN_CANNOT_DROP, MYF(0),
|
||||||
col_name, foreign->id);
|
col_name, foreign->sql_id());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7883,9 +7881,9 @@ bool check_col_is_in_fk_indexes(
|
|||||||
span<const dict_foreign_t *> drop_fk,
|
span<const dict_foreign_t *> drop_fk,
|
||||||
span<const dict_foreign_t *> add_fk)
|
span<const dict_foreign_t *> 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 ||
|
if (!f->foreign_index ||
|
||||||
std::find(drop_fk.begin(), drop_fk.end(), f) != drop_fk.end())
|
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++)
|
for (ulint i= 0; i < f->n_fields; i++)
|
||||||
if (f->foreign_index->fields[i].col == col)
|
if (f->foreign_index->fields[i].col == col)
|
||||||
{
|
{
|
||||||
fk_id= f->id;
|
fk= f;
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &a : add_fk)
|
for (const auto a : add_fk)
|
||||||
{
|
{
|
||||||
if (!a->foreign_index) continue;
|
if (!a->foreign_index) continue;
|
||||||
for (ulint i= 0; i < a->n_fields; i++)
|
for (ulint i= 0; i < a->n_fields; i++)
|
||||||
{
|
{
|
||||||
if (a->foreign_index->fields[i].col == col)
|
if (a->foreign_index->fields[i].col == col)
|
||||||
{
|
{
|
||||||
fk_id= a->id;
|
fk= a;
|
||||||
goto err_exit;
|
goto err_exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &f : table->referenced_set)
|
for (const auto f : table->referenced_set)
|
||||||
{
|
{
|
||||||
if (!f->referenced_index) continue;
|
if (!f->referenced_index) continue;
|
||||||
for (ulint i= 0; i < f->n_fields; i++)
|
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)
|
if (f->referenced_index->fields[i].col == col)
|
||||||
{
|
{
|
||||||
my_error(ER_FK_COLUMN_CANNOT_CHANGE_CHILD, MYF(0),
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7927,8 +7925,7 @@ bool check_col_is_in_fk_indexes(
|
|||||||
return false;
|
return false;
|
||||||
err_exit:
|
err_exit:
|
||||||
my_error(ER_FK_COLUMN_CANNOT_CHANGE, MYF(0), col_name,
|
my_error(ER_FK_COLUMN_CANNOT_CHANGE, MYF(0), col_name,
|
||||||
fk_id ? fk_id :
|
fk->id ? fk->sql_id() : "0");
|
||||||
(std::string(table->name.m_name) + "_ibfk_0").c_str());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -8289,22 +8286,11 @@ check_if_ok_to_rename:
|
|||||||
|
|
||||||
dict_foreign_t* foreign;
|
dict_foreign_t* foreign;
|
||||||
|
|
||||||
for (dict_foreign_set::iterator it
|
for (dict_foreign_t* fk : m_prebuilt->table->foreign_set) {
|
||||||
= m_prebuilt->table->foreign_set.begin();
|
if (Lex_ident_column(Lex_cstring_strlen
|
||||||
it != m_prebuilt->table->foreign_set.end();
|
(fk->sql_id())).
|
||||||
++it) {
|
streq(drop.name)) {
|
||||||
|
foreign = fk;
|
||||||
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)) {
|
|
||||||
goto found_fk;
|
goto found_fk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10051,14 +10037,11 @@ innobase_update_foreign_try(
|
|||||||
trx_t* trx,
|
trx_t* trx,
|
||||||
const char* table_name)
|
const char* table_name)
|
||||||
{
|
{
|
||||||
ulint foreign_id;
|
|
||||||
ulint i;
|
ulint i;
|
||||||
|
|
||||||
DBUG_ENTER("innobase_update_foreign_try");
|
DBUG_ENTER("innobase_update_foreign_try");
|
||||||
|
|
||||||
foreign_id = dict_table_get_highest_foreign_id(ctx->new_table);
|
ulint foreign_id = dict_table_get_foreign_id(*ctx->new_table);
|
||||||
|
|
||||||
foreign_id++;
|
|
||||||
|
|
||||||
for (i = 0; i < ctx->num_to_add_fk; i++) {
|
for (i = 0; i < ctx->num_to_add_fk; i++) {
|
||||||
dict_foreign_t* fk = ctx->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
|
ut_ad(fk->foreign_table == ctx->new_table
|
||||||
|| fk->foreign_table == ctx->old_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);
|
&foreign_id, ctx->old_table->name.m_name, fk);
|
||||||
|
/* After this point, it is safe to call fk->sql_id(). */
|
||||||
if (error != DB_SUCCESS) {
|
|
||||||
my_error(ER_TOO_LONG_IDENT, MYF(0),
|
|
||||||
fk->id);
|
|
||||||
DBUG_RETURN(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!fk->foreign_index) {
|
if (!fk->foreign_index) {
|
||||||
fk->foreign_index = dict_foreign_find_index(
|
fk->foreign_index = dict_foreign_find_index(
|
||||||
@@ -10086,7 +10064,7 @@ innobase_update_foreign_try(
|
|||||||
NULL, NULL, NULL);
|
NULL, NULL, NULL);
|
||||||
if (!fk->foreign_index) {
|
if (!fk->foreign_index) {
|
||||||
my_error(ER_FK_INCORRECT_OPTION,
|
my_error(ER_FK_INCORRECT_OPTION,
|
||||||
MYF(0), table_name, fk->id);
|
MYF(0), table_name, fk->sql_id());
|
||||||
DBUG_RETURN(true);
|
DBUG_RETURN(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10094,7 +10072,7 @@ innobase_update_foreign_try(
|
|||||||
/* The fk->foreign_col_names[] uses renamed column
|
/* The fk->foreign_col_names[] uses renamed column
|
||||||
names, while the columns in ctx->old_table have not
|
names, while the columns in ctx->old_table have not
|
||||||
been renamed yet. */
|
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);
|
ctx->old_table->name.m_name, fk, trx);
|
||||||
|
|
||||||
DBUG_EXECUTE_IF(
|
DBUG_EXECUTE_IF(
|
||||||
|
@@ -5742,7 +5742,7 @@ i_s_dict_fill_sys_foreign(
|
|||||||
|
|
||||||
fields = table_to_fill->field;
|
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],
|
OK(field_store_string(fields[SYS_FOREIGN_FOR_NAME],
|
||||||
foreign->foreign_table_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");
|
DBUG_ENTER("i_s_dict_fill_sys_foreign_cols");
|
||||||
|
|
||||||
fields = table_to_fill->field;
|
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));
|
OK(field_store_string(fields[SYS_FOREIGN_COL_FOR_NAME], for_col_name));
|
||||||
|
|
||||||
|
@@ -117,20 +117,6 @@ dict_create_index_tree_in_mem(
|
|||||||
dict_index_t* index, /*!< in/out: index */
|
dict_index_t* index, /*!< in/out: index */
|
||||||
const trx_t* trx); /*!< in: InnoDB transaction handle */
|
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
|
/** Adds the given set of foreign key objects to the dictionary tables
|
||||||
in the database. This function does not modify the dictionary cache. The
|
in the database. This function does not modify the dictionary cache. The
|
||||||
caller must ensure that all foreign key objects contain a valid constraint
|
caller must ensure that all foreign key objects contain a valid constraint
|
||||||
|
@@ -24,75 +24,6 @@ Database object creation
|
|||||||
Created 1/8/1996 Heikki Tuuri
|
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<char*>(
|
|
||||||
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
|
/** 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
|
of Sys_columns. The column number includes both its virtual column sequence
|
||||||
(the "nth" virtual column) and its actual column position in original table
|
(the "nth" virtual column) and its actual column position in original table
|
||||||
|
@@ -61,16 +61,6 @@ void
|
|||||||
dict_foreign_free(
|
dict_foreign_free(
|
||||||
/*==============*/
|
/*==============*/
|
||||||
dict_foreign_t* foreign); /*!< in, own: foreign key struct */
|
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.
|
/** Check whether the dict_table_t is a partition.
|
||||||
A partitioned table on the SQL level is composed of InnoDB tables,
|
A partitioned table on the SQL level is composed of InnoDB tables,
|
||||||
where each InnoDB table is a [sub]partition including its secondary indexes
|
where each InnoDB table is a [sub]partition including its secondary indexes
|
||||||
|
@@ -1671,6 +1671,18 @@ public:
|
|||||||
}
|
}
|
||||||
return true;
|
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&
|
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<
|
typedef std::set<
|
||||||
dict_foreign_t*,
|
dict_foreign_t*,
|
||||||
dict_foreign_compare,
|
dict_foreign_compare,
|
||||||
|
@@ -347,16 +347,6 @@ innobase_next_autoinc(
|
|||||||
ulonglong max_value) /*!< in: max value for type */
|
ulonglong max_value) /*!< in: max value for type */
|
||||||
MY_ATTRIBUTE((pure, warn_unused_result));
|
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. */
|
Converts an identifier from my_charset_filename to UTF-8 charset. */
|
||||||
uint
|
uint
|
||||||
|
@@ -2502,29 +2502,28 @@ dberr_t
|
|||||||
row_delete_constraint(
|
row_delete_constraint(
|
||||||
/*==================*/
|
/*==================*/
|
||||||
const char* id, /*!< in: constraint id */
|
const char* id, /*!< in: constraint id */
|
||||||
const char* database_name, /*!< in: database name, with the
|
const char* name, /*!< in: table name */
|
||||||
trailing '/' */
|
|
||||||
mem_heap_t* heap, /*!< in: memory heap */
|
mem_heap_t* heap, /*!< in: memory heap */
|
||||||
trx_t* trx) /*!< in: transaction handle */
|
trx_t* trx) /*!< in: transaction handle */
|
||||||
{
|
{
|
||||||
dberr_t err;
|
const size_t s= strlen(id) + strlen(name) + 2;
|
||||||
|
char *fk= static_cast<char*>(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 <databasename>/<constraintname>. */
|
return err;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************//**
|
/*********************************************************************//**
|
||||||
@@ -2664,132 +2663,49 @@ row_rename_table_for_mysql(
|
|||||||
if (err != DB_SUCCESS) {
|
if (err != DB_SUCCESS) {
|
||||||
// Assume the caller guarantees destination name doesn't exist.
|
// Assume the caller guarantees destination name doesn't exist.
|
||||||
ut_ad(err != DB_DUPLICATE_KEY);
|
ut_ad(err != DB_DUPLICATE_KEY);
|
||||||
goto rollback_and_exit;
|
} else if (/* fk == RENAME_IGNORE_FK || */ !new_is_tmp) {
|
||||||
}
|
|
||||||
|
|
||||||
if (/* fk == RENAME_IGNORE_FK || */ !new_is_tmp) {
|
|
||||||
/* Rename all constraints. */
|
/* 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();
|
info = pars_info_create();
|
||||||
|
|
||||||
pars_info_add_str_literal(info, "new_table_name", new_name);
|
pars_info_add_str_literal(info, "new_name", new_name);
|
||||||
pars_info_add_str_literal(info, "old_table_name", old_name);
|
pars_info_add_str_literal(info, "old_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);
|
|
||||||
|
|
||||||
err = que_eval_sql(
|
err = que_eval_sql(
|
||||||
info,
|
info,
|
||||||
"PROCEDURE RENAME_CONSTRAINT_IDS () IS\n"
|
"PROCEDURE RENAME_CONSTRAINT_IDS () IS\n"
|
||||||
"gen_constr_prefix CHAR;\n"
|
"old CHAR; new CHAR; found INT; p INT;\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"
|
|
||||||
"BEGIN\n"
|
"BEGIN\n"
|
||||||
"found := 1;\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"
|
"WHILE found = 1 LOOP\n"
|
||||||
" SELECT ID INTO foreign_id\n"
|
" SELECT ID INTO old FROM SYS_FOREIGN\n"
|
||||||
" FROM SYS_FOREIGN\n"
|
" WHERE FOR_NAME = :old_name\n"
|
||||||
" WHERE FOR_NAME = :old_table_name\n"
|
" AND TO_BINARY(FOR_NAME)=TO_BINARY(:old_name)\n"
|
||||||
" AND TO_BINARY(FOR_NAME)\n"
|
" LOCK IN SHARE MODE;\n"
|
||||||
" = TO_BINARY(:old_table_name)\n"
|
" IF (SQL % NOTFOUND) THEN\n"
|
||||||
" LOCK IN SHARE MODE;\n"
|
" found := 0;\n"
|
||||||
" IF (SQL % NOTFOUND) THEN\n"
|
" ELSE\n"
|
||||||
" found := 0;\n"
|
" p := INSTR(old, '\377');\n"
|
||||||
" ELSE\n"
|
" IF p = 0 THEN p := INSTR(old, '/'); END IF;\n"
|
||||||
" UPDATE SYS_FOREIGN\n"
|
" new:=CONCAT(:new_name,'\377',\n"
|
||||||
" SET FOR_NAME = :new_table_name\n"
|
" SUBSTR(old,p,LENGTH(old)-1));\n"
|
||||||
" WHERE ID = foreign_id;\n"
|
" UPDATE SYS_FOREIGN\n"
|
||||||
" id_len := LENGTH(foreign_id);\n"
|
" SET ID=new, FOR_NAME=:new_name WHERE ID=old;\n"
|
||||||
" IF (INSTR(foreign_id, '/') > 0) THEN\n"
|
" UPDATE SYS_FOREIGN_COLS\n"
|
||||||
" IF (INSTR(foreign_id,\n"
|
" SET ID=new WHERE ID=old;\n"
|
||||||
" gen_constr_prefix) > 0)\n"
|
" END IF;\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"
|
|
||||||
"END LOOP;\n"
|
"END LOOP;\n"
|
||||||
"UPDATE SYS_FOREIGN SET REF_NAME = :new_table_name\n"
|
"UPDATE SYS_FOREIGN SET REF_NAME = :new_name\n"
|
||||||
"WHERE REF_NAME = :old_table_name\n"
|
"WHERE REF_NAME = :old_name\n"
|
||||||
" AND TO_BINARY(REF_NAME)\n"
|
"AND TO_BINARY(REF_NAME)=TO_BINARY(:old_name);\n"
|
||||||
" = TO_BINARY(:old_table_name);\n"
|
|
||||||
"END;\n", trx);
|
"END;\n", trx);
|
||||||
|
if (err == DB_DUPLICATE_KEY) {
|
||||||
|
err = DB_FOREIGN_DUPLICATE_KEY;
|
||||||
|
}
|
||||||
} else if (n_constraints_to_drop > 0) {
|
} else if (n_constraints_to_drop > 0) {
|
||||||
/* Drop some constraints of tmp tables. */
|
/* Drop some constraints of tmp tables. */
|
||||||
|
for (auto i = n_constraints_to_drop; i--; ) {
|
||||||
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++) {
|
|
||||||
err = row_delete_constraint(constraints_to_drop[i],
|
err = row_delete_constraint(constraints_to_drop[i],
|
||||||
db_name, heap, trx);
|
old_name, heap, trx);
|
||||||
|
|
||||||
if (err != DB_SUCCESS) {
|
if (err != DB_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
@@ -2799,34 +2715,20 @@ row_rename_table_for_mysql(
|
|||||||
|
|
||||||
if (err == DB_SUCCESS
|
if (err == DB_SUCCESS
|
||||||
&& (dict_table_has_fts_index(table)
|
&& (dict_table_has_fts_index(table)
|
||||||
|| DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID))
|
|| DICT_TF2_FLAG_IS_SET(table, DICT_TF2_FTS_HAS_DOC_ID))
|
||||||
&& !dict_tables_have_same_db(old_name, new_name)) {
|
&& !dict_tables_have_same_db(old_name, new_name)) {
|
||||||
err = fts_rename_aux_tables(table, new_name, trx);
|
err = fts_rename_aux_tables(table, new_name, trx);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (err) {
|
if (err == DB_SUCCESS) {
|
||||||
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:
|
|
||||||
DEBUG_SYNC_C("innodb_rename_in_cache");
|
DEBUG_SYNC_C("innodb_rename_in_cache");
|
||||||
/* The following call will also rename the .ibd file */
|
/* The following call will also rename the .ibd file */
|
||||||
err = dict_table_rename_in_cache(
|
err = dict_table_rename_in_cache(
|
||||||
table, span<const char>{new_name,strlen(new_name)},
|
table, span<const char>{new_name,strlen(new_name)},
|
||||||
false);
|
false);
|
||||||
if (err != DB_SUCCESS) {
|
}
|
||||||
goto rollback_and_exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (err == DB_SUCCESS) {
|
||||||
/* In case of copy alter, template db_name and
|
/* In case of copy alter, template db_name and
|
||||||
table_name should be renamed only for newly
|
table_name should be renamed only for newly
|
||||||
created table. */
|
created table. */
|
||||||
@@ -2860,7 +2762,7 @@ row_rename_table_for_mysql(
|
|||||||
" definition.";
|
" definition.";
|
||||||
if (!trx->check_foreigns) {
|
if (!trx->check_foreigns) {
|
||||||
err = DB_SUCCESS;
|
err = DB_SUCCESS;
|
||||||
break;
|
goto funct_exit;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ib::error() << "In RENAME TABLE table "
|
ib::error() << "In RENAME TABLE table "
|
||||||
@@ -2869,29 +2771,23 @@ row_rename_table_for_mysql(
|
|||||||
" constraints which are not compatible"
|
" constraints which are not compatible"
|
||||||
" with the new table definition.";
|
" with the new table definition.";
|
||||||
}
|
}
|
||||||
|
} else if (dict_foreigns_has_s_base_col(table->foreign_set,
|
||||||
goto rollback_and_exit;
|
table)) {
|
||||||
}
|
|
||||||
|
|
||||||
/* 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)) {
|
|
||||||
err = DB_NO_FK_ON_S_BASE_COL;
|
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:
|
funct_exit:
|
||||||
|
@@ -5,11 +5,11 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
- KEY `a` (`a`),
|
- KEY `a` (`a`),
|
||||||
- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
||||||
+ KEY `a` (`a`)
|
+ KEY `a` (`a`)
|
||||||
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# The statement|command succeeded unexpectedly.
|
||||||
@@ -21,7 +21,7 @@
|
|||||||
INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d');
|
INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d');
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
||||||
UPDATE t2 SET a=a+1;
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# 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).
|
+# Also, this problem may cause a chain effect (more errors of different kinds in the test).
|
||||||
+# -------------------------------------------
|
+# -------------------------------------------
|
||||||
UPDATE t1 SET a=3 WHERE a=2;
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2)
|
||||||
DELETE FROM t1 WHERE a=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)
|
+# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# The statement|command succeeded unexpectedly.
|
||||||
@@ -72,11 +72,11 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
- KEY `a` (`a`),
|
- 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`)
|
+ KEY `a` (`a`)
|
||||||
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b'),(3,'c'),(4,'d');
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a');
|
INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a');
|
||||||
+ERROR 42S02: Table 'test.t1' doesn't exist
|
+ERROR 42S02: Table 'test.t1' doesn't exist
|
||||||
@@ -130,7 +130,7 @@
|
|||||||
+4 d
|
+4 d
|
||||||
+4 e
|
+4 e
|
||||||
TRUNCATE TABLE t1;
|
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 42S02: Table 'test.t1' doesn't exist
|
||||||
+# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK)
|
+# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
|
@@ -5,12 +5,12 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
- KEY `a` (`a`),
|
- KEY `a` (`a`),
|
||||||
- CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
- CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
|
||||||
-) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
-) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
+ KEY `a` (`a`)
|
+ KEY `a` (`a`)
|
||||||
+) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t2`)
|
+) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci INSERT_METHOD=LAST UNION=(`mrg`.`t2`)
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# The statement|command succeeded unexpectedly.
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d');
|
INSERT INTO t1 (a,b) VALUES (1,'c'),(2,'d');
|
||||||
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
INSERT INTO t2 (a,b) VALUES (1,'a'),(2,'b');
|
||||||
UPDATE t2 SET a=a+1;
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# 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).
|
+# Also, this problem may cause a chain effect (more errors of different kinds in the test).
|
||||||
+# -------------------------------------------
|
+# -------------------------------------------
|
||||||
UPDATE t1 SET a=3 WHERE a=2;
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2)
|
||||||
DELETE FROM t1 WHERE a=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)
|
+# ERROR: Statement succeeded (expected results: ER_ROW_IS_REFERENCED_2)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
+# The statement|command succeeded unexpectedly.
|
+# The statement|command succeeded unexpectedly.
|
||||||
@@ -73,12 +73,12 @@
|
|||||||
`a` int(11) DEFAULT NULL,
|
`a` int(11) DEFAULT NULL,
|
||||||
`b` char(8) DEFAULT NULL,
|
`b` char(8) DEFAULT NULL,
|
||||||
- KEY `a` (`a`),
|
- 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
|
||||||
-) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1
|
-) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
|
||||||
+ KEY `a` (`a`)
|
+ KEY `a` (`a`)
|
||||||
+) ENGINE=<STORAGE_ENGINE> DEFAULT CHARSET=latin1 INSERT_METHOD=LAST UNION=(`mrg`.`t2`)
|
+) ENGINE=<STORAGE_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');
|
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)
|
+# ERROR: Statement succeeded (expected results: ER_NO_REFERENCED_ROW_2)
|
||||||
INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a');
|
INSERT INTO t1 (a,b) VALUES (3,'a'),(4,'a');
|
||||||
+ERROR 42S02: Table 'test.t1' doesn't exist
|
+ERROR 42S02: Table 'test.t1' doesn't exist
|
||||||
@@ -132,7 +132,7 @@
|
|||||||
+4 d
|
+4 d
|
||||||
+4 e
|
+4 e
|
||||||
TRUNCATE TABLE t1;
|
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 42S02: Table 'test.t1' doesn't exist
|
||||||
+# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK)
|
+# ERROR: Statement ended with errno 1146, errname ER_NO_SUCH_TABLE (expected results: ER_TRUNCATE_ILLEGAL_FK)
|
||||||
+# ------------ UNEXPECTED RESULT ------------
|
+# ------------ UNEXPECTED RESULT ------------
|
||||||
|
Reference in New Issue
Block a user