2001-01-12 01:16:26 +01:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2024-01-04 02:49:05 +01:00
|
|
|
# Copyright (c) 2021-2024, PostgreSQL Global Development Group
|
2021-05-07 16:56:14 +02:00
|
|
|
|
2010-09-20 22:08:53 +02:00
|
|
|
# contrib/intarray/bench/create_test.pl
|
2006-03-11 05:38:42 +01:00
|
|
|
|
2001-01-12 01:16:26 +01:00
|
|
|
use strict;
|
2023-12-29 18:01:53 +01:00
|
|
|
use warnings FATAL => 'all';
|
2020-04-13 17:55:45 +02:00
|
|
|
|
2001-01-12 01:16:26 +01:00
|
|
|
print <<EOT;
|
|
|
|
create table message (
|
|
|
|
mid int not null,
|
|
|
|
sections int[]
|
|
|
|
);
|
|
|
|
create table message_section_map (
|
2010-11-23 21:27:50 +01:00
|
|
|
mid int not null,
|
2001-01-12 01:16:26 +01:00
|
|
|
sid int not null
|
|
|
|
);
|
|
|
|
|
|
|
|
EOT
|
|
|
|
|
2023-05-19 23:24:48 +02:00
|
|
|
open(my $msg, '>', "message.tmp") || die;
|
2017-03-27 04:24:13 +02:00
|
|
|
open(my $map, '>', "message_section_map.tmp") || die;
|
2012-07-05 03:47:49 +02:00
|
|
|
|
|
|
|
srand(1);
|
2001-01-12 01:16:26 +01:00
|
|
|
|
|
|
|
#foreach my $i ( 1..1778 ) {
|
|
|
|
#foreach my $i ( 1..3443 ) {
|
|
|
|
#foreach my $i ( 1..5000 ) {
|
|
|
|
#foreach my $i ( 1..29362 ) {
|
|
|
|
#foreach my $i ( 1..33331 ) {
|
|
|
|
#foreach my $i ( 1..83268 ) {
|
2012-07-05 03:47:49 +02:00
|
|
|
foreach my $i (1 .. 200000)
|
|
|
|
{
|
2001-01-12 01:16:26 +01:00
|
|
|
my @sect;
|
2012-07-05 03:47:49 +02:00
|
|
|
if (rand() < 0.7)
|
|
|
|
{
|
|
|
|
$sect[0] = int((rand()**4) * 100);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-01-12 01:16:26 +01:00
|
|
|
my %hash;
|
2012-07-05 03:47:49 +02:00
|
|
|
@sect =
|
|
|
|
grep { $hash{$_}++; $hash{$_} <= 1 }
|
|
|
|
map { int((rand()**4) * 100) } 0 .. (int(rand() * 5));
|
2001-01-12 01:16:26 +01:00
|
|
|
}
|
2012-07-05 03:47:49 +02:00
|
|
|
if ($#sect < 0 || rand() < 0.1)
|
|
|
|
{
|
2017-03-27 04:24:13 +02:00
|
|
|
print $msg "$i\t\\N\n";
|
2012-07-05 03:47:49 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-03-27 04:24:13 +02:00
|
|
|
print $msg "$i\t{" . join(',', @sect) . "}\n";
|
2021-08-31 11:07:04 +02:00
|
|
|
print $map "$i\t$_\n" foreach @sect;
|
2001-01-12 01:16:26 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-27 04:24:13 +02:00
|
|
|
close $map;
|
|
|
|
close $msg;
|
2001-01-12 01:16:26 +01:00
|
|
|
|
|
|
|
copytable('message');
|
|
|
|
copytable('message_section_map');
|
|
|
|
|
|
|
|
print <<EOT;
|
|
|
|
|
|
|
|
CREATE unique index message_key on message ( mid );
|
|
|
|
--CREATE unique index message_section_map_key1 on message_section_map ( mid, sid );
|
|
|
|
CREATE unique index message_section_map_key2 on message_section_map ( sid, mid );
|
2001-08-21 18:36:06 +02:00
|
|
|
CREATE INDEX message_rdtree_idx on message using gist ( sections gist__int_ops );
|
2001-01-12 01:16:26 +01:00
|
|
|
VACUUM ANALYZE;
|
|
|
|
|
|
|
|
select count(*) from message;
|
|
|
|
select count(*) from message_section_map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EOT
|
|
|
|
|
|
|
|
|
|
|
|
unlink 'message.tmp', 'message_section_map.tmp';
|
|
|
|
|
2012-07-05 03:47:49 +02:00
|
|
|
sub copytable
|
|
|
|
{
|
2001-01-12 01:16:26 +01:00
|
|
|
my $t = shift;
|
2010-11-23 21:27:50 +01:00
|
|
|
|
2001-01-12 01:16:26 +01:00
|
|
|
print "COPY $t from stdin;\n";
|
2017-03-27 04:24:13 +02:00
|
|
|
open(my $fff, '<', "$t.tmp") || die;
|
|
|
|
while (<$fff>) { print; }
|
|
|
|
close $fff;
|
2001-01-12 01:16:26 +01:00
|
|
|
print "\\.\n";
|
2018-05-27 15:08:42 +02:00
|
|
|
return;
|
2001-01-12 01:16:26 +01:00
|
|
|
}
|