On Fri, Mar 03, 2023 at 09:37:27AM +0900, Michael Paquier wrote: > Thanks for double-checking, applied 0001 to finish this part of the > work. I am attaching the remaining bits as of the attached, combined > into a single patch.
Doing so as a single patch was not feeling right as this actually fixes issues with the location calculations for the Const node, so I have split that into three commits and finally applied the whole. As a bonus, please see attached a patch to apply the normalization to CALL statements using the new automated infrastructure. OUT parameters can be passed to a procedure, hence I guess that these had better be silenced as well. This is not aimed at being integrated, just for reference. -- Michael
From 7fff41b050b8da4b7a006071b51ae5fa43bc7c0b Mon Sep 17 00:00:00 2001 From: Michael Paquier <mich...@paquier.xyz> Date: Wed, 8 Mar 2023 15:14:15 +0900 Subject: [PATCH] Apply normalization to CALL statements --- src/include/nodes/parsenodes.h | 6 ++-- src/backend/nodes/queryjumblefuncs.c | 12 +++++++ .../pg_stat_statements/expected/utility.out | 33 ++++++++++++++++--- contrib/pg_stat_statements/sql/utility.sql | 9 +++++ 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/src/include/nodes/parsenodes.h b/src/include/nodes/parsenodes.h index 259e814253..32e5f535c1 100644 --- a/src/include/nodes/parsenodes.h +++ b/src/include/nodes/parsenodes.h @@ -3227,12 +3227,14 @@ typedef struct InlineCodeBlock */ typedef struct CallStmt { + pg_node_attr(custom_query_jumble) + NodeTag type; FuncCall *funccall; /* 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 diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/queryjumblefuncs.c index d7fd72d70f..709f91ab0e 100644 --- a/src/backend/nodes/queryjumblefuncs.c +++ b/src/backend/nodes/queryjumblefuncs.c @@ -52,6 +52,7 @@ static void _jumbleNode(JumbleState *jstate, Node *node); static void _jumbleA_Const(JumbleState *jstate, Node *node); static void _jumbleList(JumbleState *jstate, Node *node); static void _jumbleRangeTblEntry(JumbleState *jstate, Node *node); +static void _jumbleCallStmt(JumbleState *jstate, Node *node); /* * Given a possibly multi-statement source string, confine our attention to the @@ -395,3 +396,14 @@ _jumbleRangeTblEntry(JumbleState *jstate, Node *node) break; } } + +static void +_jumbleCallStmt(JumbleState *jstate, Node *node) +{ + CallStmt *expr = (CallStmt *) node; + FuncExpr *func = expr->funcexpr; + + JUMBLE_FIELD_SINGLE(func->funcid); + _jumbleNode(jstate, (Node *) func->args); + _jumbleNode(jstate, (Node *) expr->outargs); +} diff --git a/contrib/pg_stat_statements/expected/utility.out b/contrib/pg_stat_statements/expected/utility.out index 0047aba5d1..b5a8c6937c 100644 --- a/contrib/pg_stat_statements/expected/utility.out +++ b/contrib/pg_stat_statements/expected/utility.out @@ -240,6 +240,12 @@ DECLARE BEGIN SELECT (i + i)::int INTO r; END; $$ LANGUAGE plpgsql; +CREATE OR REPLACE PROCEDURE sum_out(IN i int, IN j int, OUT k int, OUT l int) AS $$ +DECLARE + r int; +BEGIN + SELECT (i + i)::int INTO r; +END; $$ LANGUAGE plpgsql; CREATE OR REPLACE PROCEDURE sum_two(i int, j int) AS $$ DECLARE r int; @@ -256,15 +262,32 @@ CALL sum_one(3); CALL sum_one(199); CALL sum_two(1,1); CALL sum_two(1,2); +CALL sum_out(1,1,1,1); + k | l +---+--- + | +(1 row) + +CALL sum_out(2,2,1,1); + k | l +---+--- + | +(1 row) + +CALL sum_out(2,3,4,5); + k | l +---+--- + | +(1 row) + 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) + 2 | 0 | CALL sum_one($1) + 3 | 0 | CALL sum_out($1,$2,$3,$4) + 2 | 0 | CALL sum_two($1,$2) 1 | 1 | SELECT pg_stat_statements_reset() -(5 rows) +(4 rows) -- COPY CREATE TABLE copy_stats (a int, b int); diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_statements/sql/utility.sql index 225d30a62a..dbf38c31bc 100644 --- a/contrib/pg_stat_statements/sql/utility.sql +++ b/contrib/pg_stat_statements/sql/utility.sql @@ -131,6 +131,12 @@ DECLARE BEGIN SELECT (i + i)::int INTO r; END; $$ LANGUAGE plpgsql; +CREATE OR REPLACE PROCEDURE sum_out(IN i int, IN j int, OUT k int, OUT l int) AS $$ +DECLARE + r int; +BEGIN + SELECT (i + i)::int INTO r; +END; $$ LANGUAGE plpgsql; CREATE OR REPLACE PROCEDURE sum_two(i int, j int) AS $$ DECLARE r int; @@ -142,6 +148,9 @@ CALL sum_one(3); CALL sum_one(199); CALL sum_two(1,1); CALL sum_two(1,2); +CALL sum_out(1,1,1,1); +CALL sum_out(2,2,1,1); +CALL sum_out(2,3,4,5); SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "C"; -- COPY -- 2.39.2
signature.asc
Description: PGP signature