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  */
85  /* these aren't subclasses of Plan: */
89 
90  /*
91  * TAGS FOR PLAN STATE NODES (execnodes.h)
92  *
93  * These should correspond one-to-one with Plan node types.
94  */
136 
137  /*
138  * TAGS FOR PRIMITIVE NODES (primnodes.h)
139  */
191 
192  /*
193  * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
194  *
195  * These correspond (not always one-for-one) to primitive nodes derived
196  * from Expr.
197  */
226 
227  /*
228  * TAGS FOR PLANNER NODES (relation.h)
229  */
269  /* these aren't subclasses of Path: */
282 
283  /*
284  * TAGS FOR MEMORY NODES (memnodes.h)
285  */
289 
290  /*
291  * TAGS FOR VALUE NODES (value.h)
292  */
299 
300  /*
301  * TAGS FOR LIST NODES (pg_list.h)
302  */
306 
307  /*
308  * TAGS FOR EXTENSIBLE NODES (extensible.h)
309  */
311 
312  /*
313  * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
314  */
428 
429  /*
430  * TAGS FOR PARSE TREE NODES (parsenodes.h)
431  */
482 
483  /*
484  * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
485  */
493 
494  /*
495  * TAGS FOR RANDOM OTHER STUFF
496  *
497  * These are objects that aren't part of parse/plan/execute node tree
498  * structures, but we give them NodeTags anyway for identification
499  * purposes (usually because they are involved in APIs where we want to
500  * pass multiple object types through the same pointer).
501  */
502  T_TriggerData, /* in commands/trigger.h */
503  T_EventTriggerData, /* in commands/event_trigger.h */
504  T_ReturnSetInfo, /* in nodes/execnodes.h */
505  T_WindowObjectData, /* private in nodeWindowAgg.c */
506  T_TIDBitmap, /* in nodes/tidbitmap.h */
507  T_InlineCodeBlock, /* in nodes/parsenodes.h */
508  T_FdwRoutine, /* in foreign/fdwapi.h */
509  T_IndexAmRoutine, /* in access/amapi.h */
510  T_TsmRoutine, /* in access/tsmapi.h */
511  T_ForeignKeyCacheInfo /* in utils/rel.h */
512 } NodeTag;
513 
514 /*
515  * The first field of a node of any type is guaranteed to be the NodeTag.
516  * Hence the type of any node can be gotten by casting it to Node. Declaring
517  * a variable to be of Node * (instead of void *) can also facilitate
518  * debugging.
519  */
520 typedef struct Node
521 {
523 } Node;
524 
525 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
526 
527 /*
528  * newNode -
529  * create a new node of the specified size and tag the node with the
530  * specified tag.
531  *
532  * !WARNING!: Avoid using newNode directly. You should be using the
533  * macro makeNode. eg. to create a Query node, use makeNode(Query)
534  *
535  * Note: the size argument should always be a compile-time constant, so the
536  * apparent risk of multiple evaluation doesn't matter in practice.
537  */
538 #ifdef __GNUC__
539 
540 /* With GCC, we can use a compound statement within an expression */
541 #define newNode(size, tag) \
542 ({ Node *_result; \
543  AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
544  _result = (Node *) palloc0fast(size); \
545  _result->type = (tag); \
546  _result; \
547 })
548 #else
549 
550 /*
551  * There is no way to dereference the palloc'ed pointer to assign the
552  * tag, and also return the pointer itself, so we need a holder variable.
553  * Fortunately, this macro isn't recursive so we just define
554  * a global variable for this purpose.
555  */
557 
558 #define newNode(size, tag) \
559 ( \
560  AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
561  newNodeMacroHolder = (Node *) palloc0fast(size), \
562  newNodeMacroHolder->type = (tag), \
563  newNodeMacroHolder \
564 )
565 #endif /* __GNUC__ */
566 
567 
568 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
569 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
570 
571 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
572 
573 /*
574  * castNode(type, ptr) casts ptr to "type *", and if assertions are enabled,
575  * verifies that the node has the appropriate type (using its nodeTag()).
576  *
577  * Use an inline function when assertions are enabled, to avoid multiple
578  * evaluations of the ptr argument (which could e.g. be a function call).
579  */
580 #ifdef USE_ASSERT_CHECKING
581 static inline Node *
582 castNodeImpl(NodeTag type, void *ptr)
583 {
584  Assert(ptr == NULL || nodeTag(ptr) == type);
585  return (Node *) ptr;
586 }
587 #define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
588 #else
589 #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
590 #endif /* USE_ASSERT_CHECKING */
591 
592 
593 /* ----------------------------------------------------------------
594  * extern declarations follow
595  * ----------------------------------------------------------------
596  */
597 
598 /*
599  * nodes/{outfuncs.c,print.c}
600  */
601 struct Bitmapset; /* not to include bitmapset.h here */
602 struct StringInfoData; /* not to include stringinfo.h here */
603 
604 extern void outNode(struct StringInfoData *str, const void *obj);
605 extern void outToken(struct StringInfoData *str, const char *s);
606 extern void outBitmapset(struct StringInfoData *str,
607  const struct Bitmapset *bms);
608 extern void outDatum(struct StringInfoData *str, uintptr_t value,
609  int typlen, bool typbyval);
610 extern char *nodeToString(const void *obj);
611 extern char *bmsToString(const struct Bitmapset *bms);
612 
613 /*
614  * nodes/{readfuncs.c,read.c}
615  */
616 extern void *stringToNode(char *str);
617 extern struct Bitmapset *readBitmapset(void);
618 extern uintptr_t readDatum(bool typbyval);
619 extern bool *readBoolCols(int numCols);
620 extern int *readIntCols(int numCols);
621 extern Oid *readOidCols(int numCols);
622 extern int16 *readAttrNumberCols(int numCols);
623 
624 /*
625  * nodes/copyfuncs.c
626  */
627 extern void *copyObject(const void *obj);
628 
629 /*
630  * nodes/equalfuncs.c
631  */
632 extern bool equal(const void *a, const void *b);
633 
634 
635 /*
636  * Typedefs for identifying qualifier selectivities and plan costs as such.
637  * These are just plain "double"s, but declaring a variable as Selectivity
638  * or Cost makes the intent more obvious.
639  *
640  * These could have gone into plannodes.h or some such, but many files
641  * depend on them...
642  */
643 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
644 typedef double Cost; /* execution cost (in page-access units) */
645 
646 
647 /*
648  * CmdType -
649  * enums for type of operation represented by a Query or PlannedStmt
650  *
651  * This is needed in both parsenodes.h and plannodes.h, so put it here...
652  */
653 typedef enum CmdType
654 {
656  CMD_SELECT, /* select stmt */
657  CMD_UPDATE, /* update stmt */
658  CMD_INSERT, /* insert stmt */
660  CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
661  * etc. */
662  CMD_NOTHING /* dummy command for instead nothing rules
663  * with qual */
664 } CmdType;
665 
666 
667 /*
668  * JoinType -
669  * enums for types of relation joins
670  *
671  * JoinType determines the exact semantics of joining two relations using
672  * a matching qualification. For example, it tells what to do with a tuple
673  * that has no match in the other relation.
674  *
675  * This is needed in both parsenodes.h and plannodes.h, so put it here...
676  */
677 typedef enum JoinType
678 {
679  /*
680  * The canonical kinds of joins according to the SQL JOIN syntax. Only
681  * these codes can appear in parser output (e.g., JoinExpr nodes).
682  */
683  JOIN_INNER, /* matching tuple pairs only */
684  JOIN_LEFT, /* pairs + unmatched LHS tuples */
685  JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
686  JOIN_RIGHT, /* pairs + unmatched RHS tuples */
687 
688  /*
689  * Semijoins and anti-semijoins (as defined in relational theory) do not
690  * appear in the SQL JOIN syntax, but there are standard idioms for
691  * representing them (e.g., using EXISTS). The planner recognizes these
692  * cases and converts them to joins. So the planner and executor must
693  * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
694  * which matching RHS row is joined to. In JOIN_ANTI output, the row is
695  * guaranteed to be null-extended.
696  */
697  JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
698  JOIN_ANTI, /* 1 copy of each LHS row that has no match */
699 
700  /*
701  * These codes are used internally in the planner, but are not supported
702  * by the executor (nor, indeed, by most of the planner).
703  */
704  JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
705  JOIN_UNIQUE_INNER /* RHS path must be made unique */
706 
707  /*
708  * We might need additional join types someday.
709  */
710 } JoinType;
711 
712 /*
713  * OUTER joins are those for which pushed-down quals must behave differently
714  * from the join's own quals. This is in fact everything except INNER and
715  * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
716  * since those are temporary proxies for what will eventually be an INNER
717  * join.
718  *
719  * Note: semijoins are a hybrid case, but we choose to treat them as not
720  * being outer joins. This is okay principally because the SQL syntax makes
721  * it impossible to have a pushed-down qual that refers to the inner relation
722  * of a semijoin; so there is no strong need to distinguish join quals from
723  * pushed-down quals. This is convenient because for almost all purposes,
724  * quals attached to a semijoin can be treated the same as innerjoin quals.
725  */
726 #define IS_OUTER_JOIN(jointype) \
727  (((1 << (jointype)) & \
728  ((1 << JOIN_LEFT) | \
729  (1 << JOIN_FULL) | \
730  (1 << JOIN_RIGHT) | \
731  (1 << JOIN_ANTI))) != 0)
732 
733 /*
734  * AggStrategy -
735  * overall execution strategies for Agg plan nodes
736  *
737  * This is needed in both plannodes.h and relation.h, so put it here...
738  */
739 typedef enum AggStrategy
740 {
741  AGG_PLAIN, /* simple agg across all input rows */
742  AGG_SORTED, /* grouped agg, input must be sorted */
743  AGG_HASHED /* grouped agg, use internal hashtable */
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:2648
signed short int16
Definition: c.h:255
Definition: nodes.h:76
Oid * readOidCols(int numCols)
Definition: readfuncs.c:2729
static struct @78 value
Definition: nodes.h:78
Definition: nodes.h:53
char * bmsToString(const struct Bitmapset *bms)
Definition: nodes.h:520
int16 * readAttrNumberCols(int numCols)
Definition: readfuncs.c:2705
Definition: nodes.h:48
Definition: nodes.h:74
double Selectivity
Definition: nodes.h:643
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:1063
JoinType
Definition: nodes.h:677
char * nodeToString(const void *obj)
Definition: outfuncs.c:4123
void * stringToNode(char *str)
Definition: read.c:38
void * copyObject(const void *obj)
Definition: copyfuncs.c:4605
#define AGGSPLITOP_DESERIALIZE
Definition: nodes.h:757
Definition: nodes.h:45
Definition: nodes.h:143
#define AGGSPLITOP_COMBINE
Definition: nodes.h:754
Definition: nodes.h:75
struct Bitmapset * readBitmapset(void)
Definition: readfuncs.c:218
NodeTag type
Definition: nodes.h:522
Definition: nodes.h:140
Definition: nodes.h:303
Definition: nodes.h:145
Definition: nodes.h:144
Definition: nodes.h:316
struct Node Node
Definition: nodes.h:81
bool * readBoolCols(int numCols)
Definition: readfuncs.c:2777
#define AGGSPLITOP_SERIALIZE
Definition: nodes.h:756
#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:2753
AggSplit
Definition: nodes.h:760
Definition: nodes.h:293
#define AGGSPLITOP_SKIPFINAL
Definition: nodes.h:755
void outBitmapset(struct StringInfoData *str, const struct Bitmapset *bms)
#define nodeTag(nodeptr)
Definition: nodes.h:525
Definition: nodes.h:44
Definition: nodes.h:69
PGDLLIMPORT Node * newNodeMacroHolder
Definition: nodes.c:31
Definition: nodes.h:298
Definition: nodes.h:82
Definition: nodes.h:295
AggStrategy
Definition: nodes.h:739
SetOpCmd
Definition: nodes.h:782
Definition: nodes.h:79
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2934
Definition: nodes.h:236
OnConflictAction
Definition: nodes.h:802
CmdType
Definition: nodes.h:653
double Cost
Definition: nodes.h:644
Definition: nodes.h:38
void outNode(struct StringInfoData *str, const void *obj)
Definition: nodes.h:146
Definition: nodes.h:84