postgresql/src/backend/nodes
Amit Langote 6185c9737c Add SQL/JSON query functions
This introduces the following SQL/JSON functions for querying JSON
data using jsonpath expressions:

JSON_EXISTS(), which can be used to apply a jsonpath expression to a
JSON value to check if it yields any values.

JSON_QUERY(), which can be used to to apply a jsonpath expression to
a JSON value to get a JSON object, an array, or a string.  There are
various options to control whether multi-value result uses array
wrappers and whether the singleton scalar strings are quoted or not.

JSON_VALUE(), which can be used to apply a jsonpath expression to a
JSON value to return a single scalar value, producing an error if it
multiple values are matched.

Both JSON_VALUE() and JSON_QUERY() functions have options for
handling EMPTY and ERROR conditions, which can be used to specify
the behavior when no values are matched and when an error occurs
during jsonpath evaluation, respectively.

Author: Nikita Glukhov <n.gluhov@postgrespro.ru>
Author: Teodor Sigaev <teodor@sigaev.ru>
Author: Oleg Bartunov <obartunov@gmail.com>
Author: Alexander Korotkov <aekorotkov@gmail.com>
Author: Andrew Dunstan <andrew@dunslane.net>
Author: Amit Langote <amitlangote09@gmail.com>
Author: Peter Eisentraut <peter@eisentraut.org>
Author: Jian He <jian.universality@gmail.com>

Reviewers have included (in no particular order):

Andres Freund, Alexander Korotkov, Pavel Stehule, Andrew Alsup,
Erik Rijkers, Zihong Yu, Himanshu Upadhyaya, Daniel Gustafsson,
Justin Pryzby, Álvaro Herrera, Jian He, Anton A. Melnikov,
Nikita Malakhov, Peter Eisentraut, Tomas Vondra

Discussion: https://postgr.es/m/cd0bb935-0158-78a7-08b5-904886deac4b@postgrespro.ru
Discussion: https://postgr.es/m/20220616233130.rparivafipt6doj3@alap3.anarazel.de
Discussion: https://postgr.es/m/abd9b83b-aa66-f230-3d6d-734817f0995d%40postgresql.org
Discussion: https://postgr.es/m/CA+HiwqHROpf9e644D8BRqYvaAPmgBZVup-xKMDPk-nd4EpgzHw@mail.gmail.com
Discussion: https://postgr.es/m/CA+HiwqE4XTdfb1nW=Ojoy_tQSRhYt-q_kb6i5d4xcKyrLC1Nbg@mail.gmail.com
2024-03-21 17:07:03 +09:00
..
.gitignore Automatically generate node support functions 2022-07-09 08:53:59 +02:00
Makefile Simplify newNode() by removing special cases 2023-12-19 12:11:47 +02:00
README Fix make maintainer-clean with queryjumblefuncs.*.c files in src/backend/nodes/ 2023-03-22 07:51:16 +09:00
bitmapset.c Move some bitmap logic out of bitmapset.c 2024-03-06 14:30:16 +07:00
copyfuncs.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
equalfuncs.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
extensible.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
gen_node_support.pl gen_node_support.pl: Mark location fields as type alias ParseLoc 2024-03-19 16:56:44 +01:00
list.c Use new overflow-safe integer comparison functions. 2024-02-16 14:05:36 -06:00
makefuncs.c Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
meson.build Update copyright for 2024 2024-01-03 20:49:05 -05:00
multibitmapset.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
nodeFuncs.c Add SQL/JSON query functions 2024-03-21 17:07:03 +09:00
outfuncs.c Fix description and grouping of RangeTblEntry.inh 2024-03-07 12:13:09 +01:00
params.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
print.c Update copyright for 2024 2024-01-03 20:49:05 -05:00
queryjumblefuncs.c Fix description and grouping of RangeTblEntry.inh 2024-03-07 12:13:09 +01:00
read.c Use a safer outfuncs/readfuncs representation for BitStrings. 2024-02-13 12:18:25 -05:00
readfuncs.c Fix description and grouping of RangeTblEntry.inh 2024-03-07 12:13:09 +01:00
tidbitmap.c Use new overflow-safe integer comparison functions. 2024-02-16 14:05:36 -06:00
value.c Update copyright for 2024 2024-01-03 20:49:05 -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.)