1 -- source include/have_innodb_plugin.inc
4 --echo # Bug#21704: Renaming column does not update FK definition.
8 --echo # Test that it's not possible to rename columns participating in a
9 --echo # foreign key (either in the referencing or referenced table).
13 DROP TABLE IF EXISTS t1;
14 DROP TABLE IF EXISTS t2;
15 DROP TABLE IF EXISTS t3;
18 CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ROW_FORMAT=COMPACT ENGINE=INNODB;
20 CREATE TABLE t2 (a INT PRIMARY KEY, b INT,
21 CONSTRAINT fk1 FOREIGN KEY (a) REFERENCES t1(a))
22 ROW_FORMAT=COMPACT ENGINE=INNODB;
24 CREATE TABLE t3 (a INT PRIMARY KEY, b INT, KEY(b), C INT,
25 CONSTRAINT fk2 FOREIGN KEY (b) REFERENCES t3 (a))
26 ROW_FORMAT=COMPACT ENGINE=INNODB;
28 INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
29 INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
30 INSERT INTO t3 VALUES (1,1,1),(2,2,2),(3,3,3);
33 --echo # Test renaming the column in the referenced table.
36 # mysqltest first does replace_regex, then replace_result
37 --replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
38 # Embedded server doesn't chdir to data directory
39 --replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ ''
40 --error ER_ERROR_ON_RENAME
41 ALTER TABLE t1 CHANGE a c INT;
43 --echo # Ensure that online column rename works.
46 ALTER TABLE t1 CHANGE b c INT;
50 --echo # Test renaming the column in the referencing table
53 # mysqltest first does replace_regex, then replace_result
54 --replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
55 # Embedded server doesn't chdir to data directory
56 --replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ ''
57 --error ER_ERROR_ON_RENAME
58 ALTER TABLE t2 CHANGE a c INT;
60 --echo # Ensure that online column rename works.
63 ALTER TABLE t2 CHANGE b c INT;
67 --echo # Test with self-referential constraints
70 # mysqltest first does replace_regex, then replace_result
71 --replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
72 # Embedded server doesn't chdir to data directory
73 --replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ ''
74 --error ER_ERROR_ON_RENAME
75 ALTER TABLE t3 CHANGE a d INT;
77 # mysqltest first does replace_regex, then replace_result
78 --replace_regex /'[^']*test\/#sql-[0-9a-f_]*'/'#sql-temporary'/
79 # Embedded server doesn't chdir to data directory
80 --replace_result $MYSQLTEST_VARDIR . mysqld.1/data/ ''
81 --error ER_ERROR_ON_RENAME
82 ALTER TABLE t3 CHANGE b d INT;
84 --echo # Ensure that online column rename works.
87 ALTER TABLE t3 CHANGE c d INT;