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  */
417 
418  /*
419  * TAGS FOR PARSE TREE NODES (parsenodes.h)
420  */
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 /* cast result back to argument type, if supported by compiler */
618 #ifdef HAVE_TYPEOF
619 #define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
620 #else
621 #define copyObject(obj) copyObjectImpl(obj)
622 #endif
623 
624 /*
625  * nodes/equalfuncs.c
626  */
627 extern bool equal(const void *a, const void *b);
628 
629 
630 /*
631  * Typedefs for identifying qualifier selectivities and plan costs as such.
632  * These are just plain "double"s, but declaring a variable as Selectivity
633  * or Cost makes the intent more obvious.
634  *
635  * These could have gone into plannodes.h or some such, but many files
636  * depend on them...
637  */
638 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
639 typedef double Cost; /* execution cost (in page-access units) */
640 
641 
642 /*
643  * CmdType -
644  * enums for type of operation represented by a Query or PlannedStmt
645  *
646  * This is needed in both parsenodes.h and plannodes.h, so put it here...
647  */
648 typedef enum CmdType
649 {
651  CMD_SELECT, /* select stmt */
652  CMD_UPDATE, /* update stmt */
653  CMD_INSERT, /* insert stmt */
655  CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
656  * etc. */
657  CMD_NOTHING /* dummy command for instead nothing rules
658  * with qual */
659 } CmdType;
660 
661 
662 /*
663  * JoinType -
664  * enums for types of relation joins
665  *
666  * JoinType determines the exact semantics of joining two relations using
667  * a matching qualification. For example, it tells what to do with a tuple
668  * that has no match in the other relation.
669  *
670  * This is needed in both parsenodes.h and plannodes.h, so put it here...
671  */
672 typedef enum JoinType
673 {
674  /*
675  * The canonical kinds of joins according to the SQL JOIN syntax. Only
676  * these codes can appear in parser output (e.g., JoinExpr nodes).
677  */
678  JOIN_INNER, /* matching tuple pairs only */
679  JOIN_LEFT, /* pairs + unmatched LHS tuples */
680  JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
681  JOIN_RIGHT, /* pairs + unmatched RHS tuples */
682 
683  /*
684  * Semijoins and anti-semijoins (as defined in relational theory) do not
685  * appear in the SQL JOIN syntax, but there are standard idioms for
686  * representing them (e.g., using EXISTS). The planner recognizes these
687  * cases and converts them to joins. So the planner and executor must
688  * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
689  * which matching RHS row is joined to. In JOIN_ANTI output, the row is
690  * guaranteed to be null-extended.
691  */
692  JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
693  JOIN_ANTI, /* 1 copy of each LHS row that has no match */
694 
695  /*
696  * These codes are used internally in the planner, but are not supported
697  * by the executor (nor, indeed, by most of the planner).
698  */
699  JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
700  JOIN_UNIQUE_INNER /* RHS path must be made unique */
701 
702  /*
703  * We might need additional join types someday.
704  */
705 } JoinType;
706 
707 /*
708  * OUTER joins are those for which pushed-down quals must behave differently
709  * from the join's own quals. This is in fact everything except INNER and
710  * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
711  * since those are temporary proxies for what will eventually be an INNER
712  * join.
713  *
714  * Note: semijoins are a hybrid case, but we choose to treat them as not
715  * being outer joins. This is okay principally because the SQL syntax makes
716  * it impossible to have a pushed-down qual that refers to the inner relation
717  * of a semijoin; so there is no strong need to distinguish join quals from
718  * pushed-down quals. This is convenient because for almost all purposes,
719  * quals attached to a semijoin can be treated the same as innerjoin quals.
720  */
721 #define IS_OUTER_JOIN(jointype) \
722  (((1 << (jointype)) & \
723  ((1 << JOIN_LEFT) | \
724  (1 << JOIN_FULL) | \
725  (1 << JOIN_RIGHT) | \
726  (1 << JOIN_ANTI))) != 0)
727 
728 /*
729  * AggStrategy -
730  * overall execution strategies for Agg plan nodes
731  *
732  * This is needed in both plannodes.h and relation.h, so put it here...
733  */
734 typedef enum AggStrategy
735 {
736  AGG_PLAIN, /* simple agg across all input rows */
737  AGG_SORTED, /* grouped agg, input must be sorted */
738  AGG_HASHED, /* grouped agg, use internal hashtable */
739  AGG_MIXED /* grouped agg, hash and sort both used */
740 } AggStrategy;
741 
742 /*
743  * AggSplit -
744  * splitting (partial aggregation) modes for Agg plan nodes
745  *
746  * This is needed in both plannodes.h and relation.h, so put it here...
747  */
748 
749 /* Primitive options supported by nodeAgg.c: */
750 #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */
751 #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */
752 #define AGGSPLITOP_SERIALIZE 0x04 /* apply serializefn to output */
753 #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserializefn to input */
754 
755 /* Supported operating modes (i.e., useful combinations of these options): */
756 typedef enum AggSplit
757 {
758  /* Basic, non-split aggregation: */
760  /* Initial phase of partial aggregation, with serialization: */
762  /* Final phase of partial aggregation, with deserialization: */
764 } AggSplit;
765 
766 /* Test whether an AggSplit value selects each primitive option: */
767 #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0)
768 #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0)
769 #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0)
770 #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0)
771 
772 /*
773  * SetOpCmd and SetOpStrategy -
774  * overall semantics and execution strategies for SetOp plan nodes
775  *
776  * This is needed in both plannodes.h and relation.h, so put it here...
777  */
778 typedef enum SetOpCmd
779 {
784 } SetOpCmd;
785 
786 typedef enum SetOpStrategy
787 {
788  SETOP_SORTED, /* input must be sorted */
789  SETOP_HASHED /* use internal hashtable */
790 } SetOpStrategy;
791 
792 /*
793  * OnConflictAction -
794  * "ON CONFLICT" clause type of query
795  *
796  * This is needed in both parsenodes.h and plannodes.h, so put it here...
797  */
798 typedef enum OnConflictAction
799 {
800  ONCONFLICT_NONE, /* No "ON CONFLICT" clause */
801  ONCONFLICT_NOTHING, /* ON CONFLICT ... DO NOTHING */
802  ONCONFLICT_UPDATE /* ON CONFLICT ... DO UPDATE */
804 
805 #endif /* NODES_H */
uintptr_t readDatum(bool typbyval)
Definition: readfuncs.c:2659
signed short int16
Definition: c.h:255
Definition: nodes.h:77
Oid * readOidCols(int numCols)
Definition: readfuncs.c:2740
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:2716
Definition: nodes.h:48
Definition: nodes.h:75
double Selectivity
Definition: nodes.h:638
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:786
#define PGDLLIMPORT
Definition: c.h:1063
JoinType
Definition: nodes.h:672
char * nodeToString(const void *obj)
Definition: outfuncs.c:4217
void * stringToNode(char *str)
Definition: read.c:38
#define AGGSPLITOP_DESERIALIZE
Definition: nodes.h:753
Definition: nodes.h:45
Definition: nodes.h:145
#define AGGSPLITOP_COMBINE
Definition: nodes.h:750
Definition: nodes.h:76
struct Bitmapset * readBitmapset(void)
Definition: readfuncs.c:218
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:2788
#define AGGSPLITOP_SERIALIZE
Definition: nodes.h:752
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
void outDatum(struct StringInfoData *str, uintptr_t value, int typlen, bool typbyval)
int * readIntCols(int numCols)
Definition: readfuncs.c:2764
AggSplit
Definition: nodes.h:756
Definition: nodes.h:281
#define AGGSPLITOP_SKIPFINAL
Definition: nodes.h:751
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:4664
Definition: nodes.h:283
AggStrategy
Definition: nodes.h:734
SetOpCmd
Definition: nodes.h:778
Definition: nodes.h:80
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2961
static struct @121 value
Definition: nodes.h:221
OnConflictAction
Definition: nodes.h:798
CmdType
Definition: nodes.h:648
double Cost
Definition: nodes.h:639
Definition: nodes.h:38
void outNode(struct StringInfoData *str, const void *obj)
Definition: nodes.h:148
Definition: nodes.h:85