文件首頁
MySQL 9.0 參考手冊
相關文件 下載本手冊
PDF (美式信紙) - 40.0Mb
PDF (A4) - 40.1Mb
Man Pages (TGZ) - 258.2Kb
Man Pages (Zip) - 365.3Kb
Info (Gzip) - 4.0Mb
Info (Zip) - 4.0Mb


MySQL 9.0 參考手冊  /  ...  /  ps_thread_trx_info() 函數

30.4.5.17 ps_thread_trx_info() 函數

傳回一個 JSON 物件,其中包含有關指定執行緒的資訊。該資訊包括目前的交易,以及它已經執行的陳述式,這些資訊來自 Performance Schema 的 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。該值應與來自某個 Performance Schema 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。

傳回值

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