CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

CREATE TABLE foo1(a int);
CREATE TABLE foo2(b int);
CREATE TABLE foo3(c int);
CREATE TABLE foo4(d int);
-- test the simple table names
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

SELECT * FROM foo1;
 a 
---
(0 rows)

SELECT * FROM foo1, foo2;
 a | b 
---+---
(0 rows)

SELECT * FROM foo1, foo2, foo3;
 a | b | c 
---+---+---
(0 rows)

SELECT * FROM foo1, foo2, foo3, foo4;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
                query                 |                     relations                     
--------------------------------------+---------------------------------------------------
 SELECT * FROM foo1                   | {public.foo1}
 SELECT * FROM foo1, foo2             | {public.foo1,public.foo2}
 SELECT * FROM foo1, foo2, foo3       | {public.foo1,public.foo2,public.foo3}
 SELECT * FROM foo1, foo2, foo3, foo4 | {public.foo1,public.foo2,public.foo3,public.foo4}
 SELECT pg_stat_monitor_reset()       | 
(5 rows)

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

-- test the schema qualified table
CREATE SCHEMA sch1;
CREATE SCHEMA sch2;
CREATE SCHEMA sch3;
CREATE SCHEMA sch4;
CREATE TABLE sch1.foo1(a int);
CREATE TABLE sch2.foo2(b int);
CREATE TABLE sch3.foo3(c int);
CREATE TABLE sch4.foo4(d int);
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

SELECT * FROM sch1.foo1;
 a 
---
(0 rows)

SELECT * FROM sch1.foo1, sch2.foo2;
 a | b 
---+---
(0 rows)

SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3;
 a | b | c 
---+---+---
(0 rows)

SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3, sch4.foo4;
 a | b | c | d 
---+---+---+---
(0 rows)

SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
                          query                           |                 relations                 
----------------------------------------------------------+-------------------------------------------
 SELECT * FROM sch1.foo1                                  | {sch1.foo1}
 SELECT * FROM sch1.foo1, sch2.foo2                       | {sch1.foo1,sch2.foo2}
 SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3            | {sch1.foo1,sch2.foo2,sch3.foo3}
 SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3, sch4.foo4 | {sch1.foo1,sch2.foo2,sch3.foo3,sch4.foo4}
 SELECT pg_stat_monitor_reset()                           | 
(5 rows)

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

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

SELECT * FROM sch1.foo1, foo1;
 a | a 
---+---
(0 rows)

SELECT * FROM sch1.foo1, sch2.foo2, foo1, foo2;
 a | b | a | b 
---+---+---+---
(0 rows)

SELECT query, relations from pg_stat_monitor ORDER BY query;
                     query                      |                   relations                   
------------------------------------------------+-----------------------------------------------
 SELECT * FROM sch1.foo1, foo1                  | {sch1.foo1,public.foo1}
 SELECT * FROM sch1.foo1, sch2.foo2, foo1, foo2 | {sch1.foo1,sch2.foo2,public.foo1,public.foo2}
 SELECT pg_stat_monitor_reset()                 | 
(3 rows)

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

-- test the view
CREATE VIEW v1 AS SELECT * from foo1;
CREATE VIEW v2 AS SELECT * from foo1,foo2;
CREATE VIEW v3 AS SELECT * from foo1,foo2,foo3;
CREATE VIEW v4 AS SELECT * from foo1,foo2,foo3,foo4;
SELECT pg_stat_monitor_reset();
 pg_stat_monitor_reset 
-----------------------
 
(1 row)

SELECT * FROM v1;
 a 
---
(0 rows)

SELECT * FROM v1,v2;
 a | a | b 
---+---+---
(0 rows)

SELECT * FROM v1,v2,v3;
 a | a | b | a | b | c 
---+---+---+---+---+---
(0 rows)

SELECT * FROM v1,v2,v3,v4;
 a | a | b | a | b | c | a | b | c | d 
---+---+---+---+---+---+---+---+---+---
(0 rows)

SELECT query, relations from pg_stat_monitor ORDER BY query collate "C";
             query              |                                           relations                                           
--------------------------------+-----------------------------------------------------------------------------------------------
 SELECT * FROM v1               | {public.v1*,public.foo1}
 SELECT * FROM v1,v2            | {public.v1*,public.foo1,public.v2*,public.foo2}
 SELECT * FROM v1,v2,v3         | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3}
 SELECT * FROM v1,v2,v3,v4      | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3,public.v4*,public.foo4}
 SELECT pg_stat_monitor_reset() | 
(5 rows)

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

DROP VIEW v1;
DROP VIEW v2;
DROP VIEW v3;
DROP VIEW v4;
DROP TABLE foo1;
DROP TABLE foo2;
DROP TABLE foo3;
DROP TABLE foo4;
DROP TABLE sch1.foo1;
DROP TABLE sch2.foo2;
DROP TABLE sch3.foo3;
DROP TABLE sch4.foo4;
DROP SCHEMA sch1;
DROP SCHEMA sch2;
DROP SCHEMA sch3;
DROP SCHEMA sch4;
DROP EXTENSION pg_stat_monitor;
