MySQL - 索引innodb外键(MySQL - indexing innodb foreign keys)
InnoDB中索引外键的性能有所改善吗? 据我所知,InnoDB会自动为外键创建索引。
这是给我创建表的查询。
DROP TABLE IF EXISTS `assignments`; CREATE TABLE `assignments` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `user` INTEGER NOT NULL, `job` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `job_fk1` (`user`), INDEX `job_fk2` (`job`), CONSTRAINT `job_fk1` FOREIGN KEY (`user`) REFERENCES `users` (`id`), CONSTRAINT `job_fk2` FOREIGN KEY (`job`) REFERENCES `jobs` (`id`) ) ENGINE=InnoDB;
在那里,他创建了名为job_fk1和job_fk2的外键。 他使用这些外键的名称作为索引的名称。
Is there an improvement in performance in indexing foreign keys in InnoDB? As far as I have read, InnoDB automatically creates an index for the foreign key.
Here is the query given to me for creating the table.
DROP TABLE IF EXISTS `assignments`; CREATE TABLE `assignments` ( `id` INTEGER NOT NULL AUTO_INCREMENT, `user` INTEGER NOT NULL, `job` INTEGER NOT NULL, `created_at` DATETIME, `updated_at` DATETIME, PRIMARY KEY (`id`), INDEX `job_fk1` (`user`), INDEX `job_fk2` (`job`), CONSTRAINT `job_fk1` FOREIGN KEY (`user`) REFERENCES `users` (`id`), CONSTRAINT `job_fk2` FOREIGN KEY (`job`) REFERENCES `jobs` (`id`) ) ENGINE=InnoDB;
In there, he created foreign keys named job_fk1 and job_fk2. He used the names of these foreign keys as the name of the index.
原文:https://stackoverflow.com/questions/28977982
更新时间:2022-04-10 14:04