Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZn9T-00071Y-8c for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Mar 2023 06:19:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZn9R-0003Yu-Ks for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Mar 2023 06:19:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZn9Q-0003Ye-60 for pgsql-hackers@lists.postgresql.org; Wed, 08 Mar 2023 06:19:49 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZn9L-0007oy-R9 for pgsql-hackers@lists.postgresql.org; Wed, 08 Mar 2023 06:19:47 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id B1A0732006F5; Wed, 8 Mar 2023 01:19:40 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Wed, 08 Mar 2023 01:19:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:sender :subject:subject:to:to; s=fm1; t=1678256380; x=1678342780; bh=lm QXxDF0/jZpMtFiH3jXJGjCX2LRLeqabShj2rJ9DuA=; b=PUpBLwnk51MrPw2pwe YSkcddU7+2Rt7zbQCatGid+nxcBcgzS6c4Ggl8XLOQ78drRegKhDrWsxAWAKpEnK hYDiQ4HLewWLGkmhUXWXiRpYuTwkTRBxzgFRJrteVy/cLyg8Hg4SdFM2AgLaKIlF lwDzkWMCLIkq0SnfFeGVGXSELxAq4dNwWC1B7sefI+Jdpvo9veL0uFDVmCwB5QKV 5qg0T73KrxaVwG5o32Pmoym7MwoUyWqAHzWJk6QqnpzEFbkxGxvWkO/97jMT4Cyl wZWTRkYV6eBIExWRd8KyXvSNz6IuSd1M13Z8YYZwgMy0Rv2pv1Oh6rG88UQ0Ghye u/6A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1678256380; x=1678342780; bh=lmQXxDF0/jZpM tFiH3jXJGjCX2LRLeqabShj2rJ9DuA=; b=YFWbrxxZbGGXhqWJEbM4kfM7wHLEi SYoiApicAE3P/Vf/LQz1EuJyLNJ/jjrwl7GQviQH/AbCg13yo4L0gcid0hjbFPex vFroYoCX22FGK+OjvSF+FLK7tP4FyhYRYfzwDf6NVYpBp8EL3r/CYh48k49jL/Yx OTMLRvJxGEVkitglGLu/Tdy86v1NuhDCJqWBnCOZqRlgMMBMDR72RV4g9MaGG3XP 7wyTSBQwVhx8Npw3TVXIBqpOPKNn529Lkjtw1fCzHfe16sosYbSar4GwXsbIOWJV t6ylFBj/7gvjZvjIl/3wXTcsvkXjIqIEnifBseTTrbW5TJNYHQgrMjh2w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdduuddgledvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredt tddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesph grqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeg geegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptd enucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiih ii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 8 Mar 2023 01:19:38 -0500 (EST) Date: Wed, 8 Mar 2023 15:19:33 +0900 From: Michael Paquier To: "Drouvot, Bertrand" Cc: Postgres hackers Subject: Re: Normalization of utility queries in pg_stat_statements Message-ID: References: <0e067034-e92c-302b-24ed-492bca228e26@gmail.com> <14965f63-6d78-45ff-d029-daafe8eddb40@gmail.com> <1f84685f-1ffd-4937-de63-aaa1513a0b7e@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="gjltmvdgsKx5c7K1" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gjltmvdgsKx5c7K1 Content-Type: multipart/mixed; boundary="ngBh6IzZBy5NJv7V" Content-Disposition: inline --ngBh6IzZBy5NJv7V Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --ngBh6IzZBy5NJv7V Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Apply-normalization-to-CALL-statements.patch" Content-Transfer-Encoding: quoted-printable =46rom 7fff41b050b8da4b7a006071b51ae5fa43bc7c0b Mon Sep 17 00:00:00 2001 =46rom: Michael Paquier 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; =20 typedef struct CallContext diff --git a/src/backend/nodes/queryjumblefuncs.c b/src/backend/nodes/query= jumblefuncs.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); =20 /* * Given a possibly multi-statement source string, confine our attention t= o the @@ -395,3 +396,14 @@ _jumbleRangeTblEntry(JumbleState *jstate, Node *node) break; } } + +static void +_jumbleCallStmt(JumbleState *jstate, Node *node) +{ + CallStmt *expr =3D (CallStmt *) node; + FuncExpr *func =3D 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_s= tat_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 i= nt) 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=20 +---+--- + | =20 +(1 row) + +CALL sum_out(2,2,1,1); + k | l=20 +---+--- + | =20 +(1 row) + +CALL sum_out(2,3,4,5); + k | l=20 +---+--- + | =20 +(1 row) + SELECT calls, rows, query FROM pg_stat_statements ORDER BY query COLLATE "= C"; calls | rows | query =20 -------+------+----------------------------------- - 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) =20 -- COPY CREATE TABLE copy_stats (a int, b int); diff --git a/contrib/pg_stat_statements/sql/utility.sql b/contrib/pg_stat_s= tatements/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 i= nt) 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"; =20 -- COPY --=20 2.39.2 --ngBh6IzZBy5NJv7V-- --gjltmvdgsKx5c7K1 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmQIKPUACgkQnvQgOdby QH17LRAAiLWCyDIih6rwv6JtjjNB75TBopjBEK65JJEis9JEmZtDb6TAE+Bq1EEB wzi+qe++WHl++xtD1GnTLWvGawT8gxqhbw+dktoc49S8Nkp8bSvcD95j+boJdAzL fR1DQ2LLKo0kQiA0/29PwVULe//t5aUPH+fs2OMvpvT/b+4gqhsY7UnoQa4Skuax ZRZ3y8hrZeMa5w44WHnawUATZuKry+GoJrwKPaNY7fg2EuDk0hNc1dC8C14ocWbE gg6wu5icc8JR86FrxcM/4g28zTb6/e8ST2eG07M/nflt/4iZlf2aFWsFIyepyxrI glsVMsvFOxJo0PvFUxZQeHx7/EVf6aPF0ng/qNmwYnf5J3XwpzRzkhaty9Qsqfhh qlFJQiBTpIopVyDrt7R9biXTzog9OFASBS+6wKTLv6Aj3je3Ul9ir9B+dWU4Y6oV 22Q8LrT40yEpf6YMyJIIihJZsJVmzzqub+iF7FCML0Q0twAQZ3RcEX77O4FkpPcT Gq9TpxzrsoIKJ7ZbhbH9j0PCmfY2oo77Idm7HW/qWGMLvtiKF3FrMpcqIRG9MP+r F1fkPhG1kH3NjK5iQ3zSlx19UhS8eRrUlgSOoHeDRtYAmyCZdPOzA/Mb/kYVjXqI Z8d+eYLTWYiQ/I/9pwLhvWbr/a2nU+NXX4Bko5PFLd4OSioKn6g= =RBd1 -----END PGP SIGNATURE----- --gjltmvdgsKx5c7K1--