Re: pg_stat_statements: more test coverage - Mailing list pgsql-hackers

From Julien Rouhaud
Subject Re: pg_stat_statements: more test coverage
Date
Msg-id CAOBaU_YvCnJ0aEcSE-KTRp8YZjyf5OS_=L1RHkjo6RbF4JhqZQ@mail.gmail.com
Whole thread Raw
In response to Re: pg_stat_statements: more test coverage  (Peter Eisentraut <peter@eisentraut.org>)
Responses Re: pg_stat_statements: more test coverage
List pgsql-hackers
Hi,

On Tue, Dec 26, 2023 at 10:03 PM Peter Eisentraut <peter@eisentraut.org> wrote:
>
> On 24.12.23 03:03, Michael Paquier wrote:
> > - Use a DO block of a PL function, say with something like that to
> > ensure an amount of N queries?  Say with something like that after
> > tweaking pg_stat_statements.track:
> > CREATE OR REPLACE FUNCTION create_tables(num_tables int)
> >    RETURNS VOID AS
> >    $func$
> >    BEGIN
> >    FOR i IN 1..num_tables LOOP
> >      EXECUTE format('
> >        CREATE TABLE IF NOT EXISTS %I (id int)', 't_' || i);
> >    END LOOP;
> > END
> > $func$ LANGUAGE plpgsql;
>
> I tried it like this first, but this doesn't register as separately
> executed commands for pg_stat_statements.

I was a bit surprised by that so I checked locally.  It does work as
expected provided that you set pg_stat_statements.track to all:
=# select create_tables(5);
=# select queryid, query from pg_stat_statements where query like 'CREATE%';
       queryid        |                  query
----------------------+-----------------------------------------
 -4985234599080337259 | CREATE TABLE IF NOT EXISTS t_5 (id int)
  -790506371630237058 | CREATE TABLE IF NOT EXISTS t_2 (id int)
 -1104545884488896333 | CREATE TABLE IF NOT EXISTS t_3 (id int)
 -2961032912789520428 | CREATE TABLE IF NOT EXISTS t_4 (id int)
  7273321309563119428 | CREATE TABLE IF NOT EXISTS t_1 (id int)



pgsql-hackers by date:

Previous
From: Nisha Moond
Date:
Subject: Re: Intermittent failure with t/003_logical_slots.pl test on windows
Next
From: Richard Guo
Date:
Subject: Revise the Asserts added to bimapset manipulation functions