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

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

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

28.4.28 INFORMATION_SCHEMA INNODB_TRX 表28.4.28 The INFORMATION_SCHEMA INNODB_TRX Table

INNODB_TRX 表提供了关于当前在 InnoDB 中执行的每个事务的信息,包括事务是否在等待锁、事务开始时间,以及事务正在执行的 SQL 语句(如果有的话)。The INNODB_TRX table provides information about every transaction currently executing inside InnoDB, including whether the transaction is waiting for a lock, when the transaction started, and the SQL statement the transaction is executing, if any.

有关使用信息,请参见 第 17.15.2.1 节,“使用 InnoDB 事务和锁信息”。For usage information, see Section 17.15.2.1, “Using InnoDB Transaction and Locking Information”.

INNODB_TRX 表包含以下列:The INNODB_TRX table has these columns:

  • TRX_ID

    A unique transaction ID number, internal to InnoDB. These IDs are not created for transactions that are read only and nonlocking. For details, see Section 10.5.3, “Optimizing InnoDB Read-Only Transactions”.

  • TRX_WEIGHT

    事务的权重,反映(但不一定完全等于)事务修改的行数和事务锁定的行数。为了解决死锁,InnoDB 会选择权重最小的事务作为“牺牲者”来回滚。修改了非事务表的事务被认为比其他事务更重,无论修改和锁定的行数多少。The weight of a transaction, reflecting (but not necessarily the exact count of) the number of rows altered and the number of rows locked by the transaction. To resolve a deadlock, InnoDB selects the transaction with the smallest weight as the “victim” to roll back. Transactions that have changed nontransactional tables are considered heavier than others, regardless of the number of altered and locked rows.

  • TRX_STATE

    事务执行状态。允许的值有 RUNNING、LOCK WAIT、ROLLING BACK 和 COMMITTING。The transaction execution state. Permitted values are RUNNING, LOCK WAIT, ROLLING BACK, and COMMITTING.

  • TRX_STARTED

    事务开始时间。The transaction start time.

  • TRX_REQUESTED_LOCK_ID

    事务当前正在等待的锁的 ID,如果TRX_STATE为LOCK WAIT;否则为NULL。要获取锁的详细信息,请将此列与性能模式表data_locks的ENGINE_LOCK_ID列关联。The ID of the lock the transaction is currently waiting for, if TRX_STATE is LOCK WAIT; otherwise NULL. To obtain details about the lock, join this column with the ENGINE_LOCK_ID column of the Performance Schema data_locks table.

  • TRX_WAIT_STARTED

    事务开始等待锁的时间,如果TRX_STATE为LOCK WAIT;否则为NULL。The time when the transaction started waiting on the lock, if TRX_STATE is LOCK WAIT; otherwise NULL.

  • TRX_MYSQL_THREAD_ID

    MySQL 线程 ID。要获取有关线程的详细信息,请将此列与 INFORMATION_SCHEMA PROCESSLIST 表的 ID 列连接,但请参见 第 17.15.2.3 节,“InnoDB 事务和锁信息的持久性与一致性”。The MySQL thread ID. To obtain details about the thread, join this column with the ID column of the INFORMATION_SCHEMA PROCESSLIST table, but see Section 17.15.2.3, “Persistence and Consistency of InnoDB Transaction and Locking Information”.

  • TRX_QUERY

    事务正在执行的 SQL 语句。The SQL statement that is being executed by the transaction.

  • TRX_OPERATION_STATE

    事务当前的操作(如果有);否则为 NULL。The transaction's current operation, if any; otherwise NULL.

  • TRX_TABLES_IN_USE

    当前事务处理的 SQL 语句使用的 InnoDB 表的数量。The number of InnoDB tables used while processing the current SQL statement of this transaction.

  • TRX_TABLES_LOCKED

    当前 SQL 语句上拥有行锁的 InnoDB 表的数量。(因为这些是行锁,而不是表锁,所以通常即使某些行被锁定,表仍然可以被多个事务读取和写入。)The number of InnoDB tables that the current SQL statement has row locks on. (Because these are row locks, not table locks, the tables can usually still be read from and written to by multiple transactions, despite some rows being locked.)

  • TRX_LOCK_STRUCTS

    事务保留的锁的数量。The number of locks reserved by the transaction.

  • TRX_LOCK_MEMORY_BYTES

    此事务在内存中锁结构占用的总大小。The total size taken up by the lock structures of this transaction in memory.

  • TRX_ROWS_LOCKED

    此事务锁定的行的近似数量。该值可能包括物理存在但对事务不可见的删除标记行。The approximate number or rows locked by this transaction. The value might include delete-marked rows that are physically present but not visible to the transaction.

  • TRX_ROWS_MODIFIED

    该事务中被修改和插入的行数。The number of modified and inserted rows in this transaction.

  • TRX_CONCURRENCY_TICKETS

    一个值,指示当前事务在被换出之前可以完成多少工作,由系统变量 innodb_concurrency_tickets 指定。A value indicating how much work the current transaction can do before being swapped out, as specified by the innodb_concurrency_tickets system variable.

  • TRX_ISOLATION_LEVEL

    当前事务的隔离级别。The isolation level of the current transaction.

  • TRX_UNIQUE_CHECKS

    当前事务是否开启唯一性检查。例如,在批量数据加载期间,唯一性检查可能被关闭。Whether unique checks are turned on or off for the current transaction. For example, they might be turned off during a bulk data load.

  • TRX_FOREIGN_KEY_CHECKS

    当前事务的外键检查是否已开启或关闭。例如,在批量数据加载期间,它们可能被关闭。Whether foreign key checks are turned on or off for the current transaction. For example, they might be turned off during a bulk data load.

  • TRX_LAST_FOREIGN_KEY_ERROR

    最近一次外键错误的详细错误信息(如果有);否则为 NULL。The detailed error message for the last foreign key error, if any; otherwise NULL.

  • TRX_ADAPTIVE_HASH_LATCHED

    当前事务是否锁定了自适应哈希索引。当自适应哈希索引搜索系统被分区时,单个事务不会锁定整个自适应哈希索引。自适应哈希索引分区由 innodb_adaptive_hash_index_parts 控制,默认设置为 8。Whether the adaptive hash index is locked by the current transaction. When the adaptive hash index search system is partitioned, a single transaction does not lock the entire adaptive hash index. Adaptive hash index partitioning is controlled by innodb_adaptive_hash_index_parts, which is set to 8 by default.

  • TRX_ADAPTIVE_HASH_TIMEOUT

    在 MySQL 5.7.8 中已废弃。始终返回 0。Deprecated in MySQL 5.7.8. Always returns 0.

    是否立即释放自适应哈希索引的搜索锁存器,或在 MySQL 调用期间保留它。当没有自适应哈希索引争用时,此值保持为零,语句会保留锁存器直到完成。在争用期间,它会递减到零,语句在每次行查找后立即释放锁存器。当自适应哈希索引搜索系统被分区(由 innodb_adaptive_hash_index_parts 控制)时,该值保持为 0。Whether to relinquish the search latch immediately for the adaptive hash index, or reserve it across calls from MySQL. When there is no adaptive hash index contention, this value remains zero and statements reserve the latch until they finish. During times of contention, it counts down to zero, and statements release the latch immediately after each row lookup. When the adaptive hash index search system is partitioned (controlled by innodb_adaptive_hash_index_parts), the value remains 0.

  • TRX_IS_READ_ONLY

    值为 1 表示事务为只读。A value of 1 indicates the transaction is read only.

  • TRX_AUTOCOMMIT_NON_LOCKING

    值为 1 表示该事务是一个SELECT语句,并且未使用FOR UPDATE或LOCK IN SHARED MODE子句,而且在启用autocommit时执行,因此该事务只包含这一条语句。当此列和TRX_IS_READ_ONLY都为 1 时,InnoDB会优化事务以减少与修改表数据的事务相关的开销。A value of 1 indicates the transaction is a SELECT statement that does not use the FOR UPDATE or LOCK IN SHARED MODE clauses, and is executing with autocommit enabled so that the transaction contains only this one statement. When this column and TRX_IS_READ_ONLY are both 1, InnoDB optimizes the transaction to reduce the overhead associated with transactions that change table data.

  • TRX_SCHEDULE_WEIGHT

    由争用感知事务调度(CATS)算法分配给等待锁的事务的事务调度权重。该值相对于其他事务的值而言。值越高,权重越大。只有处于LOCK WAIT状态的事务会计算此值,如TRX_STATE列所示。对于未等待锁的事务,将报告 NULL 值。TRX_SCHEDULE_WEIGHT值不同于TRX_WEIGHT值,后者由不同算法为不同目的计算。The transaction schedule weight assigned by the Contention-Aware Transaction Scheduling (CATS) algorithm to transactions waiting for a lock. The value is relative to the values of other transactions. A higher value has a greater weight. A value is computed only for transactions in a LOCK WAIT state, as reported by the TRX_STATE column. A NULL value is reported for transactions that are not waiting for a lock. The TRX_SCHEDULE_WEIGHT value is different from the TRX_WEIGHT value, which is computed by a different algorithm for a different purpose.

示例Example

mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX\G
*************************** 1. row ***************************
                    trx_id: 1510
                 trx_state: RUNNING
               trx_started: 2014-11-19 13:24:40
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 586739
       trx_mysql_thread_id: 2
                 trx_query: DELETE FROM employees.salaries WHERE salary > 65000
       trx_operation_state: updating or deleting
         trx_tables_in_use: 1
         trx_tables_locked: 1
          trx_lock_structs: 3003
     trx_lock_memory_bytes: 450768
           trx_rows_locked: 1407513
         trx_rows_modified: 583736
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 10000
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
       trx_schedule_weight: NULL

注释Notes