table of Contents
Not a transaction is committed, processlist in
Two, information_schema.innodb_trx in uncommitted transactions
Three, performance_schema.events_statements_current in uncommitted transactions
We often encounter such a situation, a transaction executed over uncommitted, a follow-up again DDL and DML operations, leading to the back of the session either in waiting for metadata lock, lock wait timeout either. Then we often only find transaction id of the transaction uncommitted and session id, but generally are in the sleep state, what is wrong in the end is content analysis of the transaction, so often rude to kill after this session to solve the problem, but the application R & D personnel layers often can not find what matters in the end is caused when the problem will repeat kill again later.
Not a transaction is committed, processlist in
For transactions executed a complete but not submitted, can not find the information in the output of the show processlist:
-- session 1
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> use test;
Database changed
mysql> create table t1(a int);
Query OK, 0 rows affected (0.45 sec)
mysql> insert into t1 values (1);
Query OK, 1 row affected (0.00 sec)
mysql> select connection_id() from dual;
+-----------------+
| connection_id() |
+-----------------+
| 6 |
+-----------------+
1 row in set (0.00 sec)
-- session 2
mysql> show processlist;
+----+------+-----------+------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+-----------+------+---------+------+-------+------------------+
| 6 | root | localhost | test | Sleep | 44 | | NULL |
| 7 | root | localhost | NULL | Query | 0 | init | show processlist |
+----+------+-----------+------+---------+------+-------+------------------+
2 rows in set (0.00 sec)
You can see, Command uncommitted transactions for Sleep, State null, Info to NULL.
Two, information_schema.innodb_trx in uncommitted transactions
Similarly, information_schema.innodb_trx.trx_query also is NULL, we can not provide uncommitted transactions SQL statement:
mysql> select * from information_schema.innodb_trx\G
*************************** 1. row ***************************
trx_id: 4632
trx_state: RUNNING
trx_started: 2020-03-28 07:18:32
trx_requested_lock_id: NULL
trx_wait_started: NULL
trx_weight: 2
trx_mysql_thread_id: 6
trx_query: NULL
trx_operation_state: NULL
trx_tables_in_use: 0
trx_tables_locked: 0
trx_lock_structs: 1
trx_lock_memory_bytes: 376
trx_rows_locked: 0
trx_rows_modified: 1
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
1 row in set (0.00 sec)
Three, performance_schema.events_statements_current in uncommitted transactions
You can be seen by looking at performance_schema.events_statements_current table sql each session is being executed, even if it is still executing completed, but did not submit:
mysql> select * from performance_schema.events_statements_current where sql_text not like 'select * from performance_schema.events_statements_current%'\G
*************************** 1. row ***************************
THREAD_ID: 25
EVENT_ID: 9
END_EVENT_ID: 9
EVENT_NAME: statement/sql/select
SOURCE: mysqld.cc:937
TIMER_START: 1897350780117784000
TIMER_END: 1897350780310674000
TIMER_WAIT: 192890000
LOCK_TIME: 0
SQL_TEXT: select connection_id() from dual
DIGEST: e5d97521478adc05b74560b51be5d6f7
DIGEST_TEXT: SELECT `connection_id` ( ) FROM DUAL
CURRENT_SCHEMA: test
OBJECT_TYPE: NULL
OBJECT_SCHEMA: NULL
OBJECT_NAME: NULL
OBJECT_INSTANCE_BEGIN: NULL
MYSQL_ERRNO: 0
RETURNED_SQLSTATE: NULL
MESSAGE_TEXT: NULL
ERRORS: 0
WARNINGS: 0
ROWS_AFFECTED: 0
ROWS_SENT: 1
ROWS_EXAMINED: 0
CREATED_TMP_DISK_TABLES: 0
CREATED_TMP_TABLES: 0
SELECT_FULL_JOIN: 0
SELECT_FULL_RANGE_JOIN: 0
SELECT_RANGE: 0
SELECT_RANGE_CHECK: 0
SELECT_SCAN: 0
SORT_MERGE_PASSES: 0
SORT_RANGE: 0
SORT_ROWS: 0
SORT_SCAN: 0
NO_INDEX_USED: 0
NO_GOOD_INDEX_USED: 0
NESTING_EVENT_ID: NULL
NESTING_EVENT_TYPE: NULL
1 row in set (0.00 sec)
The program has a flaw: a transaction may be composed of a set of sql, this method can only see the final execution of the transaction is what SQL, you can not see all of them. You can be related by performance_schema.threads table, information_schema.processlist and performance_schema.events_statements_current one-up:
mysql> select t1.id, t2.thread_id, t3.sql_text
-> from information_schema.processlist t1,
-> performance_schema.threads t2,
-> performance_schema.events_statements_current t3
-> where t1.id=6
-> and t1.id=t2.processlist_id
-> and t2.thread_id = t3.thread_id\G
*************************** 1. row ***************************
id: 6
thread_id: 25
sql_text: select connection_id() from dual
1 row in set (0.00 sec)