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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

17.6.6 撤销日志17.6.6 Undo Logs

回滚日志是与单个读写事务关联的一组回滚日志记录。回滚日志记录包含有关如何撤销事务对聚簇索引记录的最新更改的信息。如果另一个事务需要在一致性读取操作中查看原始数据,则从回滚日志记录中检索未修改的数据。回滚日志存在于回滚日志段中,这些日志段包含在回滚段中。回滚段位于回滚表空间和全局临时表空间中。An undo log is a collection of undo log records associated with a single read-write transaction. An undo log record contains information about how to undo the latest change by a transaction to a clustered index record. If another transaction needs to see the original data as part of a consistent read operation, the unmodified data is retrieved from undo log records. Undo logs exist within undo log segments, which are contained within rollback segments. Rollback segments reside in undo tablespaces and in the global temporary tablespace.

位于全局临时表空间中的回滚日志用于修改用户定义临时表数据的事务。这些回滚日志不会进行重做日志记录,因为它们不用于崩溃恢复。它们仅在服务器运行时用于回滚。这类回滚日志通过避免重做日志 I/O 来提升性能。Undo logs that reside in the global temporary tablespace are used for transactions that modify data in user-defined temporary tables. These undo logs are not redo-logged, as they are not required for crash recovery. They are used only for rollback while the server is running. This type of undo log benefits performance by avoiding redo logging I/O.

有关回滚日志静态数据加密的详细信息,请参见 回滚日志加密。For information about data-at-rest encryption for undo logs, see Undo Log Encryption.

每个回滚表空间和全局临时表空间单独支持最多 128 个回滚段。innodb_rollback_segments 变量定义了回滚段的数量。Each undo tablespace and the global temporary tablespace individually support a maximum of 128 rollback segments. The innodb_rollback_segments variable defines the number of rollback segments.

回滚段支持的事务数量取决于回滚段中的撤销槽数量以及每个事务所需的撤销日志数量。回滚段中的撤销槽数量根据 InnoDB 页大小而有所不同。The number of transactions that a rollback segment supports depends on the number of undo slots in the rollback segment and the number of undo logs required by each transaction. The number of undo slots in a rollback segment differs according to InnoDB page size.

InnoDB 页大小InnoDB Page Size 回滚段中的撤销槽数量(InnoDB 页大小 / 16)Number of Undo Slots in a Rollback Segment (InnoDB Page Size / 16)
4096 (4KB) 256
8192 (8KB) 512
16384 (16KB) 1024
32768 (32KB) 2048
65536 (64KB) 4096

一个事务最多分配四个撤销日志,每个日志对应以下操作类型之一:A transaction is assigned up to four undo logs, one for each of the following operation types:

  1. INSERT 对用户定义表的操作INSERT operations on user-defined tables

  2. UPDATE 和 DELETE 操作在用户定义的表上UPDATE and DELETE operations on user-defined tables

  3. INSERT 操作在用户定义的临时表上INSERT operations on user-defined temporary tables

  4. UPDATE 和 DELETE 操作在用户定义的临时表上UPDATE and DELETE operations on user-defined temporary tables

撤销日志按需分配。例如,对常规表和临时表执行 INSERT、UPDATE 和 DELETE 操作的事务需要完整分配四个撤销日志。仅对常规表执行 INSERT 操作的事务则只需要一个撤销日志。Undo logs are assigned as needed. For example, a transaction that performs INSERT, UPDATE, and DELETE operations on regular and temporary tables requires a full assignment of four undo logs. A transaction that performs only INSERT operations on regular tables requires a single undo log.

对常规表执行操作的事务会从分配的回滚段的撤消表空间中分配撤消日志。对临时表执行操作的事务会从分配的全局临时表空间回滚段中分配撤消日志。A transaction that performs operations on regular tables is assigned undo logs from an assigned undo tablespace rollback segment. A transaction that performs operations on temporary tables is assigned undo logs from an assigned global temporary tablespace rollback segment.

分配给事务的撤消日志在整个事务期间保持附着。例如,分配给某事务用于常规表的 INSERT 操作的撤消日志,将用于该事务对常规表执行的所有 INSERT 操作。An undo log assigned to a transaction remains attached to the transaction for its duration. For example, an undo log assigned to a transaction for an INSERT operation on a regular table is used for all INSERT operations on regular tables performed by that transaction.

根据上述因素,可以使用以下公式来估算 InnoDB 可支持的并发读写事务数。Given the factors described above, the following formulas can be used to estimate the number of concurrent read-write transactions that InnoDB is capable of supporting.

Note

在达到 InnoDB 能够支持的并发读写事务数量之前,可能会遇到并发事务限制错误。当分配给事务的回滚段的撤销槽用完时,就会发生这种情况。在这种情况下,请尝试重新运行该事务。It is possible to encounter a concurrent transaction limit error before reaching the number of concurrent read-write transactions that InnoDB is capable of supporting. This occurs when a rollback segment assigned to a transaction runs out of undo slots. In such cases, try rerunning the transaction.

当事务对临时表执行操作时,InnoDB 能够支持的并发读写事务数量受限于分配给全局临时表空间的回滚段数量,默认情况下为 128。When transactions perform operations on temporary tables, the number of concurrent read-write transactions that InnoDB is capable of supporting is constrained by the number of rollback segments allocated to the global temporary tablespace, which is 128 by default.

  • 如果每个事务执行 INSERT 或 UPDATE 或 DELETE 操作,那么 InnoDB 能够支持的并发读写事务数量是:If each transaction performs either an INSERT or an UPDATE or DELETE operation, the number of concurrent read-write transactions that InnoDB is capable of supporting is:

    (innodb_page_size / 16) * innodb_rollback_segments * number of undo tablespaces
    
  • 如果每个事务执行一个 INSERT 和 一个 UPDATE 或 DELETE 操作,InnoDB 能支持的并发读写事务数量是:If each transaction performs an INSERT and an UPDATE or DELETE operation, the number of concurrent read-write transactions that InnoDB is capable of supporting is:

    (innodb_page_size / 16 / 2) * innodb_rollback_segments * number of undo tablespaces
    
  • 如果每个事务在临时表上执行一个 INSERT 操作,InnoDB 能支持的并发读写事务数量是:If each transaction performs an INSERT operation on a temporary table, the number of concurrent read-write transactions that InnoDB is capable of supporting is:

    (innodb_page_size / 16) * innodb_rollback_segments
    
  • 如果每个事务在临时表上执行一个 INSERT 和 一个 UPDATE 或 DELETE 操作,那么 InnoDB 能够支持的并发读写事务数为:If each transaction performs an INSERT and an UPDATE or DELETE operation on a temporary table, the number of concurrent read-write transactions that InnoDB is capable of supporting is:

    (innodb_page_size / 16 / 2) * innodb_rollback_segments