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
This commit is contained in:
Michael Paquier 2023-03-03 10:41:51 +09:00
parent d0028e35a0
commit d28a449854
3 changed files with 36 additions and 2 deletions

View File

@ -9,7 +9,7 @@
#
#-------------------------------------------------------------------------
EXTRA_INSTALL=contrib/test_decoding contrib/pg_prewarm
EXTRA_INSTALL=contrib/pg_prewarm contrib/pg_stat_statements contrib/test_decoding
subdir = src/test/recovery
top_builddir = ../../..

View File

@ -10,7 +10,8 @@ Running the tests
NOTE: You must have given the --enable-tap-tests argument to configure.
Also, to use "make installcheck", you must have built and installed
contrib/pg_prewarm and contrib/test_decoding in addition to the core code.
contrib/pg_prewarm, contrib/pg_stat_statements and contrib/test_decoding
in addition to the core code.
Run
make check

View File

@ -14,6 +14,17 @@ $node_primary->init(allows_streaming => 1);
$node_primary->adjust_conf('postgresql.conf', 'max_connections', '25');
$node_primary->append_conf('postgresql.conf',
'max_prepared_transactions = 10');
# Enable pg_stat_statements to force tests to do query jumbling.
# pg_stat_statements.max should be large enough to hold all the entries
# of the regression database.
$node_primary->append_conf(
'postgresql.conf',
qq{shared_preload_libraries = 'pg_stat_statements'
pg_stat_statements.max = 50000
compute_query_id = 'regress'
});
# We'll stick with Cluster->new's small default shared_buffers, but since that
# makes synchronized seqscans more probable, it risks changing the results of
# some test queries. Disable synchronized seqscans to prevent that.
@ -106,6 +117,28 @@ command_ok(
[ 'diff', $outputdir . '/primary.dump', $outputdir . '/standby.dump' ],
'compare primary and standby dumps');
# Check some data from pg_stat_statements.
$node_primary->safe_psql('postgres', 'CREATE EXTENSION pg_stat_statements');
# This gathers data based on the first characters for some common query types,
# checking that reports are generated for SELECT, DMLs, and DDL queries with
# CREATE.
my $result = $node_primary->safe_psql(
'postgres',
qq{WITH select_stats AS
(SELECT upper(substr(query, 1, 6)) AS select_query
FROM pg_stat_statements
WHERE upper(substr(query, 1, 6)) IN ('SELECT', 'UPDATE',
'INSERT', 'DELETE',
'CREATE'))
SELECT select_query, count(select_query) > 1 AS some_rows
FROM select_stats
GROUP BY select_query ORDER BY select_query;});
is( $result, qq(CREATE|t
DELETE|t
INSERT|t
SELECT|t
UPDATE|t), 'check contents of pg_stat_statements on regression database');
$node_standby_1->stop;
$node_primary->stop;