]> granicus.if.org Git - postgresql/commitdiff
Improve inefficient regexes in vacuumdb TAP test.
authorTom Lane <tgl@sss.pgh.pa.us>
Wed, 9 May 2018 00:17:43 +0000 (20:17 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Wed, 9 May 2018 00:17:43 +0000 (20:17 -0400)
The regexes used in 102_vacuumdb_stages.pl to check the postmaster log
for expected output contained several places with ".*.*", which is
underdetermined and can cause exponential runtime growth in Perl's regex
matcher (since it's not bright enough not to waste time seeing whether
different splits of the same substring would allow a match).  We were
fortunate that the amount of text in the postmaster log was generally not
enough to make the runtime go to the moon; although commit 6271fceb8 had
been on the hairy edge of an obvious problem, thanks to its increasing the
default log verbosity to DEBUG1.  Experimentation shows that anyone who
tried to run this test case with an even higher log verbosity would have
been in for serious pain.  But even at default logging level, fixing this
saves several hundred ms on my workstation, more on slower buildfarm
members.

Remove the extra ".*"s, restoring more-or-less-linear matching speed.
Back-patch to 9.4 where the test case was added, mostly in case anyone
tries to do related debugging in a back branch.

Discussion: https://postgr.es/m/32459.1525657786@sss.pgh.pa.us

src/bin/scripts/t/102_vacuumdb_stages.pl

index 392944143b3f4eb328a637c562fdf363e845305a..17a7fc720d2b1adc8cf4619528b8703f27b852c3 100644 (file)
@@ -10,26 +10,26 @@ $node->start;
 
 $node->issues_sql_like(
        [ 'vacuumdb', '--analyze-in-stages', 'postgres' ],
-       qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
-                   .*statement:\ ANALYZE.*
+       qr/statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
+                   .*statement:\ ANALYZE
                    .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay;
-                   .*statement:\ ANALYZE.*
+                   .*statement:\ ANALYZE
                    .*statement:\ RESET\ default_statistics_target;
                    .*statement:\ ANALYZE/sx,
        'analyze three times');
 
 $node->issues_sql_like(
        [ 'vacuumdb', '--analyze-in-stages', '--all' ],
-       qr/.*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
-                   .*statement:\ ANALYZE.*
+       qr/statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
+                   .*statement:\ ANALYZE
                    .*statement:\ SET\ default_statistics_target=1;\ SET\ vacuum_cost_delay=0;
-                   .*statement:\ ANALYZE.*
+                   .*statement:\ ANALYZE
                    .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay;
-                   .*statement:\ ANALYZE.*
+                   .*statement:\ ANALYZE
                    .*statement:\ SET\ default_statistics_target=10;\ RESET\ vacuum_cost_delay;
-                   .*statement:\ ANALYZE.*
+                   .*statement:\ ANALYZE
                    .*statement:\ RESET\ default_statistics_target;
-                   .*statement:\ ANALYZE.*
+                   .*statement:\ ANALYZE
                    .*statement:\ RESET\ default_statistics_target;
                    .*statement:\ ANALYZE/sx,
        'analyze more than one database in stages');