Skip to content

Commit 09568ec

Browse files
committed
Create a separate oid range for oids assigned by genbki.pl.
The changes I made in 578b229 assigned oids below FirstBootstrapObjectId to objects in include/catalog/*.dat files that did not have an oid assigned, starting at the max oid explicitly assigned. Tom criticized that for mainly two reasons: 1) It's not clear which values are manually and which explicitly assigned. 2) The space below FirstBootstrapObjectId gets pretty crowded, and some PostgreSQL forks have used oids >= 9000 for their own objects, to avoid conflicting. Thus create a new range for objects not assigned explicit oids, but assigned by genbki.pl. For now 1-9999 is for explicitly assigned oids, FirstGenbkiObjectId (10000) to FirstBootstrapObjectId (1200) -1 is for genbki.pl assigned oids, and < FirstNormalObjectId (16384) is for oids assigned during bootstrap. It's possible that we'll have to adjust these boundaries, but there's some headroom for now. Add a note suggesting that oids in forks should be assigned in the 9000-9999 range. Catversion bump for obvious reasons. Per complaint from Tom Lane. Author: Andres Freund Discussion: https://postgr.es/m/[email protected]
1 parent 84d5148 commit 09568ec

File tree

9 files changed

+47
-33
lines changed

9 files changed

+47
-33
lines changed

contrib/postgres_fdw/shippable.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
137137
/*
138138
* Return true if given object is one of PostgreSQL's built-in objects.
139139
*
140-
* We use FirstBootstrapObjectId as the cutoff, so that we only consider
140+
* We use FirstGenbkiObjectId as the cutoff, so that we only consider
141141
* objects with hand-assigned OIDs to be "built in", not for instance any
142142
* function or type defined in the information_schema.
143143
*
@@ -154,7 +154,7 @@ lookup_shippable(Oid objectId, Oid classId, PgFdwRelationInfo *fpinfo)
154154
bool
155155
is_builtin(Oid objectId)
156156
{
157-
return (objectId < FirstBootstrapObjectId);
157+
return (objectId < FirstGenbkiObjectId);
158158
}
159159

160160
/*

src/backend/catalog/Makefile

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ generated-header-symlinks: $(top_builddir)/src/include/catalog/header-stamp
8888
# instead is cheating a bit, but it will achieve the goal of updating the
8989
# version number when it changes.
9090
bki-stamp: genbki.pl Catalog.pm $(POSTGRES_BKI_SRCS) $(POSTGRES_BKI_DATA) $(top_srcdir)/configure.in
91-
$(PERL) -I $(catalogdir) $< --set-version=$(MAJORVERSION) $(POSTGRES_BKI_SRCS)
91+
$(PERL) -I $(catalogdir) $< \
92+
-I $(top_srcdir)/src/include/ --set-version=$(MAJORVERSION) \
93+
$(POSTGRES_BKI_SRCS)
9294
touch $@
9395

9496
# The generated headers must all be symlinked into builddir/src/include/,

src/backend/catalog/genbki.pl

+18-10
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
my @input_files;
2323
my $output_path = '';
2424
my $major_version;
25+
my $include_path;
2526

2627
# Process command line switches.
2728
while (@ARGV)
@@ -31,6 +32,10 @@
3132
{
3233
push @input_files, $arg;
3334
}
35+
elsif ($arg =~ /^-I/)
36+
{
37+
$include_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
38+
}
3439
elsif ($arg =~ /^-o/)
3540
{
3641
$output_path = length($arg) > 2 ? substr($arg, 2) : shift @ARGV;
@@ -50,6 +55,7 @@
5055
# Sanity check arguments.
5156
die "No input files.\n" if !@input_files;
5257
die "--set-version must be specified.\n" if !defined $major_version;
58+
die "-I, the header include path, must be specified.\n" if !$include_path;
5359

5460
# Make sure output_path ends in a slash.
5561
if ($output_path ne '' && substr($output_path, -1) ne '/')
@@ -133,24 +139,25 @@
133139
# While duplicate OIDs would only cause a failure if they appear in
134140
# the same catalog, our project policy is that manually assigned OIDs
135141
# should be globally unique, to avoid confusion.
136-
#
137-
# Also use the loop to determine the maximum explicitly assigned oid
138-
# found in the data file, we'll use that for default oid assignments.
139142
my $found = 0;
140-
my $maxoid = 0;
141143
foreach my $oid (keys %oidcounts)
142144
{
143-
if ($oid > $maxoid)
144-
{
145-
$maxoid = $oid;
146-
}
147145
next unless $oidcounts{$oid} > 1;
148146
print STDERR "Duplicate OIDs detected:\n" if !$found;
149147
print STDERR "$oid\n";
150148
$found++;
151149
}
152150
die "found $found duplicate OID(s) in catalog data\n" if $found;
153151

152+
153+
# Oids not specified in the input files are automatically assigned,
154+
# starting at FirstGenbkiObjectId.
155+
my $FirstGenbkiObjectId =
156+
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
157+
'FirstGenbkiObjectId');
158+
my $GenbkiNextOid = $FirstGenbkiObjectId;
159+
160+
154161
# Fetch some special data that we will substitute into the output file.
155162
# CAUTION: be wary about what symbols you substitute into the .bki file here!
156163
# It's okay to substitute things that are expected to be really constant
@@ -418,8 +425,8 @@
418425
# Assign oid if oid column exists and no explicit assignment in row
419426
if ($attname eq "oid" and not defined $bki_values{$attname})
420427
{
421-
$bki_values{$attname} = $maxoid;
422-
$maxoid++;
428+
$bki_values{$attname} = $GenbkiNextOid;
429+
$GenbkiNextOid++;
423430
}
424431

425432
# Substitute constant values we acquired above.
@@ -858,6 +865,7 @@ sub usage
858865
Usage: genbki.pl [options] header...
859866
860867
Options:
868+
-I include path
861869
-o output path
862870
--set-version PostgreSQL version number for initdb cross-check
863871

src/backend/utils/Gen_fmgrtab.pl

+6-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@
7979
}
8080

8181
# Fetch some values for later.
82-
my $FirstBootstrapObjectId =
82+
my $FirstGenbkiObjectId =
8383
Catalog::FindDefinedSymbol('access/transam.h', $include_path,
84-
'FirstBootstrapObjectId');
84+
'FirstGenbkiObjectId');
8585
my $INTERNALlanguageId =
8686
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
8787
'INTERNALlanguageId');
@@ -252,13 +252,13 @@
252252

253253
# Create fmgr_builtins_oid_index table.
254254
#
255-
# Note that the array has to be filled up to FirstBootstrapObjectId,
255+
# Note that the array has to be filled up to FirstGenbkiObjectId,
256256
# as we can't rely on zero initialization as 0 is a valid mapping.
257257
print $tfh qq|
258-
const uint16 fmgr_builtin_oid_index[FirstBootstrapObjectId] = {
258+
const uint16 fmgr_builtin_oid_index[FirstGenbkiObjectId] = {
259259
|;
260260

261-
for (my $i = 0; $i < $FirstBootstrapObjectId; $i++)
261+
for (my $i = 0; $i < $FirstGenbkiObjectId; $i++)
262262
{
263263
my $oid = $fmgr_builtin_oid_index[$i];
264264

@@ -269,7 +269,7 @@
269269
$oid = 'InvalidOidBuiltinMapping';
270270
}
271271

272-
if ($i + 1 == $FirstBootstrapObjectId)
272+
if ($i + 1 == $FirstGenbkiObjectId)
273273
{
274274
print $tfh " $oid\n";
275275
}

src/backend/utils/fmgr/fmgr.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ fmgr_isbuiltin(Oid id)
7575
uint16 index;
7676

7777
/* fast lookup only possible if original oid still assigned */
78-
if (id >= FirstBootstrapObjectId)
78+
if (id >= FirstGenbkiObjectId)
7979
return NULL;
8080

8181
/*

src/include/access/transam.h

+11-7
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,30 @@
7171
/* ----------
7272
* Object ID (OID) zero is InvalidOid.
7373
*
74-
* OIDs 1-9999 are reserved for manual assignment (see the files
75-
* in src/include/catalog/).
74+
* OIDs 1-9999 are reserved for manual assignment (see .dat files in
75+
* src/include/catalog/), with 9000-9999 tentatively reserved for forks.
7676
*
77-
* OIDS 10000-16383 are reserved for assignment during initdb
78-
* using the OID generator. (We start the generator at 10000.)
77+
* OIDs 10000-12000 are reserved for assignment by genbki.pl, when the
78+
* .dat files in src/include/catalog/ do not specify oids.
79+
*
80+
* OIDS 12000-16383 are reserved for assignment during initdb
81+
* using the OID generator. (We start the generator at 12000.)
7982
*
8083
* OIDs beginning at 16384 are assigned from the OID generator
8184
* during normal multiuser operation. (We force the generator up to
8285
* 16384 as soon as we are in normal operation.)
8386
*
84-
* The choices of 10000 and 16384 are completely arbitrary, and can be moved
85-
* if we run low on OIDs in either category. Changing the macros below
87+
* The choices of 10000, 12000 and 16384 are completely arbitrary, and can be
88+
* moved if we run low on OIDs in either category. Changing the macros below
8689
* should be sufficient to do this.
8790
*
8891
* NOTE: if the OID generator wraps around, we skip over OIDs 0-16383
8992
* and resume with 16384. This minimizes the odds of OID conflict, by not
9093
* reassigning OIDs that might have been assigned during initdb.
9194
* ----------
9295
*/
93-
#define FirstBootstrapObjectId 10000
96+
#define FirstGenbkiObjectId 10000
97+
#define FirstBootstrapObjectId 12000
9498
#define FirstNormalObjectId 16384
9599

96100
/*

src/include/catalog/unused_oids

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ my @input_files = (glob("pg_*.h"), qw(indexing.h toasting.h));
3232

3333
my $oids = Catalog::FindAllOidsFromHeaders(@input_files);
3434

35-
# Also push FirstBootstrapObjectId to serve as a terminator for the last gap.
36-
my $FirstBootstrapObjectId =
35+
# Also push FirstGenbkiObjectId to serve as a terminator for the last gap.
36+
my $FirstGenbkiObjectId =
3737
Catalog::FindDefinedSymbol('access/transam.h', '..',
38-
'FirstBootstrapObjectId');
39-
push @{$oids}, $FirstBootstrapObjectId;
38+
'FirstGenbkiObjectId');
39+
push @{$oids}, $FirstGenbkiObjectId;
4040

4141
my $prev_oid = 0;
4242
foreach my $oid (sort { $a <=> $b } @{$oids})

src/include/utils/fmgrtab.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ extern const int fmgr_nbuiltins; /* number of entries in table */
4141
* array.
4242
*/
4343
#define InvalidOidBuiltinMapping PG_UINT16_MAX
44-
extern const uint16 fmgr_builtin_oid_index[FirstBootstrapObjectId];
44+
extern const uint16 fmgr_builtin_oid_index[FirstGenbkiObjectId];
4545

4646
#endif /* FMGRTAB_H */

src/tools/msvc/Solution.pm

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ EOF
493493
{
494494
chdir('src/backend/catalog');
495495
my $bki_srcs = join(' ../../../src/include/catalog/', @bki_srcs);
496-
system("perl genbki.pl --set-version=$self->{majorver} $bki_srcs");
496+
system("perl genbki.pl -I../../../src/include/ --set-version=$self->{majorver} $bki_srcs");
497497
open(my $f, '>', 'bki-stamp')
498498
|| confess "Could not touch bki-stamp";
499499
close($f);

0 commit comments

Comments
 (0)