On 10/11/2013 03:57 AM, Tom Lane wrote:
Peter Eisentraut <pete...@gmx.net> writes:
Replace duplicate_oids with Perl implementation
It is more portable, more robust, and more readable.
From: Andrew Dunstan <and...@dunslane.net>
What about unused_oids?

                        


Here's a quick version I whipped up along the same lines that you can play with.

There's probably a good case for combining them.

cheers

andrew
#!/usr/bin/perl

use strict;
use warnings;

BEGIN
{
        @ARGV = (glob("pg_*.h"), qw(indexing.h toasting.h));
}

my %oidcounts;

while(<>)
{
        next if /^CATALOG\(.*BKI_BOOTSTRAP/;
        next unless
                /^DATA\(insert *OID *= *(\d+)/ ||
                /^CATALOG\([^,]*, *(\d+).*BKI_ROWTYPE_OID\((\d+)\)/ ||
                /^CATALOG\([^,]*, *(\d+)/ ||
                /^DECLARE_INDEX\([^,]*, *(\d+)/ ||
                /^DECLARE_UNIQUE_INDEX\([^,]*, *(\d+)/ ||
                /^DECLARE_TOAST\([^,]*, *(\d+), *(\d+)/;
        $oidcounts{$1}++;
        $oidcounts{$2}++ if $2;
}

my $firstobjectid;
my $handle;
open($handle,"../access/transam.h") || die "cannot access transam.h: $!";
while (<$handle>)
{
        if (/^#define\s+FirstBootstrapObjectId\s+(\d+)/)
        {
                $firstobjectid = $1;
                last;
        }
}
close($handle);
die "no first object found" unless $firstobjectid;

my $last = 0;
foreach my $oid (sort {$a <=> $b} keys %oidcounts)
{
        if ($oid > $last + 1) 
        {
                if ($oid > $last + 2) {
                        print $last + 1, "-", $oid - 1,"\n";
                } 
                else 
                {
                        print $last + 1,"\n";
                }
        }
        $last = $oid;
}

print $last + 1, "-" , $firstobjectid -1, "\n";

exit 0;

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to