Исходный код СУБД RuDB — свободной СУБД с открытым исходным кодом на базе PostgreSQL
rudb
2 days ago bd039d1e92813358c5c5a1e346b49074baf513f2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
#----------------------------------------------------------------------
#
# unused_oids
#    Finds blocks of manually-assignable OIDs that have not already been
#    claimed by previous hackers.  The main use is for finding available
#    OIDs for new internal functions.  The numbers printed are inclusive
#    ranges of unused OIDs.
#
#    Before using a large empty block, make sure you aren't about
#    to take over what was intended as expansion space for something
#    else.
#
# Portions Copyright (c) 1996-2026, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
# src/include/catalog/unused_oids
#
#----------------------------------------------------------------------
 
use strict;
use warnings FATAL => 'all';
 
# Must run in src/include/catalog
use FindBin;
chdir $FindBin::RealBin or die "could not cd to $FindBin::RealBin: $!\n";
 
use lib "$FindBin::RealBin/../../backend/catalog/";
use Catalog;
 
my @input_files = grep {
    open(my $fh, "<", $_) or die "could not open $_: $!\n";
    my $is_catalog = grep { /^\s*CATALOG\s*\(/ } <$fh>;
    close($fh);
    $is_catalog;
} glob("*.h");
 
my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
 
# Also push FirstGenbkiObjectId to serve as a terminator for the last gap.
my $FirstGenbkiObjectId =
  Catalog::FindDefinedSymbol('access/transam.h', '..', 'FirstGenbkiObjectId');
push @{$oids}, $FirstGenbkiObjectId;
 
my $prev_oid = 0;
my @sortedoids = sort { $a <=> $b } @{$oids};
foreach my $oid (@sortedoids)
{
    if ($oid > $prev_oid + 1)
    {
        if ($oid > $prev_oid + 2)
        {
            printf "%d - %d\n", $prev_oid + 1, $oid - 1;
        }
        else
        {
            printf "%d\n", $prev_oid + 1;
        }
    }
    $prev_oid = $oid;
}
 
my $suggestion;
do
{
    $suggestion = int(8000 + rand(2000));
} while (grep(/^$suggestion$/, @{$oids}));
 
my $navailable = 0;
foreach my $oid (@sortedoids)
{
    if ($oid > $suggestion)
    {
        $navailable = $oid - $suggestion;
        last;
    }
}
 
printf "Patches should use a more-or-less consecutive range of OIDs.\n";
printf
  "Best practice is to start with a random choice in the range 8000-9999.\n";
printf
  "Suggested random unused OID: $suggestion ($navailable consecutive OID(s) available starting here)\n";