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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

17.12.3 在线 DDL 空间需求17.12.3 Online DDL Space Requirements

下文概述了在线 DDL 操作的磁盘空间需求。此需求不适用于即时执行的操作。Disk space requirements for online DDL operations are outlined below. The requirements do not apply to operations that are performed instantly.

  • 临时日志文件:Temporary log files:

    当在线 DDL 操作创建索引或修改表时,临时日志文件会记录并发的 DML。根据 innodb_sort_buffer_size 的值,临时日志文件会根据需要进行扩展,最大不超过 innodb_online_alter_log_max_size 指定的值。如果操作耗时较长,并发 DML 修改表的程度使临时日志文件的大小超过 innodb_online_alter_log_max_size 的值,则在线 DDL 操作会失败,并返回 DB_ONLINE_LOG_TOO_BIG 错误,未提交的并发 DML 操作会被回滚。较大的 innodb_online_alter_log_max_size 设置允许在在线 DDL 操作期间执行更多的 DML,但也会延长 DDL 操作结束时表被锁定以应用已记录 DML 的时间。A temporary log file records concurrent DML when an online DDL operation creates an index or alters a table. The temporary log file is extended as required by the value of innodb_sort_buffer_size up to a maximum specified by innodb_online_alter_log_max_size. If the operation takes a long time and concurrent DML modifies the table so much that the size of the temporary log file exceeds the value of innodb_online_alter_log_max_size, the online DDL operation fails with a DB_ONLINE_LOG_TOO_BIG error, and uncommitted concurrent DML operations are rolled back. A large innodb_online_alter_log_max_size setting permits more DML during an online DDL operation, but it also extends the period of time at the end of the DDL operation when the table is locked to apply logged DML.

    innodb_sort_buffer_size 变量还定义了临时日志文件读取缓冲区和写入缓冲区的大小。The innodb_sort_buffer_size variable also defines the size of the temporary log file read buffer and write buffer.

  • 临时排序文件:Temporary sort files:

    在重建表的在线 DDL 操作中,会在 MySQL 临时目录中写入临时排序文件(Unix 上为 $TMPDIR,Windows 上为 %TEMP%,或者由 --tmpdir 指定的目录),用于索引创建。临时排序文件不会在包含原始表的目录中创建。每个临时排序文件足够大,可以容纳一列数据,并且在其数据合并到最终表或索引时,会删除该排序文件。涉及临时排序文件的操作可能需要的临时空间等于表及索引中数据的总量。如果在线 DDL 操作使用了数据目录所在文件系统的所有可用磁盘空间,将报告错误。Online DDL operations that rebuild the table write temporary sort files to the MySQL temporary directory ($TMPDIR on Unix, %TEMP% on Windows, or the directory specified by --tmpdir) during index creation. Temporary sort files are not created in the directory that contains the original table. Each temporary sort file is large enough to hold one column of data, and each sort file is removed when its data is merged into the final table or index. Operations involving temporary sort files may require temporary space equal to the amount of data in the table plus indexes. An error is reported if online DDL operation uses all of the available disk space on the file system where the data directory resides.

    如果 MySQL 临时目录不足以容纳排序文件,请将 tmpdir 设置为其他目录。或者,使用 innodb_tmpdir 为在线 DDL 操作定义一个单独的临时目录。引入此选项是为了帮助避免由于大型临时排序文件导致的临时目录溢出。If the MySQL temporary directory is not large enough to hold the sort files, set tmpdir to a different directory. Alternatively, define a separate temporary directory for online DDL operations using innodb_tmpdir. This option was introduced to help avoid temporary directory overflows that could occur as a result of large temporary sort files.

  • 中间表文件:Intermediate table files:

    某些重建表的在线 DDL 操作会在与原始表相同的目录中创建临时中间表文件。中间表文件可能需要与原始表相同大小的空间。中间表文件名以 #sql-ib 前缀开头,并且仅在在线 DDL 操作期间短暂出现。Some online DDL operations that rebuild the table create a temporary intermediate table file in the same directory as the original table. An intermediate table file may require space equal to the size of the original table. Intermediate table file names begin with #sql-ib prefix and only appear briefly during the online DDL operation.

    innodb_tmpdir 选项不适用于中间表文件。The innodb_tmpdir option is not applicable to intermediate table files.