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