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