mysql - MySQL InnoDB 是否总是需要为每个外键约束创建一个索引?

标签 mysql foreign-keys innodb

我正在使用 phpMyAdmin。为了使用 InnoDB 设置外键约束(在“结构”选项卡上的“关系 View ”链接下),看来我需要为要添加约束的字段添加索引。这显然会对表的插入/更新性能产生影响,尤其是当我想添加多个约束时。是否可以在不需要为所需字段创建索引的情况下在 InnoDB 中指定外键约束或关系完整性?

非常感谢 JS,伦敦

最佳答案

来自MySQL reference manual :

InnoDB requires indexes on foreign keys and referenced keys so that foreign key checks can be fast and not require a table scan. In the referencing table, there must be an index where the foreign key columns are listed as the first columns in the same order. Such an index is created on the referencing table automatically if it does not exist. (This is in contrast to some older versions, in which indexes had to be created explicitly or the creation of foreign key constraints would fail.)

关于mysql - MySQL InnoDB 是否总是需要为每个外键约束创建一个索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1721841/

相关文章:

mysql - 如果我的 SQL 脚本更改,我如何让我的 Liquibase 变更集运行?

PHP 从 gridview 编辑行

sql - 无法解释此错误: there is no unique constraint matching given keys for referenced table

c - 使用与文件 B 共享的元素(外键)访问文件 A 中的数据

jquery - 是否可以使用 jquery post 或 get 请求来保存访客统计信息?

Mysql,检索超过X天的记录

php 分解一个数组(一列)并将其放入 mysql(不同的列)

postgresql - 添加主键 : Table contains duplicated values

mysql - 如何加快Mysql中日期时间的查询速度

mysql - 为什么 MySQL 在使用 DATE (`table` .`column` 时会删除我的索引)