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