Header And Logo

PostgreSQL
| The world's most advanced open source database.

nodes.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  * nodes.h
00004  *    Definitions for tagged nodes.
00005  *
00006  *
00007  * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group
00008  * Portions Copyright (c) 1994, Regents of the University of California
00009  *
00010  * src/include/nodes/nodes.h
00011  *
00012  *-------------------------------------------------------------------------
00013  */
00014 #ifndef NODES_H
00015 #define NODES_H
00016 
00017 /*
00018  * The first field of every node is NodeTag. Each node created (with makeNode)
00019  * will have one of the following tags as the value of its first field.
00020  *
00021  * Note that the numbers of the node tags are not contiguous. We left holes
00022  * here so that we can add more tags without changing the existing enum's.
00023  * (Since node tag numbers never exist outside backend memory, there's no
00024  * real harm in renumbering, it just costs a full rebuild ...)
00025  */
00026 typedef enum NodeTag
00027 {
00028     T_Invalid = 0,
00029 
00030     /*
00031      * TAGS FOR EXECUTOR NODES (execnodes.h)
00032      */
00033     T_IndexInfo = 10,
00034     T_ExprContext,
00035     T_ProjectionInfo,
00036     T_JunkFilter,
00037     T_ResultRelInfo,
00038     T_EState,
00039     T_TupleTableSlot,
00040 
00041     /*
00042      * TAGS FOR PLAN NODES (plannodes.h)
00043      */
00044     T_Plan = 100,
00045     T_Result,
00046     T_ModifyTable,
00047     T_Append,
00048     T_MergeAppend,
00049     T_RecursiveUnion,
00050     T_BitmapAnd,
00051     T_BitmapOr,
00052     T_Scan,
00053     T_SeqScan,
00054     T_IndexScan,
00055     T_IndexOnlyScan,
00056     T_BitmapIndexScan,
00057     T_BitmapHeapScan,
00058     T_TidScan,
00059     T_SubqueryScan,
00060     T_FunctionScan,
00061     T_ValuesScan,
00062     T_CteScan,
00063     T_WorkTableScan,
00064     T_ForeignScan,
00065     T_Join,
00066     T_NestLoop,
00067     T_MergeJoin,
00068     T_HashJoin,
00069     T_Material,
00070     T_Sort,
00071     T_Group,
00072     T_Agg,
00073     T_WindowAgg,
00074     T_Unique,
00075     T_Hash,
00076     T_SetOp,
00077     T_LockRows,
00078     T_Limit,
00079     /* these aren't subclasses of Plan: */
00080     T_NestLoopParam,
00081     T_PlanRowMark,
00082     T_PlanInvalItem,
00083 
00084     /*
00085      * TAGS FOR PLAN STATE NODES (execnodes.h)
00086      *
00087      * These should correspond one-to-one with Plan node types.
00088      */
00089     T_PlanState = 200,
00090     T_ResultState,
00091     T_ModifyTableState,
00092     T_AppendState,
00093     T_MergeAppendState,
00094     T_RecursiveUnionState,
00095     T_BitmapAndState,
00096     T_BitmapOrState,
00097     T_ScanState,
00098     T_SeqScanState,
00099     T_IndexScanState,
00100     T_IndexOnlyScanState,
00101     T_BitmapIndexScanState,
00102     T_BitmapHeapScanState,
00103     T_TidScanState,
00104     T_SubqueryScanState,
00105     T_FunctionScanState,
00106     T_ValuesScanState,
00107     T_CteScanState,
00108     T_WorkTableScanState,
00109     T_ForeignScanState,
00110     T_JoinState,
00111     T_NestLoopState,
00112     T_MergeJoinState,
00113     T_HashJoinState,
00114     T_MaterialState,
00115     T_SortState,
00116     T_GroupState,
00117     T_AggState,
00118     T_WindowAggState,
00119     T_UniqueState,
00120     T_HashState,
00121     T_SetOpState,
00122     T_LockRowsState,
00123     T_LimitState,
00124 
00125     /*
00126      * TAGS FOR PRIMITIVE NODES (primnodes.h)
00127      */
00128     T_Alias = 300,
00129     T_RangeVar,
00130     T_Expr,
00131     T_Var,
00132     T_Const,
00133     T_Param,
00134     T_Aggref,
00135     T_WindowFunc,
00136     T_ArrayRef,
00137     T_FuncExpr,
00138     T_NamedArgExpr,
00139     T_OpExpr,
00140     T_DistinctExpr,
00141     T_NullIfExpr,
00142     T_ScalarArrayOpExpr,
00143     T_BoolExpr,
00144     T_SubLink,
00145     T_SubPlan,
00146     T_AlternativeSubPlan,
00147     T_FieldSelect,
00148     T_FieldStore,
00149     T_RelabelType,
00150     T_CoerceViaIO,
00151     T_ArrayCoerceExpr,
00152     T_ConvertRowtypeExpr,
00153     T_CollateExpr,
00154     T_CaseExpr,
00155     T_CaseWhen,
00156     T_CaseTestExpr,
00157     T_ArrayExpr,
00158     T_RowExpr,
00159     T_RowCompareExpr,
00160     T_CoalesceExpr,
00161     T_MinMaxExpr,
00162     T_XmlExpr,
00163     T_NullTest,
00164     T_BooleanTest,
00165     T_CoerceToDomain,
00166     T_CoerceToDomainValue,
00167     T_SetToDefault,
00168     T_CurrentOfExpr,
00169     T_TargetEntry,
00170     T_RangeTblRef,
00171     T_JoinExpr,
00172     T_FromExpr,
00173     T_IntoClause,
00174 
00175     /*
00176      * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
00177      *
00178      * These correspond (not always one-for-one) to primitive nodes derived
00179      * from Expr.
00180      */
00181     T_ExprState = 400,
00182     T_GenericExprState,
00183     T_WholeRowVarExprState,
00184     T_AggrefExprState,
00185     T_WindowFuncExprState,
00186     T_ArrayRefExprState,
00187     T_FuncExprState,
00188     T_ScalarArrayOpExprState,
00189     T_BoolExprState,
00190     T_SubPlanState,
00191     T_AlternativeSubPlanState,
00192     T_FieldSelectState,
00193     T_FieldStoreState,
00194     T_CoerceViaIOState,
00195     T_ArrayCoerceExprState,
00196     T_ConvertRowtypeExprState,
00197     T_CaseExprState,
00198     T_CaseWhenState,
00199     T_ArrayExprState,
00200     T_RowExprState,
00201     T_RowCompareExprState,
00202     T_CoalesceExprState,
00203     T_MinMaxExprState,
00204     T_XmlExprState,
00205     T_NullTestState,
00206     T_CoerceToDomainState,
00207     T_DomainConstraintState,
00208 
00209     /*
00210      * TAGS FOR PLANNER NODES (relation.h)
00211      */
00212     T_PlannerInfo = 500,
00213     T_PlannerGlobal,
00214     T_RelOptInfo,
00215     T_IndexOptInfo,
00216     T_ParamPathInfo,
00217     T_Path,
00218     T_IndexPath,
00219     T_BitmapHeapPath,
00220     T_BitmapAndPath,
00221     T_BitmapOrPath,
00222     T_NestPath,
00223     T_MergePath,
00224     T_HashPath,
00225     T_TidPath,
00226     T_ForeignPath,
00227     T_AppendPath,
00228     T_MergeAppendPath,
00229     T_ResultPath,
00230     T_MaterialPath,
00231     T_UniquePath,
00232     T_EquivalenceClass,
00233     T_EquivalenceMember,
00234     T_PathKey,
00235     T_RestrictInfo,
00236     T_PlaceHolderVar,
00237     T_SpecialJoinInfo,
00238     T_LateralJoinInfo,
00239     T_AppendRelInfo,
00240     T_PlaceHolderInfo,
00241     T_MinMaxAggInfo,
00242     T_PlannerParamItem,
00243 
00244     /*
00245      * TAGS FOR MEMORY NODES (memnodes.h)
00246      */
00247     T_MemoryContext = 600,
00248     T_AllocSetContext,
00249 
00250     /*
00251      * TAGS FOR VALUE NODES (value.h)
00252      */
00253     T_Value = 650,
00254     T_Integer,
00255     T_Float,
00256     T_String,
00257     T_BitString,
00258     T_Null,
00259 
00260     /*
00261      * TAGS FOR LIST NODES (pg_list.h)
00262      */
00263     T_List,
00264     T_IntList,
00265     T_OidList,
00266 
00267     /*
00268      * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
00269      */
00270     T_Query = 700,
00271     T_PlannedStmt,
00272     T_InsertStmt,
00273     T_DeleteStmt,
00274     T_UpdateStmt,
00275     T_SelectStmt,
00276     T_AlterTableStmt,
00277     T_AlterTableCmd,
00278     T_AlterDomainStmt,
00279     T_SetOperationStmt,
00280     T_GrantStmt,
00281     T_GrantRoleStmt,
00282     T_AlterDefaultPrivilegesStmt,
00283     T_ClosePortalStmt,
00284     T_ClusterStmt,
00285     T_CopyStmt,
00286     T_CreateStmt,
00287     T_DefineStmt,
00288     T_DropStmt,
00289     T_TruncateStmt,
00290     T_CommentStmt,
00291     T_FetchStmt,
00292     T_IndexStmt,
00293     T_CreateFunctionStmt,
00294     T_AlterFunctionStmt,
00295     T_DoStmt,
00296     T_RenameStmt,
00297     T_RuleStmt,
00298     T_NotifyStmt,
00299     T_ListenStmt,
00300     T_UnlistenStmt,
00301     T_TransactionStmt,
00302     T_ViewStmt,
00303     T_LoadStmt,
00304     T_CreateDomainStmt,
00305     T_CreatedbStmt,
00306     T_DropdbStmt,
00307     T_VacuumStmt,
00308     T_ExplainStmt,
00309     T_CreateTableAsStmt,
00310     T_CreateSeqStmt,
00311     T_AlterSeqStmt,
00312     T_VariableSetStmt,
00313     T_VariableShowStmt,
00314     T_DiscardStmt,
00315     T_CreateTrigStmt,
00316     T_CreatePLangStmt,
00317     T_CreateRoleStmt,
00318     T_AlterRoleStmt,
00319     T_DropRoleStmt,
00320     T_LockStmt,
00321     T_ConstraintsSetStmt,
00322     T_ReindexStmt,
00323     T_CheckPointStmt,
00324     T_CreateSchemaStmt,
00325     T_AlterDatabaseStmt,
00326     T_AlterDatabaseSetStmt,
00327     T_AlterRoleSetStmt,
00328     T_CreateConversionStmt,
00329     T_CreateCastStmt,
00330     T_CreateOpClassStmt,
00331     T_CreateOpFamilyStmt,
00332     T_AlterOpFamilyStmt,
00333     T_PrepareStmt,
00334     T_ExecuteStmt,
00335     T_DeallocateStmt,
00336     T_DeclareCursorStmt,
00337     T_CreateTableSpaceStmt,
00338     T_DropTableSpaceStmt,
00339     T_AlterObjectSchemaStmt,
00340     T_AlterOwnerStmt,
00341     T_DropOwnedStmt,
00342     T_ReassignOwnedStmt,
00343     T_CompositeTypeStmt,
00344     T_CreateEnumStmt,
00345     T_CreateRangeStmt,
00346     T_AlterEnumStmt,
00347     T_AlterTSDictionaryStmt,
00348     T_AlterTSConfigurationStmt,
00349     T_CreateFdwStmt,
00350     T_AlterFdwStmt,
00351     T_CreateForeignServerStmt,
00352     T_AlterForeignServerStmt,
00353     T_CreateUserMappingStmt,
00354     T_AlterUserMappingStmt,
00355     T_DropUserMappingStmt,
00356     T_AlterTableSpaceOptionsStmt,
00357     T_SecLabelStmt,
00358     T_CreateForeignTableStmt,
00359     T_CreateExtensionStmt,
00360     T_AlterExtensionStmt,
00361     T_AlterExtensionContentsStmt,
00362     T_CreateEventTrigStmt,
00363     T_AlterEventTrigStmt,
00364     T_RefreshMatViewStmt,
00365 
00366     /*
00367      * TAGS FOR PARSE TREE NODES (parsenodes.h)
00368      */
00369     T_A_Expr = 900,
00370     T_ColumnRef,
00371     T_ParamRef,
00372     T_A_Const,
00373     T_FuncCall,
00374     T_A_Star,
00375     T_A_Indices,
00376     T_A_Indirection,
00377     T_A_ArrayExpr,
00378     T_ResTarget,
00379     T_TypeCast,
00380     T_CollateClause,
00381     T_SortBy,
00382     T_WindowDef,
00383     T_RangeSubselect,
00384     T_RangeFunction,
00385     T_TypeName,
00386     T_ColumnDef,
00387     T_IndexElem,
00388     T_Constraint,
00389     T_DefElem,
00390     T_RangeTblEntry,
00391     T_SortGroupClause,
00392     T_WindowClause,
00393     T_PrivGrantee,
00394     T_FuncWithArgs,
00395     T_AccessPriv,
00396     T_CreateOpClassItem,
00397     T_TableLikeClause,
00398     T_FunctionParameter,
00399     T_LockingClause,
00400     T_RowMarkClause,
00401     T_XmlSerialize,
00402     T_WithClause,
00403     T_CommonTableExpr,
00404 
00405     /*
00406      * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
00407      */
00408     T_IdentifySystemCmd,
00409     T_BaseBackupCmd,
00410     T_StartReplicationCmd,
00411     T_TimeLineHistoryCmd,
00412 
00413     /*
00414      * TAGS FOR RANDOM OTHER STUFF
00415      *
00416      * These are objects that aren't part of parse/plan/execute node tree
00417      * structures, but we give them NodeTags anyway for identification
00418      * purposes (usually because they are involved in APIs where we want to
00419      * pass multiple object types through the same pointer).
00420      */
00421     T_TriggerData = 950,        /* in commands/trigger.h */
00422     T_EventTriggerData,         /* in commands/event_trigger.h */
00423     T_ReturnSetInfo,            /* in nodes/execnodes.h */
00424     T_WindowObjectData,         /* private in nodeWindowAgg.c */
00425     T_TIDBitmap,                /* in nodes/tidbitmap.h */
00426     T_InlineCodeBlock,          /* in nodes/parsenodes.h */
00427     T_FdwRoutine                /* in foreign/fdwapi.h */
00428 } NodeTag;
00429 
00430 /*
00431  * The first field of a node of any type is guaranteed to be the NodeTag.
00432  * Hence the type of any node can be gotten by casting it to Node. Declaring
00433  * a variable to be of Node * (instead of void *) can also facilitate
00434  * debugging.
00435  */
00436 typedef struct Node
00437 {
00438     NodeTag     type;
00439 } Node;
00440 
00441 #define nodeTag(nodeptr)        (((const Node*)(nodeptr))->type)
00442 
00443 /*
00444  * newNode -
00445  *    create a new node of the specified size and tag the node with the
00446  *    specified tag.
00447  *
00448  * !WARNING!: Avoid using newNode directly. You should be using the
00449  *    macro makeNode.  eg. to create a Query node, use makeNode(Query)
00450  *
00451  * Note: the size argument should always be a compile-time constant, so the
00452  * apparent risk of multiple evaluation doesn't matter in practice.
00453  */
00454 #ifdef __GNUC__
00455 
00456 /* With GCC, we can use a compound statement within an expression */
00457 #define newNode(size, tag) \
00458 ({  Node   *_result; \
00459     AssertMacro((size) >= sizeof(Node));        /* need the tag, at least */ \
00460     _result = (Node *) palloc0fast(size); \
00461     _result->type = (tag); \
00462     _result; \
00463 })
00464 #else
00465 
00466 /*
00467  *  There is no way to dereference the palloc'ed pointer to assign the
00468  *  tag, and also return the pointer itself, so we need a holder variable.
00469  *  Fortunately, this macro isn't recursive so we just define
00470  *  a global variable for this purpose.
00471  */
00472 extern PGDLLIMPORT Node *newNodeMacroHolder;
00473 
00474 #define newNode(size, tag) \
00475 ( \
00476     AssertMacro((size) >= sizeof(Node)),        /* need the tag, at least */ \
00477     newNodeMacroHolder = (Node *) palloc0fast(size), \
00478     newNodeMacroHolder->type = (tag), \
00479     newNodeMacroHolder \
00480 )
00481 #endif   /* __GNUC__ */
00482 
00483 
00484 #define makeNode(_type_)        ((_type_ *) newNode(sizeof(_type_),T_##_type_))
00485 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
00486 
00487 #define IsA(nodeptr,_type_)     (nodeTag(nodeptr) == T_##_type_)
00488 
00489 /* ----------------------------------------------------------------
00490  *                    extern declarations follow
00491  * ----------------------------------------------------------------
00492  */
00493 
00494 /*
00495  * nodes/{outfuncs.c,print.c}
00496  */
00497 extern char *nodeToString(const void *obj);
00498 
00499 /*
00500  * nodes/{readfuncs.c,read.c}
00501  */
00502 extern void *stringToNode(char *str);
00503 
00504 /*
00505  * nodes/copyfuncs.c
00506  */
00507 extern void *copyObject(const void *obj);
00508 
00509 /*
00510  * nodes/equalfuncs.c
00511  */
00512 extern bool equal(const void *a, const void *b);
00513 
00514 
00515 /*
00516  * Typedefs for identifying qualifier selectivities and plan costs as such.
00517  * These are just plain "double"s, but declaring a variable as Selectivity
00518  * or Cost makes the intent more obvious.
00519  *
00520  * These could have gone into plannodes.h or some such, but many files
00521  * depend on them...
00522  */
00523 typedef double Selectivity;     /* fraction of tuples a qualifier will pass */
00524 typedef double Cost;            /* execution cost (in page-access units) */
00525 
00526 
00527 /*
00528  * CmdType -
00529  *    enums for type of operation represented by a Query or PlannedStmt
00530  *
00531  * This is needed in both parsenodes.h and plannodes.h, so put it here...
00532  */
00533 typedef enum CmdType
00534 {
00535     CMD_UNKNOWN,
00536     CMD_SELECT,                 /* select stmt */
00537     CMD_UPDATE,                 /* update stmt */
00538     CMD_INSERT,                 /* insert stmt */
00539     CMD_DELETE,
00540     CMD_UTILITY,                /* cmds like create, destroy, copy, vacuum,
00541                                  * etc. */
00542     CMD_NOTHING                 /* dummy command for instead nothing rules
00543                                  * with qual */
00544 } CmdType;
00545 
00546 
00547 /*
00548  * JoinType -
00549  *    enums for types of relation joins
00550  *
00551  * JoinType determines the exact semantics of joining two relations using
00552  * a matching qualification.  For example, it tells what to do with a tuple
00553  * that has no match in the other relation.
00554  *
00555  * This is needed in both parsenodes.h and plannodes.h, so put it here...
00556  */
00557 typedef enum JoinType
00558 {
00559     /*
00560      * The canonical kinds of joins according to the SQL JOIN syntax. Only
00561      * these codes can appear in parser output (e.g., JoinExpr nodes).
00562      */
00563     JOIN_INNER,                 /* matching tuple pairs only */
00564     JOIN_LEFT,                  /* pairs + unmatched LHS tuples */
00565     JOIN_FULL,                  /* pairs + unmatched LHS + unmatched RHS */
00566     JOIN_RIGHT,                 /* pairs + unmatched RHS tuples */
00567 
00568     /*
00569      * Semijoins and anti-semijoins (as defined in relational theory) do not
00570      * appear in the SQL JOIN syntax, but there are standard idioms for
00571      * representing them (e.g., using EXISTS).  The planner recognizes these
00572      * cases and converts them to joins.  So the planner and executor must
00573      * support these codes.  NOTE: in JOIN_SEMI output, it is unspecified
00574      * which matching RHS row is joined to.  In JOIN_ANTI output, the row is
00575      * guaranteed to be null-extended.
00576      */
00577     JOIN_SEMI,                  /* 1 copy of each LHS row that has match(es) */
00578     JOIN_ANTI,                  /* 1 copy of each LHS row that has no match */
00579 
00580     /*
00581      * These codes are used internally in the planner, but are not supported
00582      * by the executor (nor, indeed, by most of the planner).
00583      */
00584     JOIN_UNIQUE_OUTER,          /* LHS path must be made unique */
00585     JOIN_UNIQUE_INNER           /* RHS path must be made unique */
00586 
00587     /*
00588      * We might need additional join types someday.
00589      */
00590 } JoinType;
00591 
00592 /*
00593  * OUTER joins are those for which pushed-down quals must behave differently
00594  * from the join's own quals.  This is in fact everything except INNER and
00595  * SEMI joins.  However, this macro must also exclude the JOIN_UNIQUE symbols
00596  * since those are temporary proxies for what will eventually be an INNER
00597  * join.
00598  *
00599  * Note: semijoins are a hybrid case, but we choose to treat them as not
00600  * being outer joins.  This is okay principally because the SQL syntax makes
00601  * it impossible to have a pushed-down qual that refers to the inner relation
00602  * of a semijoin; so there is no strong need to distinguish join quals from
00603  * pushed-down quals.  This is convenient because for almost all purposes,
00604  * quals attached to a semijoin can be treated the same as innerjoin quals.
00605  */
00606 #define IS_OUTER_JOIN(jointype) \
00607     (((1 << (jointype)) & \
00608       ((1 << JOIN_LEFT) | \
00609        (1 << JOIN_FULL) | \
00610        (1 << JOIN_RIGHT) | \
00611        (1 << JOIN_ANTI))) != 0)
00612 
00613 #endif   /* NODES_H */