Created
August 31, 2016 01:23
-
-
Save revmischa/86c0ee0da810fbe526021581be679d0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# convert postgres slow query log query w/ separate 'parameters:' line into an executable EXPLAIN ANALYZE query | |
use strict; | |
use warnings; | |
use Data::Dump qw/ddx/; | |
my $qfile = shift @ARGV or die "query file required"; | |
my $qf_contents; | |
my $fh; | |
open($fh, $qfile) or die $!; | |
{ | |
local $/; | |
$qf_contents = <$fh>; | |
} | |
close($fh); | |
my %matches = $qf_contents =~ m/\$(\d+) = '([^']+)/msg; | |
$qf_contents =~ s/^.*parameters: .+$//m; | |
my ($k, $v); | |
while (($k, $v) = each %matches) { | |
$qf_contents =~ s/\$${k}/$v/e; | |
} | |
chomp $qf_contents; | |
print "EXPLAIN ANALYZE $qf_contents;\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment