Debian Codegraph @

mysql-test/suite/innodb/r/innodb_bug21704.result

raw
1 #
2 # Bug#21704: Renaming column does not update FK definition.
3 #
4
5 # Test that it's not possible to rename columns participating in a
6 # foreign key (either in the referencing or referenced table).
7
8 CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ROW_FORMAT=COMPACT ENGINE=INNODB;
9 CREATE TABLE t2 (a INT PRIMARY KEY, b INT,
10 CONSTRAINT fk1 FOREIGN KEY (a) REFERENCES t1(a))
11 ROW_FORMAT=COMPACT ENGINE=INNODB;
12 CREATE TABLE t3 (a INT PRIMARY KEY, b INT, KEY(b), C INT,
13 CONSTRAINT fk2 FOREIGN KEY (b) REFERENCES t3 (a))
14 ROW_FORMAT=COMPACT ENGINE=INNODB;
15 INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
16 INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
17 INSERT INTO t3 VALUES (1,1,1),(2,2,2),(3,3,3);
18
19 # Test renaming the column in the referenced table.
20
21 ALTER TABLE t1 CHANGE a e INT;
22 affected rows: 0
23 info: Records: 0 Duplicates: 0 Warnings: 0
24 # Ensure that online column rename works.
25 ALTER TABLE t1 CHANGE b c INT;
26 affected rows: 0
27 info: Records: 0 Duplicates: 0 Warnings: 0
28
29 # Test renaming the column in the referencing table
30
31 ALTER TABLE t2 CHANGE a z INT;
32 affected rows: 0
33 info: Records: 0 Duplicates: 0 Warnings: 0
34 # Ensure that online column rename works.
35 ALTER TABLE t2 CHANGE b c INT;
36 affected rows: 0
37 info: Records: 0 Duplicates: 0 Warnings: 0
38
39 # Test with self-referential constraints
40
41 ALTER TABLE t3 CHANGE a f INT;
42 affected rows: 0
43 info: Records: 0 Duplicates: 0 Warnings: 0
44 ALTER TABLE t3 CHANGE b g INT;
45 affected rows: 0
46 info: Records: 0 Duplicates: 0 Warnings: 0
47 # Ensure that online column rename works.
48 ALTER TABLE t3 CHANGE c d INT;
49 affected rows: 0
50 info: Records: 0 Duplicates: 0 Warnings: 0
51
52 # Cleanup.
53
54 SHOW CREATE TABLE t1;
55 Table Create Table
56 t1 CREATE TABLE `t1` (
57 `e` int NOT NULL,
58 `c` int DEFAULT NULL,
59 PRIMARY KEY (`e`)
60 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT
61 SHOW CREATE TABLE t2;
62 Table Create Table
63 t2 CREATE TABLE `t2` (
64 `z` int NOT NULL,
65 `c` int DEFAULT NULL,
66 PRIMARY KEY (`z`),
67 CONSTRAINT `fk1` FOREIGN KEY (`z`) REFERENCES `t1` (`e`)
68 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT
69 SHOW CREATE TABLE t3;
70 Table Create Table
71 t3 CREATE TABLE `t3` (
72 `f` int NOT NULL,
73 `g` int DEFAULT NULL,
74 `d` int DEFAULT NULL,
75 PRIMARY KEY (`f`),
76 KEY `b` (`g`),
77 CONSTRAINT `fk2` FOREIGN KEY (`g`) REFERENCES `t3` (`f`)
78 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT
79 SELECT f.FOR_NAME, f.REF_NAME, f.N_COLS, f.TYPE, c.FOR_COL_NAME, c.REF_COL_NAME, c.POS
80 FROM INFORMATION_SCHEMA.INNODB_FOREIGN_COLS c
81 INNER JOIN INFORMATION_SCHEMA.INNODB_FOREIGN f
82 ON c.ID=f.ID
83 WHERE FOR_NAME LIKE 'test/t%';
84 FOR_NAME REF_NAME N_COLS TYPE FOR_COL_NAME REF_COL_NAME POS
85 test/t2 test/t1 1 48 z e 1
86 test/t3 test/t3 1 48 g f 1
87 DROP TABLE t3;
88 DROP TABLE t2;
89 DROP TABLE t1;