1/*-------------------------------------------------------------------------
4 * Definitions for tagged nodes.
7 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/nodes/nodes.h
12 *-------------------------------------------------------------------------
18 * The first field of every node is NodeTag. Each node created (with makeNode)
19 * will have one of the following tags as the value of its first field.
21 * Note that inserting or deleting node types changes the numbers of other
22 * node types later in the list. This is no problem during development, since
23 * the node numbers are never stored on disk. But don't do it in a released
24 * branch, because that would represent an ABI break for extensions.
30#include "nodes/nodetags.h"
34 * pg_node_attr() - Used in node definitions to set extra information for
37 * Attributes can be attached to a node as a whole (place the attribute
38 * specification on the first line after the struct's opening brace)
39 * or to a specific field (place it at the end of that field's line). The
40 * argument is a comma-separated list of attributes. Unrecognized attributes
43 * Valid node attributes:
45 * - abstract: Abstract types are types that cannot be instantiated but that
46 * can be supertypes of other types. We track their fields, so that
47 * subtypes can use them, but we don't emit a node tag, so you can't
50 * - custom_copy_equal: Has custom implementations in copyfuncs.c and
53 * - custom_read_write: Has custom implementations in outfuncs.c and
56 * - custom_query_jumble: Has custom implementation in queryjumblefuncs.c.
57 * Also available as a node field attribute.
59 * - no_copy: Does not support copyObject() at all.
61 * - no_equal: Does not support equal() at all.
63 * - no_copy_equal: Shorthand for both no_copy and no_equal.
65 * - no_query_jumble: Does not support JumbleQuery() at all.
67 * - no_read: Does not support nodeRead() at all.
69 * - nodetag_only: Does not support copyObject(), equal(), jumbleQuery()
70 * outNode() or nodeRead().
72 * - special_read_write: Has special treatment in outNode() and nodeRead().
74 * - nodetag_number(VALUE): assign the specified nodetag number instead of
75 * an auto-generated number. Typically this would only be used in stable
76 * branches, to give a newly-added node type a number without breaking ABI
77 * by changing the numbers of existing node types.
79 * Node types can be supertypes of other types whether or not they are marked
80 * abstract: if a node struct appears as the first field of another struct
81 * type, then it is the supertype of that type. The no_copy, no_equal,
82 * no_query_jumble and no_read node attributes are automatically inherited
83 * from the supertype. (Notice that nodetag_only does not inherit, so it's
84 * not quite equivalent to a combination of other attributes.)
86 * Valid node field attributes:
88 * - array_size(OTHERFIELD): This field is a dynamically allocated array with
89 * size indicated by the mentioned other field. The other field is either a
90 * scalar or a list, in which case the length of the list is used.
92 * - copy_as(VALUE): In copyObject(), replace the field's value with VALUE.
94 * - copy_as_scalar: In copyObject(), copy the field as a scalar value
95 * (e.g. a pointer) even if it is a node-type pointer.
97 * - equal_as_scalar: In equal(), compare the field as a scalar value
98 * even if it is a node-type pointer.
100 * - equal_ignore: Ignore the field for equality.
102 * - equal_ignore_if_zero: Ignore the field for equality if it is zero.
103 * (Otherwise, compare normally.)
105 * - custom_query_jumble: Has custom implementation in queryjumblefuncs.c
106 * for the field of a node. Also available as a node attribute.
108 * - query_jumble_ignore: Ignore the field for the query jumbling. Note
109 * that typmod and collation information are usually irrelevant for the
112 * - query_jumble_squash: Squash multiple values during query jumbling.
114 * - query_jumble_location: Mark the field as a location to track. This is
115 * only allowed for integer fields that include "location" in their name.
117 * - read_as(VALUE): In nodeRead(), replace the field's value with VALUE.
119 * - read_write_ignore: Ignore the field for read/write. This is only allowed
120 * if the node type is marked no_read or read_as() is also specified.
122 * - write_only_relids, write_only_nondefault_pathtarget, write_only_req_outer:
123 * Special handling for Path struct; see there.
126 #define pg_node_attr(...)
129 * The first field of a node of any type is guaranteed to be the NodeTag.
130 * Hence the type of any node can be gotten by casting it to Node. Declaring
131 * a variable to be of Node * (instead of void *) can also facilitate
139 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
143 * create a new node of the specified size and tag the node with the
146 * !WARNING!: Avoid using newNode directly. You should be using the
147 * macro makeNode. eg. to create a Query node, use makeNode(Query)
154 Assert(size >=
sizeof(
Node));
/* need the tag, at least */
161 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
162 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
164 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
167 * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled,
168 * verifies that the node has the appropriate type (using its nodeTag()).
170 * Use an inline function when assertions are enabled, to avoid multiple
171 * evaluations of the ptr argument (which could e.g. be a function call).
173#ifdef USE_ASSERT_CHECKING
180#define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
182 #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
183#endif /* USE_ASSERT_CHECKING */
186/* ----------------------------------------------------------------
187 * extern declarations follow
188 * ----------------------------------------------------------------
194 * nodes/{outfuncs.c,print.c}
196struct Bitmapset;
/* not to include bitmapset.h here */
204 int typlen,
bool typbyval);
210 * nodes/{readfuncs.c,read.c}
213#ifdef DEBUG_NODE_TESTS_ENABLED
214extern void *stringToNodeWithLocations(
const char *
str);
228/* cast result back to argument type, if supported by compiler */
230#define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
232 #define copyObject(obj) copyObjectImpl(obj)
238extern bool equal(
const void *
a,
const void *
b);
240#endif /* !FRONTEND */
244 * Typedef for parse location. This is just an int, but this way
245 * gen_node_support.pl knows which fields should get special treatment for
248 * -1 is used for unknown.
253 * Typedefs for identifying qualifier selectivities, plan costs, and row
254 * counts as such. These are just plain "double"s, but declaring a variable
255 * as Selectivity, Cost, or Cardinality makes the intent more obvious.
257 * These could have gone into plannodes.h or some such, but many files
260 typedef double Selectivity;
/* fraction of tuples a qualifier will pass */
261 typedef double Cost;
/* execution cost (in page-access units) */
262 typedef double Cardinality;
/* (estimated) number of rows or other integer
268 * enums for type of operation represented by a Query or PlannedStmt
270 * This is needed in both parsenodes.h and plannodes.h, so put it here...
289 * enums for types of relation joins
291 * JoinType determines the exact semantics of joining two relations using
292 * a matching qualification. For example, it tells what to do with a tuple
293 * that has no match in the other relation.
295 * This is needed in both parsenodes.h and plannodes.h, so put it here...
300 * The canonical kinds of joins according to the SQL JOIN syntax. Only
301 * these codes can appear in parser output (e.g., JoinExpr nodes).
309 * Semijoins and anti-semijoins (as defined in relational theory) do not
310 * appear in the SQL JOIN syntax, but there are standard idioms for
311 * representing them (e.g., using EXISTS). The planner recognizes these
312 * cases and converts them to joins. So the planner and executor must
313 * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
314 * which matching RHS row is joined to. In JOIN_ANTI output, the row is
315 * guaranteed to be null-extended.
317 JOIN_SEMI,
/* 1 copy of each LHS row that has match(es) */
318 JOIN_ANTI,
/* 1 copy of each LHS row that has no match */
323 * These codes are used internally in the planner, but are not supported
324 * by the executor (nor, indeed, by most of the planner).
330 * We might need additional join types someday.
335 * OUTER joins are those for which pushed-down quals must behave differently
336 * from the join's own quals. This is in fact everything except INNER, SEMI
337 * and RIGHT_SEMI joins. However, this macro must also exclude the
338 * JOIN_UNIQUE symbols since those are temporary proxies for what will
339 * eventually be an INNER join.
341 * Note: semijoins are a hybrid case, but we choose to treat them as not
342 * being outer joins. This is okay principally because the SQL syntax makes
343 * it impossible to have a pushed-down qual that refers to the inner relation
344 * of a semijoin; so there is no strong need to distinguish join quals from
345 * pushed-down quals. This is convenient because for almost all purposes,
346 * quals attached to a semijoin can be treated the same as innerjoin quals.
348 #define IS_OUTER_JOIN(jointype) \
349 (((1 << (jointype)) & \
350 ((1 << JOIN_LEFT) | \
352 (1 << JOIN_RIGHT) | \
354 (1 << JOIN_RIGHT_ANTI))) != 0)
358 * overall execution strategies for Agg plan nodes
360 * This is needed in both pathnodes.h and plannodes.h, so put it here...
372 * splitting (partial aggregation) modes for Agg plan nodes
374 * This is needed in both pathnodes.h and plannodes.h, so put it here...
377/* Primitive options supported by nodeAgg.c: */
378 #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */
379 #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */
380 #define AGGSPLITOP_SERIALIZE 0x04 /* apply serialfn to output */
381 #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserialfn to input */
383/* Supported operating modes (i.e., useful combinations of these options): */
386 /* Basic, non-split aggregation: */
388 /* Initial phase of partial aggregation, with serialization: */
390 /* Final phase of partial aggregation, with deserialization: */
394/* Test whether an AggSplit value selects each primitive option: */
395 #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0)
396 #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0)
397 #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0)
398 #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0)
401 * SetOpCmd and SetOpStrategy -
402 * overall semantics and execution strategies for SetOp plan nodes
404 * This is needed in both pathnodes.h and plannodes.h, so put it here...
422 * "ON CONFLICT" clause type of query
424 * This is needed in both parsenodes.h and plannodes.h, so put it here...
435 * LIMIT option of query
437 * This is needed in both parsenodes.h and plannodes.h, so put it here...
Assert(PointerIsAligned(start, uint64))
void * palloc0(Size size)
void * stringToNode(const char *str)
void outToken(struct StringInfoData *str, const char *s)
char * bmsToString(const struct Bitmapset *bms)
char * nodeToStringWithLocations(const void *obj)
#define AGGSPLITOP_DESERIALIZE
#define AGGSPLITOP_SKIPFINAL
struct Bitmapset * readBitmapset(void)
#define AGGSPLITOP_SERIALIZE
void outDatum(struct StringInfoData *str, Datum value, int typlen, bool typbyval)
void outBitmapset(struct StringInfoData *str, const struct Bitmapset *bms)
bool equal(const void *a, const void *b)
char * nodeToString(const void *obj)
@ AGGSPLIT_FINAL_DESERIAL
@ AGGSPLIT_INITIAL_SERIAL
Datum readDatum(bool typbyval)
void * copyObjectImpl(const void *from)
int * readIntCols(int numCols)
static Node * newNode(size_t size, NodeTag tag)
#define AGGSPLITOP_COMBINE
void outNode(struct StringInfoData *str, const void *obj)
Oid * readOidCols(int numCols)
int16 * readAttrNumberCols(int numCols)
bool * readBoolCols(int numCols)