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