Current Path : /home/usr.opt/mysql57/mysql-test/suite/innodb/r/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //home/usr.opt/mysql57/mysql-test/suite/innodb/r/foreign_key.result |
# # Bug #19027905 ASSERT RET.SECOND DICT_CREATE_FOREIGN_CONSTRAINTS_LOW # DICT_CREATE_FOREIGN_CONSTR # create table t1 (f1 int primary key) engine=InnoDB; create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1), constraint c1 foreign key (f1) references t1(f1)) engine=InnoDB; ERROR HY000: Cannot add foreign key constraint create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb; alter table t2 add constraint c1 foreign key (f1) references t1(f1); ERROR 23000: Can't write; duplicate key in table '#sql-temporary' set foreign_key_checks = 0; alter table t2 add constraint c1 foreign key (f1) references t1(f1); ERROR HY000: Duplicate foreign key constraint name 'test/c1' drop table t2, t1; # # Bug #20031243 CREATE TABLE FAILS TO CHECK IF FOREIGN KEY COLUMN # NULL/NOT NULL MISMATCH # set foreign_key_checks = 1; show variables like 'foreign_key_checks'; Variable_name Value foreign_key_checks ON CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, INDEX idx(a)) ENGINE=InnoDB; CREATE TABLE t2 (a INT KEY, b INT, INDEX ind(b), FOREIGN KEY (b) REFERENCES t1(a) ON DELETE CASCADE ON UPDATE CASCADE) ENGINE=InnoDB; show create table t1; Table Create Table t1 CREATE TABLE `t1` ( `a` int(11) NOT NULL, `b` int(11) NOT NULL, KEY `idx` (`a`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 show create table t2; Table Create Table t2 CREATE TABLE `t2` ( `a` int(11) NOT NULL, `b` int(11) DEFAULT NULL, PRIMARY KEY (`a`), KEY `ind` (`b`), CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=latin1 INSERT INTO t1 VALUES (1, 80); INSERT INTO t1 VALUES (2, 81); INSERT INTO t1 VALUES (3, 82); INSERT INTO t1 VALUES (4, 83); INSERT INTO t1 VALUES (5, 84); INSERT INTO t2 VALUES (51, 1); INSERT INTO t2 VALUES (52, 2); INSERT INTO t2 VALUES (53, 3); INSERT INTO t2 VALUES (54, 4); INSERT INTO t2 VALUES (55, 5); SELECT a, b FROM t1 ORDER BY a; a b 1 80 2 81 3 82 4 83 5 84 SELECT a, b FROM t2 ORDER BY a; a b 51 1 52 2 53 3 54 4 55 5 INSERT INTO t2 VALUES (56, 6); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`a`) ON DELETE CASCADE ON UPDATE CASCADE) ALTER TABLE t1 CHANGE a id INT; SELECT id, b FROM t1 ORDER BY id; id b 1 80 2 81 3 82 4 83 5 84 SELECT a, b FROM t2 ORDER BY a; a b 51 1 52 2 53 3 54 4 55 5 # Operations on child table INSERT INTO t2 VALUES (56, 6); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `t1` (`id`) ON DELETE CASCADE ON UPDATE CASCADE) 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) DELETE FROM t2 WHERE a = 53; SELECT id, b FROM t1 ORDER BY id; id b 1 80 2 81 3 82 4 83 5 84 SELECT a, b FROM t2 ORDER BY a; a b 51 1 52 2 54 4 55 5 # Operations on parent table DELETE FROM t1 WHERE id = 1; UPDATE t1 SET id = 50 WHERE id = 5; SELECT id, b FROM t1 ORDER BY id; id b 2 81 3 82 4 83 50 84 SELECT a, b FROM t2 ORDER BY a; a b 52 2 54 4 55 50 DROP TABLE t2, t1; # # bug#25126722 FOREIGN KEY CONSTRAINT NAME IS NULL AFTER RESTART # base bug#24818604 [GR] # CREATE TABLE t1 (c1 INT PRIMARY KEY); CREATE TABLE t2 (c1 INT PRIMARY KEY, FOREIGN KEY (c1) REFERENCES t1(c1)); INSERT INTO t1 VALUES (1); INSERT INTO t2 VALUES (1); SELECT unique_constraint_name FROM information_schema.referential_constraints WHERE table_name = 't2'; unique_constraint_name PRIMARY # restart SELECT unique_constraint_name FROM information_schema.referential_constraints WHERE table_name = 't2'; unique_constraint_name PRIMARY SELECT * FROM t1; c1 1 SELECT unique_constraint_name FROM information_schema.referential_constraints WHERE table_name = 't2'; unique_constraint_name PRIMARY DROP TABLE t2; DROP TABLE t1; # # Bug#33053297 VIRTUAL INDEX CORRUPTED DURING CASCADE UPDATE ON CHILD TABLE # #Test-Case 1 CREATE TABLE `emails` ( `id` int unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; CREATE TABLE `email_stats` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `email_id` int unsigned DEFAULT NULL, `date_sent` datetime NOT NULL, `generated_sent_date` date GENERATED ALWAYS AS (concat(year(`date_sent`),'-',lpad(month(`date_sent`),2,'0'), '-',lpad(dayofmonth(`date_sent`),2,'0'))) VIRTUAL, PRIMARY KEY (`id`), KEY `IDX_ES1` (`email_id`), KEY `mautic_generated_sent_date_email_id` (`generated_sent_date`,`email_id`), CONSTRAINT `FK_EA1` FOREIGN KEY (`email_id`) REFERENCES `emails` (`id`) ON DELETE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; INSERT INTO `emails` VALUES (1); INSERT INTO `email_stats` (`id`, `email_id`, `date_sent`) VALUES (1,1,'2020-10-22 13:32:41'); SELECT * FROM `email_stats`; id email_id date_sent generated_sent_date 1 1 2020-10-22 13:32:41 2020-10-22 DELETE FROM `emails`; DELETE FROM `email_stats`; DROP TABLE `email_stats`; DROP TABLE `emails`; # Test-Case 2 CREATE TABLE `emails` ( `id` int unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; CREATE TABLE `email_stats` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `email_id` int unsigned DEFAULT NULL, `date_sent` datetime NOT NULL, `generated_sent_date` date GENERATED ALWAYS AS (concat(year(`date_sent`),'-',lpad(month(`date_sent`),2,'0'), '-',lpad(dayofmonth(`date_sent`),2,'0'))) VIRTUAL, PRIMARY KEY (`id`), KEY `IDX_ES1` (`email_id`), KEY `mautic_generated_sent_date_email_id` (`generated_sent_date`,`email_id`), CONSTRAINT `FK_EA1` FOREIGN KEY (`email_id`) REFERENCES `emails` (`id`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; INSERT INTO `emails` VALUES (1); INSERT INTO `email_stats` (`id`, `email_id`, `date_sent`) VALUES (1,1,'2020-10-22 13:32:41'); UPDATE `emails` SET `id` = 2 where `id` = 1; SELECT id FROM `email_stats` WHERE `generated_sent_date` IS NULL; id SELECT * FROM `email_stats`; id email_id date_sent generated_sent_date 1 NULL 2020-10-22 13:32:41 2020-10-22 UPDATE `email_stats` SET `email_id`=2 WHERE DATE(`generated_sent_date`) = '2020-10-22'; SELECT * FROM `email_stats`; id email_id date_sent generated_sent_date 1 2 2020-10-22 13:32:41 2020-10-22 DROP TABLE `email_stats`; DROP TABLE `emails`; # test-case 3 CREATE TABLE `emails` ( `id` int unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; CREATE TABLE `email_stats` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `email_id` int unsigned DEFAULT NULL, `date_sent` datetime NOT NULL, `generated_sent_email` varchar(20) GENERATED ALWAYS AS (CONCAT(YEAR(`date_sent`),'-', COALESCE(`email_id`, ' '))) VIRTUAL, PRIMARY KEY (`id`), KEY `idx_es1` (`email_id`), KEY `mautic_generated_sent_date_email` (`generated_sent_email`,`email_id`), CONSTRAINT `fk_ea1` FOREIGN KEY (`email_id`) REFERENCES `emails` (`id`) ON DELETE SET NULL ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; INSERT INTO `emails` VALUES (1); INSERT INTO `email_stats` (`id`, `email_id`, `date_sent`) VALUES (1,1,'2020-10-22 13:32:41'); SELECT * FROM `email_stats`; id email_id date_sent generated_sent_email 1 1 2020-10-22 13:32:41 2020-1 SELECT `date_sent` FROM `email_stats` WHERE `generated_sent_email` = '2020-1'; date_sent 2020-10-22 13:32:41 DELETE FROM `emails`; SELECT * FROM `email_stats`; id email_id date_sent generated_sent_email 1 NULL 2020-10-22 13:32:41 2020- SELECT `date_sent` FROM `email_stats` WHERE `generated_sent_email` = '2020-'; date_sent 2020-10-22 13:32:41 DROP TABLE `email_stats`; DROP TABLE `emails`; # test-case 4 CREATE TABLE `emails` ( `id` int unsigned NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`) ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; CREATE TABLE `email_stats` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `email_id` int unsigned DEFAULT NULL, `date_sent` datetime NOT NULL, `generated_sent_email` varchar(20) GENERATED ALWAYS AS (CONCAT(YEAR(`date_sent`),'-', COALESCE(`email_id`, ' '))) VIRTUAL, PRIMARY KEY (`id`), KEY `idx_es1` (`email_id`), KEY `mautic_generated_sent_date_email` (`generated_sent_email`,`email_id`), CONSTRAINT `fk_ea1` FOREIGN KEY (`email_id`) REFERENCES `emails` (`id`) ON UPDATE SET NULL ) ENGINE=INNODB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC; INSERT INTO `emails` VALUES (1); INSERT INTO `email_stats` (`id`, `email_id`, `date_sent`) VALUES (1,1,'2020-10-22 13:32:41'); SELECT * FROM `email_stats`; id email_id date_sent generated_sent_email 1 1 2020-10-22 13:32:41 2020-1 SELECT `date_sent` FROM `email_stats` WHERE `generated_sent_email` = '2020-1'; date_sent 2020-10-22 13:32:41 UPDATE `emails` SET `id` = 2 WHERE `id` = 1; SELECT * FROM `email_stats`; id email_id date_sent generated_sent_email 1 NULL 2020-10-22 13:32:41 2020- SELECT `date_sent` FROM `email_stats` WHERE `generated_sent_email` = '2020-'; date_sent 2020-10-22 13:32:41 DROP TABLE `email_stats`; DROP TABLE `emails`;