]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
1ce5d81b2c0f900e801dfb7f1a6744fd36eb0d97
[postgresql] / src / include / nodes / nodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * nodes.h
4  *        Definitions for tagged nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2011, 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 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 ...)
25  */
26 typedef enum NodeTag
27 {
28         T_Invalid = 0,
29
30         /*
31          * TAGS FOR EXECUTOR NODES (execnodes.h)
32          */
33         T_IndexInfo = 10,
34         T_ExprContext,
35         T_ProjectionInfo,
36         T_JunkFilter,
37         T_ResultRelInfo,
38         T_EState,
39         T_TupleTableSlot,
40
41         /*
42          * TAGS FOR PLAN NODES (plannodes.h)
43          */
44         T_Plan = 100,
45         T_Result,
46         T_ModifyTable,
47         T_Append,
48         T_MergeAppend,
49         T_RecursiveUnion,
50         T_BitmapAnd,
51         T_BitmapOr,
52         T_Scan,
53         T_SeqScan,
54         T_IndexScan,
55         T_BitmapIndexScan,
56         T_BitmapHeapScan,
57         T_TidScan,
58         T_SubqueryScan,
59         T_FunctionScan,
60         T_ValuesScan,
61         T_CteScan,
62         T_WorkTableScan,
63         T_Join,
64         T_NestLoop,
65         T_MergeJoin,
66         T_HashJoin,
67         T_Material,
68         T_Sort,
69         T_Group,
70         T_Agg,
71         T_WindowAgg,
72         T_Unique,
73         T_Hash,
74         T_SetOp,
75         T_LockRows,
76         T_Limit,
77         /* these aren't subclasses of Plan: */
78         T_NestLoopParam,
79         T_PlanRowMark,
80         T_PlanInvalItem,
81
82         /*
83          * TAGS FOR PLAN STATE NODES (execnodes.h)
84          *
85          * These should correspond one-to-one with Plan node types.
86          */
87         T_PlanState = 200,
88         T_ResultState,
89         T_ModifyTableState,
90         T_AppendState,
91         T_MergeAppendState,
92         T_RecursiveUnionState,
93         T_BitmapAndState,
94         T_BitmapOrState,
95         T_ScanState,
96         T_SeqScanState,
97         T_IndexScanState,
98         T_BitmapIndexScanState,
99         T_BitmapHeapScanState,
100         T_TidScanState,
101         T_SubqueryScanState,
102         T_FunctionScanState,
103         T_ValuesScanState,
104         T_CteScanState,
105         T_WorkTableScanState,
106         T_JoinState,
107         T_NestLoopState,
108         T_MergeJoinState,
109         T_HashJoinState,
110         T_MaterialState,
111         T_SortState,
112         T_GroupState,
113         T_AggState,
114         T_WindowAggState,
115         T_UniqueState,
116         T_HashState,
117         T_SetOpState,
118         T_LockRowsState,
119         T_LimitState,
120
121         /*
122          * TAGS FOR PRIMITIVE NODES (primnodes.h)
123          */
124         T_Alias = 300,
125         T_RangeVar,
126         T_Expr,
127         T_Var,
128         T_Const,
129         T_Param,
130         T_Aggref,
131         T_WindowFunc,
132         T_ArrayRef,
133         T_FuncExpr,
134         T_NamedArgExpr,
135         T_OpExpr,
136         T_DistinctExpr,
137         T_ScalarArrayOpExpr,
138         T_BoolExpr,
139         T_SubLink,
140         T_SubPlan,
141         T_AlternativeSubPlan,
142         T_FieldSelect,
143         T_FieldStore,
144         T_RelabelType,
145         T_CoerceViaIO,
146         T_ArrayCoerceExpr,
147         T_ConvertRowtypeExpr,
148         T_CaseExpr,
149         T_CaseWhen,
150         T_CaseTestExpr,
151         T_ArrayExpr,
152         T_RowExpr,
153         T_RowCompareExpr,
154         T_CoalesceExpr,
155         T_MinMaxExpr,
156         T_XmlExpr,
157         T_NullIfExpr,
158         T_NullTest,
159         T_BooleanTest,
160         T_CoerceToDomain,
161         T_CoerceToDomainValue,
162         T_SetToDefault,
163         T_CurrentOfExpr,
164         T_TargetEntry,
165         T_RangeTblRef,
166         T_JoinExpr,
167         T_FromExpr,
168         T_IntoClause,
169
170         /*
171          * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
172          *
173          * These correspond (not always one-for-one) to primitive nodes derived
174          * from Expr.
175          */
176         T_ExprState = 400,
177         T_GenericExprState,
178         T_AggrefExprState,
179         T_WindowFuncExprState,
180         T_ArrayRefExprState,
181         T_FuncExprState,
182         T_ScalarArrayOpExprState,
183         T_BoolExprState,
184         T_SubPlanState,
185         T_AlternativeSubPlanState,
186         T_FieldSelectState,
187         T_FieldStoreState,
188         T_CoerceViaIOState,
189         T_ArrayCoerceExprState,
190         T_ConvertRowtypeExprState,
191         T_CaseExprState,
192         T_CaseWhenState,
193         T_ArrayExprState,
194         T_RowExprState,
195         T_RowCompareExprState,
196         T_CoalesceExprState,
197         T_MinMaxExprState,
198         T_XmlExprState,
199         T_NullTestState,
200         T_CoerceToDomainState,
201         T_DomainConstraintState,
202
203         /*
204          * TAGS FOR PLANNER NODES (relation.h)
205          */
206         T_PlannerInfo = 500,
207         T_PlannerGlobal,
208         T_RelOptInfo,
209         T_IndexOptInfo,
210         T_Path,
211         T_IndexPath,
212         T_BitmapHeapPath,
213         T_BitmapAndPath,
214         T_BitmapOrPath,
215         T_NestPath,
216         T_MergePath,
217         T_HashPath,
218         T_TidPath,
219         T_AppendPath,
220         T_MergeAppendPath,
221         T_ResultPath,
222         T_MaterialPath,
223         T_UniquePath,
224         T_EquivalenceClass,
225         T_EquivalenceMember,
226         T_PathKey,
227         T_RestrictInfo,
228         T_InnerIndexscanInfo,
229         T_PlaceHolderVar,
230         T_SpecialJoinInfo,
231         T_AppendRelInfo,
232         T_PlaceHolderInfo,
233         T_MinMaxAggInfo,
234         T_PlannerParamItem,
235
236         /*
237          * TAGS FOR MEMORY NODES (memnodes.h)
238          */
239         T_MemoryContext = 600,
240         T_AllocSetContext,
241
242         /*
243          * TAGS FOR VALUE NODES (value.h)
244          */
245         T_Value = 650,
246         T_Integer,
247         T_Float,
248         T_String,
249         T_BitString,
250         T_Null,
251
252         /*
253          * TAGS FOR LIST NODES (pg_list.h)
254          */
255         T_List,
256         T_IntList,
257         T_OidList,
258
259         /*
260          * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
261          */
262         T_Query = 700,
263         T_PlannedStmt,
264         T_InsertStmt,
265         T_DeleteStmt,
266         T_UpdateStmt,
267         T_SelectStmt,
268         T_AlterTableStmt,
269         T_AlterTableCmd,
270         T_AlterDomainStmt,
271         T_SetOperationStmt,
272         T_GrantStmt,
273         T_GrantRoleStmt,
274         T_AlterDefaultPrivilegesStmt,
275         T_ClosePortalStmt,
276         T_ClusterStmt,
277         T_CopyStmt,
278         T_CreateStmt,
279         T_DefineStmt,
280         T_DropStmt,
281         T_TruncateStmt,
282         T_CommentStmt,
283         T_FetchStmt,
284         T_IndexStmt,
285         T_CreateFunctionStmt,
286         T_AlterFunctionStmt,
287         T_RemoveFuncStmt,
288         T_DoStmt,
289         T_RenameStmt,
290         T_RuleStmt,
291         T_NotifyStmt,
292         T_ListenStmt,
293         T_UnlistenStmt,
294         T_TransactionStmt,
295         T_ViewStmt,
296         T_LoadStmt,
297         T_CreateDomainStmt,
298         T_CreatedbStmt,
299         T_DropdbStmt,
300         T_VacuumStmt,
301         T_ExplainStmt,
302         T_CreateSeqStmt,
303         T_AlterSeqStmt,
304         T_VariableSetStmt,
305         T_VariableShowStmt,
306         T_DiscardStmt,
307         T_CreateTrigStmt,
308         T_DropPropertyStmt,
309         T_CreatePLangStmt,
310         T_DropPLangStmt,
311         T_CreateRoleStmt,
312         T_AlterRoleStmt,
313         T_DropRoleStmt,
314         T_LockStmt,
315         T_ConstraintsSetStmt,
316         T_ReindexStmt,
317         T_CheckPointStmt,
318         T_CreateSchemaStmt,
319         T_AlterDatabaseStmt,
320         T_AlterDatabaseSetStmt,
321         T_AlterRoleSetStmt,
322         T_CreateConversionStmt,
323         T_CreateCastStmt,
324         T_DropCastStmt,
325         T_CreateOpClassStmt,
326         T_CreateOpFamilyStmt,
327         T_AlterOpFamilyStmt,
328         T_RemoveOpClassStmt,
329         T_RemoveOpFamilyStmt,
330         T_PrepareStmt,
331         T_ExecuteStmt,
332         T_DeallocateStmt,
333         T_DeclareCursorStmt,
334         T_CreateTableSpaceStmt,
335         T_DropTableSpaceStmt,
336         T_AlterObjectSchemaStmt,
337         T_AlterOwnerStmt,
338         T_DropOwnedStmt,
339         T_ReassignOwnedStmt,
340         T_CompositeTypeStmt,
341         T_CreateEnumStmt,
342         T_AlterEnumStmt,
343         T_AlterTSDictionaryStmt,
344         T_AlterTSConfigurationStmt,
345         T_CreateFdwStmt,
346         T_AlterFdwStmt,
347         T_DropFdwStmt,
348         T_CreateForeignServerStmt,
349         T_AlterForeignServerStmt,
350         T_DropForeignServerStmt,
351         T_CreateUserMappingStmt,
352         T_AlterUserMappingStmt,
353         T_DropUserMappingStmt,
354         T_AlterTableSpaceOptionsStmt,
355         T_SecLabelStmt,
356
357         /*
358          * TAGS FOR PARSE TREE NODES (parsenodes.h)
359          */
360         T_A_Expr = 900,
361         T_ColumnRef,
362         T_ParamRef,
363         T_A_Const,
364         T_FuncCall,
365         T_A_Star,
366         T_A_Indices,
367         T_A_Indirection,
368         T_A_ArrayExpr,
369         T_ResTarget,
370         T_TypeCast,
371         T_SortBy,
372         T_WindowDef,
373         T_RangeSubselect,
374         T_RangeFunction,
375         T_TypeName,
376         T_ColumnDef,
377         T_IndexElem,
378         T_Constraint,
379         T_DefElem,
380         T_RangeTblEntry,
381         T_SortGroupClause,
382         T_WindowClause,
383         T_PrivGrantee,
384         T_FuncWithArgs,
385         T_AccessPriv,
386         T_CreateOpClassItem,
387         T_InhRelation,
388         T_FunctionParameter,
389         T_LockingClause,
390         T_RowMarkClause,
391         T_XmlSerialize,
392         T_WithClause,
393         T_CommonTableExpr,
394
395         /*
396          * TAGS FOR RANDOM OTHER STUFF
397          *
398          * These are objects that aren't part of parse/plan/execute node tree
399          * structures, but we give them NodeTags anyway for identification
400          * purposes (usually because they are involved in APIs where we want to
401          * pass multiple object types through the same pointer).
402          */
403         T_TriggerData = 950,            /* in commands/trigger.h */
404         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
405         T_WindowObjectData,                     /* private in nodeWindowAgg.c */
406         T_TIDBitmap,                            /* in nodes/tidbitmap.h */
407         T_InlineCodeBlock                       /* in nodes/parsenodes.h */
408 } NodeTag;
409
410 /*
411  * The first field of a node of any type is guaranteed to be the NodeTag.
412  * Hence the type of any node can be gotten by casting it to Node. Declaring
413  * a variable to be of Node * (instead of void *) can also facilitate
414  * debugging.
415  */
416 typedef struct Node
417 {
418         NodeTag         type;
419 } Node;
420
421 #define nodeTag(nodeptr)                (((Node*)(nodeptr))->type)
422
423 /*
424  * newNode -
425  *        create a new node of the specified size and tag the node with the
426  *        specified tag.
427  *
428  * !WARNING!: Avoid using newNode directly. You should be using the
429  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
430  *
431  * Note: the size argument should always be a compile-time constant, so the
432  * apparent risk of multiple evaluation doesn't matter in practice.
433  */
434 #ifdef __GNUC__
435
436 /* With GCC, we can use a compound statement within an expression */
437 #define newNode(size, tag) \
438 ({      Node   *_result; \
439         AssertMacro((size) >= sizeof(Node));            /* need the tag, at least */ \
440         _result = (Node *) palloc0fast(size); \
441         _result->type = (tag); \
442         _result; \
443 })
444 #else
445
446 /*
447  *      There is no way to dereference the palloc'ed pointer to assign the
448  *      tag, and also return the pointer itself, so we need a holder variable.
449  *      Fortunately, this macro isn't recursive so we just define
450  *      a global variable for this purpose.
451  */
452 extern PGDLLIMPORT Node *newNodeMacroHolder;
453
454 #define newNode(size, tag) \
455 ( \
456         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
457         newNodeMacroHolder = (Node *) palloc0fast(size), \
458         newNodeMacroHolder->type = (tag), \
459         newNodeMacroHolder \
460 )
461 #endif   /* __GNUC__ */
462
463
464 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
465 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
466
467 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
468
469 /* ----------------------------------------------------------------
470  *                                        extern declarations follow
471  * ----------------------------------------------------------------
472  */
473
474 /*
475  * nodes/{outfuncs.c,print.c}
476  */
477 extern char *nodeToString(void *obj);
478
479 /*
480  * nodes/{readfuncs.c,read.c}
481  */
482 extern void *stringToNode(char *str);
483
484 /*
485  * nodes/copyfuncs.c
486  */
487 extern void *copyObject(void *obj);
488
489 /*
490  * nodes/equalfuncs.c
491  */
492 extern bool equal(void *a, void *b);
493
494
495 /*
496  * Typedefs for identifying qualifier selectivities and plan costs as such.
497  * These are just plain "double"s, but declaring a variable as Selectivity
498  * or Cost makes the intent more obvious.
499  *
500  * These could have gone into plannodes.h or some such, but many files
501  * depend on them...
502  */
503 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
504 typedef double Cost;                    /* execution cost (in page-access units) */
505
506
507 /*
508  * CmdType -
509  *        enums for type of operation represented by a Query or PlannedStmt
510  *
511  * This is needed in both parsenodes.h and plannodes.h, so put it here...
512  */
513 typedef enum CmdType
514 {
515         CMD_UNKNOWN,
516         CMD_SELECT,                                     /* select stmt */
517         CMD_UPDATE,                                     /* update stmt */
518         CMD_INSERT,                                     /* insert stmt */
519         CMD_DELETE,
520         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
521                                                                  * etc. */
522         CMD_NOTHING                                     /* dummy command for instead nothing rules
523                                                                  * with qual */
524 } CmdType;
525
526
527 /*
528  * JoinType -
529  *        enums for types of relation joins
530  *
531  * JoinType determines the exact semantics of joining two relations using
532  * a matching qualification.  For example, it tells what to do with a tuple
533  * that has no match in the other relation.
534  *
535  * This is needed in both parsenodes.h and plannodes.h, so put it here...
536  */
537 typedef enum JoinType
538 {
539         /*
540          * The canonical kinds of joins according to the SQL JOIN syntax. Only
541          * these codes can appear in parser output (e.g., JoinExpr nodes).
542          */
543         JOIN_INNER,                                     /* matching tuple pairs only */
544         JOIN_LEFT,                                      /* pairs + unmatched LHS tuples */
545         JOIN_FULL,                                      /* pairs + unmatched LHS + unmatched RHS */
546         JOIN_RIGHT,                                     /* pairs + unmatched RHS tuples */
547
548         /*
549          * Semijoins and anti-semijoins (as defined in relational theory) do not
550          * appear in the SQL JOIN syntax, but there are standard idioms for
551          * representing them (e.g., using EXISTS).      The planner recognizes these
552          * cases and converts them to joins.  So the planner and executor must
553          * support these codes.  NOTE: in JOIN_SEMI output, it is unspecified
554          * which matching RHS row is joined to.  In JOIN_ANTI output, the row is
555          * guaranteed to be null-extended.
556          */
557         JOIN_SEMI,                                      /* 1 copy of each LHS row that has match(es) */
558         JOIN_ANTI,                                      /* 1 copy of each LHS row that has no match */
559
560         /*
561          * These codes are used internally in the planner, but are not supported
562          * by the executor (nor, indeed, by most of the planner).
563          */
564         JOIN_UNIQUE_OUTER,                      /* LHS path must be made unique */
565         JOIN_UNIQUE_INNER                       /* RHS path must be made unique */
566
567         /*
568          * We might need additional join types someday.
569          */
570 } JoinType;
571
572 /*
573  * OUTER joins are those for which pushed-down quals must behave differently
574  * from the join's own quals.  This is in fact everything except INNER and
575  * SEMI joins.  However, this macro must also exclude the JOIN_UNIQUE symbols
576  * since those are temporary proxies for what will eventually be an INNER
577  * join.
578  *
579  * Note: semijoins are a hybrid case, but we choose to treat them as not
580  * being outer joins.  This is okay principally because the SQL syntax makes
581  * it impossible to have a pushed-down qual that refers to the inner relation
582  * of a semijoin; so there is no strong need to distinguish join quals from
583  * pushed-down quals.  This is convenient because for almost all purposes,
584  * quals attached to a semijoin can be treated the same as innerjoin quals.
585  */
586 #define IS_OUTER_JOIN(jointype) \
587         (((1 << (jointype)) & \
588           ((1 << JOIN_LEFT) | \
589            (1 << JOIN_FULL) | \
590            (1 << JOIN_RIGHT) | \
591            (1 << JOIN_ANTI))) != 0)
592
593 #endif   /* NODES_H */