1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Show GIDs of two-phase commit commands as constants in pg_stat_statements

This relies on the "location" field added to TransactionStmt in 31de7e6,
now applied to the "gid" field used by 2PC commands.  These commands are
now reported like:
COMMIT PREPARED $1
PREPARE TRANSACTION $1
ROLLBACK PREPARED $1

Applying constants for these commands is a huge advantage for workloads
that rely a lot on 2PC commands with different GIDs.  Some tests are
added to track the new behavior.

Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/ZMhT9kNtJJsHw6jK@paquier.xyz
This commit is contained in:
Michael Paquier
2023-08-12 10:44:15 +09:00
parent 5dc456b7dd
commit 638d42a3c5
5 changed files with 39 additions and 4 deletions

View File

@ -197,6 +197,29 @@ SELECT pg_stat_statements_reset();
(1 row)
-- Two-phase transactions
BEGIN;
PREPARE TRANSACTION 'stat_trans1';
COMMIT PREPARED 'stat_trans1';
BEGIN;
PREPARE TRANSACTION 'stat_trans2';
ROLLBACK PREPARED 'stat_trans2';
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
calls | rows | query
-------+------+-----------------------------------
2 | 0 | BEGIN
1 | 0 | COMMIT PREPARED $1
2 | 0 | PREPARE TRANSACTION $1
1 | 0 | ROLLBACK PREPARED $1
1 | 1 | SELECT pg_stat_statements_reset()
(5 rows)
SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------
(1 row)
-- Savepoints
BEGIN;
SAVEPOINT sp1;