[check_postgres] [commit] Replace large regex in bloat sub with split - much faster.

check_postgres at bucardo.org check_postgres at bucardo.org
Wed Jul 16 22:24:59 UTC 2008


Committed by Greg Sabino Mullane <greg at endpoint.com>

Replace large regex in bloat sub with split - much faster.

---
 check_postgres.pl |   15 ++++-----------
 1 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/check_postgres.pl b/check_postgres.pl
index d366f7d..d1bc4ab 100755
--- a/check_postgres.pl
+++ b/check_postgres.pl
@@ -1478,17 +1478,9 @@ ORDER BY wastedbytes DESC LIMIT $LIMIT
 		ndie $info->{db}[0]{error};
 	}
 
-	## schema, table, rows, pages, otta, bloat, wastedpages, wastedbytes, wastedsize
-	##         index, ""     "" ...
-	my $N = qr{ (.+?)\s*\|};
-	my $D = qr{\s+(\d+) \|};
-	my $F = qr{\s+(\d+\.\d) \|};
-	my $S = qr{ (\d+ \w+)\s+\|};
-	my $E = qr{ (\d+ \w+)\s*};
-	my $L = qr{$N$N$D$D$D$F$D$D$S$N$D$D$D$F$D$D$E$};
 	my %seenit;
 	for $db (@{$info->{db}}) {
-		if ($db->{slurp} !~ /$L/) {
+		if ($db->{slurp} !~ /\w+\s+\|/o) {
 			add_ok q{no relations meet the minimum bloat criteria} unless $MRTG;
 			next;
 		}
@@ -1504,10 +1496,11 @@ ORDER BY wastedbytes DESC LIMIT $LIMIT
 		}
 		my $max = -1;
 		my $maxmsg = '?';
-	  SLURP: while ($db->{slurp} =~ /$L/gsm) { ## no critic (ProhibitUselessRegexModifiers)
+	  SLURP: for (split /\n/ => $db->{slurp}) {
 			my ($schema,$table,$tups,$pages,$otta,$bloat,$wp,$wb,$ws,
 				$index,$irows,$ipages,$iotta,$ibloat,$iwp,$iwb,$iws)
-				= ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18);
+				= split /\s*\|\s*/;
+			$schema =~ s/^\s+//;
 			next SLURP if skip_item($table, $schema);
 			## Made it past the exclusions
 			$max = -2 if $max == -1;
-- 
1.5.5.4



More information about the Check_postgres mailing list