| 1 |
#!/usr/bin/perl |
| 2 |
|
| 3 |
# Copyright (c) 2021-2025, PostgreSQL Global Development Group |
| 4 |
|
| 5 |
# contrib/intarray/bench/create_test.pl |
| 6 |
|
| 7 |
use strict; |
| 8 |
use warnings FATAL => 'all'; |
| 9 |
|
| 10 |
print <<EOT; |
| 11 |
create table message ( |
| 12 |
mid int not null, |
| 13 |
sections int[] |
| 14 |
); |
| 15 |
create table message_section_map ( |
| 16 |
mid int not null, |
| 17 |
sid int not null |
| 18 |
); |
| 19 |
|
| 20 |
EOT |
| 21 |
|
| 22 |
open(my $msg, '>', "message.tmp") || die; |
| 23 |
open(my $map, '>', "message_section_map.tmp") || die; |
| 24 |
|
| 25 |
srand(1); |
| 26 |
|
| 27 |
#foreach my $i ( 1..1778 ) { |
| 28 |
#foreach my $i ( 1..3443 ) { |
| 29 |
#foreach my $i ( 1..5000 ) { |
| 30 |
#foreach my $i ( 1..29362 ) { |
| 31 |
#foreach my $i ( 1..33331 ) { |
| 32 |
#foreach my $i ( 1..83268 ) { |
| 33 |
foreach my $i (1 .. 200000) |
| 34 |
{ |
| 35 |
my @sect; |
| 36 |
if (rand() < 0.7) |
| 37 |
{ |
| 38 |
$sect[0] = int((rand()**4) * 100); |
| 39 |
} |
| 40 |
else |
| 41 |
{ |
| 42 |
my %hash; |
| 43 |
@sect = |
| 44 |
grep { $hash{$_}++; $hash{$_} <= 1 } |
| 45 |
map { int((rand()**4) * 100) } 0 .. (int(rand() * 5)); |
| 46 |
} |
| 47 |
if ($#sect < 0 || rand() < 0.1) |
| 48 |
{ |
| 49 |
print $msg "$i\t\\N\n"; |
| 50 |
} |
| 51 |
else |
| 52 |
{ |
| 53 |
print $msg "$i\t{" . join(',', @sect) . "}\n"; |
| 54 |
print $map "$i\t$_\n" foreach @sect; |
| 55 |
} |
| 56 |
} |
| 57 |
close $map; |
| 58 |
close $msg; |
| 59 |
|
| 60 |
copytable('message'); |
| 61 |
copytable('message_section_map'); |
| 62 |
|
| 63 |
print <<EOT; |
| 64 |
|
| 65 |
CREATE unique index message_key on message ( mid ); |
| 66 |
--CREATE unique index message_section_map_key1 on message_section_map ( mid, sid ); |
| 67 |
CREATE unique index message_section_map_key2 on message_section_map ( sid, mid ); |
| 68 |
CREATE INDEX message_rdtree_idx on message using gist ( sections gist__int_ops ); |
| 69 |
VACUUM ANALYZE; |
| 70 |
|
| 71 |
select count(*) from message; |
| 72 |
select count(*) from message_section_map; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
EOT |
| 77 |
|
| 78 |
|
| 79 |
unlink 'message.tmp', 'message_section_map.tmp'; |
| 80 |
|
| 81 |
sub copytable |
| 82 |
{ |
| 83 |
my $t = shift; |
| 84 |
|
| 85 |
print "COPY $t from stdin;\n"; |
| 86 |
open(my $fff, '<', "$t.tmp") || die; |
| 87 |
while (<$fff>) { print; } |
| 88 |
close $fff; |
| 89 |
print "\\.\n"; |
| 90 |
return; |
| 91 |
} |