Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3aa0395

Browse files
committed
Remove remaining hard-wired OID references in the initial catalog data.
In the v11-era commits that taught genbki.pl to resolve symbolic OID references in the initial catalog data, we didn't bother to make every last reference symbolic; some of the catalogs have so few initial rows that it didn't seem worthwhile. However, the new project policy that OIDs assigned by new patches should be automatically renumberable changes this calculus. A patch that wants to add a row in one of these catalogs would have a problem when the OID it assigns gets renumbered. Hence, do the mop-up work needed to make all OID references in initial data be symbolic, and establish an associated project policy that we'll never again write a hard-wired OID reference there. No catversion bump since the contents of postgres.bki aren't actually changed by this commit. Discussion: https://postgr.es/m/CAH2-WzmMTGMcPuph4OvsO7Ykut0AOCF_i-=eaochT0dd2BN9CQ@mail.gmail.com
1 parent a641707 commit 3aa0395

15 files changed

+381
-190
lines changed

doc/src/sgml/bki.sgml

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@
187187
# A comment could appear here.
188188
{ oid => '1', oid_symbol => 'TemplateDbOid',
189189
descr => 'database\'s default template',
190-
datname => 'template1', datdba => 'PGUID', encoding => 'ENCODING',
191-
datcollate => 'LC_COLLATE', datctype => 'LC_CTYPE', datistemplate => 't',
192-
datallowconn => 't', datconnlimit => '-1', datlastsysoid => '0',
193-
datfrozenxid => '0', datminmxid => '1', dattablespace => '1663',
194-
datacl => '_null_' },
190+
datname => 'template1', encoding => 'ENCODING', datcollate => 'LC_COLLATE',
191+
datctype => 'LC_CTYPE', datistemplate => 't', datallowconn => 't',
192+
datconnlimit => '-1', datlastsysoid => '0', datfrozenxid => '0',
193+
datminmxid => '1', dattablespace => 'pg_default', datacl => '_null_' },
195194

196195
]
197196
</programlisting>
@@ -229,6 +228,9 @@
229228
While the metadata keys are optional, the catalog's defined columns
230229
must all be provided, except when the catalog's <literal>.h</literal>
231230
file specifies a default value for the column.
231+
(In the example above, the <structfield>datdba</structfield> field has
232+
been omitted because <filename>pg_database.h</filename> supplies a
233+
suitable default value for it.)
232234
</para>
233235
</listitem>
234236

@@ -264,8 +266,10 @@
264266

265267
<listitem>
266268
<para>
267-
To aid readability, field values that are OIDs of other catalog
268-
entries can be represented by names rather than numeric OIDs.
269+
Field values that are OIDs of other catalog entries should be
270+
represented by symbolic names rather than actual numeric OIDs.
271+
(In the example above, <structfield>dattablespace</structfield>
272+
contains such a reference.)
269273
This is described in <xref linkend="system-catalog-oid-references"/>
270274
below.
271275
</para>
@@ -438,13 +442,13 @@
438442
<title>OID Reference Lookup</title>
439443

440444
<para>
441-
Cross-references from one initial catalog row to another can be written
442-
by just writing the preassigned OID of the referenced row. But
443-
that's error-prone and hard to understand, so for frequently-referenced
444-
catalogs, <filename>genbki.pl</filename> provides mechanisms to write
445-
symbolic references instead. Currently this is possible for references
446-
to access methods, functions, languages,
447-
operators, opclasses, opfamilies, types, and encodings.
445+
In principle, cross-references from one initial catalog row to another
446+
could be written just by writing the preassigned OID of the referenced
447+
row in the referencing field. However, that is against project
448+
policy, because it is error-prone, hard to read, and subject to
449+
breakage if a newly-assigned OID is renumbered. Therefore
450+
<filename>genbki.pl</filename> provides mechanisms to write
451+
symbolic references instead.
448452
The rules are as follows:
449453
</para>
450454

@@ -455,19 +459,20 @@
455459
Use of symbolic references is enabled in a particular catalog column
456460
by attaching <literal>BKI_LOOKUP(<replaceable>lookuprule</replaceable>)</literal>
457461
to the column's definition, where <replaceable>lookuprule</replaceable>
458-
is <literal>pg_am</literal>, <literal>pg_proc</literal>,
459-
<literal>pg_language</literal>,
460-
<literal>pg_operator</literal>, <literal>pg_opclass</literal>,
461-
<literal>pg_opfamily</literal>,
462-
<literal>pg_type</literal>,
463-
or <literal>encoding</literal>.
462+
is the name of the referenced catalog, e.g. <literal>pg_proc</literal>.
464463
<literal>BKI_LOOKUP</literal> can be attached to columns of
465464
type <type>Oid</type>, <type>regproc</type>, <type>oidvector</type>,
466465
or <type>Oid[]</type>; in the latter two cases it implies performing a
467466
lookup on each element of the array.
468-
It's also permissible to attach <literal>BKI_LOOKUP</literal>
469-
to integer columns; this should be done only for encodings,
470-
which are not currently represented as catalog OIDs.
467+
</para>
468+
</listitem>
469+
470+
<listitem>
471+
<para>
472+
It's also permissible to attach <literal>BKI_LOOKUP(encoding)</literal>
473+
to integer columns to reference character set encodings, which are
474+
not currently represented as catalog OIDs, but have a set of values
475+
known to <filename>genbki.pl</filename>.
471476
</para>
472477
</listitem>
473478

@@ -483,10 +488,11 @@
483488

484489
<listitem>
485490
<para>
486-
Access methods are just represented by their names, as are types.
487-
Type names must match the referenced <structname>pg_type</structname>
488-
entry's <structfield>typname</structfield>; you do not get to use any
489-
aliases such as <literal>integer</literal>
491+
Most kinds of catalog objects are simply referenced by their names.
492+
Note that type names must exactly match the
493+
referenced <structname>pg_type</structname>
494+
entry's <structfield>typname</structfield>; you do not get to use
495+
any aliases such as <literal>integer</literal>
490496
for <literal>int4</literal>.
491497
</para>
492498
</listitem>
@@ -530,7 +536,18 @@
530536
<para>
531537
In none of these cases is there any provision for
532538
schema-qualification; all objects created during bootstrap are
533-
expected to be in the pg_catalog schema.
539+
expected to be in the <literal>pg_catalog</literal> schema.
540+
</para>
541+
</listitem>
542+
543+
<listitem>
544+
<para>
545+
In addition to the generic lookup mechanisms, there is a special
546+
convention that <literal>PGNSP</literal> is replaced by the OID of
547+
the <literal>pg_catalog</literal> schema,
548+
and <literal>PGUID</literal> is replaced by the OID of the bootstrap
549+
superuser role. These usages are somewhat historical but so far
550+
there hasn't been a need to generalize them.
534551
</para>
535552
</listitem>
536553
</itemizedlist>

src/backend/catalog/genbki.pl

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@
160160
my $PG_CATALOG_NAMESPACE =
161161
Catalog::FindDefinedSymbolFromData($catalog_data{pg_namespace},
162162
'PG_CATALOG_NAMESPACE');
163-
my $PG_HEAP_AM =
164-
Catalog::FindDefinedSymbolFromData($catalog_data{pg_am},
165-
'HEAP_TABLE_AM_OID');
166163

167164

168165
# Build lookup tables.
@@ -174,6 +171,20 @@
174171
$amoids{ $row->{amname} } = $row->{oid};
175172
}
176173

174+
# class (relation) OID lookup (note this only covers bootstrap catalogs!)
175+
my %classoids;
176+
foreach my $row (@{ $catalog_data{pg_class} })
177+
{
178+
$classoids{ $row->{relname} } = $row->{oid};
179+
}
180+
181+
# collation OID lookup
182+
my %collationoids;
183+
foreach my $row (@{ $catalog_data{pg_collation} })
184+
{
185+
$collationoids{ $row->{collname} } = $row->{oid};
186+
}
187+
177188
# language OID lookup
178189
my %langoids;
179190
foreach my $row (@{ $catalog_data{pg_language} })
@@ -243,6 +254,41 @@
243254
}
244255
}
245256

257+
# tablespace OID lookup
258+
my %tablespaceoids;
259+
foreach my $row (@{ $catalog_data{pg_tablespace} })
260+
{
261+
$tablespaceoids{ $row->{spcname} } = $row->{oid};
262+
}
263+
264+
# text search configuration OID lookup
265+
my %tsconfigoids;
266+
foreach my $row (@{ $catalog_data{pg_ts_config} })
267+
{
268+
$tsconfigoids{ $row->{cfgname} } = $row->{oid};
269+
}
270+
271+
# text search dictionary OID lookup
272+
my %tsdictoids;
273+
foreach my $row (@{ $catalog_data{pg_ts_dict} })
274+
{
275+
$tsdictoids{ $row->{dictname} } = $row->{oid};
276+
}
277+
278+
# text search parser OID lookup
279+
my %tsparseroids;
280+
foreach my $row (@{ $catalog_data{pg_ts_parser} })
281+
{
282+
$tsparseroids{ $row->{prsname} } = $row->{oid};
283+
}
284+
285+
# text search template OID lookup
286+
my %tstemplateoids;
287+
foreach my $row (@{ $catalog_data{pg_ts_template} })
288+
{
289+
$tstemplateoids{ $row->{tmplname} } = $row->{oid};
290+
}
291+
246292
# type lookups
247293
my %typeoids;
248294
my %types;
@@ -287,14 +333,21 @@
287333
288334
# Map lookup name to the corresponding hash table.
289335
my %lookup_kind = (
290-
pg_am => \%amoids,
291-
pg_language => \%langoids,
292-
pg_opclass => \%opcoids,
293-
pg_operator => \%operoids,
294-
pg_opfamily => \%opfoids,
295-
pg_proc => \%procoids,
296-
pg_type => \%typeoids,
297-
encoding => \%encids);
336+
pg_am => \%amoids,
337+
pg_class => \%classoids,
338+
pg_collation => \%collationoids,
339+
pg_language => \%langoids,
340+
pg_opclass => \%opcoids,
341+
pg_operator => \%operoids,
342+
pg_opfamily => \%opfoids,
343+
pg_proc => \%procoids,
344+
pg_tablespace => \%tablespaceoids,
345+
pg_ts_config => \%tsconfigoids,
346+
pg_ts_dict => \%tsdictoids,
347+
pg_ts_parser => \%tsparseroids,
348+
pg_ts_template => \%tstemplateoids,
349+
pg_type => \%typeoids,
350+
encoding => \%encids);
298351
299352
300353
# Open temp files
@@ -467,7 +520,6 @@
467520
# (It's intentional that this can apply to parts of a field).
468521
$bki_values{$attname} =~ s/\bPGUID\b/$BOOTSTRAP_SUPERUSERID/g;
469522
$bki_values{$attname} =~ s/\bPGNSP\b/$PG_CATALOG_NAMESPACE/g;
470-
$bki_values{$attname} =~ s/\bPGHEAPAM\b/$PG_HEAP_AM/g;
471523
472524
# Replace OID synonyms with OIDs per the appropriate lookup rule.
473525
#
@@ -730,8 +782,8 @@ sub morph_row_for_pgattr
730782
$row->{attndims} = $type->{typcategory} eq 'A' ? '1' : '0';
731783

732784
# collation-aware catalog columns must use C collation
733-
$row->{attcollation} = $type->{typcollation} != 0 ?
734-
$C_COLLATION_OID : 0;
785+
$row->{attcollation} =
786+
$type->{typcollation} ne '0' ? $C_COLLATION_OID : 0;
735787

736788
if (defined $attr->{forcenotnull})
737789
{

src/include/catalog/pg_class.dat

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,48 +21,44 @@
2121
# similarly, "1" in relminmxid stands for FirstMultiXactId
2222

2323
{ oid => '1247',
24-
relname => 'pg_type', relnamespace => 'PGNSP', reltype => '71',
25-
reloftype => '0', relowner => 'PGUID', relam => 'PGHEAPAM',
26-
relfilenode => '0', reltablespace => '0', relpages => '0', reltuples => '0',
27-
relallvisible => '0', reltoastrelid => '0', relhasindex => 'f',
28-
relisshared => 'f', relpersistence => 'p', relkind => 'r', relnatts => '31',
29-
relchecks => '0', relhasrules => 'f', relhastriggers => 'f',
30-
relhassubclass => 'f', relrowsecurity => 'f', relforcerowsecurity => 'f',
31-
relispopulated => 't', relreplident => 'n', relispartition => 'f',
32-
relrewrite => '0', relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
24+
relname => 'pg_type', reltype => 'pg_type', relam => 'heap',
25+
relfilenode => '0', relpages => '0', reltuples => '0', relallvisible => '0',
26+
reltoastrelid => '0', relhasindex => 'f', relisshared => 'f',
27+
relpersistence => 'p', relkind => 'r', relnatts => '31', relchecks => '0',
28+
relhasrules => 'f', relhastriggers => 'f', relhassubclass => 'f',
29+
relrowsecurity => 'f', relforcerowsecurity => 'f', relispopulated => 't',
30+
relreplident => 'n', relispartition => 'f', relrewrite => '0',
31+
relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
3332
reloptions => '_null_', relpartbound => '_null_' },
3433
{ oid => '1249',
35-
relname => 'pg_attribute', relnamespace => 'PGNSP', reltype => '75',
36-
reloftype => '0', relowner => 'PGUID', relam => 'PGHEAPAM',
37-
relfilenode => '0', reltablespace => '0', relpages => '0', reltuples => '0',
38-
relallvisible => '0', reltoastrelid => '0', relhasindex => 'f',
39-
relisshared => 'f', relpersistence => 'p', relkind => 'r', relnatts => '24',
40-
relchecks => '0', relhasrules => 'f', relhastriggers => 'f',
41-
relhassubclass => 'f', relrowsecurity => 'f', relforcerowsecurity => 'f',
42-
relispopulated => 't', relreplident => 'n', relispartition => 'f',
43-
relrewrite => '0', relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
34+
relname => 'pg_attribute', reltype => 'pg_attribute', relam => 'heap',
35+
relfilenode => '0', relpages => '0', reltuples => '0', relallvisible => '0',
36+
reltoastrelid => '0', relhasindex => 'f', relisshared => 'f',
37+
relpersistence => 'p', relkind => 'r', relnatts => '24', relchecks => '0',
38+
relhasrules => 'f', relhastriggers => 'f', relhassubclass => 'f',
39+
relrowsecurity => 'f', relforcerowsecurity => 'f', relispopulated => 't',
40+
relreplident => 'n', relispartition => 'f', relrewrite => '0',
41+
relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
4442
reloptions => '_null_', relpartbound => '_null_' },
4543
{ oid => '1255',
46-
relname => 'pg_proc', relnamespace => 'PGNSP', reltype => '81',
47-
reloftype => '0', relowner => 'PGUID', relam => 'PGHEAPAM',
48-
relfilenode => '0', reltablespace => '0', relpages => '0', reltuples => '0',
49-
relallvisible => '0', reltoastrelid => '0', relhasindex => 'f',
50-
relisshared => 'f', relpersistence => 'p', relkind => 'r', relnatts => '29',
51-
relchecks => '0', relhasrules => 'f', relhastriggers => 'f',
52-
relhassubclass => 'f', relrowsecurity => 'f', relforcerowsecurity => 'f',
53-
relispopulated => 't', relreplident => 'n', relispartition => 'f',
54-
relrewrite => '0', relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
44+
relname => 'pg_proc', reltype => 'pg_proc', relam => 'heap',
45+
relfilenode => '0', relpages => '0', reltuples => '0', relallvisible => '0',
46+
reltoastrelid => '0', relhasindex => 'f', relisshared => 'f',
47+
relpersistence => 'p', relkind => 'r', relnatts => '29', relchecks => '0',
48+
relhasrules => 'f', relhastriggers => 'f', relhassubclass => 'f',
49+
relrowsecurity => 'f', relforcerowsecurity => 'f', relispopulated => 't',
50+
relreplident => 'n', relispartition => 'f', relrewrite => '0',
51+
relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
5552
reloptions => '_null_', relpartbound => '_null_' },
5653
{ oid => '1259',
57-
relname => 'pg_class', relnamespace => 'PGNSP', reltype => '83',
58-
reloftype => '0', relowner => 'PGUID', relam => 'PGHEAPAM',
59-
relfilenode => '0', reltablespace => '0', relpages => '0', reltuples => '0',
60-
relallvisible => '0', reltoastrelid => '0', relhasindex => 'f',
61-
relisshared => 'f', relpersistence => 'p', relkind => 'r', relnatts => '33',
62-
relchecks => '0', relhasrules => 'f', relhastriggers => 'f',
63-
relhassubclass => 'f', relrowsecurity => 'f', relforcerowsecurity => 'f',
64-
relispopulated => 't', relreplident => 'n', relispartition => 'f',
65-
relrewrite => '0', relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
54+
relname => 'pg_class', reltype => 'pg_class', relam => 'heap',
55+
relfilenode => '0', relpages => '0', reltuples => '0', relallvisible => '0',
56+
reltoastrelid => '0', relhasindex => 'f', relisshared => 'f',
57+
relpersistence => 'p', relkind => 'r', relnatts => '33', relchecks => '0',
58+
relhasrules => 'f', relhastriggers => 'f', relhassubclass => 'f',
59+
relrowsecurity => 'f', relforcerowsecurity => 'f', relispopulated => 't',
60+
relreplident => 'n', relispartition => 'f', relrewrite => '0',
61+
relfrozenxid => '3', relminmxid => '1', relacl => '_null_',
6662
reloptions => '_null_', relpartbound => '_null_' },
6763

6864
]

0 commit comments

Comments
 (0)