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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 17 InnoDB 存储引擎 / 17.16 InnoDB 与 MySQL 性能模式集成 / 17.16.1 使用性能模式监控 InnoDB 表的 ALTER TABLE 进度
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

17.16.1 使用性能模式监控 InnoDB 表的 ALTER TABLE 进度17.16.1 Monitoring ALTER TABLE Progress for InnoDB Tables Using Performance Schema

您可以使用 性能模式 来监控 InnoDB 表的 ALTER TABLE 进度。You can monitor ALTER TABLE progress for InnoDB tables using Performance Schema.

有七个阶段事件,表示 ALTER TABLE 的不同阶段。每个阶段事件都报告了整体 ALTER TABLE 操作在其不同阶段的 WORK_COMPLETED 和 WORK_ESTIMATED 的累计值。WORK_ESTIMATED 是使用一个考虑了 ALTER TABLE 执行的所有工作量的公式计算出来的,并可能在 ALTER TABLE 处理过程中进行修正。WORK_COMPLETED 和 WORK_ESTIMATED 值是 ALTER TABLE 执行的所有工作的抽象表示。There are seven stage events that represent different phases of ALTER TABLE. Each stage event reports a running total of WORK_COMPLETED and WORK_ESTIMATED for the overall ALTER TABLE operation as it progresses through its different phases. WORK_ESTIMATED is calculated using a formula that takes into account all of the work that ALTER TABLE performs, and may be revised during ALTER TABLE processing. WORK_COMPLETED and WORK_ESTIMATED values are an abstract representation of all of the work performed by ALTER TABLE.

按照发生顺序,ALTER TABLE 阶段事件包括:In order of occurrence, ALTER TABLE stage events include:

  • stage/innodb/alter table (read PK and internal sort):当 ALTER TABLE 处于读取主键阶段时,该阶段处于活动状态。它以 WORK_COMPLETED=0 开始,并且 WORK_ESTIMATED 设置为主键中估计的页面数量。当该阶段完成时,WORK_ESTIMATED 会更新为主键中的实际页面数量。stage/innodb/alter table (read PK and internal sort): This stage is active when ALTER TABLE is in the reading-primary-key phase. It starts with WORK_COMPLETED=0 and WORK_ESTIMATED set to the estimated number of pages in the primary key. When the stage is completed, WORK_ESTIMATED is updated to the actual number of pages in the primary key.

  • stage/innodb/alter table (merge sort):此阶段会针对每个由 ALTER TABLE 操作添加的索引重复执行。stage/innodb/alter table (merge sort): This stage is repeated for each index added by the ALTER TABLE operation.

  • stage/innodb/alter table (insert):此阶段会针对每个由 ALTER TABLE 操作添加的索引重复执行。stage/innodb/alter table (insert): This stage is repeated for each index added by the ALTER TABLE operation.

  • stage/innodb/alter table (log apply index):此阶段包括在运行 ALTER TABLE 时生成的 DML 日志的应用。stage/innodb/alter table (log apply index): This stage includes the application of DML log generated while ALTER TABLE was running.

  • stage/innodb/alter table (flush):在此阶段开始之前,WORK_ESTIMATED 会根据刷新列表的长度更新为更准确的估计值。stage/innodb/alter table (flush): Before this stage begins, WORK_ESTIMATED is updated with a more accurate estimate, based on the length of the flush list.

  • stage/innodb/alter table (log apply table):此阶段包括应用在 ALTER TABLE 运行期间生成的并发 DML 日志。此阶段的持续时间取决于表更改的范围。如果表上没有运行并发 DML,则此阶段是瞬时的。stage/innodb/alter table (log apply table): This stage includes the application of concurrent DML log generated while ALTER TABLE was running. The duration of this phase depends on the extent of table changes. This phase is instant if no concurrent DML was run on the table.

  • stage/innodb/alter table (end):包括刷新阶段后出现的任何剩余工作,例如重新应用在 ALTER TABLE 运行期间在表上执行的 DML。stage/innodb/alter table (end): Includes any remaining work that appeared after the flush phase, such as reapplying DML that was executed on the table while ALTER TABLE was running.

Note

InnoDB ALTER TABLE 阶段事件当前尚未考虑空间索引的添加。InnoDB ALTER TABLE stage events do not currently account for the addition of spatial indexes.

使用性能模式监控 ALTER TABLE 的示例ALTER TABLE Monitoring Example Using Performance Schema

下面的示例演示了如何启用 stage/innodb/alter table% 阶段事件工具和相关的消费者表来监控 ALTER TABLE 的进度。有关性能模式阶段事件工具和相关消费者的信息,请参阅第 29.12.5 节,“性能模式阶段事件表”。The following example demonstrates how to enable the stage/innodb/alter table% stage event instruments and related consumer tables to monitor ALTER TABLE progress. For information about Performance Schema stage event instruments and related consumers, see Section 29.12.5, “Performance Schema Stage Event Tables”.

  1. 启用 stage/innodb/alter% 工具:Enable the stage/innodb/alter% instruments:

    mysql> UPDATE performance_schema.setup_instruments
           SET ENABLED = 'YES'
           WHERE NAME LIKE 'stage/innodb/alter%';
    Query OK, 7 rows affected (0.00 sec)
    Rows matched: 7  Changed: 7  Warnings: 0
    
  2. 启用阶段事件消费者表,其中包括 events_stages_current、events_stages_history 和 events_stages_history_long。Enable the stage event consumer tables, which include events_stages_current, events_stages_history, and events_stages_history_long.

    mysql> UPDATE performance_schema.setup_consumers
           SET ENABLED = 'YES'
           WHERE NAME LIKE '%stages%';
    Query OK, 3 rows affected (0.00 sec)
    Rows matched: 3  Changed: 3  Warnings: 0
    
  3. 执行 ALTER TABLE 操作。在本例中,在 employees 示例数据库的 employees 表中添加一个 middle_name 列。Run an ALTER TABLE operation. In this example, a middle_name column is added to the employees table of the employees sample database.

    mysql> ALTER TABLE employees.employees ADD COLUMN middle_name varchar(14) AFTER first_name;
    Query OK, 0 rows affected (9.27 sec)
    Records: 0  Duplicates: 0  Warnings: 0
    
  4. 通过查询性能模式 events_stages_current 表来检查 ALTER TABLE 操作的进度。显示的阶段事件根据当前正在进行的 ALTER TABLE 阶段而有所不同。WORK_COMPLETED 列显示已完成的工作量。WORK_ESTIMATED 列提供剩余工作量的估计。Check the progress of the ALTER TABLE operation by querying the Performance Schema events_stages_current table. The stage event shown differs depending on which ALTER TABLE phase is currently in progress. The WORK_COMPLETED column shows the work completed. The WORK_ESTIMATED column provides an estimate of the remaining work.

    mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED
           FROM performance_schema.events_stages_current;
    +------------------------------------------------------+----------------+----------------+
    | EVENT_NAME                                           | WORK_COMPLETED | WORK_ESTIMATED |
    +------------------------------------------------------+----------------+----------------+
    | stage/innodb/alter table (read PK and internal sort) |            280 |           1245 |
    +------------------------------------------------------+----------------+----------------+
    1 row in set (0.01 sec)
    

    events_stages_current 表在 ALTER TABLE 操作完成后返回空集。在这种情况下,您可以检查events_stages_history 表,以查看已完成操作的事件数据。例如:The events_stages_current table returns an empty set if the ALTER TABLE operation has completed. In this case, you can check the events_stages_history table to view event data for the completed operation. For example:

    mysql> SELECT EVENT_NAME, WORK_COMPLETED, WORK_ESTIMATED
           FROM performance_schema.events_stages_history;
    +------------------------------------------------------+----------------+----------------+
    | EVENT_NAME                                           | WORK_COMPLETED | WORK_ESTIMATED |
    +------------------------------------------------------+----------------+----------------+
    | stage/innodb/alter table (read PK and internal sort) |            886 |           1213 |
    | stage/innodb/alter table (flush)                     |           1213 |           1213 |
    | stage/innodb/alter table (log apply table)           |           1597 |           1597 |
    | stage/innodb/alter table (end)                       |           1597 |           1597 |
    | stage/innodb/alter table (log apply table)           |           1981 |           1981 |
    +------------------------------------------------------+----------------+----------------+
    5 rows in set (0.00 sec)
    

    如上所示,WORK_ESTIMATED 的值在 ALTER TABLE 处理过程中进行了修改。初始阶段完成后的预计工作量为 1213。当 ALTER TABLE 处理完成时,WORK_ESTIMATED 被设置为实际值,即 1981。As shown above, the WORK_ESTIMATED value was revised during ALTER TABLE processing. The estimated work after completion of the initial stage is 1213. When ALTER TABLE processing completed, WORK_ESTIMATED was set to the actual value, which is 1981.