主键是否会加速索引? [英] does a primary key speed up an index?

查看:164
本文介绍了主键是否会加速索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了方便的自动增量和 UNIQUE 功能外,PK实际上是否加快了索引?

Aside from the convenient auto-increment and UNIQUE features, does the PK actually speed up the index?

无论是非PKed索引 INT 还是PKed(同一列,两个不同的测试),速度是否相同?如果我在同一系统上的同一个表上有相同的列,如果 UNIQUE INT 列,它会更快吗?一个索引也启用了PK? PK会使指数与它共存的速度更快吗?

Will the speed be the same whether it's a non-PKed indexed INT or PKed (same column, two different tests)? If I had the same column on the same table on the same system, will it be faster if a UNIQUE INT column with an index also has PK enabled? Does PK make the index it coexists with faster?

请实际结果只有系统统计信息才能如此善良。

Please, actual results only with system stats if you could be so kind.

推荐答案

表格的主键表示您在重要查询中使用的列或列集。它具有关联索引,用于快速查询性能。查询性能受益于 NOT NULL优化,因为它不能包含任何 NULL 值。使用 InnoDB存储引擎,表格数据物理组织为超快速查找,并根据主键列进行排序。

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. Query performance benefits from the NOT NULL optimization, because it cannot include any NULL values. With the InnoDB storage engine, the table data is physically organized to do ultra-fast lookups and sorts based on the primary key column or columns.

如果您的表很大且很重要,但没有明显的列或列集用作主键,您可以使用auto-创建一个单独的列增量值用作主键。当您使用外键连接表时,这些唯一ID 可以作为指针用于其他表中的相应行。

If your table is big and important, but does not have an obvious column or set of columns to use as a primary key, you might create a separate column with auto-increment values to use as the primary key. These unique IDs can serve as pointers to corresponding rows in other tables when you join tables using foreign keys.

另请参阅以下位置: http ://www.dbasquare.com/2012/04/04/how-important-a-primary-key-can-be-for-mysql-performance/ http://www.w3schools.com/sql/sql_primarykey.asp

Also refer the following locations : http://www.dbasquare.com/2012/04/04/how-important-a-primary-key-can-be-for-mysql-performance/ and http://www.w3schools.com/sql/sql_primarykey.asp

这篇关于主键是否会加速索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆