4
# make sure we are in a sane environment.
7
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
11
getopts('d:b:s:veorauc', \%opt);
13
if ( !( scalar %opt && defined $opt{s} ) ) {
16
$0 -d DATABASE -s SECTIONS [-b NUMBER] [-v] [-e] [-o] [-r] [-a] [-u]
18
-b NUMBER -number of repeats
19
-s SECTIONS -sections, format sid1[,sid2[,sid3[...]]]]
20
-v -verbose (show SQL)
33
my $dbi=DBI->connect('DBI:Pg:dbname='.$opt{d});
42
push @where, "message.sections @ '{$opt{s}}'";
44
foreach my $sid ( split(/[,\s]+/, $opt{s} )) {
45
push @where, "message.mid = msp$sid.mid";
46
push @where, "msp$sid.sid = $sid";
47
$table{"message_section_map msp$sid"}=1;
52
push @where, "message.sections && '{$opt{s}}'";
54
$table{message_section_map} = 1;
55
push @where, "message.mid = message_section_map.mid";
56
push @where, "message_section_map.sid in ($opt{s})";
62
$outf = ( $opt{u} ) ? 'count( distinct message.mid )' : 'count( message.mid )';
64
$outf = ( $opt{u} ) ? 'distinct( message.mid )' : 'message.mid';
66
my $sql = "select $outf from ".join(', ', keys %table)." where ".join(' AND ', @where).';';
73
$dbi->do("explain $sql");
76
my $t0 = [gettimeofday];
82
@a=exec_sql($dbi,$sql);
85
my $elapsed = tv_interval ( $t0, [gettimeofday]);
88
print "$_->{mid}\t$_->{sections}\n";
91
print sprintf("total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n", $elapsed, $b, $elapsed/$b, $count+1 );
95
my ($dbi, $sql, @keys) = @_;
96
my $sth=$dbi->prepare($sql) || die;
97
$sth->execute( @keys ) || die;
100
while ( defined ( $r=$sth->fetchrow_hashref ) ) {