Skip to content

Commit d28a449

Browse files
committed
Force testing of query jumbling in 027_stream_regress.pl
Coverage of the query jumbling code has always relied on the queries included in the regression tests of pg_stat_statements. This has its limitations, as a lot of query patterns have never really stressed the query jumbling code. The situation got a bit worse since the query jumbling has been added in the backend core code (5fd9dfa), hence new nodes that should be included in the jumbling could easily be missed, resulting in failures in pg_stat_statements or any modules that require query ID computations. Forcing a load of pg_stat_statements in 027_stream_regress.pl ensures that nodes are never missed in the computations, without having to rely on a buildfarm member for this check. Before this commit, the line coverage of queryjumblefuncs.funcs.c was around 48.5%, now up to 94.6% just by running 027_stream_regress.pl. A basic check is added to show that pg_stat_statements reports are generated after the main regression test suite is finished. Discussion: https://postgr.es/m/Y+nD9LN70w+8eaG9@paquier.xyz
1 parent d0028e3 commit d28a449

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

src/test/recovery/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
#-------------------------------------------------------------------------
1111

12-
EXTRA_INSTALL=contrib/test_decoding contrib/pg_prewarm
12+
EXTRA_INSTALL=contrib/pg_prewarm contrib/pg_stat_statements contrib/test_decoding
1313

1414
subdir = src/test/recovery
1515
top_builddir = ../../..

src/test/recovery/README

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ Running the tests
1010

1111
NOTE: You must have given the --enable-tap-tests argument to configure.
1212
Also, to use "make installcheck", you must have built and installed
13-
contrib/pg_prewarm and contrib/test_decoding in addition to the core code.
13+
contrib/pg_prewarm, contrib/pg_stat_statements and contrib/test_decoding
14+
in addition to the core code.
1415

1516
Run
1617
make check

src/test/recovery/t/027_stream_regress.pl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
$node_primary->adjust_conf('postgresql.conf', 'max_connections', '25');
1515
$node_primary->append_conf('postgresql.conf',
1616
'max_prepared_transactions = 10');
17+
18+
# Enable pg_stat_statements to force tests to do query jumbling.
19+
# pg_stat_statements.max should be large enough to hold all the entries
20+
# of the regression database.
21+
$node_primary->append_conf(
22+
'postgresql.conf',
23+
qq{shared_preload_libraries = 'pg_stat_statements'
24+
pg_stat_statements.max = 50000
25+
compute_query_id = 'regress'
26+
});
27+
1728
# We'll stick with Cluster->new's small default shared_buffers, but since that
1829
# makes synchronized seqscans more probable, it risks changing the results of
1930
# some test queries. Disable synchronized seqscans to prevent that.
@@ -106,6 +117,28 @@
106117
[ 'diff', $outputdir . '/primary.dump', $outputdir . '/standby.dump' ],
107118
'compare primary and standby dumps');
108119

120+
# Check some data from pg_stat_statements.
121+
$node_primary->safe_psql('postgres', 'CREATE EXTENSION pg_stat_statements');
122+
# This gathers data based on the first characters for some common query types,
123+
# checking that reports are generated for SELECT, DMLs, and DDL queries with
124+
# CREATE.
125+
my $result = $node_primary->safe_psql(
126+
'postgres',
127+
qq{WITH select_stats AS
128+
(SELECT upper(substr(query, 1, 6)) AS select_query
129+
FROM pg_stat_statements
130+
WHERE upper(substr(query, 1, 6)) IN ('SELECT', 'UPDATE',
131+
'INSERT', 'DELETE',
132+
'CREATE'))
133+
SELECT select_query, count(select_query) > 1 AS some_rows
134+
FROM select_stats
135+
GROUP BY select_query ORDER BY select_query;});
136+
is( $result, qq(CREATE|t
137+
DELETE|t
138+
INSERT|t
139+
SELECT|t
140+
UPDATE|t), 'check contents of pg_stat_statements on regression database');
141+
109142
$node_standby_1->stop;
110143
$node_primary->stop;
111144

0 commit comments

Comments
 (0)