From d28a449854202d0a409e13e2e73f78373da1ed75 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Fri, 3 Mar 2023 10:41:51 +0900 Subject: [PATCH] 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 --- src/test/recovery/Makefile | 2 +- src/test/recovery/README | 3 ++- src/test/recovery/t/027_stream_regress.pl | 33 +++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/test/recovery/Makefile b/src/test/recovery/Makefile index 570bf42b58..c60314d195 100644 --- a/src/test/recovery/Makefile +++ b/src/test/recovery/Makefile @@ -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 = ../../.. diff --git a/src/test/recovery/README b/src/test/recovery/README index 3ae3758d3b..896df0ad05 100644 --- a/src/test/recovery/README +++ b/src/test/recovery/README @@ -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 diff --git a/src/test/recovery/t/027_stream_regress.pl b/src/test/recovery/t/027_stream_regress.pl index 13482adbaf..255c45a4ff 100644 --- a/src/test/recovery/t/027_stream_regress.pl +++ b/src/test/recovery/t/027_stream_regress.pl @@ -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; -- 2.11.4.GIT