Documentation Home

26.4.5.17 ps_thread_trx_info() 函数

返回一个包含给定线程信息的 JSON 对象。这些信息包括当前事务,以及它已经执行的语句,这些语句来自性能模式 events_transactions_currentevents_statements_history表。(必须启用这些表的使用者以获取 JSON 对象中的完整数据。)

如果输出超过截断长度(默认为65535),则返回一个JSON错误对象,例如:

{ "error": "Trx info truncated: Row 6 was cut by GROUP_CONCAT()" }

对于函数执行期间引发的其他警告和异常,将返回类似的错误对象。

参数
  • in_thread_id BIGINT UNSIGNED:返回事务信息的线程 ID。该值应与THREAD_ID 某些 Performance Schema threads表行中的列相匹配。

配置选项

ps_thread_trx_info()可以使用以下配置选项或其相应的用户定义变量修改操作(请参阅 第 26.4.2.1 节,“sys_config 表”):

  • ps_thread_trx_info.max_length, @sys.ps_thread_trx_info.max_length

    输出的最大长度。默认值为 65535。

返回值

一个LONGTEXT值。

例子
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
      }
    ]
  }
]