diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-27 15:55:08 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2021-05-27 15:55:08 -0400 |
commit | a4390abecf0f5152cff864e82b67e5f6c8489698 (patch) | |
tree | bce1454f802af7fb52a3e3463df5c79c12de29bc /src/backend/catalog/genbki.pl | |
parent | e6241d8e030fbd2746b3ea3f44e728224298f35b (diff) | |
download | postgresql-a4390abecf0f5152cff864e82b67e5f6c8489698.tar.gz |
Reduce the range of OIDs reserved for genbki.pl.
Commit ab596105b increased FirstBootstrapObjectId from 12000 to 13000,
but we've had some push-back about that. It's worrisome to reduce the
daylight between there and FirstNormalObjectId, because the number of
OIDs consumed during initdb for collation objects is hard to predict.
We can improve the situation by abandoning the assumption that these
OIDs must be globally unique. It should be sufficient for them to be
unique per-catalog. (Any code that's unhappy about that is broken
anyway, since no more than per-catalog uniqueness can be guaranteed
once the OID counter wraps around.) With that change, the largest OID
assigned during genbki.pl (starting from a base of 10000) is a bit
under 11000. This allows reverting FirstBootstrapObjectId to 12000
with reasonable confidence that that will be sufficient for many years
to come.
We are not, at this time, abandoning the expectation that
hand-assigned OIDs (below 10000) are globally unique. Someday that'll
likely be necessary, but the need seems years away still.
This is late for v14, but it seems worth doing it now so that
downstream software doesn't have to deal with the consequences of
a change in FirstBootstrapObjectId. In any case, we already
bought into forcing an initdb for beta2, so another catversion
bump won't hurt.
Discussion: https://postgr.es/m/1665197.1622065382@sss.pgh.pa.us
Diffstat (limited to 'src/backend/catalog/genbki.pl')
-rw-r--r-- | src/backend/catalog/genbki.pl | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index f893ae4f45..81363a0710 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -167,15 +167,17 @@ foreach my $oid (keys %oidcounts) die "found $found duplicate OID(s) in catalog data\n" if $found; -# Oids not specified in the input files are automatically assigned, +# OIDs not specified in the input files are automatically assigned, # starting at FirstGenbkiObjectId, extending up to FirstBootstrapObjectId. +# We allow such OIDs to be assigned independently within each catalog. my $FirstGenbkiObjectId = Catalog::FindDefinedSymbol('access/transam.h', $include_path, 'FirstGenbkiObjectId'); my $FirstBootstrapObjectId = Catalog::FindDefinedSymbol('access/transam.h', $include_path, 'FirstBootstrapObjectId'); -my $GenbkiNextOid = $FirstGenbkiObjectId; +# Hash of next available OID, indexed by catalog name. +my %GenbkiNextOids; # Fetch some special data that we will substitute into the output file. @@ -563,8 +565,7 @@ EOM # Assign oid if oid column exists and no explicit assignment in row if ($attname eq "oid" and not defined $bki_values{$attname}) { - $bki_values{$attname} = $GenbkiNextOid; - $GenbkiNextOid++; + $bki_values{$attname} = assign_next_oid($catname); } # Replace OID synonyms with OIDs per the appropriate lookup rule. @@ -669,11 +670,6 @@ foreach my $declaration (@index_decls) # last command in the BKI file: build the indexes declared above print $bki "build indices\n"; -# check that we didn't overrun available OIDs -die - "genbki OID counter reached $GenbkiNextOid, overrunning FirstBootstrapObjectId\n" - if $GenbkiNextOid > $FirstBootstrapObjectId; - # Now generate system_constraints.sql foreach my $c (@system_constraints) @@ -1079,6 +1075,25 @@ sub form_pg_type_symbol return $name . $arraystr . 'OID'; } +# Assign an unused OID within the specified catalog. +sub assign_next_oid +{ + my $catname = shift; + + # Initialize, if no previous request for this catalog. + $GenbkiNextOids{$catname} = $FirstGenbkiObjectId + if !defined($GenbkiNextOids{$catname}); + + my $result = $GenbkiNextOids{$catname}++; + + # Check that we didn't overrun available OIDs + die + "genbki OID counter for $catname reached $result, overrunning FirstBootstrapObjectId\n" + if $result >= $FirstBootstrapObjectId; + + return $result; +} + sub usage { die <<EOM; |