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