文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.3.2 主键优化10.3.2 Primary Key Optimization

表的主键代表您在最重要查询中使用的列或列集合。它有一个关联的索引,以提高查询性能。查询性能受益于 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.

如果你的表很大且重要,但没有明显的列或列集可用作主键,你可以创建一个带有自增值的单独列作为主键。这些唯一的 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.