Remove special BKI_LOOKUP magic for namespace and role OIDs.

Now that commit 62f34097c attached BKI_LOOKUP annotation to all the
namespace and role OID columns in the catalogs, there's no real reason
to have the magic PGNSP and PGUID symbols.  Get rid of them in favor
of implementing those lookups according to genbki.pl's normal pattern.

This means that in the catalog headers, BKI_DEFAULT(PGNSP) becomes
BKI_DEFAULT(pg_catalog), which seems a lot more transparent.
BKI_DEFAULT(PGUID) becomes BKI_DEFAULT(POSTGRES), which is perhaps
less so; but you can look into pg_authid.dat to discover that
POSTGRES is the nonce name for the bootstrap superuser.

This change also means that if we ever need cross-references in the
initial catalog data to any of the other built-in roles besides
POSTGRES, or to some other built-in schema besides pg_catalog,
we can just do it.

No catversion bump here, as there's no actual change in the contents
of postgres.bki.

Discussion: https://postgr.es/m/3240355.1612129197@sss.pgh.pa.us
This commit is contained in:
Tom Lane 2021-02-03 12:01:48 -05:00
parent 0bf83648a5
commit ba0faf81c6
19 changed files with 46 additions and 52 deletions

View File

@ -540,17 +540,6 @@
expected to be in the <literal>pg_catalog</literal> schema. expected to be in the <literal>pg_catalog</literal> schema.
</para> </para>
</listitem> </listitem>
<listitem>
<para>
In addition to the generic lookup mechanisms, there is a special
convention that <literal>PGNSP</literal> is replaced by the OID of
the <literal>pg_catalog</literal> schema,
and <literal>PGUID</literal> is replaced by the OID of the bootstrap
superuser role. These usages are somewhat historical but so far
there hasn't been a need to generalize them.
</para>
</listitem>
</itemizedlist> </itemizedlist>
<para> <para>

View File

@ -184,15 +184,9 @@ my $GenbkiNextOid = $FirstGenbkiObjectId;
# within a given Postgres release, such as fixed OIDs. Do not substitute # within a given Postgres release, such as fixed OIDs. Do not substitute
# anything that could depend on platform or configuration. (The right place # anything that could depend on platform or configuration. (The right place
# to handle those sorts of things is in initdb.c's bootstrap_template1().) # to handle those sorts of things is in initdb.c's bootstrap_template1().)
my $BOOTSTRAP_SUPERUSERID =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_authid},
'BOOTSTRAP_SUPERUSERID');
my $C_COLLATION_OID = my $C_COLLATION_OID =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_collation}, Catalog::FindDefinedSymbolFromData($catalog_data{pg_collation},
'C_COLLATION_OID'); 'C_COLLATION_OID');
my $PG_CATALOG_NAMESPACE =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_namespace},
'PG_CATALOG_NAMESPACE');
# Fill in pg_class.relnatts by looking at the referenced catalog's schema. # Fill in pg_class.relnatts by looking at the referenced catalog's schema.
@ -213,11 +207,12 @@ foreach my $row (@{ $catalog_data{pg_am} })
$amoids{ $row->{amname} } = $row->{oid}; $amoids{ $row->{amname} } = $row->{oid};
} }
# There is only one authid at bootstrap time, and we handle it specially: # role OID lookup
# the usually-defaulted symbol PGUID becomes the bootstrap superuser's OID.
# (We could drop this in favor of writing out BKI_DEFAULT(POSTGRES) ...)
my %authidoids; my %authidoids;
$authidoids{'PGUID'} = $BOOTSTRAP_SUPERUSERID; foreach my $row (@{ $catalog_data{pg_authid} })
{
$authidoids{ $row->{rolname} } = $row->{oid};
}
# class (relation) OID lookup (note this only covers bootstrap catalogs!) # class (relation) OID lookup (note this only covers bootstrap catalogs!)
my %classoids; my %classoids;
@ -240,11 +235,12 @@ foreach my $row (@{ $catalog_data{pg_language} })
$langoids{ $row->{lanname} } = $row->{oid}; $langoids{ $row->{lanname} } = $row->{oid};
} }
# There is only one namespace at bootstrap time, and we handle it specially: # namespace (schema) OID lookup
# the usually-defaulted symbol PGNSP becomes the pg_catalog namespace's OID.
# (We could drop this in favor of writing out BKI_DEFAULT(pg_catalog) ...)
my %namespaceoids; my %namespaceoids;
$namespaceoids{'PGNSP'} = $PG_CATALOG_NAMESPACE; foreach my $row (@{ $catalog_data{pg_namespace} })
{
$namespaceoids{ $row->{nspname} } = $row->{oid};
}
# opclass OID lookup # opclass OID lookup
my %opcoids; my %opcoids;

View File

@ -15,6 +15,10 @@
# The C code typically refers to these roles using the #define symbols, # The C code typically refers to these roles using the #define symbols,
# so make sure every entry has an oid_symbol value. # so make sure every entry has an oid_symbol value.
# The bootstrap superuser is named POSTGRES according to this data and
# according to BKI_DEFAULT entries in other catalogs. However, initdb
# will replace that at database initialization time.
{ oid => '10', oid_symbol => 'BOOTSTRAP_SUPERUSERID', { oid => '10', oid_symbol => 'BOOTSTRAP_SUPERUSERID',
rolname => 'POSTGRES', rolsuper => 't', rolinherit => 't', rolname => 'POSTGRES', rolsuper => 't', rolinherit => 't',
rolcreaterole => 't', rolcreatedb => 't', rolcanlogin => 't', rolcreaterole => 't', rolcreatedb => 't', rolcanlogin => 't',

View File

@ -38,7 +38,7 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat
NameData relname; NameData relname;
/* OID of namespace containing this class */ /* OID of namespace containing this class */
Oid relnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid relnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* OID of entry in pg_type for relation's implicit row type, if any */ /* OID of entry in pg_type for relation's implicit row type, if any */
Oid reltype BKI_LOOKUP_OPT(pg_type); Oid reltype BKI_LOOKUP_OPT(pg_type);
@ -47,7 +47,7 @@ CATALOG(pg_class,1259,RelationRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(83,Relat
Oid reloftype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type); Oid reloftype BKI_DEFAULT(0) BKI_LOOKUP_OPT(pg_type);
/* class owner */ /* class owner */
Oid relowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid relowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* access method; 0 if not a table / index */ /* access method; 0 if not a table / index */
Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(pg_am); Oid relam BKI_DEFAULT(heap) BKI_LOOKUP_OPT(pg_am);

View File

@ -30,9 +30,12 @@ CATALOG(pg_collation,3456,CollationRelationId)
{ {
Oid oid; /* oid */ Oid oid; /* oid */
NameData collname; /* collation name */ NameData collname; /* collation name */
Oid collnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); /* OID of namespace
* containing collation */ /* OID of namespace containing this collation */
Oid collowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); /* owner of collation */ Oid collnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* owner of collation */
Oid collowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
char collprovider; /* see constants below */ char collprovider; /* see constants below */
bool collisdeterministic BKI_DEFAULT(t); bool collisdeterministic BKI_DEFAULT(t);
int32 collencoding; /* encoding for this collation; -1 = "all" */ int32 collencoding; /* encoding for this collation; -1 = "all" */

View File

@ -35,10 +35,10 @@ CATALOG(pg_conversion,2607,ConversionRelationId)
NameData conname; NameData conname;
/* namespace that the conversion belongs to */ /* namespace that the conversion belongs to */
Oid connamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid connamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* owner of the conversion */ /* owner of the conversion */
Oid conowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid conowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* FOR encoding id */ /* FOR encoding id */
int32 conforencoding BKI_LOOKUP(encoding); int32 conforencoding BKI_LOOKUP(encoding);

View File

@ -35,7 +35,7 @@ CATALOG(pg_database,1262,DatabaseRelationId) BKI_SHARED_RELATION BKI_ROWTYPE_OID
NameData datname; NameData datname;
/* owner of database */ /* owner of database */
Oid datdba BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid datdba BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* character encoding */ /* character encoding */
int32 encoding; int32 encoding;

View File

@ -34,7 +34,7 @@ CATALOG(pg_language,2612,LanguageRelationId)
NameData lanname; NameData lanname;
/* Language's owner */ /* Language's owner */
Oid lanowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid lanowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* Is a procedural language */ /* Is a procedural language */
bool lanispl BKI_DEFAULT(f); bool lanispl BKI_DEFAULT(f);

View File

@ -37,7 +37,7 @@ CATALOG(pg_namespace,2615,NamespaceRelationId)
Oid oid; /* oid */ Oid oid; /* oid */
NameData nspname; NameData nspname;
Oid nspowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid nspowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
#ifdef CATALOG_VARLEN /* variable-length fields start here */ #ifdef CATALOG_VARLEN /* variable-length fields start here */
aclitem nspacl[1]; aclitem nspacl[1];

View File

@ -57,10 +57,10 @@ CATALOG(pg_opclass,2616,OperatorClassRelationId)
NameData opcname; NameData opcname;
/* namespace of this opclass */ /* namespace of this opclass */
Oid opcnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid opcnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* opclass owner */ /* opclass owner */
Oid opcowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid opcowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* containing operator family */ /* containing operator family */
Oid opcfamily BKI_LOOKUP(pg_opfamily); Oid opcfamily BKI_LOOKUP(pg_opfamily);

View File

@ -36,10 +36,10 @@ CATALOG(pg_operator,2617,OperatorRelationId)
NameData oprname; NameData oprname;
/* OID of namespace containing this oper */ /* OID of namespace containing this oper */
Oid oprnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid oprnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* operator owner */ /* operator owner */
Oid oprowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid oprowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* 'l' for prefix or 'b' for infix */ /* 'l' for prefix or 'b' for infix */
char oprkind BKI_DEFAULT(b); char oprkind BKI_DEFAULT(b);

View File

@ -37,10 +37,10 @@ CATALOG(pg_opfamily,2753,OperatorFamilyRelationId)
NameData opfname; NameData opfname;
/* namespace of this opfamily */ /* namespace of this opfamily */
Oid opfnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid opfnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* opfamily owner */ /* opfamily owner */
Oid opfowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid opfowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
} FormData_pg_opfamily; } FormData_pg_opfamily;
/* ---------------- /* ----------------

View File

@ -35,10 +35,10 @@ CATALOG(pg_proc,1255,ProcedureRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81,Proce
NameData proname; NameData proname;
/* OID of namespace containing this proc */ /* OID of namespace containing this proc */
Oid pronamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid pronamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* procedure owner */ /* procedure owner */
Oid proowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid proowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* OID of pg_language entry */ /* OID of pg_language entry */
Oid prolang BKI_DEFAULT(internal) BKI_LOOKUP(pg_language); Oid prolang BKI_DEFAULT(internal) BKI_LOOKUP(pg_language);

View File

@ -30,7 +30,9 @@ CATALOG(pg_tablespace,1213,TableSpaceRelationId) BKI_SHARED_RELATION
{ {
Oid oid; /* oid */ Oid oid; /* oid */
NameData spcname; /* tablespace name */ NameData spcname; /* tablespace name */
Oid spcowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); /* owner of tablespace */
/* owner of tablespace */
Oid spcowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
#ifdef CATALOG_VARLEN /* variable-length fields start here */ #ifdef CATALOG_VARLEN /* variable-length fields start here */
aclitem spcacl[1]; /* access permissions */ aclitem spcacl[1]; /* access permissions */

View File

@ -36,10 +36,10 @@ CATALOG(pg_ts_config,3602,TSConfigRelationId)
NameData cfgname; NameData cfgname;
/* name space */ /* name space */
Oid cfgnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid cfgnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* owner */ /* owner */
Oid cfgowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid cfgowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* OID of parser */ /* OID of parser */
Oid cfgparser BKI_LOOKUP(pg_ts_parser); Oid cfgparser BKI_LOOKUP(pg_ts_parser);

View File

@ -35,10 +35,10 @@ CATALOG(pg_ts_dict,3600,TSDictionaryRelationId)
NameData dictname; NameData dictname;
/* name space */ /* name space */
Oid dictnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid dictnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* owner */ /* owner */
Oid dictowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid dictowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* dictionary's template */ /* dictionary's template */
Oid dicttemplate BKI_LOOKUP(pg_ts_template); Oid dicttemplate BKI_LOOKUP(pg_ts_template);

View File

@ -34,7 +34,7 @@ CATALOG(pg_ts_parser,3601,TSParserRelationId)
NameData prsname; NameData prsname;
/* name space */ /* name space */
Oid prsnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid prsnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* init parsing session */ /* init parsing session */
regproc prsstart BKI_LOOKUP(pg_proc); regproc prsstart BKI_LOOKUP(pg_proc);

View File

@ -34,7 +34,7 @@ CATALOG(pg_ts_template,3764,TSTemplateRelationId)
NameData tmplname; NameData tmplname;
/* name space */ /* name space */
Oid tmplnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid tmplnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* initialization method of dict (may be 0) */ /* initialization method of dict (may be 0) */
regproc tmplinit BKI_LOOKUP_OPT(pg_proc); regproc tmplinit BKI_LOOKUP_OPT(pg_proc);

View File

@ -41,10 +41,10 @@ CATALOG(pg_type,1247,TypeRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(71,TypeRelati
NameData typname; NameData typname;
/* OID of namespace containing this type */ /* OID of namespace containing this type */
Oid typnamespace BKI_DEFAULT(PGNSP) BKI_LOOKUP(pg_namespace); Oid typnamespace BKI_DEFAULT(pg_catalog) BKI_LOOKUP(pg_namespace);
/* type owner */ /* type owner */
Oid typowner BKI_DEFAULT(PGUID) BKI_LOOKUP(pg_authid); Oid typowner BKI_DEFAULT(POSTGRES) BKI_LOOKUP(pg_authid);
/* /*
* For a fixed-size type, typlen is the number of bytes we use to * For a fixed-size type, typlen is the number of bytes we use to