| 1 |
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 2 |
INSERT INTO parent VALUES(1,2),(2,3); |
| 3 |
CREATE INDEX tb ON parent(b); |
| 4 |
INSERT INTO parent VALUES(10,20),(20,30); |
| 5 |
CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB; |
| 6 |
CREATE INDEX tb ON child(a2); |
| 7 |
INSERT INTO child VALUES(10,20); |
| 8 |
ALTER TABLE child ADD FOREIGN KEY(a2) REFERENCES parent(b), |
| 9 |
ALGORITHM = INPLACE; |
| 10 |
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Adding foreign keys needs foreign_key_checks=OFF. Try ALGORITHM=COPY |
| 11 |
SET foreign_key_checks = 0; |
| 12 |
ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2) |
| 13 |
REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, |
| 14 |
ALGORITHM = INPLACE; |
| 15 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 16 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 17 |
test/fk_1 test/child test/parent 1 6 |
| 18 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 19 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 20 |
test/fk_1 a2 b 0 |
| 21 |
ALTER TABLE child ADD CONSTRAINT fk_1 FOREIGN KEY (a2) |
| 22 |
REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, |
| 23 |
ALGORITHM = INPLACE; |
| 24 |
ERROR HY000: Duplicate FOREIGN KEY constraint name 'test/fk_1' |
| 25 |
SET foreign_key_checks = 1; |
| 26 |
INSERT INTO child VALUES(1,2),(2,3); |
| 27 |
INSERT INTO child VALUES(4,4); |
| 28 |
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) |
| 29 |
SELECT * FROM parent; |
| 30 |
a b |
| 31 |
1 2 |
| 32 |
2 3 |
| 33 |
10 20 |
| 34 |
20 30 |
| 35 |
SET foreign_key_checks = 0; |
| 36 |
ALTER TABLE child ADD CONSTRAINT fk_20 FOREIGN KEY (a1, a2) |
| 37 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 38 |
ALGORITHM = INPLACE; |
| 39 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_20' in the referenced table 'parent' |
| 40 |
SHOW WARNINGS; |
| 41 |
Level Code Message |
| 42 |
Error 1822 Failed to add the foreign key constraint. Missing index for constraint 'fk_20' in the referenced table 'parent' |
| 43 |
SHOW ERRORS; |
| 44 |
Level Code Message |
| 45 |
Error 1822 Failed to add the foreign key constraint. Missing index for constraint 'fk_20' in the referenced table 'parent' |
| 46 |
CREATE INDEX idx1 on parent(a, b); |
| 47 |
ALTER TABLE child ADD CONSTRAINT fk_10 FOREIGN KEY (a1, a2) |
| 48 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 49 |
ALGORITHM = INPLACE; |
| 50 |
ALTER TABLE child ADD CONSTRAINT fk_2 FOREIGN KEY (a1, a2) |
| 51 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, ADD INDEX idx1(a1,a2), |
| 52 |
ALGORITHM = INPLACE; |
| 53 |
ALTER TABLE child ADD CONSTRAINT fk_3 FOREIGN KEY (a1, a2) |
| 54 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE; |
| 55 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 56 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 57 |
test/fk_1 test/child test/parent 1 6 |
| 58 |
test/fk_10 test/child test/parent 2 5 |
| 59 |
test/fk_2 test/child test/parent 2 5 |
| 60 |
test/fk_3 test/child test/parent 2 5 |
| 61 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 62 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 63 |
test/fk_1 a2 b 0 |
| 64 |
test/fk_10 a1 a 0 |
| 65 |
test/fk_10 a2 b 1 |
| 66 |
test/fk_2 a1 a 0 |
| 67 |
test/fk_2 a2 b 1 |
| 68 |
test/fk_3 a1 a 0 |
| 69 |
test/fk_3 a2 b 1 |
| 70 |
SET foreign_key_checks = 1; |
| 71 |
INSERT INTO child VALUES(5,4); |
| 72 |
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) |
| 73 |
SHOW CREATE TABLE child; |
| 74 |
Table Create Table |
| 75 |
child CREATE TABLE `child` ( |
| 76 |
`a1` int(11) NOT NULL, |
| 77 |
`a2` int(11) DEFAULT NULL, |
| 78 |
PRIMARY KEY (`a1`), |
| 79 |
KEY `tb` (`a2`), |
| 80 |
KEY `idx1` (`a1`,`a2`), |
| 81 |
CONSTRAINT `fk_1` FOREIGN KEY (`a2`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 82 |
CONSTRAINT `fk_10` FOREIGN KEY (`a1`, `a2`) REFERENCES `parent` (`a`, `b`) ON DELETE CASCADE ON UPDATE CASCADE, |
| 83 |
CONSTRAINT `fk_2` FOREIGN KEY (`a1`, `a2`) REFERENCES `parent` (`a`, `b`) ON DELETE CASCADE ON UPDATE CASCADE, |
| 84 |
CONSTRAINT `fk_3` FOREIGN KEY (`a1`, `a2`) REFERENCES `parent` (`a`, `b`) ON DELETE CASCADE ON UPDATE CASCADE |
| 85 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 86 |
DELETE FROM parent where a = 1; |
| 87 |
SELECT * FROM child; |
| 88 |
a1 a2 |
| 89 |
1 NULL |
| 90 |
2 3 |
| 91 |
10 20 |
| 92 |
SET foreign_key_checks = 0; |
| 93 |
SET @saved_debug_dbug = @@SESSION.debug_dbug; |
| 94 |
SET DEBUG_DBUG = '+d,innodb_test_open_ref_fail'; |
| 95 |
ALTER TABLE child ADD CONSTRAINT fk_4 FOREIGN KEY (a1, a2) |
| 96 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 97 |
ALGORITHM = INPLACE; |
| 98 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 99 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 100 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 101 |
test/fk_1 test/child test/parent 1 6 |
| 102 |
test/fk_10 test/child test/parent 2 5 |
| 103 |
test/fk_2 test/child test/parent 2 5 |
| 104 |
test/fk_3 test/child test/parent 2 5 |
| 105 |
test/fk_4 test/child test/parent 2 5 |
| 106 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 107 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 108 |
test/fk_1 a2 b 0 |
| 109 |
test/fk_10 a1 a 0 |
| 110 |
test/fk_10 a2 b 1 |
| 111 |
test/fk_2 a1 a 0 |
| 112 |
test/fk_2 a2 b 1 |
| 113 |
test/fk_3 a1 a 0 |
| 114 |
test/fk_3 a2 b 1 |
| 115 |
test/fk_4 a1 a 0 |
| 116 |
test/fk_4 a2 b 1 |
| 117 |
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; |
| 118 |
name name |
| 119 |
test/child a1 |
| 120 |
test/child a2 |
| 121 |
SELECT NAME FROM information_schema.INNODB_SYS_TABLES; |
| 122 |
NAME |
| 123 |
SYS_FOREIGN |
| 124 |
SYS_FOREIGN_COLS |
| 125 |
SYS_VIRTUAL |
| 126 |
mysql/innodb_index_stats |
| 127 |
mysql/innodb_table_stats |
| 128 |
mysql/transaction_registry |
| 129 |
test/child |
| 130 |
test/parent |
| 131 |
INSERT INTO child VALUES(5,4); |
| 132 |
SET foreign_key_checks = 1; |
| 133 |
INSERT INTO child VALUES(6,5); |
| 134 |
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) |
| 135 |
SET foreign_key_checks = 0; |
| 136 |
CREATE TABLE `#parent` (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 137 |
CREATE INDEX tb ON `#parent`(a, b); |
| 138 |
CREATE TABLE `#child` (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB; |
| 139 |
CREATE INDEX tb ON `#child`(a1, a2); |
| 140 |
SET DEBUG_DBUG = '+d,innodb_test_no_foreign_idx'; |
| 141 |
ALTER TABLE `#child` ADD CONSTRAINT fk_40 FOREIGN KEY (a1, a2) |
| 142 |
REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 143 |
ALGORITHM = INPLACE; |
| 144 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_40' in the foreign table '#child' |
| 145 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 146 |
SHOW ERRORS; |
| 147 |
Level Code Message |
| 148 |
Error 1821 Failed to add the foreign key constraint. Missing index for constraint 'fk_40' in the foreign table '#child' |
| 149 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 150 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 151 |
test/fk_1 test/child test/parent 1 6 |
| 152 |
test/fk_10 test/child test/parent 2 5 |
| 153 |
test/fk_2 test/child test/parent 2 5 |
| 154 |
test/fk_3 test/child test/parent 2 5 |
| 155 |
test/fk_4 test/child test/parent 2 5 |
| 156 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 157 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 158 |
test/fk_1 a2 b 0 |
| 159 |
test/fk_10 a1 a 0 |
| 160 |
test/fk_10 a2 b 1 |
| 161 |
test/fk_2 a1 a 0 |
| 162 |
test/fk_2 a2 b 1 |
| 163 |
test/fk_3 a1 a 0 |
| 164 |
test/fk_3 a2 b 1 |
| 165 |
test/fk_4 a1 a 0 |
| 166 |
test/fk_4 a2 b 1 |
| 167 |
SET DEBUG_DBUG = '+d,innodb_test_no_reference_idx'; |
| 168 |
ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2) |
| 169 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 170 |
ALGORITHM = INPLACE; |
| 171 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_42' in the referenced table 'parent' |
| 172 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 173 |
SHOW ERRORS; |
| 174 |
Level Code Message |
| 175 |
Error 1822 Failed to add the foreign key constraint. Missing index for constraint 'fk_42' in the referenced table 'parent' |
| 176 |
SET DEBUG_DBUG = '+d,innodb_test_wrong_fk_option'; |
| 177 |
ALTER TABLE child ADD CONSTRAINT fk_42 FOREIGN KEY (a1, a2) |
| 178 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 179 |
ALGORITHM = INPLACE; |
| 180 |
ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'test/fk_42' |
| 181 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 182 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 183 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 184 |
test/fk_1 test/child test/parent 1 6 |
| 185 |
test/fk_10 test/child test/parent 2 5 |
| 186 |
test/fk_2 test/child test/parent 2 5 |
| 187 |
test/fk_3 test/child test/parent 2 5 |
| 188 |
test/fk_4 test/child test/parent 2 5 |
| 189 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 190 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 191 |
test/fk_1 a2 b 0 |
| 192 |
test/fk_10 a1 a 0 |
| 193 |
test/fk_10 a2 b 1 |
| 194 |
test/fk_2 a1 a 0 |
| 195 |
test/fk_2 a2 b 1 |
| 196 |
test/fk_3 a1 a 0 |
| 197 |
test/fk_3 a2 b 1 |
| 198 |
test/fk_4 a1 a 0 |
| 199 |
test/fk_4 a2 b 1 |
| 200 |
SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system'; |
| 201 |
ALTER TABLE `#child` ADD CONSTRAINT fk_43 FOREIGN KEY (a1, a2) |
| 202 |
REFERENCES `#parent`(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 203 |
ALGORITHM = INPLACE; |
| 204 |
ERROR HY000: Failed to add the foreign key constraint 'test/fk_43' to system tables |
| 205 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 206 |
SHOW ERRORS; |
| 207 |
Level Code Message |
| 208 |
Error 1823 Failed to add the foreign key constraint 'test/fk_43' to system tables |
| 209 |
DROP TABLE `#child`; |
| 210 |
DROP TABLE `#parent`; |
| 211 |
SET foreign_key_checks = 0; |
| 212 |
ALTER TABLE child ADD CONSTRAINT fk_5 FOREIGN KEY (a2) REFERENCES parent(b) |
| 213 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 214 |
ADD CONSTRAINT fk_6 FOREIGN KEY (a1, a2) |
| 215 |
REFERENCES parent(a, b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 216 |
ALGORITHM = INPLACE; |
| 217 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 218 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 219 |
test/fk_1 test/child test/parent 1 6 |
| 220 |
test/fk_10 test/child test/parent 2 5 |
| 221 |
test/fk_2 test/child test/parent 2 5 |
| 222 |
test/fk_3 test/child test/parent 2 5 |
| 223 |
test/fk_4 test/child test/parent 2 5 |
| 224 |
test/fk_5 test/child test/parent 1 6 |
| 225 |
test/fk_6 test/child test/parent 2 5 |
| 226 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 227 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 228 |
test/fk_1 a2 b 0 |
| 229 |
test/fk_10 a1 a 0 |
| 230 |
test/fk_10 a2 b 1 |
| 231 |
test/fk_2 a1 a 0 |
| 232 |
test/fk_2 a2 b 1 |
| 233 |
test/fk_3 a1 a 0 |
| 234 |
test/fk_3 a2 b 1 |
| 235 |
test/fk_4 a1 a 0 |
| 236 |
test/fk_4 a2 b 1 |
| 237 |
test/fk_5 a2 b 0 |
| 238 |
test/fk_6 a1 a 0 |
| 239 |
test/fk_6 a2 b 1 |
| 240 |
DROP TABLE child; |
| 241 |
DROP TABLE parent; |
| 242 |
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 243 |
INSERT INTO parent VALUES(1,2),(2,3); |
| 244 |
CREATE INDEX tb ON parent(b); |
| 245 |
INSERT INTO parent VALUES(10,20),(20,30); |
| 246 |
CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB; |
| 247 |
CREATE INDEX tb ON child(a2); |
| 248 |
INSERT INTO child VALUES(10,20); |
| 249 |
SET foreign_key_checks = 0; |
| 250 |
ALTER TABLE child DROP INDEX tb, ADD CONSTRAINT fk_4 FOREIGN KEY (a2) |
| 251 |
REFERENCES parent(b) ON DELETE CASCADE ON UPDATE CASCADE, |
| 252 |
ALGORITHM = INPLACE; |
| 253 |
SHOW CREATE TABLE child; |
| 254 |
Table Create Table |
| 255 |
child CREATE TABLE `child` ( |
| 256 |
`a1` int(11) NOT NULL, |
| 257 |
`a2` int(11) DEFAULT NULL, |
| 258 |
PRIMARY KEY (`a1`), |
| 259 |
KEY `fk_4` (`a2`), |
| 260 |
CONSTRAINT `fk_4` FOREIGN KEY (`a2`) REFERENCES `parent` (`b`) ON DELETE CASCADE ON UPDATE CASCADE |
| 261 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 262 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN; |
| 263 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 264 |
test/fk_4 test/child test/parent 1 5 |
| 265 |
SELECT * FROM information_schema.INNODB_SYS_FOREIGN_COLS; |
| 266 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 267 |
test/fk_4 a2 b 0 |
| 268 |
SET foreign_key_checks = 1; |
| 269 |
DROP TABLE child; |
| 270 |
DROP TABLE parent; |
| 271 |
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 272 |
INSERT INTO parent VALUES(1,2),(2,3); |
| 273 |
CREATE INDEX tb ON parent(b); |
| 274 |
INSERT INTO parent VALUES(10,20),(20,30); |
| 275 |
CREATE TABLE child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB; |
| 276 |
CREATE INDEX tb ON child(a2); |
| 277 |
SET foreign_key_checks = 0; |
| 278 |
ALTER TABLE child CHANGE a2 a3 INT, |
| 279 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) |
| 280 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 281 |
ALGORITHM = INPLACE; |
| 282 |
ERROR 42000: Key column 'a2' doesn't exist in table |
| 283 |
ALTER TABLE child CHANGE a2 a3 INT, |
| 284 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b) |
| 285 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 286 |
ALGORITHM = INPLACE; |
| 287 |
DROP TABLE child; |
| 288 |
DROP TABLE parent; |
| 289 |
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 290 |
INSERT INTO parent VALUES(1,2),(2,3); |
| 291 |
CREATE INDEX tb ON parent(b); |
| 292 |
INSERT INTO parent VALUES(10,20),(20,30); |
| 293 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB; |
| 294 |
CREATE INDEX tb ON child(a2); |
| 295 |
SET foreign_key_checks = 0; |
| 296 |
SET DEBUG_DBUG = '+d,innodb_test_cannot_add_fk_system'; |
| 297 |
ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, |
| 298 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) |
| 299 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 300 |
ALGORITHM = INPLACE; |
| 301 |
ERROR HY000: Failed to add the foreign key constraint 'test/fk_1' to system tables |
| 302 |
SET DEBUG_DBUG = @saved_debug_dbug; |
| 303 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; |
| 304 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 305 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; |
| 306 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 307 |
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; |
| 308 |
name name |
| 309 |
test/child a1 |
| 310 |
test/child a2 |
| 311 |
SELECT NAME FROM information_schema.INNODB_SYS_TABLES; |
| 312 |
NAME |
| 313 |
SYS_FOREIGN |
| 314 |
SYS_FOREIGN_COLS |
| 315 |
SYS_VIRTUAL |
| 316 |
mysql/innodb_index_stats |
| 317 |
mysql/innodb_table_stats |
| 318 |
mysql/transaction_registry |
| 319 |
test/child |
| 320 |
test/parent |
| 321 |
ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, |
| 322 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) |
| 323 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 324 |
ALGORITHM = INPLACE; |
| 325 |
Warnings: |
| 326 |
Warning 1280 Name 'idx' ignored for PRIMARY key. |
| 327 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; |
| 328 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 329 |
test/fk_1 test/child test/parent 1 6 |
| 330 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; |
| 331 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 332 |
test/fk_1 a2 b 0 |
| 333 |
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; |
| 334 |
name name |
| 335 |
test/child a2 |
| 336 |
test/child a3 |
| 337 |
SELECT NAME FROM information_schema.INNODB_SYS_TABLES; |
| 338 |
NAME |
| 339 |
SYS_FOREIGN |
| 340 |
SYS_FOREIGN_COLS |
| 341 |
SYS_VIRTUAL |
| 342 |
mysql/innodb_index_stats |
| 343 |
mysql/innodb_table_stats |
| 344 |
mysql/transaction_registry |
| 345 |
test/child |
| 346 |
test/parent |
| 347 |
SHOW CREATE TABLE child; |
| 348 |
Table Create Table |
| 349 |
child CREATE TABLE `child` ( |
| 350 |
`a3` int(11) NOT NULL, |
| 351 |
`a2` int(11) DEFAULT NULL, |
| 352 |
PRIMARY KEY (`a3`), |
| 353 |
KEY `tb` (`a2`), |
| 354 |
CONSTRAINT `fk_1` FOREIGN KEY (`a2`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE |
| 355 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 356 |
DROP TABLE child; |
| 357 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB; |
| 358 |
ALTER TABLE child ADD PRIMARY KEY idx (a1), |
| 359 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) |
| 360 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 361 |
ALGORITHM = INPLACE; |
| 362 |
Warnings: |
| 363 |
Warning 1280 Name 'idx' ignored for PRIMARY key. |
| 364 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 365 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 366 |
test/fk_1 test/child test/parent 1 6 |
| 367 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 368 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 369 |
test/fk_1 a2 b 0 |
| 370 |
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; |
| 371 |
name name |
| 372 |
test/child a1 |
| 373 |
test/child a2 |
| 374 |
SELECT NAME FROM information_schema.INNODB_SYS_TABLES; |
| 375 |
NAME |
| 376 |
SYS_FOREIGN |
| 377 |
SYS_FOREIGN_COLS |
| 378 |
SYS_VIRTUAL |
| 379 |
mysql/innodb_index_stats |
| 380 |
mysql/innodb_table_stats |
| 381 |
mysql/transaction_registry |
| 382 |
test/child |
| 383 |
test/parent |
| 384 |
SHOW CREATE TABLE child; |
| 385 |
Table Create Table |
| 386 |
child CREATE TABLE `child` ( |
| 387 |
`a1` int(11) NOT NULL, |
| 388 |
`a2` int(11) DEFAULT NULL, |
| 389 |
PRIMARY KEY (`a1`), |
| 390 |
KEY `fk_1` (`a2`), |
| 391 |
CONSTRAINT `fk_1` FOREIGN KEY (`a2`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE |
| 392 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 393 |
DROP TABLE child; |
| 394 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB; |
| 395 |
ALTER TABLE child CHANGE a1 a3 INT, |
| 396 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b) |
| 397 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 398 |
ALGORITHM = INPLACE; |
| 399 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 400 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 401 |
test/fk_1 test/child test/parent 1 6 |
| 402 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 403 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 404 |
test/fk_1 a3 b 0 |
| 405 |
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; |
| 406 |
name name |
| 407 |
test/child a2 |
| 408 |
test/child a3 |
| 409 |
SELECT NAME FROM information_schema.INNODB_SYS_TABLES; |
| 410 |
NAME |
| 411 |
SYS_FOREIGN |
| 412 |
SYS_FOREIGN_COLS |
| 413 |
SYS_VIRTUAL |
| 414 |
mysql/innodb_index_stats |
| 415 |
mysql/innodb_table_stats |
| 416 |
mysql/transaction_registry |
| 417 |
test/child |
| 418 |
test/parent |
| 419 |
SHOW CREATE TABLE child; |
| 420 |
Table Create Table |
| 421 |
child CREATE TABLE `child` ( |
| 422 |
`a3` int(11) DEFAULT NULL, |
| 423 |
`a2` int(11) DEFAULT NULL, |
| 424 |
KEY `fk_1` (`a3`), |
| 425 |
CONSTRAINT `fk_1` FOREIGN KEY (`a3`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE |
| 426 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 427 |
DROP TABLE child; |
| 428 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT) ENGINE = InnoDB; |
| 429 |
ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, |
| 430 |
ADD CONSTRAINT fk_1 FOREIGN KEY (a3) REFERENCES parent(b) |
| 431 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 432 |
ALGORITHM = INPLACE; |
| 433 |
ERROR HY000: Failed to add the foreign key constraint on table 'child'. Incorrect options in FOREIGN KEY constraint 'test/fk_1' |
| 434 |
DROP TABLE parent; |
| 435 |
DROP TABLE child; |
| 436 |
CREATE TABLE parent (a INT PRIMARY KEY, b INT NOT NULL, c INT) ENGINE = InnoDB; |
| 437 |
INSERT INTO parent VALUES(1,2,3),(2,3,4); |
| 438 |
CREATE INDEX tb ON parent(b); |
| 439 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB; |
| 440 |
CREATE INDEX tb ON child(a2); |
| 441 |
ALTER TABLE child |
| 442 |
ADD CONSTRAINT fk_a FOREIGN KEY (a2) REFERENCES parent(b) |
| 443 |
ON DELETE SET NULL ON UPDATE CASCADE, |
| 444 |
ALGORITHM = INPLACE; |
| 445 |
ALTER TABLE child |
| 446 |
ADD CONSTRAINT fk_b FOREIGN KEY (a1) REFERENCES parent(a), |
| 447 |
ALGORITHM = INPLACE; |
| 448 |
ALTER TABLE child CHANGE a2 a2_new INT, CHANGE a1 a1_new INT; |
| 449 |
SHOW CREATE TABLE child; |
| 450 |
Table Create Table |
| 451 |
child CREATE TABLE `child` ( |
| 452 |
`a1_new` int(11) DEFAULT NULL, |
| 453 |
`a2_new` int(11) DEFAULT NULL, |
| 454 |
`a3` int(11) DEFAULT NULL, |
| 455 |
KEY `tb` (`a2_new`), |
| 456 |
KEY `fk_b` (`a1_new`), |
| 457 |
CONSTRAINT `fk_a` FOREIGN KEY (`a2_new`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 458 |
CONSTRAINT `fk_b` FOREIGN KEY (`a1_new`) REFERENCES `parent` (`a`) |
| 459 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 460 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 461 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 462 |
test/fk_a test/child test/parent 1 6 |
| 463 |
test/fk_b test/child test/parent 1 0 |
| 464 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 465 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 466 |
test/fk_a a2_new b 0 |
| 467 |
test/fk_b a1_new a 0 |
| 468 |
ALTER TABLE child |
| 469 |
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b), |
| 470 |
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a), |
| 471 |
ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(c), |
| 472 |
ALGORITHM = INPLACE; |
| 473 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_new_3' in the referenced table 'parent' |
| 474 |
SHOW CREATE TABLE child; |
| 475 |
Table Create Table |
| 476 |
child CREATE TABLE `child` ( |
| 477 |
`a1_new` int(11) DEFAULT NULL, |
| 478 |
`a2_new` int(11) DEFAULT NULL, |
| 479 |
`a3` int(11) DEFAULT NULL, |
| 480 |
KEY `tb` (`a2_new`), |
| 481 |
KEY `fk_b` (`a1_new`), |
| 482 |
CONSTRAINT `fk_a` FOREIGN KEY (`a2_new`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 483 |
CONSTRAINT `fk_b` FOREIGN KEY (`a1_new`) REFERENCES `parent` (`a`) |
| 484 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 485 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 486 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 487 |
test/fk_a test/child test/parent 1 6 |
| 488 |
test/fk_b test/child test/parent 1 0 |
| 489 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 490 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 491 |
test/fk_a a2_new b 0 |
| 492 |
test/fk_b a1_new a 0 |
| 493 |
ALTER TABLE child |
| 494 |
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1_new) REFERENCES parent(b), |
| 495 |
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2_new) REFERENCES parent(a), |
| 496 |
ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(a), |
| 497 |
ALGORITHM = INPLACE; |
| 498 |
SHOW CREATE TABLE child; |
| 499 |
Table Create Table |
| 500 |
child CREATE TABLE `child` ( |
| 501 |
`a1_new` int(11) DEFAULT NULL, |
| 502 |
`a2_new` int(11) DEFAULT NULL, |
| 503 |
`a3` int(11) DEFAULT NULL, |
| 504 |
KEY `tb` (`a2_new`), |
| 505 |
KEY `fk_new_1` (`a1_new`), |
| 506 |
KEY `fk_new_3` (`a3`), |
| 507 |
CONSTRAINT `fk_a` FOREIGN KEY (`a2_new`) REFERENCES `parent` (`b`) ON DELETE SET NULL ON UPDATE CASCADE, |
| 508 |
CONSTRAINT `fk_b` FOREIGN KEY (`a1_new`) REFERENCES `parent` (`a`), |
| 509 |
CONSTRAINT `fk_new_1` FOREIGN KEY (`a1_new`) REFERENCES `parent` (`b`), |
| 510 |
CONSTRAINT `fk_new_2` FOREIGN KEY (`a2_new`) REFERENCES `parent` (`a`), |
| 511 |
CONSTRAINT `fk_new_3` FOREIGN KEY (`a3`) REFERENCES `parent` (`a`) |
| 512 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 513 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 514 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 515 |
test/fk_a test/child test/parent 1 6 |
| 516 |
test/fk_b test/child test/parent 1 0 |
| 517 |
test/fk_new_1 test/child test/parent 1 0 |
| 518 |
test/fk_new_2 test/child test/parent 1 0 |
| 519 |
test/fk_new_3 test/child test/parent 1 0 |
| 520 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 521 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 522 |
test/fk_a a2_new b 0 |
| 523 |
test/fk_b a1_new a 0 |
| 524 |
test/fk_new_1 a1_new b 0 |
| 525 |
test/fk_new_2 a2_new a 0 |
| 526 |
test/fk_new_3 a3 a 0 |
| 527 |
DROP TABLE child; |
| 528 |
CREATE TABLE child (a1 INT NOT NULL, a2 INT, a3 INT) ENGINE = InnoDB; |
| 529 |
CREATE INDEX tb ON child(a2); |
| 530 |
ALTER TABLE child ADD PRIMARY KEY idx (a1), |
| 531 |
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1) REFERENCES parent(b), |
| 532 |
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2) REFERENCES parent(a), |
| 533 |
ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(c), |
| 534 |
ALGORITHM = INPLACE; |
| 535 |
ERROR HY000: Failed to add the foreign key constraint. Missing index for constraint 'fk_new_3' in the referenced table 'parent' |
| 536 |
SHOW CREATE TABLE child; |
| 537 |
Table Create Table |
| 538 |
child CREATE TABLE `child` ( |
| 539 |
`a1` int(11) NOT NULL, |
| 540 |
`a2` int(11) DEFAULT NULL, |
| 541 |
`a3` int(11) DEFAULT NULL, |
| 542 |
KEY `tb` (`a2`) |
| 543 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 544 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 545 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 546 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 547 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 548 |
ALTER TABLE child ADD PRIMARY KEY idx (a1), |
| 549 |
ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1) REFERENCES parent(b), |
| 550 |
ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2) REFERENCES parent(a), |
| 551 |
ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(a), |
| 552 |
ALGORITHM = INPLACE; |
| 553 |
Warnings: |
| 554 |
Warning 1280 Name 'idx' ignored for PRIMARY key. |
| 555 |
SHOW CREATE TABLE child; |
| 556 |
Table Create Table |
| 557 |
child CREATE TABLE `child` ( |
| 558 |
`a1` int(11) NOT NULL, |
| 559 |
`a2` int(11) DEFAULT NULL, |
| 560 |
`a3` int(11) DEFAULT NULL, |
| 561 |
PRIMARY KEY (`a1`), |
| 562 |
KEY `tb` (`a2`), |
| 563 |
KEY `fk_new_3` (`a3`), |
| 564 |
CONSTRAINT `fk_new_1` FOREIGN KEY (`a1`) REFERENCES `parent` (`b`), |
| 565 |
CONSTRAINT `fk_new_2` FOREIGN KEY (`a2`) REFERENCES `parent` (`a`), |
| 566 |
CONSTRAINT `fk_new_3` FOREIGN KEY (`a3`) REFERENCES `parent` (`a`) |
| 567 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 568 |
SELECT * from information_schema.INNODB_SYS_FOREIGN; |
| 569 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 570 |
test/fk_new_1 test/child test/parent 1 0 |
| 571 |
test/fk_new_2 test/child test/parent 1 0 |
| 572 |
test/fk_new_3 test/child test/parent 1 0 |
| 573 |
SELECT * from information_schema.INNODB_SYS_FOREIGN_COLS; |
| 574 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 575 |
test/fk_new_1 a1 b 0 |
| 576 |
test/fk_new_2 a2 a 0 |
| 577 |
test/fk_new_3 a3 a 0 |
| 578 |
SET foreign_key_checks = 1; |
| 579 |
DROP TABLE child; |
| 580 |
DROP TABLE parent; |
| 581 |
CREATE TABLE Parent (a INT PRIMARY KEY, b INT NOT NULL) ENGINE = InnoDB; |
| 582 |
INSERT INTO Parent VALUES(1,2),(2,3); |
| 583 |
CREATE INDEX tb ON Parent(b); |
| 584 |
INSERT INTO Parent VALUES(10,20),(20,30); |
| 585 |
CREATE TABLE Child (a1 INT PRIMARY KEY, a2 INT) ENGINE = InnoDB; |
| 586 |
CREATE INDEX tb ON Child(a2); |
| 587 |
INSERT INTO Child VALUES(10,20); |
| 588 |
SET foreign_key_checks = 0; |
| 589 |
ALTER TABLE Child ADD CONSTRAINT fk_1 FOREIGN KEY (a2) |
| 590 |
REFERENCES Parent(b) ON DELETE SET NULL ON UPDATE CASCADE, |
| 591 |
ALGORITHM = INPLACE; |
| 592 |
DROP TABLE Child; |
| 593 |
DROP TABLE Parent; |
| 594 |
CREATE TABLE `t2`(a int,c int,d int) ENGINE=INNODB; |
| 595 |
CREATE TABLE `t3`(a int,c int,d int) ENGINE=INNODB; |
| 596 |
CREATE INDEX idx ON t3(a); |
| 597 |
ALTER TABLE `t2` ADD CONSTRAINT `fw` FOREIGN KEY (`c`) REFERENCES t3 (a); |
| 598 |
ALTER TABLE `t2` ADD CONSTRAINT `e` foreign key (`d`) REFERENCES t3(a); |
| 599 |
ALTER TABLE `t3` ADD CONSTRAINT `e` foreign key (`c`) REFERENCES `t2`(`c`) ON UPDATE SET NULL; |
| 600 |
ERROR HY000: Failed to add the foreign key constraint 'test/e' to system tables |
| 601 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; |
| 602 |
ID FOR_NAME REF_NAME N_COLS TYPE |
| 603 |
test/e test/t2 test/t3 1 0 |
| 604 |
test/fw test/t2 test/t3 1 0 |
| 605 |
SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS; |
| 606 |
ID FOR_COL_NAME REF_COL_NAME POS |
| 607 |
test/e d a 0 |
| 608 |
test/fw c a 0 |
| 609 |
DROP TABLE t2; |
| 610 |
DROP TABLE t3; |
| 611 |
# Bug #17449901 TABLE DISAPPEARS WHEN ALTERING |
| 612 |
# WITH FOREIGN KEY CHECKS OFF |
| 613 |
create table t1(f1 int,primary key(f1))engine=innodb; |
| 614 |
create table t2(f2 int,f3 int,key t(f2,f3),foreign key(f2) references t1(f1))engine=innodb; |
| 615 |
SET foreign_key_checks=0; |
| 616 |
drop index t on t2; |
| 617 |
drop table t2; |
| 618 |
drop table t1; |
| 619 |
create table t1(f1 int ,primary key(f1))engine=innodb; |
| 620 |
create table t2(f2 int,f3 int, key t(f2),foreign key(f2) references t1(f1))engine=innodb; |
| 621 |
SET foreign_key_checks = 0; |
| 622 |
alter table t2 drop key t,algorithm=inplace; |
| 623 |
show create table t2; |
| 624 |
Table Create Table |
| 625 |
t2 CREATE TABLE `t2` ( |
| 626 |
`f2` int(11) DEFAULT NULL, |
| 627 |
`f3` int(11) DEFAULT NULL, |
| 628 |
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) |
| 629 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 630 |
drop table t2; |
| 631 |
drop table t1; |
| 632 |
create table t1(f1 int ,primary key(f1))engine=innodb; |
| 633 |
create table t2(f2 int,f3 int, key t(f2),key t1(f2,f3), |
| 634 |
foreign key(f2) references t1(f1))engine=innodb; |
| 635 |
SET foreign_key_checks = 0; |
| 636 |
alter table t2 drop key t,algorithm=inplace; |
| 637 |
show create table t2; |
| 638 |
Table Create Table |
| 639 |
t2 CREATE TABLE `t2` ( |
| 640 |
`f2` int(11) DEFAULT NULL, |
| 641 |
`f3` int(11) DEFAULT NULL, |
| 642 |
KEY `t1` (`f2`,`f3`), |
| 643 |
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) |
| 644 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 645 |
drop table t2; |
| 646 |
drop table t1; |
| 647 |
# |
| 648 |
# MDEV-29092 FOREIGN_KEY_CHECKS does not prevent non-copy |
| 649 |
# alter from creating invalid FK structures |
| 650 |
# |
| 651 |
CREATE TABLE t1(f1 INT, KEY(f1), |
| 652 |
FOREIGN KEY(f1) references t1(f1))ENGINE=InnoDB; |
| 653 |
SHOW CREATE TABLE t1; |
| 654 |
Table Create Table |
| 655 |
t1 CREATE TABLE `t1` ( |
| 656 |
`f1` int(11) DEFAULT NULL, |
| 657 |
KEY `f1` (`f1`), |
| 658 |
CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) |
| 659 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 660 |
DROP TABLE t1; |
| 661 |
CREATE TABLE t1(f1 INT, KEY(f1), |
| 662 |
FOREIGN KEY(f1) REFERENCES t1(f1))ENGINE=InnoDB; |
| 663 |
SHOW CREATE TABLE t1; |
| 664 |
Table Create Table |
| 665 |
t1 CREATE TABLE `t1` ( |
| 666 |
`f1` int(11) DEFAULT NULL, |
| 667 |
KEY `f1` (`f1`), |
| 668 |
CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) |
| 669 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 670 |
ALTER TABLE t1 DROP KEY f1; |
| 671 |
SHOW CREATE TABLE t1; |
| 672 |
Table Create Table |
| 673 |
t1 CREATE TABLE `t1` ( |
| 674 |
`f1` int(11) DEFAULT NULL, |
| 675 |
CONSTRAINT `t1_ibfk_1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) |
| 676 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci |
| 677 |
DROP TABLE t1; |