下文概述了在线 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 ofinnodb_sort_buffer_sizeup to a maximum specified byinnodb_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 ofinnodb_online_alter_log_max_size, the online DDL operation fails with aDB_ONLINE_LOG_TOO_BIGerror, and uncommitted concurrent DML operations are rolled back. A largeinnodb_online_alter_log_max_sizesetting 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变量还定义了临时日志文件读取缓冲区和写入缓冲区的大小。Theinnodb_sort_buffer_sizevariable 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 ($TMPDIRon 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, settmpdirto a different directory. Alternatively, define a separate temporary directory for online DDL operations usinginnodb_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-ibprefix and only appear briefly during the online DDL operation.innodb_tmpdir选项不适用于中间表文件。Theinnodb_tmpdiroption is not applicable to intermediate table files.