mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 13:45:12 +02:00

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
89 lines
2.7 KiB
Text
89 lines
2.7 KiB
Text
#
|
|
# Bug#21704: Renaming column does not update FK definition.
|
|
#
|
|
|
|
# Test that it's not possible to rename columns participating in a
|
|
# foreign key (either in the referencing or referenced table).
|
|
|
|
CREATE TABLE t1 (a INT PRIMARY KEY, b INT) ROW_FORMAT=COMPACT ENGINE=INNODB;
|
|
CREATE TABLE t2 (a INT PRIMARY KEY, b INT,
|
|
CONSTRAINT fk1 FOREIGN KEY (a) REFERENCES t1(a))
|
|
ROW_FORMAT=COMPACT ENGINE=INNODB;
|
|
CREATE TABLE t3 (a INT PRIMARY KEY, b INT, KEY(b), C INT,
|
|
CONSTRAINT fk2 FOREIGN KEY (b) REFERENCES t3 (a))
|
|
ROW_FORMAT=COMPACT ENGINE=INNODB;
|
|
INSERT INTO t1 VALUES (1,1),(2,2),(3,3);
|
|
INSERT INTO t2 VALUES (1,1),(2,2),(3,3);
|
|
INSERT INTO t3 VALUES (1,1,1),(2,2,2),(3,3,3);
|
|
|
|
# Test renaming the column in the referenced table.
|
|
|
|
ALTER TABLE t1 CHANGE a e INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
# Ensure that online column rename works.
|
|
ALTER TABLE t1 CHANGE b c INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
|
|
# Test renaming the column in the referencing table
|
|
|
|
ALTER TABLE t2 CHANGE a z INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
# Ensure that online column rename works.
|
|
ALTER TABLE t2 CHANGE b c INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
|
|
# Test with self-referential constraints
|
|
|
|
ALTER TABLE t3 CHANGE a f INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
ALTER TABLE t3 CHANGE b g INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
# Ensure that online column rename works.
|
|
ALTER TABLE t3 CHANGE c d INT;
|
|
affected rows: 0
|
|
info: Records: 0 Duplicates: 0 Warnings: 0
|
|
|
|
# Cleanup.
|
|
|
|
SHOW CREATE TABLE t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`e` int(11) NOT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`e`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ROW_FORMAT=COMPACT
|
|
SHOW CREATE TABLE t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`z` int(11) NOT NULL,
|
|
`c` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`z`),
|
|
CONSTRAINT `fk1` FOREIGN KEY (`z`) REFERENCES `t1` (`e`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ROW_FORMAT=COMPACT
|
|
SHOW CREATE TABLE t3;
|
|
Table Create Table
|
|
t3 CREATE TABLE `t3` (
|
|
`f` int(11) NOT NULL,
|
|
`g` int(11) DEFAULT NULL,
|
|
`d` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f`),
|
|
KEY `b` (`g`),
|
|
CONSTRAINT `fk2` FOREIGN KEY (`g`) REFERENCES `t3` (`f`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ROW_FORMAT=COMPACT
|
|
SELECT f.*, c.*
|
|
FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN_COLS c
|
|
INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_FOREIGN f
|
|
ON c.ID=f.ID
|
|
WHERE FOR_NAME LIKE 'test/t%';
|
|
ID FOR_NAME REF_NAME N_COLS TYPE ID FOR_COL_NAME REF_COL_NAME POS
|
|
fk1 test/t2 test/t1 1 0 fk1 z e 0
|
|
fk2 test/t3 test/t3 1 0 fk2 g f 0
|
|
DROP TABLE t3;
|
|
DROP TABLE t2;
|
|
DROP TABLE t1;
|