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