MySQL 8.3 Release Notes
返回一个包含给定线程信息的 JSON 对象,该信息包括当前事务和已经执行的语句,来自性能模式 events_transactions_current
和 events_statements_history
表。(必须启用这些表的消费者以获取 JSON 对象中的完整数据。)
如果输出超过截断长度(默认为 65535),则返回一个 JSON 错误对象,例如:
{ "error": "Trx info truncated: Row 6 was cut by GROUP_CONCAT()" }
在函数执行期间引发的其他警告和异常也将返回类似的错误对象。
-
in_thread_id BIGINT UNSIGNED
:要返回事务信息的线程 ID。该值应与性能模式threads
表中的某一行的THREAD_ID
列相匹配。
ps_thread_trx_info()
操作可以使用以下配置选项或相应的用户定义变量(见 第 30.4.2.1 节,“sys_config 表”)进行修改:
-
ps_thread_trx_info.max_length
,@sys.ps_thread_trx_info.max_length
输出的最大长度。默认值为 65535。
mysql> SELECT sys.ps_thread_trx_info(48)\G
*************************** 1. row ***************************
sys.ps_thread_trx_info(48): [
{
"time": "790.70 us",
"state": "COMMITTED",
"mode": "READ WRITE",
"autocommitted": "NO",
"gtid": "AUTOMATIC",
"isolation": "REPEATABLE READ",
"statements_executed": [
{
"sql_text": "INSERT INTO info VALUES (1, \'foo\')",
"time": "471.02 us",
"schema": "trx",
"rows_examined": 0,
"rows_affected": 1,
"rows_sent": 0,
"tmp_tables": 0,
"tmp_disk_tables": 0,
"sort_rows": 0,
"sort_merge_passes": 0
},
{
"sql_text": "COMMIT",
"time": "254.42 us",
"schema": "trx",
"rows_examined": 0,
"rows_affected": 0,
"rows_sent": 0,
"tmp_tables": 0,
"tmp_disk_tables": 0,
"sort_rows": 0,
"sort_merge_passes": 0
}
]
},
{
"time": "426.20 us",
"state": "COMMITTED",
"mode": "READ WRITE",
"autocommitted": "NO",
"gtid": "AUTOMATIC",
"isolation": "REPEATABLE READ",
"statements_executed": [
{
"sql_text": "INSERT INTO info VALUES (2, \'bar\')",
"time": "107.33 us",
"schema": "trx",
"rows_examined": 0,
"rows_affected": 1,
"rows_sent": 0,
"tmp_tables": 0,
"tmp_disk_tables": 0,
"sort_rows": 0,
"sort_merge_passes": 0
},
{
"sql_text": "COMMIT",
"time": "213.23 us",
"schema": "trx",
"rows_examined": 0,
"rows_affected": 0,
"rows_sent": 0,
"tmp_tables": 0,
"tmp_disk_tables": 0,
"sort_rows": 0,
"sort_merge_passes": 0
}
]
}
]