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