summaryrefslogtreecommitdiff
path: root/src/backend/utils
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-04-08 13:16:50 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-04-08 13:17:27 -0400
commit372728b0d49552641f0ea83d9d2e08817de038fa (patch)
tree5beca037d3fdfeaa09467c8b559c83eab5030878 /src/backend/utils
parent02f3e558f21c0fbec9f94d5de9ad34f321eb0e57 (diff)
Replace our traditional initial-catalog-data format with a better design.
Historically, the initial catalog data to be installed during bootstrap has been written in DATA() lines in the catalog header files. This had lots of disadvantages: the format was badly underdocumented, it was very difficult to edit the data in any mechanized way, and due to the lack of any abstraction the data was verbose, hard to read/understand, and easy to get wrong. Hence, move this data into separate ".dat" files and represent it in a way that can easily be read and rewritten by Perl scripts. The new format is essentially "key => value" for each column; while it's a bit repetitive, explicit labeling of each value makes the data far more readable and less error-prone. Provide a way to abbreviate entries by omitting field values that match a specified default value for their column. This allows removal of a large amount of repetitive boilerplate and also lowers the barrier to adding new columns. Also teach genbki.pl how to translate symbolic OID references into numeric OIDs for more cases than just "regproc"-like pg_proc references. It can now do that for regprocedure-like references (thus solving the problem that regproc is ambiguous for overloaded functions), operators, types, opfamilies, opclasses, and access methods. Use this to turn nearly all OID cross-references in the initial data into symbolic form. This represents a very large step forward in readability and error resistance of the initial catalog data. It should also reduce the difficulty of renumbering OID assignments in uncommitted patches. Also, solve the longstanding problem that frontend code that would like to use OID macros and other information from the catalog headers often had difficulty with backend-only code in the headers. To do this, arrange for all generated macros, plus such other declarations as we deem fit, to be placed in "derived" header files that are safe for frontend inclusion. (Once clients migrate to using these pg_*_d.h headers, it will be possible to get rid of the pg_*_fn.h headers, which only exist to quarantine code away from clients. That is left for follow-on patches, however.) The now-automatically-generated macros include the Anum_xxx and Natts_xxx constants that we used to have to update by hand when adding or removing catalog columns. Replace the former manual method of generating OID macros for pg_type entries with an automatic method, ensuring that all built-in types have OID macros. (But note that this patch does not change the way that OID macros for pg_proc entries are built and used. It's not clear that making that match the other catalogs would be worth extra code churn.) Add SGML documentation explaining what the new data format is and how to work with it. Despite being a very large change in the catalog headers, there is no catversion bump here, because postgres.bki and related output files haven't changed at all. John Naylor, based on ideas from various people; review and minor additional coding by me; previous review by Alvaro Herrera Discussion: https://postgr.es/m/CAJVSVGWO48JbbwXkJz_yBFyGYW-M9YWxnPdxJBUosDC9ou_F0Q@mail.gmail.com
Diffstat (limited to 'src/backend/utils')
-rw-r--r--src/backend/utils/Gen_fmgrtab.pl62
-rw-r--r--src/backend/utils/Makefile15
2 files changed, 49 insertions, 28 deletions
diff --git a/src/backend/utils/Gen_fmgrtab.pl b/src/backend/utils/Gen_fmgrtab.pl
index 4ae86df1f71..3b112c69d8e 100644
--- a/src/backend/utils/Gen_fmgrtab.pl
+++ b/src/backend/utils/Gen_fmgrtab.pl
@@ -3,7 +3,7 @@
#
# Gen_fmgrtab.pl
# Perl script that generates fmgroids.h, fmgrprotos.h, and fmgrtab.c
-# from pg_proc.h
+# from pg_proc.dat
#
# Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
@@ -20,7 +20,7 @@ use strict;
use warnings;
# Collect arguments
-my $infile; # pg_proc.h
+my @input_files;
my $output_path = '';
my @include_path;
@@ -29,7 +29,7 @@ while (@ARGV)
my $arg = shift @ARGV;
if ($arg !~ /^-/)
{
- $infile = $arg;
+ push @input_files, $arg;
}
elsif ($arg =~ /^-o/)
{
@@ -52,38 +52,50 @@ if ($output_path ne '' && substr($output_path, -1) ne '/')
}
# Sanity check arguments.
-die "No input files.\n" if !$infile;
+die "No input files.\n" if !@input_files;
die "No include path; you must specify -I at least once.\n" if !@include_path;
-my $FirstBootstrapObjectId =
- Catalog::FindDefinedSymbol('access/transam.h', \@include_path, 'FirstBootstrapObjectId');
-my $INTERNALlanguageId =
- Catalog::FindDefinedSymbol('catalog/pg_language.h', \@include_path, 'INTERNALlanguageId');
+# Read all the input files into internal data structures.
+# 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,
+# but the Makefile dependencies look more sensible this way.
+my %catalogs;
+my %catalog_data;
+foreach my $datfile (@input_files)
+{
+ $datfile =~ /(.+)\.dat$/
+ or die "Input files need to be data (.dat) files.\n";
-# Read all the data from the include/catalog files.
-my $catalogs = Catalog::Catalogs($infile);
+ my $header = "$1.h";
+ die "There in no header file corresponding to $datfile"
+ if ! -e $header;
-# Collect the raw data from pg_proc.h.
-my @fmgr = ();
-my @attnames;
-foreach my $column (@{ $catalogs->{pg_proc}->{columns} })
-{
- push @attnames, $column->{name};
+ my $catalog = Catalog::ParseHeader($header);
+ my $catname = $catalog->{catname};
+ my $schema = $catalog->{columns};
+
+ $catalogs{$catname} = $catalog;
+ $catalog_data{$catname} = Catalog::ParseData($datfile, $schema, 0);
}
-my $data = $catalogs->{pg_proc}->{data};
-foreach my $row (@$data)
-{
+# Fetch some values for later.
+my $FirstBootstrapObjectId = Catalog::FindDefinedSymbol(
+ 'access/transam.h', \@include_path, 'FirstBootstrapObjectId');
+my $INTERNALlanguageId = Catalog::FindDefinedSymbolFromData(
+ $catalog_data{pg_language}, 'INTERNALlanguageId');
+
+# Collect certain fields from pg_proc.dat.
+my @fmgr = ();
- # Split line into tokens without interpreting their meaning.
- my %bki_values;
- @bki_values{@attnames} = Catalog::SplitDataLine($row->{bki_values});
+foreach my $row (@{ $catalog_data{pg_proc} })
+{
+ my %bki_values = %$row;
# Select out just the rows for internal-language procedures.
next if $bki_values{prolang} ne $INTERNALlanguageId;
push @fmgr,
- { oid => $row->{oid},
+ { oid => $bki_values{oid},
strict => $bki_values{proisstrict},
retset => $bki_values{proretset},
nargs => $bki_values{pronargs},
@@ -281,10 +293,10 @@ Catalog::RenameTempFile($tabfile, $tmpext);
sub usage
{
die <<EOM;
-Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl [path to pg_proc.h]
+Usage: perl -I [directory of Catalog.pm] Gen_fmgrtab.pl -I [include path] [path to pg_proc.dat]
Gen_fmgrtab.pl generates fmgroids.h, fmgrprotos.h, and fmgrtab.c from
-pg_proc.h
+pg_proc.dat
Report bugs to <pgsql-bugs\@postgresql.org>.
EOM
diff --git a/src/backend/utils/Makefile b/src/backend/utils/Makefile
index 163c81a1c22..343637af858 100644
--- a/src/backend/utils/Makefile
+++ b/src/backend/utils/Makefile
@@ -1,8 +1,13 @@
+#-------------------------------------------------------------------------
#
-# Makefile for utils
+# Makefile for backend/utils
+#
+# Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
+# Portions Copyright (c) 1994, Regents of the University of California
#
# src/backend/utils/Makefile
#
+#-------------------------------------------------------------------------
subdir = src/backend/utils
top_builddir = ../../..
@@ -20,6 +25,10 @@ all: errcodes.h fmgroids.h fmgrprotos.h probes.h
$(SUBDIRS:%=%-recursive): fmgroids.h fmgrprotos.h
+FMGR_DATA := $(addprefix $(top_srcdir)/src/include/catalog/,\
+ pg_language.dat pg_proc.dat \
+ )
+
# see notes in src/backend/parser/Makefile
fmgrprotos.h: fmgroids.h
touch $@
@@ -27,8 +36,8 @@ fmgrprotos.h: fmgroids.h
fmgroids.h: fmgrtab.c
touch $@
-fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
- $(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(top_srcdir)/src/include/catalog/pg_proc.h
+fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(FMGR_DATA) $(top_srcdir)/src/include/access/transam.h
+ $(PERL) -I $(catalogdir) $< -I $(top_srcdir)/src/include/ $(FMGR_DATA)
errcodes.h: $(top_srcdir)/src/backend/utils/errcodes.txt generate-errcodes.pl
$(PERL) $(srcdir)/generate-errcodes.pl $< > $@