#!/usr/bin/perl use strict; use Getopt::Std; rand($$^time()); my %opt; getopts('c:q:n:m:h', \%opt); if ( $opt{h} ) { print "Usage:\n$0 [ -c COUNT ] [ -q QUERIESNUM ] [ -n AVERAGEPERQ ] \n"; print "-c COUNT - number of record\n"; print "-q QUERIESNUM - number of queries\n"; print "-n AVERAGEPERQ - desired number of record returning by one query\n"; print "-m MEMINMEGABYTES - memory for dd in megabytes, default no\n"; exit(0); } my ($count, $name) = ( 1000000, 'pgs_test' ); $count = $opt{c} if defined $opt{c}; my ($qn, $perq) = (500, 100); $qn = $opt{q} if defined $opt{q}; $perq = $opt{n} if defined $opt{n}; my $mem = 0; $mem = $opt{m} if defined $opt{m}; if ( $perq*5 > $count ) { print "Strage option: too big AVERAGEPERQ\n"; exit(1); } #generate tables print<0; sub printtst { my ($nt, $type) = @_; print "\\echo == $nt [$type]==\n"; print "\\! rm -rf tstcrlmem.tmp\n" if $mem>0; print "\\! dd if=/dev/zero of=tstcrlmem.tmp count=".($mem*1024*1024/512)."\n" if $mem>0; print "\\! date +%s\n"; foreach my $q ( @queries ) { print "SELECT count(*) FROM ${name}_${type} WHERE pos @ sbox '$q';\n"; } print "\\! date +%s\n"; print "select a from gist_print('${type}_idx') as t(level int, a spherekey) where level=1;\n"; print "SELECT sum(relpages) FROM pg_class WHERE relkind='r' AND relname = '${name}_${type}';\n"; print "SELECT sum(relpages) FROM pg_class WHERE relkind='i' AND relname = '${type}_idx';\n"; print "select * from pg_statio_user_tables where relname = '${name}_${type}';\n"; print "select * from pg_statio_user_indexes where relname = '${name}_${type}';\n"; }