-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create index doesn't rename the old index that has same columns as the new one #43267
Comments
Another case: DDL: CREATE TABLE `User` (
`id` INTEGER AUTO_INCREMENT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `Post` (
`id` INTEGER AUTO_INCREMENT NOT NULL,
`user_id` INTEGER NOT NULL,
CONSTRAINT CustomFKName FOREIGN KEY (`user_id`) REFERENCES `User`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE,
PRIMARY KEY (`id`)
);
CREATE INDEX `Post_user_id_idx` ON `Post` (`user_id`); TiDB: Both indexes are retained ( tidb> show create table Post\G
*************************** 1. row ***************************
Table: Post
Create Table: CREATE TABLE `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */,
KEY `CustomFKName` (`user_id`),
KEY `Post_user_id_idx` (`user_id`),
CONSTRAINT `CustomFKName` FOREIGN KEY (`user_id`) REFERENCES `t3`.`User` (`id`) ON DELETE RESTRICT ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
1 row in set (0.01 sec) MySQL: The old index mysql> show create table Post\G
*************************** 1. row ***************************
Table: Post
Create Table: CREATE TABLE `Post` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
PRIMARY KEY (`id`),
KEY `Post_user_id_idx` (`user_id`),
CONSTRAINT `CustomFKName` FOREIGN KEY (`user_id`) REFERENCES `User` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1
1 row in set (0.05 sec) |
Nice catch. This is a compatibility issue with MySQL, But this doesn't affect correctness. If necessary, I might fix it in the future. |
/type compatibility |
/assign |
Since this compatibility issue doesn't affect correctness, and the behavior of MySQL is a bit strange, I don't plan to fix this issue currently, if you have a rush demand, please leave a comment describing your needs and problem scenarios. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
2. What did you expect to see? (Required)
The first index name
fk_1
has been renamed tofk_2
.3. What did you see instead (Required)
The first index name
fk_1
remains unchanged.4. What is your TiDB version? (Required)
The text was updated successfully, but these errors were encountered: