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