From: Imseih (AWS), Sami <simseih@amazon.com>
To: pgsql-hackers@postgresql.org <pgsql-hackers@postgresql.org>
Cc: Michael Paquier <michael@paquier.xyz>
Cc: Drouvot, Bertrand <bdrouvot@amazon.fr>
Subject: Jumble the CALL command in pg_stat_statements
Date: Wed, 13 Sep 2023 00:48:48 +0000
Message-ID: <B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com> (raw)
Hi,
The proposal by Bertrand in CC to jumble CALL and SET in [1] was
rejected at the time for a more robust solution to jumble DDL.
Michael also in CC made this possible with commit 3db72ebcbe.
The attached patch takes advantage of the jumbling infrastructure
added in the above mentioned commit and jumbles the CALL statement
in pg_stat_statements.
The patch also modifies existing test cases for CALL handling in pg_stat_statements
and adds additional tests which prove that a CALL to an overloaded procedure
will generate a different query_id.
As far as the SET command mentioned in [1] is concerned, it is a bit more complex
as it requires us to deal with A_Constants which is not very straightforward. We can surely
deal with SET currently by applying custom query jumbling logic to VariableSetStmt,
but this can be dealt with in a separate discussion.
Regards,
Sami Imseih
Amazon Web Services (AWS)
[1] https://www.postgresql.org/message-id/flat/36e5bffe-e989-194f-85c8-06e7bc88e6f7%40amazon.comAttachments:0001-v1-Jumble-the-CALL-command-in-pg_stat_statements.patch (application/octet-stream, 3.8K) download
From 45de0ff3bb5d555317b2e32f2de0100f2f89b4ff Mon Sep 17 00:00:00 2001
From: EC2 Default User <ec2-user@ip-172-31-44-253.ec2.internal>
Date: Wed, 13 Sep 2023 00:18:34 +0000
Subject: [PATCH 1/1] Jumble the CALL command in pg_stat_statements
3db72ebcbe introduced gen_node_support.pl for
An earlier proposal to jumble CALL and SET commands [1]
was rejected in lieu of a more comprehensive solution.
3db72ebcbe allowed gen_node_support.pl to support query jumbling.
This change takes advantage of the infrastructure introduced
in the aforementioned commit and jumbles the CALL command.
[1] https://www.postgresql.org/message-id/flat/36e5bffe-e989-194f-85c8-06e7bc88e6f7%40amazon.com
---
.../pg_stat_statements/expected/utility.out | 22 +++++++++++++++----
contrib/pg_stat_statements/sql/utility.sql | 14 ++++++++++++
src/include/nodes/parsenodes.h | 6 ++---
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_stat_statements/expected/utility.outindex f331044f3e..1c2f085d3f 100644--- a/contrib/pg_stat_statements/expected/utility.out+++ b/contrib/pg_stat_statements/expected/utility.out@@ -300,6 +300,18 @@ DECLARE
BEGIN
SELECT (i + j)::int INTO r;
END; $$ LANGUAGE plpgsql;
+CREATE OR REPLACE PROCEDURE overload(i int) AS $$+DECLARE+ r int;+BEGIN+ SELECT (i + i)::int INTO r;+END; $$ LANGUAGE plpgsql;+CREATE OR REPLACE PROCEDURE overload(i text) AS $$+DECLARE+ r text;+BEGIN+ SELECT i::text INTO r;+END; $$ LANGUAGE plpgsql;
SELECT pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------
@@ -310,13 +322,15 @@ CALL sum_one(3);
CALL sum_one(199);
CALL sum_two(1,1);
CALL sum_two(1,2);
+CALL overload(1);+CALL overload('A');
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
calls | rows | query
-------+------+-----------------------------------
- 1 | 0 | CALL sum_one(199)- 1 | 0 | CALL sum_one(3)- 1 | 0 | CALL sum_two(1,1)- 1 | 0 | CALL sum_two(1,2)+ 1 | 0 | CALL overload($1)+ 1 | 0 | CALL overload($1)+ 2 | 0 | CALL sum_one($1)+ 2 | 0 | CALL sum_two($1,$2)
1 | 1 | SELECT pg_stat_statements_reset()
(5 rows)
diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_statements/sql/utility.sqlindex 5f7d4a467f..81181207e5 100644--- a/contrib/pg_stat_statements/sql/utility.sql+++ b/contrib/pg_stat_statements/sql/utility.sql@@ -164,11 +164,25 @@ DECLARE
BEGIN
SELECT (i + j)::int INTO r;
END; $$ LANGUAGE plpgsql;
+CREATE OR REPLACE PROCEDURE overload(i int) AS $$+DECLARE+ r int;+BEGIN+ SELECT (i + i)::int INTO r;+END; $$ LANGUAGE plpgsql;+CREATE OR REPLACE PROCEDURE overload(i text) AS $$+DECLARE+ r text;+BEGIN+ SELECT i::text INTO r;+END; $$ LANGUAGE plpgsql;
SELECT pg_stat_statements_reset();
CALL sum_one(3);
CALL sum_one(199);
CALL sum_two(1,1);
CALL sum_two(1,2);
+CALL overload(1);+CALL overload('A');
SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C";
-- COPY
diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.hindex fef4c714b8..993b545739 100644--- a/src/include/nodes/parsenodes.h+++ b/src/include/nodes/parsenodes.h@@ -3376,11 +3376,11 @@ typedef struct InlineCodeBlock
typedef struct CallStmt
{
NodeTag type;
- FuncCall *funccall; /* from the parser */+ FuncCall *funccall pg_node_attr(query_jumble_ignore); /* from the parser */
/* transformed call, with only input args */
- FuncExpr *funcexpr pg_node_attr(query_jumble_ignore);+ FuncExpr *funcexpr;
/* transformed output-argument expressions */
- List *outargs pg_node_attr(query_jumble_ignore);+ List *outargs;
} CallStmt;
typedef struct CallContext
--
2.40.1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: simseih@amazon.com, michael@paquier.xyz, bdrouvot@amazon.fr
Subject: Re: Jumble the CALL command in pg_stat_statements
In-Reply-To: <B44FA29D-EBD0-4DD9-ABC2-16F1CB087074@amazon.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox