Commit 814c9019 authored by Tom Lane's avatar Tom Lane

Use symbolic references for pg_language OIDs in the bootstrap data.

This patch teaches genbki.pl to replace pg_language names by OIDs
in much the same way as it already does for pg_am names etc, and
converts pg_proc.dat to use such symbolic references in the prolang
column.

Aside from getting rid of a few more magic numbers in the initial
catalog data, this means that Gen_fmgrtab.pl no longer needs to read
pg_language.dat, since it doesn't have to know the OID of the "internal"
language; now it's just looking for the string "internal".

No need for a catversion bump, since the contents of postgres.bki
don't actually change at all.

John Naylor

Discussion: https://postgr.es/m/CAJVSVGWtUqxpfAaxS88vEGvi+jKzWZb2EStu5io-UPc4p9rSJg@mail.gmail.com
parent 7170268e
...@@ -409,8 +409,9 @@ ...@@ -409,8 +409,9 @@
that's error-prone and hard to understand, so for frequently-referenced that's error-prone and hard to understand, so for frequently-referenced
catalogs, <filename>genbki.pl</filename> provides mechanisms to write catalogs, <filename>genbki.pl</filename> provides mechanisms to write
symbolic references instead. Currently this is possible for references symbolic references instead. Currently this is possible for references
to access methods, functions, operators, opclasses, opfamilies, and to access methods, functions, languages,
types. The rules are as follows: operators, opclasses, opfamilies, and types.
The rules are as follows:
</para> </para>
<itemizedlist> <itemizedlist>
...@@ -421,6 +422,7 @@ ...@@ -421,6 +422,7 @@
by attaching <literal>BKI_LOOKUP(<replaceable>lookuprule</replaceable>)</literal> by attaching <literal>BKI_LOOKUP(<replaceable>lookuprule</replaceable>)</literal>
to the column's definition, where <replaceable>lookuprule</replaceable> to the column's definition, where <replaceable>lookuprule</replaceable>
is <literal>pg_am</literal>, <literal>pg_proc</literal>, is <literal>pg_am</literal>, <literal>pg_proc</literal>,
<literal>pg_language</literal>,
<literal>pg_operator</literal>, <literal>pg_opclass</literal>, <literal>pg_operator</literal>, <literal>pg_opclass</literal>,
<literal>pg_opfamily</literal>, or <literal>pg_type</literal>. <literal>pg_opfamily</literal>, or <literal>pg_type</literal>.
<literal>BKI_LOOKUP</literal> can be attached to columns of <literal>BKI_LOOKUP</literal> can be attached to columns of
......
...@@ -178,13 +178,20 @@ my $PG_CATALOG_NAMESPACE = ...@@ -178,13 +178,20 @@ my $PG_CATALOG_NAMESPACE =
# Build lookup tables for OID macro substitutions and for pg_attribute # Build lookup tables for OID macro substitutions and for pg_attribute
# copies of pg_type values. # copies of pg_type values.
# index access method OID lookup # access method OID lookup
my %amoids; my %amoids;
foreach my $row (@{ $catalog_data{pg_am} }) foreach my $row (@{ $catalog_data{pg_am} })
{ {
$amoids{ $row->{amname} } = $row->{oid}; $amoids{ $row->{amname} } = $row->{oid};
} }
# language OID lookup
my %langoids;
foreach my $row (@{ $catalog_data{pg_language} })
{
$langoids{ $row->{lanname} } = $row->{oid};
}
# opclass OID lookup # opclass OID lookup
my %opcoids; my %opcoids;
foreach my $row (@{ $catalog_data{pg_opclass} }) foreach my $row (@{ $catalog_data{pg_opclass} })
...@@ -259,6 +266,7 @@ foreach my $row (@{ $catalog_data{pg_type} }) ...@@ -259,6 +266,7 @@ foreach my $row (@{ $catalog_data{pg_type} })
# Map catalog name to OID lookup. # Map catalog name to OID lookup.
my %lookup_kind = ( my %lookup_kind = (
pg_am => \%amoids, pg_am => \%amoids,
pg_language => \%langoids,
pg_opclass => \%opcoids, pg_opclass => \%opcoids,
pg_operator => \%operoids, pg_operator => \%operoids,
pg_opfamily => \%opfoids, pg_opfamily => \%opfoids,
......
...@@ -59,6 +59,8 @@ die "No include path; you must specify -I.\n" if !$include_path; ...@@ -59,6 +59,8 @@ die "No include path; you must specify -I.\n" if !$include_path;
# Note: We pass data file names as arguments and then look for matching # Note: We pass data file names as arguments and then look for matching
# headers to parse the schema from. This is backwards from genbki.pl, # headers to parse the schema from. This is backwards from genbki.pl,
# but the Makefile dependencies look more sensible this way. # but the Makefile dependencies look more sensible this way.
# We currently only need pg_proc, but retain the possibility of reading
# more than one data file.
my %catalogs; my %catalogs;
my %catalog_data; my %catalog_data;
foreach my $datfile (@input_files) foreach my $datfile (@input_files)
...@@ -82,9 +84,6 @@ foreach my $datfile (@input_files) ...@@ -82,9 +84,6 @@ foreach my $datfile (@input_files)
my $FirstGenbkiObjectId = my $FirstGenbkiObjectId =
Catalog::FindDefinedSymbol('access/transam.h', $include_path, Catalog::FindDefinedSymbol('access/transam.h', $include_path,
'FirstGenbkiObjectId'); 'FirstGenbkiObjectId');
my $INTERNALlanguageId =
Catalog::FindDefinedSymbolFromData($catalog_data{pg_language},
'INTERNALlanguageId');
# Collect certain fields from pg_proc.dat. # Collect certain fields from pg_proc.dat.
my @fmgr = (); my @fmgr = ();
...@@ -94,7 +93,7 @@ foreach my $row (@{ $catalog_data{pg_proc} }) ...@@ -94,7 +93,7 @@ foreach my $row (@{ $catalog_data{pg_proc} })
my %bki_values = %$row; my %bki_values = %$row;
# Select out just the rows for internal-language procedures. # Select out just the rows for internal-language procedures.
next if $bki_values{prolang} ne $INTERNALlanguageId; next if $bki_values{prolang} ne 'internal';
push @fmgr, push @fmgr,
{ {
......
...@@ -31,15 +31,11 @@ generated-header-symlinks: $(top_builddir)/src/include/utils/header-stamp $(top_ ...@@ -31,15 +31,11 @@ generated-header-symlinks: $(top_builddir)/src/include/utils/header-stamp $(top_
$(SUBDIRS:%=%-recursive): fmgr-stamp errcodes.h $(SUBDIRS:%=%-recursive): fmgr-stamp errcodes.h
FMGR_DATA := $(addprefix $(top_srcdir)/src/include/catalog/,\
pg_language.dat pg_proc.dat \
)
# fmgr-stamp records the last time we ran Gen_fmgrtab.pl. We don't rely on # fmgr-stamp records the last time we ran Gen_fmgrtab.pl. We don't rely on
# the timestamps of the individual output files, because the Perl script # the timestamps of the individual output files, because the Perl script
# won't update them if they didn't change (to avoid unnecessary recompiles). # won't update them if they didn't change (to avoid unnecessary recompiles).
fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(FMGR_DATA) $(top_srcdir)/src/include/access/transam.h fmgr-stamp: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.dat $(top_srcdir)/src/include/access/transam.h
$(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(FMGR_DATA) $(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(top_srcdir)/src/include/catalog/pg_proc.dat
touch $@ touch $@
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
......
This diff is collapsed.
...@@ -42,7 +42,7 @@ CATALOG(pg_proc,1255,ProcedureRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81,Proce ...@@ -42,7 +42,7 @@ CATALOG(pg_proc,1255,ProcedureRelationId) BKI_BOOTSTRAP BKI_ROWTYPE_OID(81,Proce
Oid proowner BKI_DEFAULT(PGUID); Oid proowner BKI_DEFAULT(PGUID);
/* OID of pg_language entry */ /* OID of pg_language entry */
Oid prolang BKI_DEFAULT(12); Oid prolang BKI_DEFAULT(internal) BKI_LOOKUP(pg_language);
/* estimated execution cost */ /* estimated execution cost */
float4 procost BKI_DEFAULT(1); float4 procost BKI_DEFAULT(1);
......
...@@ -269,16 +269,14 @@ sub GenerateFiles ...@@ -269,16 +269,14 @@ sub GenerateFiles
"LIBPGTYPES"); "LIBPGTYPES");
chdir('src/backend/utils'); chdir('src/backend/utils');
my $pg_language_dat = '../../../src/include/catalog/pg_language.dat';
my $pg_proc_dat = '../../../src/include/catalog/pg_proc.dat'; my $pg_proc_dat = '../../../src/include/catalog/pg_proc.dat';
if ( IsNewer('fmgr-stamp', 'Gen_fmgrtab.pl') if ( IsNewer('fmgr-stamp', 'Gen_fmgrtab.pl')
|| IsNewer('fmgr-stamp', '../catalog/Catalog.pm') || IsNewer('fmgr-stamp', '../catalog/Catalog.pm')
|| IsNewer('fmgr-stamp', $pg_language_dat)
|| IsNewer('fmgr-stamp', $pg_proc_dat) || IsNewer('fmgr-stamp', $pg_proc_dat)
|| IsNewer('fmgr-stamp', '../../../src/include/access/transam.h')) || IsNewer('fmgr-stamp', '../../../src/include/access/transam.h'))
{ {
system( system(
"perl -I ../catalog Gen_fmgrtab.pl -I../../../src/include/ $pg_language_dat $pg_proc_dat" "perl -I ../catalog Gen_fmgrtab.pl -I../../../src/include/ $pg_proc_dat"
); );
open(my $f, '>', 'fmgr-stamp') open(my $f, '>', 'fmgr-stamp')
|| confess "Could not touch fmgr-stamp"; || confess "Could not touch fmgr-stamp";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment