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_IDA 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,InnoDBselects 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 areRUNNING,LOCK WAIT,ROLLING BACK, andCOMMITTING.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, ifTRX_STATEisLOCK WAIT; otherwiseNULL. To obtain details about the lock, join this column with theENGINE_LOCK_IDcolumn of the Performance Schemadata_lockstable.TRX_WAIT_STARTED事务开始等待锁的时间,如果
TRX_STATE为LOCK WAIT;否则为NULL。The time when the transaction started waiting on the lock, ifTRX_STATEisLOCK WAIT; otherwiseNULL.TRX_MYSQL_THREAD_IDMySQL 线程 ID。要获取有关线程的详细信息,请将此列与
INFORMATION_SCHEMAPROCESSLIST表的ID列连接,但请参见 第 17.15.2.3 节,“InnoDB 事务和锁信息的持久性与一致性”。The MySQL thread ID. To obtain details about the thread, join this column with theIDcolumn of theINFORMATION_SCHEMAPROCESSLISTtable, 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; otherwiseNULL.TRX_TABLES_IN_USE当前事务处理的 SQL 语句使用的
InnoDB表的数量。The number ofInnoDBtables used while processing the current SQL statement of this transaction.TRX_TABLES_LOCKED当前 SQL 语句上拥有行锁的
InnoDB表的数量。(因为这些是行锁,而不是表锁,所以通常即使某些行被锁定,表仍然可以被多个事务读取和写入。)The number ofInnoDBtables 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 theinnodb_concurrency_ticketssystem 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; otherwiseNULL.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 byinnodb_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 byinnodb_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 aSELECTstatement that does not use theFOR UPDATEorLOCK IN SHARED MODEclauses, and is executing withautocommitenabled so that the transaction contains only this one statement. When this column andTRX_IS_READ_ONLYare both 1,InnoDBoptimizes 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 aLOCK WAITstate, as reported by theTRX_STATEcolumn. A NULL value is reported for transactions that are not waiting for a lock. TheTRX_SCHEDULE_WEIGHTvalue is different from theTRX_WEIGHTvalue, 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
使用此表可以帮助诊断在高并发负载期间发生的性能问题。如在第 17.15.2.3 节,“InnoDB 事务和锁信息的持久性与一致性”中所述,表中的内容会更新。Use this table to help diagnose performance problems that occur during times of heavy concurrent load. Its contents are updated as described in Section 17.15.2.3, “Persistence and Consistency of InnoDB Transaction and Locking Information”.
你必须拥有
PROCESS权限才能查询此表。You must have thePROCESSprivilege to query this table.使用
INFORMATION_SCHEMACOLUMNS表或SHOW COLUMNS语句查看关于此表列的更多信息,包括数据类型和默认值。Use theINFORMATION_SCHEMACOLUMNStable or theSHOW COLUMNSstatement to view additional information about the columns of this table, including data types and default values.