CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_track='all';
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

CREATE TABLE t1 (a INTEGER);
CREATE TABLE t2 (b INTEGER);
CREATE TABLE t3 (c INTEGER);
CREATE TABLE t4 (d INTEGER);
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
                                      query                                      | calls 
---------------------------------------------------------------------------------+-------
 SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a |     4
 SELECT pg_stat_monitor_reset()                                                  |     1
(2 rows)

SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

do $$
declare
   n integer:= 1;
begin
	loop
		PERFORM a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;
		exit when n = 1000;
		n := n + 1;
	end loop;
end $$;
SELECT query, sum(calls) as calls FROM pg_stat_monitor GROUP BY query ORDER BY query COLLATE "C";
                                               query                                               | calls 
---------------------------------------------------------------------------------------------------+-------
 SELECT a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a                   |  1000
 SELECT pg_stat_monitor_reset()                                                                    |     1
 do $$                                                                                            +|     1
 declare                                                                                          +| 
    n integer:= 1;                                                                                +| 
 begin                                                                                            +| 
         loop                                                                                     +| 
                 PERFORM a,b,c,d FROM t1, t2, t3, t4 WHERE t1.a = t2.b AND t3.c = t4.d ORDER BY a;+| 
                 exit when n = 1000;                                                              +| 
                 n := n + 1;                                                                      +| 
         end loop;                                                                                +| 
 end $$                                                                                            | 
(3 rows)

DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
DROP EXTENSION pg_stat_monitor;
