1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-28 23:42:10 +03:00

Show names of DEALLOCATE as constants in pg_stat_statements

This commit switches query jumbling so as prepared statement names are
treated as constants in DeallocateStmt.  A boolean field is added to
DeallocateStmt to make a distinction between ALL and named prepared
statements, as "name" was used to make this difference before, NULL
meaning DEALLOCATE ALL.

Prior to this commit, DEALLOCATE was not tracked in pg_stat_statements,
for the reason that it was not possible to treat its name parameter as a
constant.  Now that query jumbling applies to all the utility nodes,
this reason does not apply anymore.

Like 638d42a3c5, this can be a huge advantage for monitoring where
prepared statement names are randomly generated, preventing bloat in
pg_stat_statements.  A couple of tests are added to track the new
behavior.

Author: Dagfinn Ilmari Mannsåker, Michael Paquier
Reviewed-by: Julien Rouhaud
Discussion: https://postgr.es/m/ZMhT9kNtJJsHw6jK@paquier.xyz
This commit is contained in:
Michael Paquier
2023-08-27 17:27:44 +09:00
parent e48b19c5db
commit bb45156f34
5 changed files with 70 additions and 8 deletions

View File

@ -472,6 +472,47 @@ SELECT pg_stat_statements_reset();
(1 row)
-- Execution statements
SELECT 1 as a;
a
---
1
(1 row)
PREPARE stat_select AS SELECT $1 AS a;
EXECUTE stat_select (1);
a
---
1
(1 row)
DEALLOCATE stat_select;
PREPARE stat_select AS SELECT $1 AS a;
EXECUTE stat_select (2);
a
---
2
(1 row)
DEALLOCATE PREPARE stat_select;
DEALLOCATE ALL;
DEALLOCATE PREPARE ALL;
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
calls | rows | query
-------+------+---------------------------------------
2 | 0 | DEALLOCATE $1
2 | 0 | DEALLOCATE ALL
2 | 2 | PREPARE stat_select AS SELECT $1 AS a
1 | 1 | SELECT $1 as a
1 | 1 | SELECT pg_stat_statements_reset()
(5 rows)
SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------
(1 row)
-- SET statements.
-- These use two different strings, still they count as one entry.
SET work_mem = '1MB';