PostgreSQL Source Code  git master
nodes.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * nodes.h
4  * Definitions for tagged nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2024, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/nodes.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef NODES_H
15 #define NODES_H
16 
17 /*
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.
20  *
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.
25  */
26 typedef enum NodeTag
27 {
28  T_Invalid = 0,
29 
30 #include "nodes/nodetags.h"
32 
33 /*
34  * pg_node_attr() - Used in node definitions to set extra information for
35  * gen_node_support.pl
36  *
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
41  * cause an error.
42  *
43  * Valid node attributes:
44  *
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
48  * instantiate them.
49  *
50  * - custom_copy_equal: Has custom implementations in copyfuncs.c and
51  * equalfuncs.c.
52  *
53  * - custom_read_write: Has custom implementations in outfuncs.c and
54  * readfuncs.c.
55  *
56  * - custom_query_jumble: Has custom implementation in queryjumblefuncs.c.
57  *
58  * - no_copy: Does not support copyObject() at all.
59  *
60  * - no_equal: Does not support equal() at all.
61  *
62  * - no_copy_equal: Shorthand for both no_copy and no_equal.
63  *
64  * - no_query_jumble: Does not support JumbleQuery() at all.
65  *
66  * - no_read: Does not support nodeRead() at all.
67  *
68  * - nodetag_only: Does not support copyObject(), equal(), jumbleQuery()
69  * outNode() or nodeRead().
70  *
71  * - special_read_write: Has special treatment in outNode() and nodeRead().
72  *
73  * - nodetag_number(VALUE): assign the specified nodetag number instead of
74  * an auto-generated number. Typically this would only be used in stable
75  * branches, to give a newly-added node type a number without breaking ABI
76  * by changing the numbers of existing node types.
77  *
78  * Node types can be supertypes of other types whether or not they are marked
79  * abstract: if a node struct appears as the first field of another struct
80  * type, then it is the supertype of that type. The no_copy, no_equal,
81  * no_query_jumble and no_read node attributes are automatically inherited
82  * from the supertype. (Notice that nodetag_only does not inherit, so it's
83  * not quite equivalent to a combination of other attributes.)
84  *
85  * Valid node field attributes:
86  *
87  * - array_size(OTHERFIELD): This field is a dynamically allocated array with
88  * size indicated by the mentioned other field. The other field is either a
89  * scalar or a list, in which case the length of the list is used.
90  *
91  * - copy_as(VALUE): In copyObject(), replace the field's value with VALUE.
92  *
93  * - copy_as_scalar: In copyObject(), copy the field as a scalar value
94  * (e.g. a pointer) even if it is a node-type pointer.
95  *
96  * - equal_as_scalar: In equal(), compare the field as a scalar value
97  * even if it is a node-type pointer.
98  *
99  * - equal_ignore: Ignore the field for equality.
100  *
101  * - equal_ignore_if_zero: Ignore the field for equality if it is zero.
102  * (Otherwise, compare normally.)
103  *
104  * - query_jumble_ignore: Ignore the field for the query jumbling. Note
105  * that typmod and collation information are usually irrelevant for the
106  * query jumbling.
107  *
108  * - query_jumble_location: Mark the field as a location to track. This is
109  * only allowed for integer fields that include "location" in their name.
110  *
111  * - read_as(VALUE): In nodeRead(), replace the field's value with VALUE.
112  *
113  * - read_write_ignore: Ignore the field for read/write. This is only allowed
114  * if the node type is marked no_read or read_as() is also specified.
115  *
116  * - write_only_relids, write_only_nondefault_pathtarget, write_only_req_outer:
117  * Special handling for Path struct; see there.
118  *
119  */
120 #define pg_node_attr(...)
121 
122 /*
123  * The first field of a node of any type is guaranteed to be the NodeTag.
124  * Hence the type of any node can be gotten by casting it to Node. Declaring
125  * a variable to be of Node * (instead of void *) can also facilitate
126  * debugging.
127  */
128 typedef struct Node
129 {
132 
133 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
134 
135 /*
136  * newNode -
137  * create a new node of the specified size and tag the node with the
138  * specified tag.
139  *
140  * !WARNING!: Avoid using newNode directly. You should be using the
141  * macro makeNode. eg. to create a Query node, use makeNode(Query)
142  */
143 static inline Node *
144 newNode(size_t size, NodeTag tag)
145 {
146  Node *result;
147 
148  Assert(size >= sizeof(Node)); /* need the tag, at least */
149  result = (Node *) palloc0(size);
150  result->type = tag;
151 
152  return result;
153 }
154 
155 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
156 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
157 
158 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
159 
160 /*
161  * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled,
162  * verifies that the node has the appropriate type (using its nodeTag()).
163  *
164  * Use an inline function when assertions are enabled, to avoid multiple
165  * evaluations of the ptr argument (which could e.g. be a function call).
166  */
167 #ifdef USE_ASSERT_CHECKING
168 static inline Node *
169 castNodeImpl(NodeTag type, void *ptr)
170 {
171  Assert(ptr == NULL || nodeTag(ptr) == type);
172  return (Node *) ptr;
173 }
174 #define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
175 #else
176 #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
177 #endif /* USE_ASSERT_CHECKING */
178 
179 
180 /* ----------------------------------------------------------------
181  * extern declarations follow
182  * ----------------------------------------------------------------
183  */
184 
185 /*
186  * nodes/{outfuncs.c,print.c}
187  */
188 struct Bitmapset; /* not to include bitmapset.h here */
189 struct StringInfoData; /* not to include stringinfo.h here */
190 
191 extern void outNode(struct StringInfoData *str, const void *obj);
192 extern void outToken(struct StringInfoData *str, const char *s);
193 extern void outBitmapset(struct StringInfoData *str,
194  const struct Bitmapset *bms);
195 extern void outDatum(struct StringInfoData *str, uintptr_t value,
196  int typlen, bool typbyval);
197 extern char *nodeToString(const void *obj);
198 extern char *bmsToString(const struct Bitmapset *bms);
199 
200 /*
201  * nodes/{readfuncs.c,read.c}
202  */
203 extern void *stringToNode(const char *str);
204 #ifdef WRITE_READ_PARSE_PLAN_TREES
205 extern void *stringToNodeWithLocations(const char *str);
206 #endif
207 extern struct Bitmapset *readBitmapset(void);
208 extern uintptr_t readDatum(bool typbyval);
209 extern bool *readBoolCols(int numCols);
210 extern int *readIntCols(int numCols);
211 extern Oid *readOidCols(int numCols);
212 extern int16 *readAttrNumberCols(int numCols);
213 
214 /*
215  * nodes/copyfuncs.c
216  */
217 extern void *copyObjectImpl(const void *from);
218 
219 /* cast result back to argument type, if supported by compiler */
220 #ifdef HAVE_TYPEOF
221 #define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
222 #else
223 #define copyObject(obj) copyObjectImpl(obj)
224 #endif
225 
226 /*
227  * nodes/equalfuncs.c
228  */
229 extern bool equal(const void *a, const void *b);
230 
231 
232 /*
233  * Typedefs for identifying qualifier selectivities, plan costs, and row
234  * counts as such. These are just plain "double"s, but declaring a variable
235  * as Selectivity, Cost, or Cardinality makes the intent more obvious.
236  *
237  * These could have gone into plannodes.h or some such, but many files
238  * depend on them...
239  */
240 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
241 typedef double Cost; /* execution cost (in page-access units) */
242 typedef double Cardinality; /* (estimated) number of rows or other integer
243  * count */
244 
245 
246 /*
247  * CmdType -
248  * enums for type of operation represented by a Query or PlannedStmt
249  *
250  * This is needed in both parsenodes.h and plannodes.h, so put it here...
251  */
252 typedef enum CmdType
253 {
255  CMD_SELECT, /* select stmt */
256  CMD_UPDATE, /* update stmt */
257  CMD_INSERT, /* insert stmt */
258  CMD_DELETE, /* delete stmt */
259  CMD_MERGE, /* merge stmt */
260  CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
261  * etc. */
262  CMD_NOTHING, /* dummy command for instead nothing rules
263  * with qual */
265 
266 
267 /*
268  * JoinType -
269  * enums for types of relation joins
270  *
271  * JoinType determines the exact semantics of joining two relations using
272  * a matching qualification. For example, it tells what to do with a tuple
273  * that has no match in the other relation.
274  *
275  * This is needed in both parsenodes.h and plannodes.h, so put it here...
276  */
277 typedef enum JoinType
278 {
279  /*
280  * The canonical kinds of joins according to the SQL JOIN syntax. Only
281  * these codes can appear in parser output (e.g., JoinExpr nodes).
282  */
283  JOIN_INNER, /* matching tuple pairs only */
284  JOIN_LEFT, /* pairs + unmatched LHS tuples */
285  JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
286  JOIN_RIGHT, /* pairs + unmatched RHS tuples */
287 
288  /*
289  * Semijoins and anti-semijoins (as defined in relational theory) do not
290  * appear in the SQL JOIN syntax, but there are standard idioms for
291  * representing them (e.g., using EXISTS). The planner recognizes these
292  * cases and converts them to joins. So the planner and executor must
293  * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
294  * which matching RHS row is joined to. In JOIN_ANTI output, the row is
295  * guaranteed to be null-extended.
296  */
297  JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
298  JOIN_ANTI, /* 1 copy of each LHS row that has no match */
299  JOIN_RIGHT_ANTI, /* 1 copy of each RHS row that has no match */
300 
301  /*
302  * These codes are used internally in the planner, but are not supported
303  * by the executor (nor, indeed, by most of the planner).
304  */
305  JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
306  JOIN_UNIQUE_INNER, /* RHS path must be made unique */
307 
308  /*
309  * We might need additional join types someday.
310  */
312 
313 /*
314  * OUTER joins are those for which pushed-down quals must behave differently
315  * from the join's own quals. This is in fact everything except INNER and
316  * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
317  * since those are temporary proxies for what will eventually be an INNER
318  * join.
319  *
320  * Note: semijoins are a hybrid case, but we choose to treat them as not
321  * being outer joins. This is okay principally because the SQL syntax makes
322  * it impossible to have a pushed-down qual that refers to the inner relation
323  * of a semijoin; so there is no strong need to distinguish join quals from
324  * pushed-down quals. This is convenient because for almost all purposes,
325  * quals attached to a semijoin can be treated the same as innerjoin quals.
326  */
327 #define IS_OUTER_JOIN(jointype) \
328  (((1 << (jointype)) & \
329  ((1 << JOIN_LEFT) | \
330  (1 << JOIN_FULL) | \
331  (1 << JOIN_RIGHT) | \
332  (1 << JOIN_ANTI) | \
333  (1 << JOIN_RIGHT_ANTI))) != 0)
334 
335 /*
336  * AggStrategy -
337  * overall execution strategies for Agg plan nodes
338  *
339  * This is needed in both pathnodes.h and plannodes.h, so put it here...
340  */
341 typedef enum AggStrategy
342 {
343  AGG_PLAIN, /* simple agg across all input rows */
344  AGG_SORTED, /* grouped agg, input must be sorted */
345  AGG_HASHED, /* grouped agg, use internal hashtable */
346  AGG_MIXED, /* grouped agg, hash and sort both used */
348 
349 /*
350  * AggSplit -
351  * splitting (partial aggregation) modes for Agg plan nodes
352  *
353  * This is needed in both pathnodes.h and plannodes.h, so put it here...
354  */
355 
356 /* Primitive options supported by nodeAgg.c: */
357 #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */
358 #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */
359 #define AGGSPLITOP_SERIALIZE 0x04 /* apply serialfn to output */
360 #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserialfn to input */
361 
362 /* Supported operating modes (i.e., useful combinations of these options): */
363 typedef enum AggSplit
364 {
365  /* Basic, non-split aggregation: */
367  /* Initial phase of partial aggregation, with serialization: */
369  /* Final phase of partial aggregation, with deserialization: */
372 
373 /* Test whether an AggSplit value selects each primitive option: */
374 #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0)
375 #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0)
376 #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0)
377 #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0)
378 
379 /*
380  * SetOpCmd and SetOpStrategy -
381  * overall semantics and execution strategies for SetOp plan nodes
382  *
383  * This is needed in both pathnodes.h and plannodes.h, so put it here...
384  */
385 typedef enum SetOpCmd
386 {
392 
393 typedef enum SetOpStrategy
394 {
395  SETOP_SORTED, /* input must be sorted */
396  SETOP_HASHED, /* use internal hashtable */
398 
399 /*
400  * OnConflictAction -
401  * "ON CONFLICT" clause type of query
402  *
403  * This is needed in both parsenodes.h and plannodes.h, so put it here...
404  */
405 typedef enum OnConflictAction
406 {
407  ONCONFLICT_NONE, /* No "ON CONFLICT" clause */
408  ONCONFLICT_NOTHING, /* ON CONFLICT ... DO NOTHING */
409  ONCONFLICT_UPDATE, /* ON CONFLICT ... DO UPDATE */
411 
412 /*
413  * LimitOption -
414  * LIMIT option of query
415  *
416  * This is needed in both parsenodes.h and plannodes.h, so put it here...
417  */
418 typedef enum LimitOption
419 {
420  LIMIT_OPTION_COUNT, /* FETCH FIRST... ONLY */
421  LIMIT_OPTION_WITH_TIES, /* FETCH FIRST... WITH TIES */
423 
424 #endif /* NODES_H */
signed short int16
Definition: c.h:482
static struct @148 value
int b
Definition: isn.c:70
int a
Definition: isn.c:69
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1232
static Node * newNode(size_t size, NodeTag tag)
Definition: nodes.h:144
SetOpCmd
Definition: nodes.h:386
@ SETOPCMD_EXCEPT
Definition: nodes.h:389
@ SETOPCMD_EXCEPT_ALL
Definition: nodes.h:390
@ SETOPCMD_INTERSECT_ALL
Definition: nodes.h:388
@ SETOPCMD_INTERSECT
Definition: nodes.h:387
SetOpStrategy
Definition: nodes.h:394
@ SETOP_HASHED
Definition: nodes.h:396
@ SETOP_SORTED
Definition: nodes.h:395
double Cost
Definition: nodes.h:241
void outToken(struct StringInfoData *str, const char *s)
#define nodeTag(nodeptr)
Definition: nodes.h:133
struct Node Node
void outDatum(struct StringInfoData *str, uintptr_t value, int typlen, bool typbyval)
int * readIntCols(int numCols)
#define AGGSPLITOP_DESERIALIZE
Definition: nodes.h:360
#define AGGSPLITOP_SKIPFINAL
Definition: nodes.h:358
OnConflictAction
Definition: nodes.h:406
@ ONCONFLICT_NONE
Definition: nodes.h:407
@ ONCONFLICT_UPDATE
Definition: nodes.h:409
@ ONCONFLICT_NOTHING
Definition: nodes.h:408
#define AGGSPLITOP_SERIALIZE
Definition: nodes.h:359
struct Bitmapset * readBitmapset(void)
Definition: readfuncs.c:245
void outBitmapset(struct StringInfoData *str, const struct Bitmapset *bms)
double Cardinality
Definition: nodes.h:242
CmdType
Definition: nodes.h:253
@ CMD_MERGE
Definition: nodes.h:259
@ CMD_UTILITY
Definition: nodes.h:260
@ CMD_INSERT
Definition: nodes.h:257
@ CMD_DELETE
Definition: nodes.h:258
@ CMD_UNKNOWN
Definition: nodes.h:254
@ CMD_UPDATE
Definition: nodes.h:256
@ CMD_SELECT
Definition: nodes.h:255
@ CMD_NOTHING
Definition: nodes.h:262
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:223
AggStrategy
Definition: nodes.h:342
@ AGG_SORTED
Definition: nodes.h:344
@ AGG_HASHED
Definition: nodes.h:345
@ AGG_MIXED
Definition: nodes.h:346
@ AGG_PLAIN
Definition: nodes.h:343
char * bmsToString(const struct Bitmapset *bms)
NodeTag
Definition: nodes.h:27
@ T_Invalid
Definition: nodes.h:28
double Selectivity
Definition: nodes.h:240
AggSplit
Definition: nodes.h:364
@ AGGSPLIT_FINAL_DESERIAL
Definition: nodes.h:370
@ AGGSPLIT_SIMPLE
Definition: nodes.h:366
@ AGGSPLIT_INITIAL_SERIAL
Definition: nodes.h:368
LimitOption
Definition: nodes.h:419
@ LIMIT_OPTION_COUNT
Definition: nodes.h:420
@ LIMIT_OPTION_WITH_TIES
Definition: nodes.h:421
void * stringToNode(const char *str)
Definition: read.c:90
bool * readBoolCols(int numCols)
#define AGGSPLITOP_COMBINE
Definition: nodes.h:357
Oid * readOidCols(int numCols)
void outNode(struct StringInfoData *str, const void *obj)
void * copyObjectImpl(const void *from)
Definition: copyfuncs.c:177
uintptr_t readDatum(bool typbyval)
Definition: readfuncs.c:589
int16 * readAttrNumberCols(int numCols)
JoinType
Definition: nodes.h:278
@ JOIN_SEMI
Definition: nodes.h:297
@ JOIN_FULL
Definition: nodes.h:285
@ JOIN_INNER
Definition: nodes.h:283
@ JOIN_RIGHT
Definition: nodes.h:286
@ JOIN_LEFT
Definition: nodes.h:284
@ JOIN_UNIQUE_OUTER
Definition: nodes.h:305
@ JOIN_RIGHT_ANTI
Definition: nodes.h:299
@ JOIN_UNIQUE_INNER
Definition: nodes.h:306
@ JOIN_ANTI
Definition: nodes.h:298
char * nodeToString(const void *obj)
Definition: outfuncs.c:762
unsigned int Oid
Definition: postgres_ext.h:31
Definition: nodes.h:129
NodeTag type
Definition: nodes.h:130
const char * type