PG-186: Add support to monitor query execution plan.

This requires refactoring of code to add this functionality. Along with
that this patch contains regression test cases.
This commit is contained in:
Ibrar Ahmed
2021-03-12 18:55:12 +00:00
parent 8f69daa5dd
commit 066162c3f6
34 changed files with 10234 additions and 1173 deletions

View File

@@ -0,0 +1,28 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT 1 AS num;
num
-----
1
(1 row)
SELECT query,application_name FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | application_name
--------------------------------------------------------------------------------+-----------------------------
SELECT $1 AS num | pg_regress/application_name
SELECT pg_stat_monitor_reset(); | pg_regress/application_name
SELECT query,application_name FROM pg_stat_monitor ORDER BY query COLLATE "C"; |
(3 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@@ -11,19 +11,20 @@ select pg_sleep(.5);
(1 row)
SELECT 1;
?column?
----------
1
SELECT 1 AS num;
num
-----
1
(1 row)
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
query
--------------------------------
SELECT $1
SELECT pg_stat_monitor_reset()
query
---------------------------------------------------------------
SELECT $1 AS num
SELECT pg_stat_monitor_reset();
SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C";
select pg_sleep($1)
(3 rows)
(4 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

@@ -0,0 +1,45 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
CREATE TABLE t1 (a INTEGER);
INSERT INTO t1 VALUES(1);
SELECT a FROM t1;
a
---
1
(1 row)
UPDATE t1 SET a = 2;
DELETE FROM t1;
SELECT a FROM t1 FOR UPDATE;
a
---
(0 rows)
TRUNCATE t1;
DROP TABLE t1;
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | cmd_type | cmd_type_text
-----------------------------------------------------------------------------------------+----------+---------------
CREATE TABLE t1 (a INTEGER); | 0 |
DELETE FROM t1; | 4 | DELETE
DROP TABLE t1; | 0 |
INSERT INTO t1 VALUES($1) | 3 | INSERT
SELECT a FROM t1; | 1 | SELECT
SELECT pg_stat_monitor_reset(); | 1 | SELECT
SELECT query, cmd_type, cmd_type_text FROM pg_stat_monitor ORDER BY query COLLATE "C"; | 0 |
TRUNCATE t1; | 0 |
UPDATE t1 SET a = $1 | 2 | UPDATE
(9 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@@ -0,0 +1,93 @@
CREATE EXTENSION pg_stat_monitor;
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,calls FROM pg_stat_monitor 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
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C"; | 1
(3 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
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,calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls
---------------------------------------------------------------------------------------------------+-------
SELECT $1 AS num | 1
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 n + $3 | 1
SELECT n = $3 | 1
SELECT pg_stat_monitor_reset(); | 1
SELECT query,calls FROM pg_stat_monitor ORDER BY query COLLATE "C"; | 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 $$; |
(7 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP TABLE t1;
DROP TABLE t2;
DROP TABLE t3;
DROP TABLE t4;
DROP EXTENSION pg_stat_monitor;

View File

@@ -0,0 +1,54 @@
CREATE EXTENSION pg_stat_monitor;
CREATE DATABASE db1;
CREATE DATABASE db2;
\c db1
CREATE TABLE t1 (a int);
CREATE TABLE t2 (b int);
\c db2
CREATE TABLE t3 (c int);
CREATE TABLE t4 (d int);
\c contrib_regression
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
\c db1
SELECT * FROM t1,t2 WHERE t1.a = t2.b;
a | b
---+---
(0 rows)
\c db2
SELECT * FROM t3,t4 WHERE t3.c = t4.d;
c | d
---+---
(0 rows)
\c contrib_regression
SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
datname | query
--------------------+------------------------------------------------------------------------
db1 | SELECT * FROM t1,t2 WHERE t1.a = t2.b;
db2 | SELECT * FROM t3,t4 WHERE t3.c = t4.d;
contrib_regression | SELECT datname, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
contrib_regression | SELECT pg_stat_monitor_reset();
(4 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
\c db1
DROP TABLE t1;
DROP TABLE t2;
\c db2
DROP TABLE t3;
DROP TABLE t4;
\c contrib_regression
DROP DATABASE db1;
DROP DATABASE db2;
DROP EXTENSION pg_stat_monitor;

View File

@@ -0,0 +1,44 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT 1/0; -- divide by zero
ERROR: division by zero
SELECT * FROM unknown; -- unknown table
ERROR: relation "unknown" does not exist
LINE 1: SELECT * FROM unknown;
^
ELECET * FROM unknown; -- syntax error
ERROR: syntax error at or near "ELECET"
LINE 1: ELECET * FROM unknown;
^
do $$
BEGIN
RAISE WARNING 'warning message';
END $$;
WARNING: warning message
SELECT query, elevel,sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | elevel | sqlcode | message
----------------------------------------------------------------------------------------+--------+---------+-----------------------------------
ELECET * FROM unknown; | 20 | 42601 | syntax error at or near "ELECET"
SELECT $1/$2 | 0 | |
SELECT * FROM unknown; | 20 | 42P01 | relation "unknown" does not exist
SELECT 1/0; | 20 | 22012 | division by zero
SELECT pg_stat_monitor_reset(); | 0 | |
SELECT query, elevel,sqlcode, message FROM pg_stat_monitor ORDER BY query COLLATE "C"; | 0 | |
do $$ +| 19 | 01000 | warning message
BEGIN +| | |
RAISE WARNING 'warning message'; +| | |
END $$; | | |
(7 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@@ -16,6 +16,7 @@ SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+---------
pg_stat_monitor.pgsm_bucket_time | 300 | 300 | Sets the time in seconds per bucket. | 1 | 2147483647 | 1
pg_stat_monitor.pgsm_enable | 1 | 1 | Enable/Disable statistics collector. | 0 | 0 | 0
pg_stat_monitor.pgsm_enable_query_plan | 0 | 0 | Enable/Disable query plan monitoring | 0 | 0 | 0
pg_stat_monitor.pgsm_histogram_buckets | 10 | 10 | Sets the maximum number of histogram buckets | 2 | 2147483647 | 1
pg_stat_monitor.pgsm_histogram_max | 100000 | 100000 | Sets the time in millisecond. | 10 | 2147483647 | 1
pg_stat_monitor.pgsm_histogram_min | 0 | 0 | Sets the time in millisecond. | 0 | 2147483647 | 1
@@ -25,8 +26,9 @@ SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C";
pg_stat_monitor.pgsm_overflow_target | 0 | 1 | Sets the overflow target for pg_stat_monitor | 0 | 1 | 1
pg_stat_monitor.pgsm_query_max_len | 1024 | 1024 | Sets the maximum length of query. | 1024 | 2147483647 | 1
pg_stat_monitor.pgsm_query_shared_buffer | 20 | 20 | Sets the maximum size of shared memory in (MB) used for query tracked by pg_stat_monitor. | 1 | 10000 | 1
pg_stat_monitor.pgsm_track_planning | 1 | 1 | Selects whether planning statistics are tracked. | 0 | 0 | 0
pg_stat_monitor.pgsm_track_utility | 1 | 1 | Selects whether utility commands are tracked. | 0 | 0 | 0
(12 rows)
(14 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset

View File

View File

@@ -1,436 +0,0 @@
CREATE EXTENSION pg_stat_monitor;
--
-- simple and compound statements
--
SET pg_stat_monitor.track_utility = FALSE;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT 1 AS "int";
int
-----
1
(1 row)
SELECT 'hello'
-- multiline
AS "text";
text
-------
hello
(1 row)
SELECT 'world' AS "text";
text
-------
world
(1 row)
-- transaction
BEGIN;
SELECT 1 AS "int";
int
-----
1
(1 row)
SELECT 'hello' AS "text";
text
-------
hello
(1 row)
COMMIT;
-- compound transaction
BEGIN \;
SELECT 2.0 AS "float" \;
SELECT 'world' AS "text" \;
COMMIT;
-- compound with empty statements and spurious leading spacing
\;\; SELECT 3 + 3 \;\;\; SELECT ' ' || ' !' \;\; SELECT 1 + 4 \;;
?column?
----------
5
(1 row)
-- non ;-terminated statements
SELECT 1 + 1 + 1 AS "add" \gset
SELECT :add + 1 + 1 AS "add" \;
SELECT :add + 1 + 1 AS "add" \gset
-- set operator
SELECT 1 AS i UNION SELECT 2 ORDER BY i;
i
---
1
2
(2 rows)
-- ? operator
select '{"a":1, "b":2}'::jsonb ? 'b';
?column?
----------
t
(1 row)
-- cte
WITH t(f) AS (
VALUES (1.0), (2.0)
)
SELECT f FROM t ORDER BY f;
f
-----
1.0
2.0
(2 rows)
-- prepared statement with parameter
PREPARE pgss_test (int) AS SELECT $1, 'test' LIMIT 1;
EXECUTE pgss_test(1);
?column? | ?column?
----------+----------
1 | test
(1 row)
DEALLOCATE pgss_test;
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
---------------------------------------------------+-------+------
BEGIN | 2 | 0
COMMIT | 2 | 0
PREPARE pgss_test (int) AS SELECT $1, $2 LIMIT $3 | 1 | 1
SELECT $1 | 2 | 2
SELECT $1 +| 4 | 4
+| |
AS "text" | |
SELECT $1 + $2 | 2 | 2
SELECT $1 + $2 + $3 AS "add" | 3 | 3
SELECT $1 AS "float" | 1 | 1
SELECT $1 AS i UNION SELECT $2 ORDER BY i | 1 | 2
SELECT $1 || $2 | 1 | 1
SELECT pg_stat_monitor_reset() | 1 | 1
WITH t(f) AS ( +| 1 | 2
VALUES ($1), ($2) +| |
) +| |
SELECT f FROM t ORDER BY f | |
select $1::jsonb ? $2 | 1 | 1
(13 rows)
--
-- CRUD: INSERT SELECT UPDATE DELETE on test table
--
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
-- utility "create table" should not be shown
CREATE TEMP TABLE test (a int, b char(20));
INSERT INTO test VALUES(generate_series(1, 10), 'aaa');
UPDATE test SET b = 'bbb' WHERE a > 7;
DELETE FROM test WHERE a > 9;
-- explicit transaction
BEGIN;
UPDATE test SET b = '111' WHERE a = 1 ;
COMMIT;
BEGIN \;
UPDATE test SET b = '222' WHERE a = 2 \;
COMMIT ;
UPDATE test SET b = '333' WHERE a = 3 \;
UPDATE test SET b = '444' WHERE a = 4 ;
BEGIN \;
UPDATE test SET b = '555' WHERE a = 5 \;
UPDATE test SET b = '666' WHERE a = 6 \;
COMMIT ;
-- many INSERT values
INSERT INTO test (a, b) VALUES (1, 'a'), (2, 'b'), (3, 'c');
-- SELECT with constants
SELECT * FROM test WHERE a > 5 ORDER BY a ;
a | b
---+----------------------
6 | 666
7 | aaa
8 | bbb
9 | bbb
(4 rows)
SELECT *
FROM test
WHERE a > 9
ORDER BY a ;
a | b
---+---
(0 rows)
-- SELECT without constants
SELECT * FROM test ORDER BY a;
a | b
---+----------------------
1 | a
1 | 111
2 | b
2 | 222
3 | c
3 | 333
4 | 444
5 | 555
6 | 666
7 | aaa
8 | bbb
9 | bbb
(12 rows)
-- SELECT with IN clause
SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5);
a | b
---+----------------------
1 | 111
2 | 222
3 | 333
4 | 444
5 | 555
1 | a
2 | b
3 | c
(8 rows)
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
-------------------------------------------------------------+-------+------
BEGIN | 3 | 0
COMMIT | 3 | 0
CREATE TEMP TABLE test (a int, b char(20)) | 1 | 0
DELETE FROM test WHERE a > $1 | 1 | 1
INSERT INTO test (a, b) VALUES ($1, $2), ($3, $4), ($5, $6) | 1 | 3
INSERT INTO test VALUES(generate_series($1, $2), $3) | 1 | 10
SELECT * FROM test ORDER BY a | 1 | 12
SELECT * FROM test WHERE a > $1 ORDER BY a | 2 | 4
SELECT * FROM test WHERE a IN ($1, $2, $3, $4, $5) | 1 | 8
SELECT pg_stat_monitor_reset() | 1 | 1
UPDATE test SET b = $1 WHERE a = $2 | 6 | 6
UPDATE test SET b = $1 WHERE a > $2 | 1 | 3
(12 rows)
--
-- pg_stat_monitor.track = none
--
SET pg_stat_monitor.track = 'none';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT 1 AS "one";
one
-----
1
(1 row)
SELECT 1 + 1 AS "two";
two
-----
2
(1 row)
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
--------------------------------+-------+------
SELECT $1 | 1 | 1
SELECT $1 + $2 | 1 | 1
SELECT pg_stat_monitor_reset() | 1 | 1
(3 rows)
--
-- pg_stat_monitor.track = top
--
SET pg_stat_monitor.track = 'top';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DO LANGUAGE plpgsql $$
BEGIN
-- this is a SELECT
PERFORM 'hello world'::TEXT;
END;
$$;
-- PL/pgSQL function
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
DECLARE
r INTEGER;
BEGIN
SELECT (i + 1 + 1.0)::INTEGER INTO r;
RETURN r;
END; $$ LANGUAGE plpgsql;
SELECT PLUS_TWO(3);
plus_two
----------
5
(1 row)
SELECT PLUS_TWO(7);
plus_two
----------
9
(1 row)
-- SQL function --- use LIMIT to keep it from being inlined
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
SELECT PLUS_ONE(8);
plus_one
----------
9
(1 row)
SELECT PLUS_ONE(10);
plus_one
----------
11
(1 row)
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
-----------------------------------------------------------+-------+------
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$+| 1 | 0
DECLARE +| |
r INTEGER; +| |
BEGIN +| |
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
RETURN r; +| |
END; $$ LANGUAGE plpgsql | |
DO LANGUAGE plpgsql $$ +| 1 | 0
BEGIN +| |
-- this is a SELECT +| |
PERFORM 'hello world'::TEXT; +| |
END; +| |
$$ | |
SELECT $1 +| 1 | 1
+| |
AS "text" | |
SELECT (i + $2 + $3)::INTEGER | 2 | 2
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
SELECT PLUS_ONE($1) | 2 | 2
SELECT PLUS_TWO($1) | 2 | 2
SELECT pg_stat_monitor_reset() | 1 | 1
(9 rows)
--
-- pg_stat_monitor.track = all
--
SET pg_stat_monitor.track = 'all';
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
-- we drop and recreate the functions to avoid any caching funnies
DROP FUNCTION PLUS_ONE(INTEGER);
DROP FUNCTION PLUS_TWO(INTEGER);
-- PL/pgSQL function
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$
DECLARE
r INTEGER;
BEGIN
SELECT (i + 1 + 1.0)::INTEGER INTO r;
RETURN r;
END; $$ LANGUAGE plpgsql;
SELECT PLUS_TWO(-1);
plus_two
----------
1
(1 row)
SELECT PLUS_TWO(2);
plus_two
----------
4
(1 row)
-- SQL function --- use LIMIT to keep it from being inlined
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL;
SELECT PLUS_ONE(3);
plus_one
----------
4
(1 row)
SELECT PLUS_ONE(1);
plus_one
----------
2
(1 row)
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
-----------------------------------------------------------+-------+------
CREATE FUNCTION PLUS_ONE(i INTEGER) RETURNS INTEGER AS +| 1 | 0
$$ SELECT (i + 1.0)::INTEGER LIMIT 1 $$ LANGUAGE SQL | |
CREATE FUNCTION PLUS_TWO(i INTEGER) RETURNS INTEGER AS $$+| 1 | 0
DECLARE +| |
r INTEGER; +| |
BEGIN +| |
SELECT (i + 1 + 1.0)::INTEGER INTO r; +| |
RETURN r; +| |
END; $$ LANGUAGE plpgsql | |
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
SELECT (i + $2 + $3)::INTEGER | 2 | 2
SELECT (i + $2)::INTEGER LIMIT $3 | 2 | 2
SELECT PLUS_ONE($1) | 2 | 2
SELECT PLUS_TWO($1) | 2 | 2
SELECT pg_stat_monitor_reset() | 1 | 1
(9 rows)
--
-- utility commands
--
SET pg_stat_monitor.track_utility = TRUE;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SELECT 1;
?column?
----------
1
(1 row)
CREATE INDEX test_b ON test(b);
DROP TABLE test \;
DROP TABLE IF EXISTS test \;
DROP FUNCTION PLUS_ONE(INTEGER);
NOTICE: table "test" does not exist, skipping
DROP TABLE IF EXISTS test \;
DROP TABLE IF EXISTS test \;
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER);
NOTICE: table "test" does not exist, skipping
NOTICE: table "test" does not exist, skipping
NOTICE: function plus_one(pg_catalog.int4) does not exist, skipping
DROP FUNCTION PLUS_TWO(INTEGER);
SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls | rows
-------------------------------------------+-------+------
CREATE INDEX test_b ON test(b) | 1 | 0
DROP FUNCTION IF EXISTS PLUS_ONE(INTEGER) | 1 | 0
DROP FUNCTION PLUS_ONE(INTEGER) | 1 | 0
DROP FUNCTION PLUS_TWO(INTEGER) | 1 | 0
DROP TABLE IF EXISTS test | 3 | 0
DROP TABLE test | 1 | 0
SELECT $1 | 1 | 1
SELECT pg_stat_monitor_reset() | 1 | 1
(8 rows)
DROP EXTENSION pg_stat_monitor;

View File

@@ -6,26 +6,46 @@ SELECT pg_stat_monitor_reset();
(1 row)
CREATE TABLE foo1(a int);
CREATE TABLE foo2(a int);
CREATE TABLE foo3(a int);
CREATE TABLE foo4(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 | a | a | a
a | b | c | d
---+---+---+---
(0 rows)
SELECT query, relations from pg_stat_monitor ORDER BY query;
query | relations
--------------------------------------+---------------------------------------------------
SELECT * FROM foo1, foo2, foo3, foo4 | {public.foo1,public.foo2,public.foo3,public.foo4}
SELECT pg_stat_monitor_reset() |
(2 rows)
query | relations
--------------------------------------------------------------+---------------------------------------------------
SELECT * FROM foo1, foo2, foo3, foo4; | {public.foo1,public.foo2,public.foo3,public.foo4}
SELECT * FROM foo1, foo2, foo3; | {public.foo1,public.foo2,public.foo3}
SELECT * FROM foo1, foo2; | {public.foo1,public.foo2}
SELECT * FROM foo1; | {public.foo1}
SELECT pg_stat_monitor_reset(); |
SELECT query, relations from pg_stat_monitor ORDER BY query; |
(6 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
@@ -33,8 +53,151 @@ SELECT 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;
query | relations
--------------------------------------------------------------+-------------------------------------------
SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3, sch4.foo4; | {sch1.foo1,sch2.foo2,sch3.foo3,sch4.foo4}
SELECT * FROM sch1.foo1, sch2.foo2, sch3.foo3; | {sch1.foo1,sch2.foo2,sch3.foo3}
SELECT * FROM sch1.foo1, sch2.foo2; | {sch1.foo1,sch2.foo2}
SELECT * FROM sch1.foo1; | {sch1.foo1}
SELECT pg_stat_monitor_reset(); |
SELECT query, relations from pg_stat_monitor ORDER BY query; |
(6 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(); |
SELECT query, relations from pg_stat_monitor ORDER BY query; |
(4 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;
query | relations
--------------------------------------------------------------+-----------------------------------------------------------------------------------------------
SELECT * FROM v1,v2,v3,v4; | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3,public.v4*,public.foo4}
SELECT * FROM v1,v2,v3; | {public.v1*,public.foo1,public.v2*,public.foo2,public.v3*,public.foo3}
SELECT * FROM v1,v2; | {public.v1*,public.foo1,public.v2*,public.foo2}
SELECT * FROM v1; | {public.v1*,public.foo1}
SELECT pg_stat_monitor_reset(); |
SELECT query, relations from pg_stat_monitor ORDER BY query; |
(6 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;

8560
regression/expected/rows.out Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,52 @@
CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS
$$
BEGIN
return (select $1 + $2);
END; $$ language plpgsql;
CREATE OR REPLACE function add2(int, int) RETURNS int as
$$
BEGIN
return add($1,$2);
END;
$$ language plpgsql;
SELECT add2(1,2);
add2
------
3
(1 row)
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | top_query
--------------------------------------------------------------------------+--------------------
CREATE OR REPLACE FUNCTION add(int, int) RETURNS INTEGER AS +|
$$ +|
BEGIN +|
return (select $1 + $2); +|
END; $$ language plpgsql; |
CREATE OR REPLACE function add2(int, int) RETURNS int as +|
$$ +|
BEGIN +|
return add($1,$2); +|
END; +|
$$ language plpgsql; |
SELECT (select $1 + $2) | SELECT add2($1,$2)
SELECT add($1,$2) |
SELECT add2($1,$2) |
SELECT pg_stat_monitor_reset(); |
SELECT query, top_query FROM pg_stat_monitor ORDER BY query COLLATE "C"; |
(7 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP EXTENSION pg_stat_monitor;

View File

@@ -0,0 +1,53 @@
DROP USER IF EXISTS su;
CREATE USER su WITH SUPERUSER;
SET ROLE su;
CREATE EXTENSION pg_stat_monitor;
CREATE USER u1;
CREATE USER u2;
SET ROLE su;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
SET ROLE u1;
CREATE TABLE t1 (a int);
SELECT * FROM t1;
a
---
(0 rows)
SET ROLE u2;
CREATE TABLE t2 (a int);
SELECT * FROM t2;
a
---
(0 rows)
SET ROLE su;
SELECT userid, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
userid | query
--------+-----------------------------------------------------------------------
u1 | CREATE TABLE t1 (a int);
u2 | CREATE TABLE t2 (a int);
u1 | SELECT * FROM t1;
u2 | SELECT * FROM t2;
su | SELECT pg_stat_monitor_reset();
su | SELECT userid, query FROM pg_stat_monitor ORDER BY query COLLATE "C";
su | SET ROLE su;
u1 | SET ROLE u1;
u2 | SET ROLE u2;
(9 rows)
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------
(1 row)
DROP TABLE t1;
DROP TABLE t2;
DROP USER u1;
DROP USER u2;
DROP EXTENSION pg_stat_monitor;

View File

@@ -2,7 +2,7 @@ CREATE EXTENSION pg_stat_monitor;
SELECT pg_stat_monitor_version();
pg_stat_monitor_version
-------------------------
0.7.0
devel
(1 row)
DROP EXTENSION pg_stat_monitor;