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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 10 优化 / 10.5 InnoDB 表的优化 / 10.5.7 优化 InnoDB DDL 操作
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

10.5.7 优化 InnoDB DDL 操作10.5.7 Optimizing InnoDB DDL Operations

  • 表和索引上的许多 DDL 操作(CREATE、ALTER 和 DROP 语句)可以在线执行。有关详细信息,请参阅第 17.12 节“InnoDB 和在线 DDL”。Many DDL operations on tables and indexes (CREATE, ALTER, and DROP statements) can be performed online. See Section 17.12, “InnoDB and Online DDL” for details.

  • 在线 DDL 支持添加二级索引,这意味着您通常可以通过创建不带二级索引的表,然后在加载数据后添加二级索引来加快创建和加载表及关联索引的过程。Online DDL support for adding secondary indexes means that you can generally speed up the process of creating and loading a table and associated indexes by creating the table without secondary indexes, then adding secondary indexes after the data is loaded.

  • 使用 TRUNCATE TABLE 清空表,而不是 DELETE FROM tbl_name。外键约束可以使 TRUNCATE 语句像常规 DELETE 语句一样工作,在这种情况下,一系列命令如 DROP TABLE 和 CREATE TABLE 可能是最快的。Use TRUNCATE TABLE to empty a table, not DELETE FROM tbl_name. Foreign key constraints can make a TRUNCATE statement work like a regular DELETE statement, in which case a sequence of commands like DROP TABLE and CREATE TABLE might be fastest.

  • 由于主键是每个 InnoDB 表的存储布局不可或缺的一部分,并且更改主键的定义涉及重新组织整个表,因此始终将主键设置为 CREATE TABLE 语句,并提前计划,以便之后不需要 ALTER 或 DROP 主键。Because the primary key is integral to the storage layout of each InnoDB table, and changing the definition of the primary key involves reorganizing the whole table, always set up the primary key as part of the CREATE TABLE statement, and plan ahead so that you do not need to ALTER or DROP the primary key afterward.