From a222adc587199c3fdce6b4ab5346156e270f740b Mon Sep 17 00:00:00 2001 From: Ibrar Ahmed Date: Mon, 15 Feb 2021 13:08:08 +0000 Subject: [PATCH] PG-178: Test cases fixes. --- expected/basic_1.out | 35 +++++++++ expected/guc_1.out | 37 ++++++++++ expected/pg_stat_monitor_1.out | 128 ++++++++++++++++++++++----------- expected/relations.out | 14 ++-- expected/relations_1.out | 40 ++++++----- guc.c | 2 +- sql/relations.sql | 3 +- 7 files changed, 193 insertions(+), 66 deletions(-) create mode 100644 expected/basic_1.out create mode 100644 expected/guc_1.out diff --git a/expected/basic_1.out b/expected/basic_1.out new file mode 100644 index 0000000..5e5dba3 --- /dev/null +++ b/expected/basic_1.out @@ -0,0 +1,35 @@ +CREATE EXTENSION pg_stat_monitor; +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +select pg_sleep(.5); + pg_sleep +---------- + +(1 row) + +SELECT 1; + ?column? +---------- + 1 +(1 row) + +SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C"; + query +-------------------------------------------------------------- + SELECT $1 + SELECT pg_stat_monitor_reset() + SELECT query FROM pg_stat_monitor ORDER BY query COLLATE "C" + select pg_sleep($1) +(4 rows) + +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +DROP EXTENSION pg_stat_monitor; diff --git a/expected/guc_1.out b/expected/guc_1.out new file mode 100644 index 0000000..093fb2c --- /dev/null +++ b/expected/guc_1.out @@ -0,0 +1,37 @@ +CREATE EXTENSION pg_stat_monitor; +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +select pg_sleep(.5); + pg_sleep +---------- + +(1 row) + +SELECT * FROM pg_stat_monitor_settings ORDER BY name COLLATE "C"; + name | value | default_value | description | minimum | maximum | restart +------------------------------------------+--------+---------------+----------------------------------------------------------------------------------------------------------+---------+------------+--------- + 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_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 + pg_stat_monitor.pgsm_max | 100 | 100 | Sets the maximum size of shared memory in (MB) used for statement's metadata tracked by pg_stat_monitor. | 1 | 1000 | 1 + pg_stat_monitor.pgsm_max_buckets | 10 | 10 | Sets the maximum number of buckets. | 1 | 10 | 1 + pg_stat_monitor.pgsm_normalized_query | 1 | 1 | Selects whether save query in normalized format. | 0 | 0 | 0 + 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) + +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +DROP EXTENSION pg_stat_monitor; diff --git a/expected/pg_stat_monitor_1.out b/expected/pg_stat_monitor_1.out index a16de31..e5f3dbc 100644 --- a/expected/pg_stat_monitor_1.out +++ b/expected/pg_stat_monitor_1.out @@ -98,6 +98,8 @@ 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 @@ -115,7 +117,7 @@ SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C"; ) +| | SELECT f FROM t ORDER BY f | | select $1::jsonb ? $2 | 1 | 1 -(11 rows) +(14 rows) -- -- CRUD: INSERT SELECT UPDATE DELETE on test table @@ -197,18 +199,22 @@ SELECT * FROM test WHERE a IN (1, 2, 3, 4, 5); (8 rows) SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C"; - query | calls | rows --------------------------------------------------------------+-------+------ - 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 -(9 rows) + 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 + SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0 + UPDATE test SET b = $1 WHERE a = $2 | 6 | 6 + UPDATE test SET b = $1 WHERE a > $2 | 1 | 3 +(13 rows) -- -- pg_stat_monitor.track = none @@ -233,12 +239,13 @@ SELECT 1 + 1 AS "two"; (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) + query | calls | rows +---------------------------------------------------------------------------+-------+------ + SELECT $1 | 1 | 1 + SELECT $1 + $2 | 1 | 1 + SELECT pg_stat_monitor_reset() | 1 | 1 + SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0 +(4 rows) -- -- pg_stat_monitor.track = top @@ -292,17 +299,33 @@ SELECT PLUS_ONE(10); (1 row) SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C"; - query | calls | rows ------------------------------------+-------+------ - 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 -(6 rows) + 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 + SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0 +(10 rows) -- -- pg_stat_monitor.track = all @@ -353,14 +376,26 @@ SELECT PLUS_ONE(1); (1 row) SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C"; - query | calls | rows ------------------------------------+-------+------ - 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 -(5 rows) + 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 + SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0 +(10 rows) -- -- utility commands @@ -391,10 +426,17 @@ 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 ---------------------------------+-------+------ - SELECT $1 | 1 | 1 - SELECT pg_stat_monitor_reset() | 1 | 1 -(2 rows) + 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 + SELECT query, calls, rows FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1 | 0 +(9 rows) DROP EXTENSION pg_stat_monitor; diff --git a/expected/relations.out b/expected/relations.out index 88d57bd..182772f 100644 --- a/expected/relations.out +++ b/expected/relations.out @@ -9,6 +9,12 @@ CREATE TABLE foo1(a int); CREATE TABLE foo2(a int); CREATE TABLE foo3(a int); CREATE TABLE foo4(a int); +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + SELECT * FROM foo1, foo2, foo3, foo4; a | a | a | a ---+---+---+--- @@ -21,14 +27,14 @@ SELECT query, relations from pg_stat_monitor ORDER BY query; SELECT pg_stat_monitor_reset() | (2 rows) -DROP TABLE foo1; -DROP TABLE foo2; -DROP TABLE foo3; -DROP TABLE foo4; SELECT pg_stat_monitor_reset(); pg_stat_monitor_reset ----------------------- (1 row) +DROP TABLE foo1; +DROP TABLE foo2; +DROP TABLE foo3; +DROP TABLE foo4; DROP EXTENSION pg_stat_monitor; diff --git a/expected/relations_1.out b/expected/relations_1.out index 3bfb623..63ea0dd 100644 --- a/expected/relations_1.out +++ b/expected/relations_1.out @@ -9,27 +9,33 @@ CREATE TABLE foo1(a int); CREATE TABLE foo2(a int); CREATE TABLE foo3(a int); CREATE TABLE foo4(a int); -SELECT * FROM foo1, foo2, foo3, foo4; - a | a | a | a ----+---+---+--- -(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() | - SELECT query, relations from pg_stat_monitor | -(3 rows) - -DROP TABLE foo1; -DROP TABLE foo2; -DROP TABLE foo3; -DROP TABLE foo4; SELECT pg_stat_monitor_reset(); pg_stat_monitor_reset ----------------------- (1 row) +SELECT * FROM foo1, foo2, foo3, foo4; + a | a | a | a +---+---+---+--- +(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() | + SELECT query, relations from pg_stat_monitor ORDER BY query | +(3 rows) + +SELECT pg_stat_monitor_reset(); + pg_stat_monitor_reset +----------------------- + +(1 row) + +DROP TABLE foo1; +DROP TABLE foo2; +DROP TABLE foo3; +DROP TABLE foo4; DROP EXTENSION pg_stat_monitor; diff --git a/guc.c b/guc.c index aebaf9f..3f1d75d 100644 --- a/guc.c +++ b/guc.c @@ -68,7 +68,7 @@ init_guc(void) conf[i] = (GucVariable) { .guc_name = "pg_stat_monitor.pgsm_track_utility", .guc_desc = "Selects whether utility commands are tracked.", - .guc_default = 0, + .guc_default = 1, .guc_min = 0, .guc_max = 0, .guc_restart = false, diff --git a/sql/relations.sql b/sql/relations.sql index fbeefa2..7eaef72 100644 --- a/sql/relations.sql +++ b/sql/relations.sql @@ -4,11 +4,12 @@ CREATE TABLE foo1(a int); CREATE TABLE foo2(a int); CREATE TABLE foo3(a int); CREATE TABLE foo4(a int); +SELECT pg_stat_monitor_reset(); SELECT * FROM foo1, foo2, foo3, foo4; SELECT query, relations from pg_stat_monitor ORDER BY query; +SELECT pg_stat_monitor_reset(); DROP TABLE foo1; DROP TABLE foo2; DROP TABLE foo3; DROP TABLE foo4; -SELECT pg_stat_monitor_reset(); DROP EXTENSION pg_stat_monitor;