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