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-2020, 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  /*
31  * TAGS FOR EXECUTOR NODES (execnodes.h)
32  */
41 
42  /*
43  * TAGS FOR PLAN NODES (plannodes.h)
44  */
87  /* these aren't subclasses of Plan: */
95 
96  /*
97  * TAGS FOR PLAN STATE NODES (execnodes.h)
98  *
99  * These should correspond one-to-one with Plan node types.
100  */
143 
144  /*
145  * TAGS FOR PRIMITIVE NODES (primnodes.h)
146  */
199 
200  /*
201  * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
202  *
203  * ExprState represents the evaluation state for a whole expression tree.
204  * Most Expr-based plan nodes do not have a corresponding expression state
205  * node, they're fully handled within execExpr* - but sometimes the state
206  * needs to be shared with other parts of the executor, as for example
207  * with AggrefExprState, which nodeAgg.c has to modify.
208  */
216 
217  /*
218  * TAGS FOR PLANNER NODES (pathnodes.h)
219  */
259  /* these aren't subclasses of Path: */
275 
276  /*
277  * TAGS FOR MEMORY NODES (memnodes.h)
278  */
283 
284  /*
285  * TAGS FOR VALUE NODES (value.h)
286  */
293 
294  /*
295  * TAGS FOR LIST NODES (pg_list.h)
296  */
300 
301  /*
302  * TAGS FOR EXTENSIBLE NODES (extensible.h)
303  */
305 
306  /*
307  * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
308  */
425 
426  /*
427  * TAGS FOR PARSE TREE NODES (parsenodes.h)
428  */
481 
482  /*
483  * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
484  */
492 
493  /*
494  * TAGS FOR RANDOM OTHER STUFF
495  *
496  * These are objects that aren't part of parse/plan/execute node tree
497  * structures, but we give them NodeTags anyway for identification
498  * purposes (usually because they are involved in APIs where we want to
499  * pass multiple object types through the same pointer).
500  */
501  T_TriggerData, /* in commands/trigger.h */
502  T_EventTriggerData, /* in commands/event_trigger.h */
503  T_ReturnSetInfo, /* in nodes/execnodes.h */
504  T_WindowObjectData, /* private in nodeWindowAgg.c */
505  T_TIDBitmap, /* in nodes/tidbitmap.h */
506  T_InlineCodeBlock, /* in nodes/parsenodes.h */
507  T_FdwRoutine, /* in foreign/fdwapi.h */
508  T_IndexAmRoutine, /* in access/amapi.h */
509  T_TableAmRoutine, /* in access/tableam.h */
510  T_TsmRoutine, /* in access/tsmapi.h */
511  T_ForeignKeyCacheInfo, /* in utils/rel.h */
512  T_CallContext, /* in nodes/parsenodes.h */
513  T_SupportRequestSimplify, /* in nodes/supportnodes.h */
514  T_SupportRequestSelectivity, /* in nodes/supportnodes.h */
515  T_SupportRequestCost, /* in nodes/supportnodes.h */
516  T_SupportRequestRows, /* in nodes/supportnodes.h */
517  T_SupportRequestIndexCondition /* in nodes/supportnodes.h */
518 } NodeTag;
519 
520 /*
521  * The first field of a node of any type is guaranteed to be the NodeTag.
522  * Hence the type of any node can be gotten by casting it to Node. Declaring
523  * a variable to be of Node * (instead of void *) can also facilitate
524  * debugging.
525  */
526 typedef struct Node
527 {
529 } Node;
530 
531 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
532 
533 /*
534  * newNode -
535  * create a new node of the specified size and tag the node with the
536  * specified tag.
537  *
538  * !WARNING!: Avoid using newNode directly. You should be using the
539  * macro makeNode. eg. to create a Query node, use makeNode(Query)
540  *
541  * Note: the size argument should always be a compile-time constant, so the
542  * apparent risk of multiple evaluation doesn't matter in practice.
543  */
544 #ifdef __GNUC__
545 
546 /* With GCC, we can use a compound statement within an expression */
547 #define newNode(size, tag) \
548 ({ Node *_result; \
549  AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
550  _result = (Node *) palloc0fast(size); \
551  _result->type = (tag); \
552  _result; \
553 })
554 #else
555 
556 /*
557  * There is no way to dereference the palloc'ed pointer to assign the
558  * tag, and also return the pointer itself, so we need a holder variable.
559  * Fortunately, this macro isn't recursive so we just define
560  * a global variable for this purpose.
561  */
563 
564 #define newNode(size, tag) \
565 ( \
566  AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
567  newNodeMacroHolder = (Node *) palloc0fast(size), \
568  newNodeMacroHolder->type = (tag), \
569  newNodeMacroHolder \
570 )
571 #endif /* __GNUC__ */
572 
573 
574 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
575 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
576 
577 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
578 
579 /*
580  * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled,
581  * verifies that the node has the appropriate type (using its nodeTag()).
582  *
583  * Use an inline function when assertions are enabled, to avoid multiple
584  * evaluations of the ptr argument (which could e.g. be a function call).
585  */
586 #ifdef USE_ASSERT_CHECKING
587 static inline Node *
588 castNodeImpl(NodeTag type, void *ptr)
589 {
590  Assert(ptr == NULL || nodeTag(ptr) == type);
591  return (Node *) ptr;
592 }
593 #define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
594 #else
595 #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
596 #endif /* USE_ASSERT_CHECKING */
597 
598 
599 /* ----------------------------------------------------------------
600  * extern declarations follow
601  * ----------------------------------------------------------------
602  */
603 
604 /*
605  * nodes/{outfuncs.c,print.c}
606  */
607 struct Bitmapset; /* not to include bitmapset.h here */
608 struct StringInfoData; /* not to include stringinfo.h here */
609 
610 extern void outNode(struct StringInfoData *str, const void *obj);
611 extern void outToken(struct StringInfoData *str, const char *s);
612 extern void outBitmapset(struct StringInfoData *str,
613  const struct Bitmapset *bms);
614 extern void outDatum(struct StringInfoData *str, uintptr_t value,
615  int typlen, bool typbyval);
616 extern char *nodeToString(const void *obj);
617 extern char *bmsToString(const struct Bitmapset *bms);
618 
619 /*
620  * nodes/{readfuncs.c,read.c}
621  */
622 extern void *stringToNode(const char *str);
623 #ifdef WRITE_READ_PARSE_PLAN_TREES
624 extern void *stringToNodeWithLocations(const char *str);
625 #endif
626 extern struct Bitmapset *readBitmapset(void);
627 extern uintptr_t readDatum(bool typbyval);
628 extern bool *readBoolCols(int numCols);
629 extern int *readIntCols(int numCols);
630 extern Oid *readOidCols(int numCols);
631 extern int16 *readAttrNumberCols(int numCols);
632 
633 /*
634  * nodes/copyfuncs.c
635  */
636 extern void *copyObjectImpl(const void *obj);
637 
638 /* cast result back to argument type, if supported by compiler */
639 #ifdef HAVE_TYPEOF
640 #define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
641 #else
642 #define copyObject(obj) copyObjectImpl(obj)
643 #endif
644 
645 /*
646  * nodes/equalfuncs.c
647  */
648 extern bool equal(const void *a, const void *b);
649 
650 
651 /*
652  * Typedefs for identifying qualifier selectivities and plan costs as such.
653  * These are just plain "double"s, but declaring a variable as Selectivity
654  * or Cost makes the intent more obvious.
655  *
656  * These could have gone into plannodes.h or some such, but many files
657  * depend on them...
658  */
659 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
660 typedef double Cost; /* execution cost (in page-access units) */
661 
662 
663 /*
664  * CmdType -
665  * enums for type of operation represented by a Query or PlannedStmt
666  *
667  * This is needed in both parsenodes.h and plannodes.h, so put it here...
668  */
669 typedef enum CmdType
670 {
672  CMD_SELECT, /* select stmt */
673  CMD_UPDATE, /* update stmt */
674  CMD_INSERT, /* insert stmt */
676  CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
677  * etc. */
678  CMD_NOTHING /* dummy command for instead nothing rules
679  * with qual */
680 } CmdType;
681 
682 
683 /*
684  * JoinType -
685  * enums for types of relation joins
686  *
687  * JoinType determines the exact semantics of joining two relations using
688  * a matching qualification. For example, it tells what to do with a tuple
689  * that has no match in the other relation.
690  *
691  * This is needed in both parsenodes.h and plannodes.h, so put it here...
692  */
693 typedef enum JoinType
694 {
695  /*
696  * The canonical kinds of joins according to the SQL JOIN syntax. Only
697  * these codes can appear in parser output (e.g., JoinExpr nodes).
698  */
699  JOIN_INNER, /* matching tuple pairs only */
700  JOIN_LEFT, /* pairs + unmatched LHS tuples */
701  JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
702  JOIN_RIGHT, /* pairs + unmatched RHS tuples */
703 
704  /*
705  * Semijoins and anti-semijoins (as defined in relational theory) do not
706  * appear in the SQL JOIN syntax, but there are standard idioms for
707  * representing them (e.g., using EXISTS). The planner recognizes these
708  * cases and converts them to joins. So the planner and executor must
709  * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
710  * which matching RHS row is joined to. In JOIN_ANTI output, the row is
711  * guaranteed to be null-extended.
712  */
713  JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
714  JOIN_ANTI, /* 1 copy of each LHS row that has no match */
715 
716  /*
717  * These codes are used internally in the planner, but are not supported
718  * by the executor (nor, indeed, by most of the planner).
719  */
720  JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
721  JOIN_UNIQUE_INNER /* RHS path must be made unique */
722 
723  /*
724  * We might need additional join types someday.
725  */
726 } JoinType;
727 
728 /*
729  * OUTER joins are those for which pushed-down quals must behave differently
730  * from the join's own quals. This is in fact everything except INNER and
731  * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
732  * since those are temporary proxies for what will eventually be an INNER
733  * join.
734  *
735  * Note: semijoins are a hybrid case, but we choose to treat them as not
736  * being outer joins. This is okay principally because the SQL syntax makes
737  * it impossible to have a pushed-down qual that refers to the inner relation
738  * of a semijoin; so there is no strong need to distinguish join quals from
739  * pushed-down quals. This is convenient because for almost all purposes,
740  * quals attached to a semijoin can be treated the same as innerjoin quals.
741  */
742 #define IS_OUTER_JOIN(jointype) \
743  (((1 << (jointype)) & \
744  ((1 << JOIN_LEFT) | \
745  (1 << JOIN_FULL) | \
746  (1 << JOIN_RIGHT) | \
747  (1 << JOIN_ANTI))) != 0)
748 
749 /*
750  * AggStrategy -
751  * overall execution strategies for Agg plan nodes
752  *
753  * This is needed in both pathnodes.h and plannodes.h, so put it here...
754  */
755 typedef enum AggStrategy
756 {
757  AGG_PLAIN, /* simple agg across all input rows */
758  AGG_SORTED, /* grouped agg, input must be sorted */
759  AGG_HASHED, /* grouped agg, use internal hashtable */
760  AGG_MIXED /* grouped agg, hash and sort both used */
761 } AggStrategy;
762 
763 /*
764  * AggSplit -
765  * splitting (partial aggregation) modes for Agg plan nodes
766  *
767  * This is needed in both pathnodes.h and plannodes.h, so put it here...
768  */
769 
770 /* Primitive options supported by nodeAgg.c: */
771 #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */
772 #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */
773 #define AGGSPLITOP_SERIALIZE 0x04 /* apply serialfn to output */
774 #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserialfn to input */
775 
776 /* Supported operating modes (i.e., useful combinations of these options): */
777 typedef enum AggSplit
778 {
779  /* Basic, non-split aggregation: */
781  /* Initial phase of partial aggregation, with serialization: */
783  /* Final phase of partial aggregation, with deserialization: */
785 } AggSplit;
786 
787 /* Test whether an AggSplit value selects each primitive option: */
788 #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0)
789 #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0)
790 #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0)
791 #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0)
792 
793 /*
794  * SetOpCmd and SetOpStrategy -
795  * overall semantics and execution strategies for SetOp plan nodes
796  *
797  * This is needed in both pathnodes.h and plannodes.h, so put it here...
798  */
799 typedef enum SetOpCmd
800 {
805 } SetOpCmd;
806 
807 typedef enum SetOpStrategy
808 {
809  SETOP_SORTED, /* input must be sorted */
810  SETOP_HASHED /* use internal hashtable */
811 } SetOpStrategy;
812 
813 /*
814  * OnConflictAction -
815  * "ON CONFLICT" clause type of query
816  *
817  * This is needed in both parsenodes.h and plannodes.h, so put it here...
818  */
819 typedef enum OnConflictAction
820 {
821  ONCONFLICT_NONE, /* No "ON CONFLICT" clause */
822  ONCONFLICT_NOTHING, /* ON CONFLICT ... DO NOTHING */
823  ONCONFLICT_UPDATE /* ON CONFLICT ... DO UPDATE */
825 
826 #endif /* NODES_H */
uintptr_t readDatum(bool typbyval)
Definition: readfuncs.c:2866
signed short int16
Definition: c.h:354
Definition: nodes.h:78
void * stringToNode(const char *str)
Definition: read.c:89
Oid * readOidCols(int numCols)
Definition: readfuncs.c:2947
Definition: nodes.h:80
Definition: nodes.h:54
char * bmsToString(const struct Bitmapset *bms)
Definition: nodes.h:526
int16 * readAttrNumberCols(int numCols)
Definition: readfuncs.c:2923
Definition: nodes.h:49
Definition: nodes.h:76
double Selectivity
Definition: nodes.h:659
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
void outToken(struct StringInfoData *str, const char *s)
SetOpStrategy
Definition: nodes.h:807
#define PGDLLIMPORT
Definition: c.h:1280
JoinType
Definition: nodes.h:693
char * nodeToString(const void *obj)
Definition: outfuncs.c:4331
#define AGGSPLITOP_DESERIALIZE
Definition: nodes.h:774
Definition: nodes.h:46
Definition: nodes.h:150
#define AGGSPLITOP_COMBINE
Definition: nodes.h:771
Definition: nodes.h:77
struct Bitmapset * readBitmapset(void)
Definition: readfuncs.c:238
NodeTag type
Definition: nodes.h:528
Definition: nodes.h:147
Definition: nodes.h:297
Definition: nodes.h:152
Definition: nodes.h:151
Definition: nodes.h:310
struct Node Node
Definition: nodes.h:83
static struct @143 value
bool * readBoolCols(int numCols)
Definition: readfuncs.c:2995
#define AGGSPLITOP_SERIALIZE
Definition: nodes.h:773
#define Assert(condition)
Definition: c.h:738
void outDatum(struct StringInfoData *str, uintptr_t value, int typlen, bool typbyval)
int * readIntCols(int numCols)
Definition: readfuncs.c:2971
AggSplit
Definition: nodes.h:777
Definition: nodes.h:287
#define AGGSPLITOP_SKIPFINAL
Definition: nodes.h:772
void outBitmapset(struct StringInfoData *str, const struct Bitmapset *bms)
#define nodeTag(nodeptr)
Definition: nodes.h:531
Definition: nodes.h:45
Definition: nodes.h:71
PGDLLIMPORT Node * newNodeMacroHolder
Definition: nodes.c:31
Definition: nodes.h:292
Definition: nodes.h:84
void * copyObjectImpl(const void *obj)
Definition: copyfuncs.c:4781
Definition: nodes.h:289
AggStrategy
Definition: nodes.h:755
SetOpCmd
Definition: nodes.h:799
Definition: nodes.h:81
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3030
Definition: nodes.h:226
OnConflictAction
Definition: nodes.h:819
CmdType
Definition: nodes.h:669
double Cost
Definition: nodes.h:660
Definition: nodes.h:39
void outNode(struct StringInfoData *str, const void *obj)
Definition: nodes.h:153
Definition: nodes.h:86