mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
Run newly-configured perltidy script on Perl files.
Run on HEAD and 9.2.
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
|
||||
# make sure we are in a sane environment.
|
||||
use DBI();
|
||||
use DBD::Pg();
|
||||
@ -10,7 +11,8 @@ use Getopt::Std;
|
||||
my %opt;
|
||||
getopts('d:b:s:veorauc', \%opt);
|
||||
|
||||
if ( !( scalar %opt && defined $opt{s} ) ) {
|
||||
if (!(scalar %opt && defined $opt{s}))
|
||||
{
|
||||
print <<EOT;
|
||||
Usage:
|
||||
$0 -d DATABASE -s SECTIONS [-b NUMBER] [-v] [-e] [-o] [-r] [-a] [-u]
|
||||
@ -30,27 +32,37 @@ EOT
|
||||
}
|
||||
|
||||
$opt{d} ||= '_int4';
|
||||
my $dbi=DBI->connect('DBI:Pg:dbname='.$opt{d});
|
||||
my $dbi = DBI->connect('DBI:Pg:dbname=' . $opt{d});
|
||||
|
||||
my %table;
|
||||
my @where;
|
||||
|
||||
$table{message}=1;
|
||||
$table{message} = 1;
|
||||
|
||||
if ( $opt{a} ) {
|
||||
if ( $opt{r} ) {
|
||||
if ($opt{a})
|
||||
{
|
||||
if ($opt{r})
|
||||
{
|
||||
push @where, "message.sections @ '{$opt{s}}'";
|
||||
} else {
|
||||
foreach my $sid ( split(/[,\s]+/, $opt{s} )) {
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach my $sid (split(/[,\s]+/, $opt{s}))
|
||||
{
|
||||
push @where, "message.mid = msp$sid.mid";
|
||||
push @where, "msp$sid.sid = $sid";
|
||||
$table{"message_section_map msp$sid"}=1;
|
||||
$table{"message_section_map msp$sid"} = 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( $opt{r} ) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($opt{r})
|
||||
{
|
||||
push @where, "message.sections && '{$opt{s}}'";
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
$table{message_section_map} = 1;
|
||||
push @where, "message.mid = message_section_map.mid";
|
||||
push @where, "message_section_map.sid in ($opt{s})";
|
||||
@ -58,48 +70,66 @@ if ( $opt{a} ) {
|
||||
}
|
||||
|
||||
my $outf;
|
||||
if ( $opt{c} ) {
|
||||
$outf = ( $opt{u} ) ? 'count( distinct message.mid )' : 'count( message.mid )';
|
||||
} else {
|
||||
$outf = ( $opt{u} ) ? 'distinct( message.mid )' : 'message.mid';
|
||||
if ($opt{c})
|
||||
{
|
||||
$outf =
|
||||
($opt{u}) ? 'count( distinct message.mid )' : 'count( message.mid )';
|
||||
}
|
||||
my $sql = "select $outf from ".join(', ', keys %table)." where ".join(' AND ', @where).';';
|
||||
else
|
||||
{
|
||||
$outf = ($opt{u}) ? 'distinct( message.mid )' : 'message.mid';
|
||||
}
|
||||
my $sql =
|
||||
"select $outf from "
|
||||
. join(', ', keys %table)
|
||||
. " where "
|
||||
. join(' AND ', @where) . ';';
|
||||
|
||||
if ( $opt{v} ) {
|
||||
if ($opt{v})
|
||||
{
|
||||
print "$sql\n";
|
||||
}
|
||||
|
||||
if ( $opt{e} ) {
|
||||
if ($opt{e})
|
||||
{
|
||||
$dbi->do("explain $sql");
|
||||
}
|
||||
|
||||
my $t0 = [gettimeofday];
|
||||
my $count=0;
|
||||
my $b=$opt{b};
|
||||
$b||=1;
|
||||
my $t0 = [gettimeofday];
|
||||
my $count = 0;
|
||||
my $b = $opt{b};
|
||||
$b ||= 1;
|
||||
my @a;
|
||||
foreach ( 1..$b ) {
|
||||
@a=exec_sql($dbi,$sql);
|
||||
$count=$#a;
|
||||
foreach (1 .. $b)
|
||||
{
|
||||
@a = exec_sql($dbi, $sql);
|
||||
$count = $#a;
|
||||
}
|
||||
my $elapsed = tv_interval ( $t0, [gettimeofday]);
|
||||
if ( $opt{o} ) {
|
||||
foreach ( @a ) {
|
||||
my $elapsed = tv_interval($t0, [gettimeofday]);
|
||||
if ($opt{o})
|
||||
{
|
||||
foreach (@a)
|
||||
{
|
||||
print "$_->{mid}\t$_->{sections}\n";
|
||||
}
|
||||
}
|
||||
print sprintf("total: %.02f sec; number: %d; for one: %.03f sec; found %d docs\n", $elapsed, $b, $elapsed/$b, $count+1 );
|
||||
$dbi -> disconnect;
|
||||
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;
|
||||
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;
|
||||
}
|
||||
|
@ -15,28 +15,38 @@ create table message_section_map (
|
||||
|
||||
EOT
|
||||
|
||||
open(MSG,">message.tmp") || die;
|
||||
open(MAP,">message_section_map.tmp") || die;
|
||||
open(MSG, ">message.tmp") || die;
|
||||
open(MAP, ">message_section_map.tmp") || die;
|
||||
|
||||
srand(1);
|
||||
|
||||
srand( 1 );
|
||||
#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 ) {
|
||||
foreach my $i ( 1..200000 ) {
|
||||
foreach my $i (1 .. 200000)
|
||||
{
|
||||
my @sect;
|
||||
if ( rand() < 0.7 ) {
|
||||
$sect[0] = int( (rand()**4)*100 );
|
||||
} else {
|
||||
my %hash;
|
||||
@sect = grep { $hash{$_}++; $hash{$_} <= 1 } map { int( (rand()**4)*100) } 0..( int(rand()*5) );
|
||||
if (rand() < 0.7)
|
||||
{
|
||||
$sect[0] = int((rand()**4) * 100);
|
||||
}
|
||||
if ( $#sect < 0 || rand() < 0.1 ) {
|
||||
else
|
||||
{
|
||||
my %hash;
|
||||
@sect =
|
||||
grep { $hash{$_}++; $hash{$_} <= 1 }
|
||||
map { int((rand()**4) * 100) } 0 .. (int(rand() * 5));
|
||||
}
|
||||
if ($#sect < 0 || rand() < 0.1)
|
||||
{
|
||||
print MSG "$i\t\\N\n";
|
||||
} else {
|
||||
print MSG "$i\t{".join(',',@sect)."}\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print MSG "$i\t{" . join(',', @sect) . "}\n";
|
||||
map { print MAP "$i\t$_\n" } @sect;
|
||||
}
|
||||
}
|
||||
@ -64,12 +74,13 @@ EOT
|
||||
|
||||
unlink 'message.tmp', 'message_section_map.tmp';
|
||||
|
||||
sub copytable {
|
||||
sub copytable
|
||||
{
|
||||
my $t = shift;
|
||||
|
||||
print "COPY $t from stdin;\n";
|
||||
open( FFF, "$t.tmp") || die;
|
||||
while(<FFF>) { print; }
|
||||
open(FFF, "$t.tmp") || die;
|
||||
while (<FFF>) { print; }
|
||||
close FFF;
|
||||
print "\\.\n";
|
||||
}
|
||||
|
@ -2,12 +2,12 @@
|
||||
$integer = '[+-]?[0-9]+';
|
||||
$real = '[+-]?[0-9]+\.[0-9]+';
|
||||
|
||||
$RANGE = '(\.\.)(\.)?';
|
||||
$PLUMIN = q(\'\+\-\');
|
||||
$FLOAT = "(($integer)|($real))([eE]($integer))?";
|
||||
$RANGE = '(\.\.)(\.)?';
|
||||
$PLUMIN = q(\'\+\-\');
|
||||
$FLOAT = "(($integer)|($real))([eE]($integer))?";
|
||||
$EXTENSION = '<|>|~';
|
||||
|
||||
$boundary = "($EXTENSION)?$FLOAT";
|
||||
$boundary = "($EXTENSION)?$FLOAT";
|
||||
$deviation = $FLOAT;
|
||||
|
||||
$rule_1 = $boundary . $PLUMIN . $deviation;
|
||||
@ -18,25 +18,33 @@ $rule_5 = $boundary;
|
||||
|
||||
|
||||
print "$rule_5\n";
|
||||
while (<>) {
|
||||
# s/ +//g;
|
||||
if ( /^($rule_1)$/ ) {
|
||||
print;
|
||||
}
|
||||
elsif ( /^($rule_2)$/ ) {
|
||||
print;
|
||||
}
|
||||
elsif ( /^($rule_3)$/ ) {
|
||||
print;
|
||||
}
|
||||
elsif ( /^($rule_4)$/ ) {
|
||||
print;
|
||||
}
|
||||
elsif ( /^($rule_5)$/ ) {
|
||||
print;
|
||||
}
|
||||
else {
|
||||
print STDERR "error in $_\n";
|
||||
}
|
||||
while (<>)
|
||||
{
|
||||
|
||||
# s/ +//g;
|
||||
if (/^($rule_1)$/)
|
||||
{
|
||||
print;
|
||||
}
|
||||
elsif (/^($rule_2)$/)
|
||||
{
|
||||
print;
|
||||
}
|
||||
elsif (/^($rule_3)$/)
|
||||
{
|
||||
print;
|
||||
}
|
||||
elsif (/^($rule_4)$/)
|
||||
{
|
||||
print;
|
||||
}
|
||||
elsif (/^($rule_5)$/)
|
||||
{
|
||||
print;
|
||||
}
|
||||
else
|
||||
{
|
||||
print STDERR "error in $_\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,19 +2,22 @@
|
||||
|
||||
# this script will sort any table with the segment data type in its last column
|
||||
|
||||
while (<>) {
|
||||
chomp;
|
||||
push @rows, $_;
|
||||
while (<>)
|
||||
{
|
||||
chomp;
|
||||
push @rows, $_;
|
||||
}
|
||||
|
||||
foreach ( sort {
|
||||
@ar = split("\t", $a);
|
||||
$valA = pop @ar;
|
||||
$valA =~ s/[~<> ]+//g;
|
||||
@ar = split("\t", $b);
|
||||
$valB = pop @ar;
|
||||
$valB =~ s/[~<> ]+//g;
|
||||
$valA <=> $valB
|
||||
} @rows ) {
|
||||
print "$_\n";;
|
||||
foreach (
|
||||
sort {
|
||||
@ar = split("\t", $a);
|
||||
$valA = pop @ar;
|
||||
$valA =~ s/[~<> ]+//g;
|
||||
@ar = split("\t", $b);
|
||||
$valB = pop @ar;
|
||||
$valB =~ s/[~<> ]+//g;
|
||||
$valA <=> $valB
|
||||
} @rows)
|
||||
{
|
||||
print "$_\n";
|
||||
}
|
||||
|
Reference in New Issue
Block a user