Re: Normalization of utility queries in pg_stat_statements

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: "Drouvot, Bertrand" <bertranddrouvot(dot)pg(at)gmail(dot)com>, Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Normalization of utility queries in pg_stat_statements
Date: 2023-08-16 09:11:47
Message-ID: CACJufxEjM5M=N+f5R5yRYghoXpMiUM=sRwSio-YczsaVxU8Xqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Mar 8, 2023 at 2:19 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
>
> 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

I tested it. all normally works fine. only 1 corner case:
set pg_stat_statements.track = 'all';
drop table if Exists cp_test;
CREATE TABLE cp_test (a int, b text);
CREATE or REPLACE PROCEDURE ptest1(x text) LANGUAGE SQL AS $$ INSERT
INTO cp_test VALUES (1, x); $$;

CREATE or REPLACE PROCEDURE ptest3(y text)
LANGUAGE SQL
AS $$
CALL ptest1(y);
CALL ptest1($1);
$$;
SELECT pg_stat_statements_reset();

CALL ptest3('b');

SELECT calls, toplevel, rows, query FROM pg_stat_statements ORDER BY
query COLLATE "C";
returns:
calls | toplevel | rows | query
-------+----------+------+------------------------------------
1 | t | 0 | CALL ptest3($1)
2 | f | 2 | INSERT INTO cp_test VALUES ($2, x)
1 | t | 1 | SELECT pg_stat_statements_reset()

here, the intermediate CALL part is optimized away. or should I expect
CALL ptest1($1) also in pg_stat_statements?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2023-08-16 09:14:18 Add 'worker_type' to pg_stat_subscription
Previous Message Malthe 2023-08-16 09:09:05 Re: regexp_replace weirdness amounts to a bug?