1 /*-------------------------------------------------------------------------
4 * Definitions for tagged nodes.
7 * Portions Copyright (c) 1996-2011, 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)
77 /* these aren't subclasses of Plan: */
83 * TAGS FOR PLAN STATE NODES (execnodes.h)
85 * These should correspond one-to-one with Plan node types.
92 T_RecursiveUnionState,
98 T_BitmapIndexScanState,
99 T_BitmapHeapScanState,
105 T_WorkTableScanState,
122 * TAGS FOR PRIMITIVE NODES (primnodes.h)
141 T_AlternativeSubPlan,
147 T_ConvertRowtypeExpr,
161 T_CoerceToDomainValue,
172 * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
174 * These correspond (not always one-for-one) to primitive nodes derived
180 T_WindowFuncExprState,
183 T_ScalarArrayOpExprState,
186 T_AlternativeSubPlanState,
190 T_ArrayCoerceExprState,
191 T_ConvertRowtypeExprState,
196 T_RowCompareExprState,
201 T_CoerceToDomainState,
202 T_DomainConstraintState,
205 * TAGS FOR PLANNER NODES (relation.h)
229 T_InnerIndexscanInfo,
238 * TAGS FOR MEMORY NODES (memnodes.h)
240 T_MemoryContext = 600,
244 * TAGS FOR VALUE NODES (value.h)
254 * TAGS FOR LIST NODES (pg_list.h)
261 * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
275 T_AlterDefaultPrivilegesStmt,
286 T_CreateFunctionStmt,
316 T_ConstraintsSetStmt,
321 T_AlterDatabaseSetStmt,
323 T_CreateConversionStmt,
327 T_CreateOpFamilyStmt,
330 T_RemoveOpFamilyStmt,
335 T_CreateTableSpaceStmt,
336 T_DropTableSpaceStmt,
337 T_AlterObjectSchemaStmt,
344 T_AlterTSDictionaryStmt,
345 T_AlterTSConfigurationStmt,
349 T_CreateForeignServerStmt,
350 T_AlterForeignServerStmt,
351 T_DropForeignServerStmt,
352 T_CreateUserMappingStmt,
353 T_AlterUserMappingStmt,
354 T_DropUserMappingStmt,
355 T_AlterTableSpaceOptionsStmt,
357 T_CreateForeignTableStmt,
358 T_CreateExtensionStmt,
361 * TAGS FOR PARSE TREE NODES (parsenodes.h)
399 * TAGS FOR RANDOM OTHER STUFF
401 * These are objects that aren't part of parse/plan/execute node tree
402 * structures, but we give them NodeTags anyway for identification
403 * purposes (usually because they are involved in APIs where we want to
404 * pass multiple object types through the same pointer).
406 T_TriggerData = 950, /* in commands/trigger.h */
407 T_ReturnSetInfo, /* in nodes/execnodes.h */
408 T_WindowObjectData, /* private in nodeWindowAgg.c */
409 T_TIDBitmap, /* in nodes/tidbitmap.h */
410 T_InlineCodeBlock /* in nodes/parsenodes.h */
414 * The first field of a node of any type is guaranteed to be the NodeTag.
415 * Hence the type of any node can be gotten by casting it to Node. Declaring
416 * a variable to be of Node * (instead of void *) can also facilitate
424 #define nodeTag(nodeptr) (((Node*)(nodeptr))->type)
428 * create a new node of the specified size and tag the node with the
431 * !WARNING!: Avoid using newNode directly. You should be using the
432 * macro makeNode. eg. to create a Query node, use makeNode(Query)
434 * Note: the size argument should always be a compile-time constant, so the
435 * apparent risk of multiple evaluation doesn't matter in practice.
439 /* With GCC, we can use a compound statement within an expression */
440 #define newNode(size, tag) \
442 AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
443 _result = (Node *) palloc0fast(size); \
444 _result->type = (tag); \
450 * There is no way to dereference the palloc'ed pointer to assign the
451 * tag, and also return the pointer itself, so we need a holder variable.
452 * Fortunately, this macro isn't recursive so we just define
453 * a global variable for this purpose.
455 extern PGDLLIMPORT Node *newNodeMacroHolder;
457 #define newNode(size, tag) \
459 AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
460 newNodeMacroHolder = (Node *) palloc0fast(size), \
461 newNodeMacroHolder->type = (tag), \
464 #endif /* __GNUC__ */
467 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
468 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
470 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
472 /* ----------------------------------------------------------------
473 * extern declarations follow
474 * ----------------------------------------------------------------
478 * nodes/{outfuncs.c,print.c}
480 extern char *nodeToString(void *obj);
483 * nodes/{readfuncs.c,read.c}
485 extern void *stringToNode(char *str);
490 extern void *copyObject(void *obj);
495 extern bool equal(void *a, void *b);
499 * Typedefs for identifying qualifier selectivities and plan costs as such.
500 * These are just plain "double"s, but declaring a variable as Selectivity
501 * or Cost makes the intent more obvious.
503 * These could have gone into plannodes.h or some such, but many files
506 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
507 typedef double Cost; /* execution cost (in page-access units) */
512 * enums for type of operation represented by a Query or PlannedStmt
514 * This is needed in both parsenodes.h and plannodes.h, so put it here...
519 CMD_SELECT, /* select stmt */
520 CMD_UPDATE, /* update stmt */
521 CMD_INSERT, /* insert stmt */
523 CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
525 CMD_NOTHING /* dummy command for instead nothing rules
532 * enums for types of relation joins
534 * JoinType determines the exact semantics of joining two relations using
535 * a matching qualification. For example, it tells what to do with a tuple
536 * that has no match in the other relation.
538 * This is needed in both parsenodes.h and plannodes.h, so put it here...
540 typedef enum JoinType
543 * The canonical kinds of joins according to the SQL JOIN syntax. Only
544 * these codes can appear in parser output (e.g., JoinExpr nodes).
546 JOIN_INNER, /* matching tuple pairs only */
547 JOIN_LEFT, /* pairs + unmatched LHS tuples */
548 JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
549 JOIN_RIGHT, /* pairs + unmatched RHS tuples */
552 * Semijoins and anti-semijoins (as defined in relational theory) do not
553 * appear in the SQL JOIN syntax, but there are standard idioms for
554 * representing them (e.g., using EXISTS). The planner recognizes these
555 * cases and converts them to joins. So the planner and executor must
556 * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
557 * which matching RHS row is joined to. In JOIN_ANTI output, the row is
558 * guaranteed to be null-extended.
560 JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
561 JOIN_ANTI, /* 1 copy of each LHS row that has no match */
564 * These codes are used internally in the planner, but are not supported
565 * by the executor (nor, indeed, by most of the planner).
567 JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
568 JOIN_UNIQUE_INNER /* RHS path must be made unique */
571 * We might need additional join types someday.
576 * OUTER joins are those for which pushed-down quals must behave differently
577 * from the join's own quals. This is in fact everything except INNER and
578 * SEMI joins. However, this macro must also exclude the JOIN_UNIQUE symbols
579 * since those are temporary proxies for what will eventually be an INNER
582 * Note: semijoins are a hybrid case, but we choose to treat them as not
583 * being outer joins. This is okay principally because the SQL syntax makes
584 * it impossible to have a pushed-down qual that refers to the inner relation
585 * of a semijoin; so there is no strong need to distinguish join quals from
586 * pushed-down quals. This is convenient because for almost all purposes,
587 * quals attached to a semijoin can be treated the same as innerjoin quals.
589 #define IS_OUTER_JOIN(jointype) \
590 (((1 << (jointype)) & \
591 ((1 << JOIN_LEFT) | \
593 (1 << JOIN_RIGHT) | \
594 (1 << JOIN_ANTI))) != 0)