From 2487f448273d4d96e0bc01a364b7b93c4d545ce5 Mon Sep 17 00:00:00 2001 From: Diego Fronza Date: Fri, 9 Aug 2024 16:23:47 -0300 Subject: [PATCH] Add query denormalization regression test for prepared statements 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. --- Makefile | 2 +- .../expected/denorm_prepared_statements.out | 35 +++++++++++++++++++ regression/sql/denorm_prepared_statements.sql | 19 ++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 regression/expected/denorm_prepared_statements.out create mode 100644 regression/sql/denorm_prepared_statements.sql diff --git a/Makefile b/Makefile index 117c4871..280dfd5c 100644 --- a/Makefile +++ b/Makefile @@ -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). diff --git a/regression/expected/denorm_prepared_statements.out b/regression/expected/denorm_prepared_statements.out new file mode 100644 index 00000000..7be03fa9 --- /dev/null +++ b/regression/expected/denorm_prepared_statements.out @@ -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; diff --git a/regression/sql/denorm_prepared_statements.sql b/regression/sql/denorm_prepared_statements.sql new file mode 100644 index 00000000..8e7ce8cc --- /dev/null +++ b/regression/sql/denorm_prepared_statements.sql @@ -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;