postgresql/src/backend/nodes
Peter Eisentraut 721856ff24 Remove distprep
A PostgreSQL release tarball contains a number of prebuilt files, in
particular files produced by bison, flex, perl, and well as html and
man documentation.  We have done this consistent with established
practice at the time to not require these tools for building from a
tarball.  Some of these tools were hard to get, or get the right
version of, from time to time, and shipping the prebuilt output was a
convenience to users.

Now this has at least two problems:

One, we have to make the build system(s) work in two modes: Building
from a git checkout and building from a tarball.  This is pretty
complicated, but it works so far for autoconf/make.  It does not
currently work for meson; you can currently only build with meson from
a git checkout.  Making meson builds work from a tarball seems very
difficult or impossible.  One particular problem is that since meson
requires a separate build directory, we cannot make the build update
files like gram.h in the source tree.  So if you were to build from a
tarball and update gram.y, you will have a gram.h in the source tree
and one in the build tree, but the way things work is that the
compiler will always use the one in the source tree.  So you cannot,
for example, make any gram.y changes when building from a tarball.
This seems impossible to fix in a non-horrible way.

Second, there is increased interest nowadays in precisely tracking the
origin of software.  We can reasonably track contributions into the
git tree, and users can reasonably track the path from a tarball to
packages and downloads and installs.  But what happens between the git
tree and the tarball is obscure and in some cases non-reproducible.

The solution for both of these issues is to get rid of the step that
adds prebuilt files to the tarball.  The tarball now only contains
what is in the git tree (*).  Getting the additional build
dependencies is no longer a problem nowadays, and the complications to
keep these dual build modes working are significant.  And of course we
want to get the meson build system working universally.

This commit removes the make distprep target altogether.  The make
dist target continues to do its job, it just doesn't call distprep
anymore.

(*) - The tarball also contains the INSTALL file that is built at make
dist time, but not by distprep.  This is unchanged for now.

The make maintainer-clean target, whose job it is to remove the
prebuilt files in addition to what make distclean does, is now just an
alias to make distprep.  (In practice, it is probably obsolete given
that git clean is available.)

The following programs are now hard build requirements in configure
(they were already required by meson.build):

- bison
- flex
- perl

Reviewed-by: Michael Paquier <michael@paquier.xyz>
Reviewed-by: Andres Freund <andres@anarazel.de>
Discussion: https://www.postgresql.org/message-id/flat/e07408d9-e5f2-d9fd-5672-f53354e9305e@eisentraut.org
2023-11-06 15:18:04 +01:00
..
.gitignore Automatically generate node support functions 2022-07-09 08:53:59 +02:00
Makefile Remove distprep 2023-11-06 15:18:04 +01:00
README Fix make maintainer-clean with queryjumblefuncs.*.c files in src/backend/nodes/ 2023-03-22 07:51:16 +09:00
bitmapset.c Remove trailing zero words from Bitmapsets 2023-07-04 12:34:48 +12:00
copyfuncs.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
equalfuncs.c Avoid copying undefined data in _readA_Const(). 2023-03-19 15:36:16 -04:00
extensible.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
gen_node_support.pl Make parseNodeString() C idiom compatible with Visual Studio 2015. 2023-06-14 05:31:54 -07:00
list.c Fix list_copy_head() with empty Lists 2023-04-20 10:34:46 +12:00
makefuncs.c Remove IndexInfo.ii_OpclassOptions field 2023-10-03 17:51:02 +02:00
meson.build Generate code for query jumbling through gen_node_support.pl 2023-01-31 15:24:05 +09:00
multibitmapset.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
nodeFuncs.c Add more SQL/JSON constructor functions 2023-07-26 17:08:33 +09:00
nodes.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
outfuncs.c Catalog not-null constraints 2023-08-25 13:31:24 +02:00
params.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
print.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
queryjumblefuncs.c Remove dependency to query text in JumbleQuery() 2023-06-28 08:59:36 +09:00
read.c Update copyright for 2023 2023-01-02 15:00:37 -05:00
readfuncs.c Catalog not-null constraints 2023-08-25 13:31:24 +02:00
tidbitmap.c Add trailing commas to enum definitions 2023-10-26 09:20:54 +02:00
value.c Update copyright for 2023 2023-01-02 15:00:37 -05:00

README

src/backend/nodes/README

Node Structures
===============

Introduction
------------

Postgres uses "node" types to organize parse trees, plan trees, and
executor state trees.  All objects that can appear in such trees must
be declared as node types.  In addition, a few object types that aren't
part of parse/plan/execute node trees receive NodeTags anyway for
identification purposes, usually because they are involved in APIs
where we want to pass multiple object types through the same pointer.

The node structures are plain old C structures with the first field
being of type NodeTag.  "Inheritance" is achieved by convention:
the first field can alternatively be of another node type.

Node types typically have support for being copied by copyObject(),
compared by equal(), serialized by outNode(), and deserialized by
nodeRead().  For some classes of Nodes, not all of these support
functions are required; for example, executor state nodes don't
presently need any of them.  So far as the system is concerned,
output and read functions are only needed for node types that can
appear in parse trees stored in the catalogs, and for plan tree
nodes because those are serialized to be passed to parallel workers.
However, we provide output functions for some other node types as well,
because they are very handy for debugging.  Currently, such coverage
exists for raw parsetrees and most planner data structures.  However,
output coverage of raw parsetrees is incomplete: in particular, utility
statements are almost entirely unsupported.

Relevant Files
--------------

Utility functions for manipulating node structures reside in this
directory.  Some support functions are automatically generated by the
gen_node_support.pl script, other functions are maintained manually.
To control the automatic generation of support functions, node types
and node fields can be annotated with pg_node_attr() specifications;
see further documentation in src/include/nodes/nodes.h.


FILES IN THIS DIRECTORY (src/backend/nodes/)

    General-purpose node manipulation functions:
	copyfuncs.c	- copy a node tree (*)
	equalfuncs.c	- compare two node trees (*)
	outfuncs.c	- convert a node tree to text representation (*)
	readfuncs.c	- convert text representation back to a node tree (*)
	makefuncs.c	- creator functions for some common node types
	nodeFuncs.c	- some other general-purpose manipulation functions
	queryjumblefuncs.c - compute a node tree for query jumbling (*)

    (*) - Most functions in these files are generated by
    gen_node_support.pl and #include'd there.

    Specialized manipulation functions:
	bitmapset.c	- Bitmapset support
	list.c		- generic list support
	multibitmapset.c - List-of-Bitmapset support
	params.c	- Param support
	tidbitmap.c	- TIDBitmap support
	value.c		- support for value nodes

FILES IN src/include/nodes/

    Node definitions primarily appear in:
	nodes.h		- define node tags (NodeTag) (*)
	primnodes.h	- primitive nodes
	parsenodes.h	- parse tree nodes
	pathnodes.h	- path tree nodes and planner internal structures
	plannodes.h	- plan tree nodes
	execnodes.h	- executor nodes
	memnodes.h	- memory nodes
	pg_list.h	- generic list

    (*) - Also #include's files generated by gen_node_support.pl.


Steps to Add a Node
-------------------

Suppose you want to define a node Foo:

1. Add the structure definition to the appropriate include/nodes/???.h file.
   If you intend to inherit from, say a Plan node, put Plan as the first field
   of your struct definition.  (The T_Foo tag is created automatically.)
2. Check that the generated support functions in copyfuncs.funcs.c,
   equalfuncs.funcs.c, outfuncs.funcs.c, queryjumblefuncs.funcs.c and
   readfuncs.funcs.c look correct.  Add attributes as necessary to control the
   outcome.  (For some classes of node types, you don't need all the support
   functions.  Use node attributes similar to those of related node types.)
3. Add cases to the functions in nodeFuncs.c as needed.  There are many
   other places you'll probably also need to teach about your new node
   type.  Best bet is to grep for references to one or two similar existing
   node types to find all the places to touch.
   (Except for frequently-created nodes, don't bother writing a creator
   function in makefuncs.c.)
4. Consider testing your new code with COPY_PARSE_PLAN_TREES,
   WRITE_READ_PARSE_PLAN_TREES, and RAW_EXPRESSION_COVERAGE_TEST to ensure
   support has been added everywhere that it's necessary; see
   pg_config_manual.h about these.

Adding a new node type moves the numbers associated with existing
tags, so you'll need to recompile the whole tree after doing this.
(--enable-depend usually helps.)  It doesn't force initdb though,
because the numbers never go to disk.  But altering or removing a node
type should usually be accompanied by an initdb-forcing catalog
version change, since the interpretation of serialized node trees
stored in system catalogs is affected by that.  (If the node type
never appears in stored parse trees, as for example Plan nodes do not,
then a catversion change is not needed to change it.)