#!/usr/bin/perl

use DBI;
use strict;
use warnings;

my $iterations = 10000;
my $dot = $iterations / 50;
$| = 1;
my $dbi = DBI->connect('DBI:Pg:', '', '',
    { 'AutoCommit' => 0, 'RaiseError' => 1, 'PrintError' => 0 });
@ARGV == 1 || die "first arg should be file containing query to explain\n";
my ($qfile) = @ARGV;
open(QFILE, '<', $qfile) || die "can't read $qfile: $!";
my $qtext = join("\n", <QFILE>);
close(QFILE);

my $explain = "EXPLAIN $qtext";
for (my $i = 0; $i < $iterations; ++$i) {
    $dbi->do($explain);
	print "." if $i % $dot == 0;
}
print "\n";

$dbi->disconnect();
