Skip to content

Commit 372728b

Browse files
committed
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
1 parent 02f3e55 commit 372728b

File tree

110 files changed

+22928
-12480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+22928
-12480
lines changed

doc/src/sgml/bki.sgml

+635-26
Large diffs are not rendered by default.

doc/src/sgml/libpq.sgml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,7 @@ Oid PQftype(const PGresult *res,
35663566
You can query the system table <literal>pg_type</literal> to
35673567
obtain the names and properties of the various data types. The
35683568
<acronym>OID</acronym>s of the built-in data types are defined
3569-
in the file <filename>src/include/catalog/pg_type.h</filename>
3569+
in the file <filename>src/include/catalog/pg_type_d.h</filename>
35703570
in the source tree.
35713571
</para>
35723572
</listitem>

src/Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ endif
4141

4242
$(recurse)
4343

44+
# Update the commonly used headers before building the subdirectories;
45+
# otherwise, in a parallel build, several different sub-jobs will try to
46+
# remake them concurrently
47+
$(SUBDIRS:%=all-%-recurse): | submake-generated-headers
48+
4449
install: install-local
4550

4651
install-local: installdirs-local

src/backend/Makefile

+9-25
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ endif
5353

5454
##########################################################################
5555

56-
all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
56+
all: submake-libpgport submake-catalog-headers postgres $(POSTGRES_IMP)
5757

5858
ifneq ($(PORTNAME), cygwin)
5959
ifneq ($(PORTNAME), win32)
@@ -151,19 +151,17 @@ utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
151151
utils/fmgrprotos.h: utils/fmgroids.h
152152
touch $@
153153

154-
utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
154+
utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.dat $(top_srcdir)/src/include/access/transam.h
155155
$(MAKE) -C utils fmgroids.h fmgrprotos.h
156156

157157
utils/probes.h: utils/probes.d
158158
$(MAKE) -C utils probes.h
159159

160160
# run this unconditionally to avoid needing to know its dependencies here:
161-
catalog/schemapg.h: | submake-schemapg
161+
submake-catalog-headers:
162+
$(MAKE) -C catalog distprep generated-header-symlinks
162163

163-
submake-schemapg:
164-
$(MAKE) -C catalog schemapg.h
165-
166-
.PHONY: submake-schemapg
164+
.PHONY: submake-catalog-headers
167165

168166
# Make symlinks for these headers in the include directory. That way
169167
# we can cut down on the -I options. Also, a symlink is automatically
@@ -178,18 +176,13 @@ submake-schemapg:
178176

179177
.PHONY: generated-headers
180178

181-
generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h
179+
generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h submake-catalog-headers
182180

183181
$(top_builddir)/src/include/parser/gram.h: parser/gram.h
184182
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
185183
cd '$(dir $@)' && rm -f $(notdir $@) && \
186184
$(LN_S) "$$prereqdir/$(notdir $<)" .
187185

188-
$(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
189-
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
190-
cd '$(dir $@)' && rm -f $(notdir $@) && \
191-
$(LN_S) "$$prereqdir/$(notdir $<)" .
192-
193186
$(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
194187
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
195188
cd '$(dir $@)' && rm -f $(notdir $@) && \
@@ -225,7 +218,7 @@ utils/probes.o: utils/probes.d $(SUBDIROBJS)
225218
distprep:
226219
$(MAKE) -C parser gram.c gram.h scan.c
227220
$(MAKE) -C bootstrap bootparse.c bootscanner.c
228-
$(MAKE) -C catalog schemapg.h postgres.bki postgres.description postgres.shdescription
221+
$(MAKE) -C catalog distprep
229222
$(MAKE) -C replication repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
230223
$(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
231224
$(MAKE) -C utils fmgrtab.c fmgroids.h fmgrprotos.h errcodes.h
@@ -327,13 +320,7 @@ endif
327320
##########################################################################
328321

329322
clean:
330-
rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
331-
$(top_builddir)/src/include/parser/gram.h \
332-
$(top_builddir)/src/include/catalog/schemapg.h \
333-
$(top_builddir)/src/include/storage/lwlocknames.h \
334-
$(top_builddir)/src/include/utils/fmgroids.h \
335-
$(top_builddir)/src/include/utils/fmgrprotos.h \
336-
$(top_builddir)/src/include/utils/probes.h
323+
rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP)
337324
ifeq ($(PORTNAME), cygwin)
338325
rm -f postgres.dll libpostgres.a
339326
endif
@@ -345,15 +332,12 @@ distclean: clean
345332
rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
346333

347334
maintainer-clean: distclean
335+
$(MAKE) -C catalog $@
348336
rm -f bootstrap/bootparse.c \
349337
bootstrap/bootscanner.c \
350338
parser/gram.c \
351339
parser/gram.h \
352340
parser/scan.c \
353-
catalog/schemapg.h \
354-
catalog/postgres.bki \
355-
catalog/postgres.description \
356-
catalog/postgres.shdescription \
357341
replication/repl_gram.c \
358342
replication/repl_scanner.c \
359343
replication/syncrep_gram.c \

src/backend/catalog/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
/postgres.description
33
/postgres.shdescription
44
/schemapg.h
5+
/pg_*_d.h
6+
/bki-stamp

0 commit comments

Comments
 (0)