MySQL警告: primary key and index on the same field in MYSQL

标签 mysql indexing

mysql warning : primary key and index on the same field in MYSQL .

正如在理论书籍中这两个术语用于解释索引一样,但在实践中,当我尝试在也是主键的特定字段上创建索引时,MySQL 会生成警告,尽管索引已创建。

谁能解释一下吗?

最佳答案

主键已经意味着构成该键的列集上的索引,因此需要第二个(单独的)索引 is redundant :

The primary key for a table represents the column or set of columns that you use in your most vital queries. It has an associated index, for fast query performance.

因此,通过创建显式索引,您不会获得任何好处,反而会让数据库承担维护两个单独索引的责任。

关于MySQL警告: primary key and index on the same field in MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19209863/

相关文章:

php - CI MySQL 查询连接表和 where 语句不返回所有行

mysql - 与加入映射时的用例

mysql - 从转储文件恢复数据库时如何记录sql错误

mysql - 从具有一对多关系的 3 个表中选择

MySQL 索引 - 根据此表和查询的最佳实践是什么

django - 在 Django 中使用 trigram 进行文本搜索

python - 如何从 python 列表中删除特定索引

sql - SQL Server如何将索引从一个表复制到另一个表

mysql - 为什么我的索引没有在 mysql 选择中使用

android - Android 中的循环 ImageView