~vcs-imports/mammoth-replicator/trunk

« back to all changes in this revision

Viewing changes to contrib/intarray/bench/create_test.pl

  • Committer: alvherre
  • Date: 2005-12-16 21:24:52 UTC
  • Revision ID: svn-v4:db760fc0-0f08-0410-9d63-cc6633f64896:trunk:1
Initial import of the REL8_0_3 sources from the Pgsql CVS repository.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
 
 
3
use strict;
 
4
print <<EOT;
 
5
create table message (
 
6
        mid     int not null,
 
7
        sections        int[]
 
8
);
 
9
create table message_section_map (
 
10
        mid     int not null,
 
11
        sid     int not null
 
12
);
 
13
 
 
14
EOT
 
15
 
 
16
open(MSG,">message.tmp") || die;
 
17
open(MAP,">message_section_map.tmp") || die;
 
18
 
 
19
srand( 1 );
 
20
#foreach my $i ( 1..1778 ) {
 
21
#foreach my $i ( 1..3443 ) {
 
22
#foreach my $i ( 1..5000 ) {
 
23
#foreach my $i ( 1..29362 ) {
 
24
#foreach my $i ( 1..33331 ) {
 
25
#foreach my $i ( 1..83268 ) {
 
26
foreach my $i ( 1..200000 ) {
 
27
        my @sect;
 
28
        if ( rand() < 0.7 ) {
 
29
                $sect[0] = int( (rand()**4)*100 );
 
30
        } else {
 
31
                my %hash;
 
32
                @sect = grep { $hash{$_}++; $hash{$_} <= 1 } map { int( (rand()**4)*100) } 0..( int(rand()*5) );
 
33
        }
 
34
        if ( $#sect < 0 || rand() < 0.1 ) {
 
35
                print MSG "$i\t\\N\n";
 
36
        } else {
 
37
                print MSG "$i\t{".join(',',@sect)."}\n";
 
38
                map { print MAP "$i\t$_\n" } @sect;
 
39
        }
 
40
}
 
41
close MAP;
 
42
close MSG;
 
43
 
 
44
copytable('message');
 
45
copytable('message_section_map');
 
46
 
 
47
print <<EOT;
 
48
 
 
49
CREATE unique index message_key on message ( mid );
 
50
--CREATE unique index message_section_map_key1 on message_section_map ( mid, sid );
 
51
CREATE unique index message_section_map_key2 on message_section_map ( sid, mid );
 
52
CREATE INDEX message_rdtree_idx on message using gist ( sections gist__int_ops );
 
53
VACUUM ANALYZE;
 
54
 
 
55
select count(*) from message;
 
56
select count(*) from message_section_map;
 
57
 
 
58
 
 
59
 
 
60
EOT
 
61
 
 
62
 
 
63
unlink 'message.tmp', 'message_section_map.tmp';
 
64
 
 
65
sub copytable {
 
66
        my $t = shift;
 
67
        
 
68
        print "COPY $t from stdin;\n";
 
69
        open( FFF, "$t.tmp") || die;
 
70
        while(<FFF>) { print; }
 
71
        close FFF;
 
72
        print "\\.\n";
 
73
}