Skip to content

Commit

Permalink
Add query denormalization regression test for prepared statements
Browse files Browse the repository at this point in the history
Ensures that the denormalization of prepared statements is working, also
ensure that a query which takes more time to execute replaces the
previous denormalized query.
  • Loading branch information
darkfronza committed Aug 9, 2024
1 parent 548dd61 commit 2487f44
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LDFLAGS_SL += $(filter -lm, $(LIBS))

TAP_TESTS = 1
REGRESS_OPTS = --temp-config $(top_srcdir)/contrib/pg_stat_monitor/pg_stat_monitor.conf --inputdir=regression
REGRESS = basic version guc pgsm_query_id functions counters relations database error_insert application_name application_name_unique top_query cmd_type error rows tags user level_tracking
REGRESS = basic version guc pgsm_query_id functions counters relations database error_insert application_name application_name_unique top_query cmd_type error rows tags user level_tracking denorm_prepared_statements

# Disabled because these tests require "shared_preload_libraries=pg_stat_statements",
# which typical installcheck users do not have (e.g. buildfarm clients).
Expand Down
35 changes: 35 additions & 0 deletions regression/expected/denorm_prepared_statements.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_normalized_query='off';
CREATE TABLE t1 (a TEXT, b TEXT, c TEXT);
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

PREPARE prepstmt(TEXT, TEXT, TEXT) AS INSERT INTO t1(a, b, c) VALUES($1, $2, $3);
EXECUTE prepstmt('A', 'B', 'C');
SELECT query, calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
query | calls
--------------------------------------------------------------------------------+-------
PREPARE prepstmt(TEXT, TEXT, TEXT) AS INSERT INTO t1(a, b, c) VALUES(A, B, C); | 1
SELECT pg_stat_monitor_reset() | 1
(2 rows)

EXECUTE prepstmt(REPEAT('XYZ', 8192), md5(random()::text), REPEAT('RANDOM', 4096));
SELECT SUBSTRING(query, 0, 128), calls FROM pg_stat_monitor ORDER BY query COLLATE "C";
substring | calls
---------------------------------------------------------------------------------------------------------------------------------+-------
PREPARE prepstmt(TEXT, TEXT, TEXT) AS INSERT INTO t1(a, b, c) VALUES(XYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZXYZX | 2
SELECT pg_stat_monitor_reset() | 1
SELECT query, calls FROM pg_stat_monitor ORDER BY query COLLATE "C" | 1
(3 rows)

DROP TABLE t1;
SELECT pg_stat_monitor_reset();
pg_stat_monitor_reset
-----------------------

(1 row)

DROP EXTENSION pg_stat_monitor;
19 changes: 19 additions & 0 deletions regression/sql/denorm_prepared_statements.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE EXTENSION pg_stat_monitor;
Set pg_stat_monitor.pgsm_normalized_query='off';

CREATE TABLE t1 (a TEXT, b TEXT, c TEXT);

SELECT pg_stat_monitor_reset();

PREPARE prepstmt(TEXT, TEXT, TEXT) AS INSERT INTO t1(a, b, c) VALUES($1, $2, $3);

EXECUTE prepstmt('A', 'B', 'C');
SELECT query, calls FROM pg_stat_monitor ORDER BY query COLLATE "C";

EXECUTE prepstmt(REPEAT('XYZ', 8192), md5(random()::text), REPEAT('RANDOM', 4096));
SELECT SUBSTRING(query, 0, 128), calls FROM pg_stat_monitor ORDER BY query COLLATE "C";

DROP TABLE t1;

SELECT pg_stat_monitor_reset();
DROP EXTENSION pg_stat_monitor;

0 comments on commit 2487f44

Please sign in to comment.