1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-27 12:41:57 +03:00

Support for emulating RTREE indexing in GiST. Contributed by

Oleg Bartunov and Teodor Sigaev.
This commit is contained in:
Tom Lane
2001-05-31 18:27:18 +00:00
parent 3043810d97
commit 16f85390f2
11 changed files with 4731 additions and 1 deletions

View File

@ -0,0 +1,67 @@
#!/usr/bin/perl -w
use strict;
# make sure we are in a sane environment.
use DBI();
use DBD::Pg();
use Time::HiRes qw( usleep ualarm gettimeofday tv_interval );
use Getopt::Std;
my %opt;
getopts('d:b:gv', \%opt);
if ( !( scalar %opt ) ) {
print <<EOT;
Usage:
$0 -d DATABASE -b N [-v] [-g]
-d DATABASE - DATABASE name
-b N -number of cycles
-v - print sql
-g -use GiST index( default built-in R-tree )
EOT
exit;
}
$opt{d} ||= 'TEST';
my $dbi=DBI->connect('DBI:Pg:dbname='.$opt{d}) || die "Couldn't connect DB: $opt{d} !\n";
my $sql;
my $notice;
my $sss = '(3000,3000,2990,2990)';
if ( $opt{g} ) {
$notice = "Testing GiST implementation of R-Tree";
$sql = "select count(*) from boxtmp where b && '$sss'::box;";
} else {
$notice = "Testing built-in implementation of R-Tree";
$sql = "select count(*) from boxtmp2 where b && '$sss'::box;";
}
my $t0 = [gettimeofday];
my $count=0;
my $b=$opt{b};
$b ||=1;
foreach ( 1..$b ) {
my @a=exec_sql($dbi,$sql);
$count=$#a;
}
my $elapsed = tv_interval ( $t0, [gettimeofday]);
print "$notice:\n";
print "$sql\n" if ( $opt{v} );
print "Done\n";
print sprintf("total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n", $elapsed, $b, $elapsed/$b, $count+1 );
$dbi -> disconnect;
sub exec_sql {
my ($dbi, $sql, @keys) = @_;
my $sth=$dbi->prepare($sql) || die;
$sth->execute( @keys ) || die;
my $r;
my @row;
while ( defined ( $r=$sth->fetchrow_hashref ) ) {
push @row, $r;
}
$sth->finish;
return @row;
}

View File

@ -0,0 +1,50 @@
#!/usr/bin/perl
use strict;
my $NUM = 20000;
print "drop table boxtmp;\n";
print "drop table boxtmp2;\n";
print "create table boxtmp (b box);\n";
print "create table boxtmp2 (b box);\n";
srand(1);
open(DAT,">bbb.dat") || die;
foreach ( 1..$NUM ) {
#print DAT '(',int( 500+500*rand() ),',',int( 500+500*rand() ),',',int( 500*rand() ),',',int( 500*rand() ),")\n";
my ( $x1,$y1, $x2,$y2 ) = (
10000*rand(),
10000*rand(),
10000*rand(),
10000*rand()
);
print DAT '(',
max($x1,$x2),',',
max($y1,$y2),',',
min($x1,$x2),',',
min($y1,$y2),")\n";
}
close DAT;
print "copy boxtmp from stdin;\n";
open(DAT,"bbb.dat") || die;
while(<DAT>) { print; }
close DAT;
print "\\.\n";
print "copy boxtmp2 from stdin;\n";
open(DAT,"bbb.dat") || die;
while(<DAT>) { print; }
close DAT;
print "\\.\n";
print "create index bix on boxtmp using gist (b gist_box_ops);\n";
print "create index bix2 on boxtmp2 using rtree (b box_ops);\n";
sub min {
return ( $_[0] < $_[1] ) ? $_[0] : $_[1];
}
sub max {
return ( $_[0] > $_[1] ) ? $_[0] : $_[1];
}