MySQL 8.4 发行说明
返回一个包含有关给定线程的信息的 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
}
]
}
]