1 /*-------------------------------------------------------------------------
4 * Definitions for tagged nodes.
7 * Portions Copyright (c) 1996-2014, 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 the numbers of the node tags are not contiguous. We left holes
22 * here so that we can add more tags without changing the existing enum's.
23 * (Since node tag numbers never exist outside backend memory, there's no
24 * real harm in renumbering, it just costs a full rebuild ...)
31 * TAGS FOR EXECUTOR NODES (execnodes.h)
42 * TAGS FOR PLAN NODES (plannodes.h)
79 /* these aren't subclasses of Plan: */
85 * TAGS FOR PLAN STATE NODES (execnodes.h)
87 * These should correspond one-to-one with Plan node types.
94 T_RecursiveUnionState,
100 T_IndexOnlyScanState,
101 T_BitmapIndexScanState,
102 T_BitmapHeapScanState,
108 T_WorkTableScanState,
126 * TAGS FOR PRIMITIVE NODES (primnodes.h)
146 T_AlternativeSubPlan,
152 T_ConvertRowtypeExpr,
166 T_CoerceToDomainValue,
176 * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
178 * These correspond (not always one-for-one) to primitive nodes derived
183 T_WholeRowVarExprState,
185 T_WindowFuncExprState,
188 T_ScalarArrayOpExprState,
191 T_AlternativeSubPlanState,
195 T_ArrayCoerceExprState,
196 T_ConvertRowtypeExprState,
201 T_RowCompareExprState,
206 T_CoerceToDomainState,
207 T_DomainConstraintState,
210 * TAGS FOR PLANNER NODES (relation.h)
245 * TAGS FOR MEMORY NODES (memnodes.h)
247 T_MemoryContext = 600,
251 * TAGS FOR VALUE NODES (value.h)
261 * TAGS FOR LIST NODES (pg_list.h)
268 * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
282 T_AlterDefaultPrivilegesStmt,
293 T_CreateFunctionStmt,
321 T_ConstraintsSetStmt,
326 T_AlterDatabaseSetStmt,
328 T_CreateConversionStmt,
331 T_CreateOpFamilyStmt,
337 T_CreateTableSpaceStmt,
338 T_DropTableSpaceStmt,
339 T_AlterObjectSchemaStmt,
347 T_AlterTSDictionaryStmt,
348 T_AlterTSConfigurationStmt,
351 T_CreateForeignServerStmt,
352 T_AlterForeignServerStmt,
353 T_CreateUserMappingStmt,
354 T_AlterUserMappingStmt,
355 T_DropUserMappingStmt,
356 T_AlterTableSpaceOptionsStmt,
357 T_AlterTableMoveAllStmt,
359 T_CreateForeignTableStmt,
360 T_CreateExtensionStmt,
361 T_AlterExtensionStmt,
362 T_AlterExtensionContentsStmt,
363 T_CreateEventTrigStmt,
364 T_AlterEventTrigStmt,
365 T_RefreshMatViewStmt,
366 T_ReplicaIdentityStmt,
370 * TAGS FOR PARSE TREE NODES (parsenodes.h)
411 * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
415 T_CreateReplicationSlotCmd,
416 T_DropReplicationSlotCmd,
417 T_StartReplicationCmd,
418 T_TimeLineHistoryCmd,
421 * TAGS FOR RANDOM OTHER STUFF
423 * These are objects that aren't part of parse/plan/execute node tree
424 * structures, but we give them NodeTags anyway for identification
425 * purposes (usually because they are involved in APIs where we want to
426 * pass multiple object types through the same pointer).
428 T_TriggerData = 950, /* in commands/trigger.h */
429 T_EventTriggerData, /* in commands/event_trigger.h */
430 T_ReturnSetInfo, /* in nodes/execnodes.h */
431 T_WindowObjectData, /* private in nodeWindowAgg.c */
432 T_TIDBitmap, /* in nodes/tidbitmap.h */
433 T_InlineCodeBlock, /* in nodes/parsenodes.h */
434 T_FdwRoutine /* in foreign/fdwapi.h */
438 * The first field of a node of any type is guaranteed to be the NodeTag.
439 * Hence the type of any node can be gotten by casting it to Node. Declaring
440 * a variable to be of Node * (instead of void *) can also facilitate
448 #define nodeTag(nodeptr) (((const Node*)(nodeptr))->type)
452 * create a new node of the specified size and tag the node with the
455 * !WARNING!: Avoid using newNode directly. You should be using the
456 * macro makeNode. eg. to create a Query node, use makeNode(Query)
458 * Note: the size argument should always be a compile-time constant, so the
459 * apparent risk of multiple evaluation doesn't matter in practice.
463 /* With GCC, we can use a compound statement within an expression */
464 #define newNode(size, tag) \
466 AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
467 _result = (Node *) palloc0fast(size); \
468 _result->type = (tag); \
474 * There is no way to dereference the palloc'ed pointer to assign the
475 * tag, and also return the pointer itself, so we need a holder variable.
476 * Fortunately, this macro isn't recursive so we just define
477 * a global variable for this purpose.
479 extern PGDLLIMPORT Node *newNodeMacroHolder;
481 #define newNode(size, tag) \
483 AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
484 newNodeMacroHolder = (Node *) palloc0fast(size), \
485 newNodeMacroHolder->type = (tag), \
488 #endif /* __GNUC__ */
491 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
492 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
494 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
496 /* ----------------------------------------------------------------
497 * extern declarations follow
498 * ----------------------------------------------------------------
502 * nodes/{outfuncs.c,print.c}
504 extern char *nodeToString(const void *obj);
507 * nodes/{readfuncs.c,read.c}
509 extern void *stringToNode(char *str);
514 extern void *copyObject(const void *obj);
519 extern bool equal(const void *a, const void *b);
523 * Typedefs for identifying qualifier selectivities and plan costs as such.
524 * These are just plain "double"s, but declaring a variable as Selectivity
525 * or Cost makes the intent more obvious.
527 * These could have gone into plannodes.h or some such, but many files
530 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
531 typedef double Cost; /* execution cost (in page-access units) */
536 * enums for type of operation represented by a Query or PlannedStmt
538 * This is needed in both parsenodes.h and plannodes.h, so put it here...
543 CMD_SELECT, /* select stmt */
544 CMD_UPDATE, /* update stmt */
545 CMD_INSERT, /* insert stmt */
547 CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
549 CMD_NOTHING /* dummy command for instead nothing rules
556 * enums for types of relation joins
558 * JoinType determines the exact semantics of joining two relations using
559 * a matching qualification. For example, it tells what to do with a tuple
560 * that has no match in the other relation.
562 * This is needed in both parsenodes.h and plannodes.h, so put it here...
564 typedef enum JoinType
567 * The canonical kinds of joins according to the SQL JOIN syntax. Only
568 * these codes can appear in parser output (e.g., JoinExpr nodes).
570 JOIN_INNER, /* matching tuple pairs only */
571 JOIN_LEFT, /* pairs + unmatched LHS tuples */
572 JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
573 JOIN_RIGHT, /* pairs + unmatched RHS tuples */
576 * Semijoins and anti-semijoins (as defined in relational theory) do not
577 * appear in the SQL JOIN syntax, but there are standard idioms for
578 * representing them (e.g., using EXISTS). The planner recognizes these
579 * cases and converts them to joins. So the planner and executor must
580 * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
581 * which matching RHS row is joined to. In JOIN_ANTI output, the row is
582 * guaranteed to be null-extended.
584 JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
585 JOIN_ANTI, /* 1 copy of each LHS row that has no match */
588 * These codes are used internally in the planner, but are not supported
589 * by the executor (nor, indeed, by most of the planner).
591 JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
592 JOIN_UNIQUE_INNER /* RHS path must be made unique */
595 * We might need additional join types someday.
600 * OUTER joins are those for which pushed-down quals must behave differently
601 * from the join's own quals. This is in fact everything except INNER and
602 * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
603 * since those are temporary proxies for what will eventually be an INNER
606 * Note: semijoins are a hybrid case, but we choose to treat them as not
607 * being outer joins. This is okay principally because the SQL syntax makes
608 * it impossible to have a pushed-down qual that refers to the inner relation
609 * of a semijoin; so there is no strong need to distinguish join quals from
610 * pushed-down quals. This is convenient because for almost all purposes,
611 * quals attached to a semijoin can be treated the same as innerjoin quals.
613 #define IS_OUTER_JOIN(jointype) \
614 (((1 << (jointype)) & \
615 ((1 << JOIN_LEFT) | \
617 (1 << JOIN_RIGHT) | \
618 (1 << JOIN_ANTI))) != 0)