1 /*-------------------------------------------------------------------------
4 * Definitions for tagged nodes.
7 * Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * src/include/nodes/nodes.h
12 *-------------------------------------------------------------------------
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.
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.
31 * TAGS FOR EXECUTOR NODES (execnodes.h)
43 * TAGS FOR PLAN NODES (plannodes.h)
67 T_NamedTuplestoreScan,
87 /* these aren't subclasses of Plan: */
93 * TAGS FOR PLAN STATE NODES (execnodes.h)
95 * These should correspond one-to-one with Plan node types.
104 T_RecursiveUnionState,
111 T_IndexOnlyScanState,
112 T_BitmapIndexScanState,
113 T_BitmapHeapScanState,
117 T_TableFuncScanState,
120 T_NamedTuplestoreScanState,
121 T_WorkTableScanState,
142 * TAGS FOR PRIMITIVE NODES (primnodes.h)
164 T_AlternativeSubPlan,
170 T_ConvertRowtypeExpr,
185 T_CoerceToDomainValue,
198 * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
200 * ExprState represents the evaluation state for a whole expression tree.
201 * Most Expr-based plan nodes do not have a corresponding expression state
202 * node, they're fully handled within execExpr* - but sometimes the state
203 * needs to be shared with other parts of the executor, as for example
204 * with AggrefExprState, which nodeAgg.c has to modify.
208 T_WindowFuncExprState,
211 T_AlternativeSubPlanState,
212 T_DomainConstraintState,
215 * TAGS FOR PLANNER NODES (relation.h)
252 T_RecursiveUnionPath,
256 /* these aren't subclasses of Path: */
265 T_PartitionedChildRelInfo,
274 * TAGS FOR MEMORY NODES (memnodes.h)
282 * TAGS FOR VALUE NODES (value.h)
292 * TAGS FOR LIST NODES (pg_list.h)
299 * TAGS FOR EXTENSIBLE NODES (extensible.h)
304 * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
321 T_AlterDefaultPrivilegesStmt,
332 T_CreateFunctionStmt,
360 T_ConstraintsSetStmt,
365 T_AlterDatabaseSetStmt,
367 T_CreateConversionStmt,
370 T_CreateOpFamilyStmt,
376 T_CreateTableSpaceStmt,
377 T_DropTableSpaceStmt,
378 T_AlterObjectDependsStmt,
379 T_AlterObjectSchemaStmt,
388 T_AlterTSDictionaryStmt,
389 T_AlterTSConfigurationStmt,
392 T_CreateForeignServerStmt,
393 T_AlterForeignServerStmt,
394 T_CreateUserMappingStmt,
395 T_AlterUserMappingStmt,
396 T_DropUserMappingStmt,
397 T_AlterTableSpaceOptionsStmt,
398 T_AlterTableMoveAllStmt,
400 T_CreateForeignTableStmt,
401 T_ImportForeignSchemaStmt,
402 T_CreateExtensionStmt,
403 T_AlterExtensionStmt,
404 T_AlterExtensionContentsStmt,
405 T_CreateEventTrigStmt,
406 T_AlterEventTrigStmt,
407 T_RefreshMatViewStmt,
408 T_ReplicaIdentityStmt,
412 T_CreateTransformStmt,
414 T_CreatePublicationStmt,
415 T_AlterPublicationStmt,
416 T_CreateSubscriptionStmt,
417 T_AlterSubscriptionStmt,
418 T_DropSubscriptionStmt,
420 T_AlterCollationStmt,
424 * TAGS FOR PARSE TREE NODES (parsenodes.h)
474 T_PartitionBoundSpec,
475 T_PartitionRangeDatum,
480 * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
484 T_CreateReplicationSlotCmd,
485 T_DropReplicationSlotCmd,
486 T_StartReplicationCmd,
487 T_TimeLineHistoryCmd,
491 * TAGS FOR RANDOM OTHER STUFF
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).
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 */
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
522 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
526 * create a new node of the specified size and tag the node with the
529 * !WARNING!: Avoid using newNode directly. You should be using the
530 * macro makeNode. eg. to create a Query node, use makeNode(Query)
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.
537 /* With GCC, we can use a compound statement within an expression */
538 #define newNode(size, tag) \
540 AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
541 _result = (Node *) palloc0fast(size); \
542 _result->type = (tag); \
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.
553 extern PGDLLIMPORT Node *newNodeMacroHolder;
555 #define newNode(size, tag) \
557 AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
558 newNodeMacroHolder = (Node *) palloc0fast(size), \
559 newNodeMacroHolder->type = (tag), \
562 #endif /* __GNUC__ */
565 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
566 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
568 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
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()).
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).
577 #ifdef USE_ASSERT_CHECKING
579 castNodeImpl(NodeTag type, void *ptr)
581 Assert(ptr == NULL || nodeTag(ptr) == type);
584 #define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
586 #define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
587 #endif /* USE_ASSERT_CHECKING */
590 /* ----------------------------------------------------------------
591 * extern declarations follow
592 * ----------------------------------------------------------------
596 * nodes/{outfuncs.c,print.c}
598 struct Bitmapset; /* not to include bitmapset.h here */
599 struct StringInfoData; /* not to include stringinfo.h here */
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);
611 * nodes/{readfuncs.c,read.c}
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);
624 extern void *copyObjectImpl(const void *obj);
626 /* cast result back to argument type, if supported by compiler */
628 #define copyObject(obj) ((typeof(obj)) copyObjectImpl(obj))
630 #define copyObject(obj) copyObjectImpl(obj)
636 extern bool equal(const void *a, const void *b);
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.
644 * These could have gone into plannodes.h or some such, but many files
647 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
648 typedef double Cost; /* execution cost (in page-access units) */
653 * enums for type of operation represented by a Query or PlannedStmt
655 * This is needed in both parsenodes.h and plannodes.h, so put it here...
660 CMD_SELECT, /* select stmt */
661 CMD_UPDATE, /* update stmt */
662 CMD_INSERT, /* insert stmt */
663 CMD_DELETE, /* delete stmt */
664 CMD_MERGE, /* merge stmt */
665 CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
667 CMD_NOTHING /* dummy command for instead nothing rules
674 * enums for types of relation joins
676 * JoinType determines the exact semantics of joining two relations using
677 * a matching qualification. For example, it tells what to do with a tuple
678 * that has no match in the other relation.
680 * This is needed in both parsenodes.h and plannodes.h, so put it here...
682 typedef enum JoinType
685 * The canonical kinds of joins according to the SQL JOIN syntax. Only
686 * these codes can appear in parser output (e.g., JoinExpr nodes).
688 JOIN_INNER, /* matching tuple pairs only */
689 JOIN_LEFT, /* pairs + unmatched LHS tuples */
690 JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
691 JOIN_RIGHT, /* pairs + unmatched RHS tuples */
694 * Semijoins and anti-semijoins (as defined in relational theory) do not
695 * appear in the SQL JOIN syntax, but there are standard idioms for
696 * representing them (e.g., using EXISTS). The planner recognizes these
697 * cases and converts them to joins. So the planner and executor must
698 * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
699 * which matching RHS row is joined to. In JOIN_ANTI output, the row is
700 * guaranteed to be null-extended.
702 JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
703 JOIN_ANTI, /* 1 copy of each LHS row that has no match */
706 * These codes are used internally in the planner, but are not supported
707 * by the executor (nor, indeed, by most of the planner).
709 JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
710 JOIN_UNIQUE_INNER /* RHS path must be made unique */
713 * We might need additional join types someday.
718 * OUTER joins are those for which pushed-down quals must behave differently
719 * from the join's own quals. This is in fact everything except INNER and
720 * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
721 * since those are temporary proxies for what will eventually be an INNER
724 * Note: semijoins are a hybrid case, but we choose to treat them as not
725 * being outer joins. This is okay principally because the SQL syntax makes
726 * it impossible to have a pushed-down qual that refers to the inner relation
727 * of a semijoin; so there is no strong need to distinguish join quals from
728 * pushed-down quals. This is convenient because for almost all purposes,
729 * quals attached to a semijoin can be treated the same as innerjoin quals.
731 #define IS_OUTER_JOIN(jointype) \
732 (((1 << (jointype)) & \
733 ((1 << JOIN_LEFT) | \
735 (1 << JOIN_RIGHT) | \
736 (1 << JOIN_ANTI))) != 0)
740 * overall execution strategies for Agg plan nodes
742 * This is needed in both plannodes.h and relation.h, so put it here...
744 typedef enum AggStrategy
746 AGG_PLAIN, /* simple agg across all input rows */
747 AGG_SORTED, /* grouped agg, input must be sorted */
748 AGG_HASHED, /* grouped agg, use internal hashtable */
749 AGG_MIXED /* grouped agg, hash and sort both used */
754 * splitting (partial aggregation) modes for Agg plan nodes
756 * This is needed in both plannodes.h and relation.h, so put it here...
759 /* Primitive options supported by nodeAgg.c: */
760 #define AGGSPLITOP_COMBINE 0x01 /* substitute combinefn for transfn */
761 #define AGGSPLITOP_SKIPFINAL 0x02 /* skip finalfn, return state as-is */
762 #define AGGSPLITOP_SERIALIZE 0x04 /* apply serializefn to output */
763 #define AGGSPLITOP_DESERIALIZE 0x08 /* apply deserializefn to input */
765 /* Supported operating modes (i.e., useful combinations of these options): */
766 typedef enum AggSplit
768 /* Basic, non-split aggregation: */
770 /* Initial phase of partial aggregation, with serialization: */
771 AGGSPLIT_INITIAL_SERIAL = AGGSPLITOP_SKIPFINAL | AGGSPLITOP_SERIALIZE,
772 /* Final phase of partial aggregation, with deserialization: */
773 AGGSPLIT_FINAL_DESERIAL = AGGSPLITOP_COMBINE | AGGSPLITOP_DESERIALIZE
776 /* Test whether an AggSplit value selects each primitive option: */
777 #define DO_AGGSPLIT_COMBINE(as) (((as) & AGGSPLITOP_COMBINE) != 0)
778 #define DO_AGGSPLIT_SKIPFINAL(as) (((as) & AGGSPLITOP_SKIPFINAL) != 0)
779 #define DO_AGGSPLIT_SERIALIZE(as) (((as) & AGGSPLITOP_SERIALIZE) != 0)
780 #define DO_AGGSPLIT_DESERIALIZE(as) (((as) & AGGSPLITOP_DESERIALIZE) != 0)
783 * SetOpCmd and SetOpStrategy -
784 * overall semantics and execution strategies for SetOp plan nodes
786 * This is needed in both plannodes.h and relation.h, so put it here...
788 typedef enum SetOpCmd
791 SETOPCMD_INTERSECT_ALL,
796 typedef enum SetOpStrategy
798 SETOP_SORTED, /* input must be sorted */
799 SETOP_HASHED /* use internal hashtable */
804 * "ON CONFLICT" clause type of query
806 * This is needed in both parsenodes.h and plannodes.h, so put it here...
808 typedef enum OnConflictAction
810 ONCONFLICT_NONE, /* No "ON CONFLICT" clause */
811 ONCONFLICT_NOTHING, /* ON CONFLICT ... DO NOTHING */
812 ONCONFLICT_UPDATE /* ON CONFLICT ... DO UPDATE */