]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
2452f792940788985bb36782abc2ab9d9bfbb7e4
[postgresql] / src / include / nodes / nodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * nodes.h
4  *        Definitions for tagged nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $PostgreSQL: pgsql/src/include/nodes/nodes.h,v 1.194 2007/02/03 14:06:55 petere Exp $
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_Append,
47         T_BitmapAnd,
48         T_BitmapOr,
49         T_Scan,
50         T_SeqScan,
51         T_IndexScan,
52         T_BitmapIndexScan,
53         T_BitmapHeapScan,
54         T_TidScan,
55         T_SubqueryScan,
56         T_FunctionScan,
57         T_ValuesScan,
58         T_Join,
59         T_NestLoop,
60         T_MergeJoin,
61         T_HashJoin,
62         T_Material,
63         T_Sort,
64         T_Group,
65         T_Agg,
66         T_Unique,
67         T_Hash,
68         T_SetOp,
69         T_Limit,
70
71         /*
72          * TAGS FOR PLAN STATE NODES (execnodes.h)
73          *
74          * These should correspond one-to-one with Plan node types.
75          */
76         T_PlanState = 200,
77         T_ResultState,
78         T_AppendState,
79         T_BitmapAndState,
80         T_BitmapOrState,
81         T_ScanState,
82         T_SeqScanState,
83         T_IndexScanState,
84         T_BitmapIndexScanState,
85         T_BitmapHeapScanState,
86         T_TidScanState,
87         T_SubqueryScanState,
88         T_FunctionScanState,
89         T_ValuesScanState,
90         T_JoinState,
91         T_NestLoopState,
92         T_MergeJoinState,
93         T_HashJoinState,
94         T_MaterialState,
95         T_SortState,
96         T_GroupState,
97         T_AggState,
98         T_UniqueState,
99         T_HashState,
100         T_SetOpState,
101         T_LimitState,
102
103         /*
104          * TAGS FOR PRIMITIVE NODES (primnodes.h)
105          */
106         T_Alias = 300,
107         T_RangeVar,
108         T_Expr,
109         T_Var,
110         T_Const,
111         T_Param,
112         T_Aggref,
113         T_ArrayRef,
114         T_FuncExpr,
115         T_OpExpr,
116         T_DistinctExpr,
117         T_ScalarArrayOpExpr,
118         T_BoolExpr,
119         T_SubLink,
120         T_SubPlan,
121         T_FieldSelect,
122         T_FieldStore,
123         T_RelabelType,
124         T_ConvertRowtypeExpr,
125         T_CaseExpr,
126         T_CaseWhen,
127         T_CaseTestExpr,
128         T_ArrayExpr,
129         T_RowExpr,
130         T_RowCompareExpr,
131         T_CoalesceExpr,
132         T_MinMaxExpr,
133         T_XmlExpr,
134         T_NullIfExpr,
135         T_NullTest,
136         T_BooleanTest,
137         T_CoerceToDomain,
138         T_CoerceToDomainValue,
139         T_SetToDefault,
140         T_TargetEntry,
141         T_RangeTblRef,
142         T_JoinExpr,
143         T_FromExpr,
144
145         /*
146          * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
147          *
148          * These correspond (not always one-for-one) to primitive nodes derived
149          * from Expr.
150          */
151         T_ExprState = 400,
152         T_GenericExprState,
153         T_AggrefExprState,
154         T_ArrayRefExprState,
155         T_FuncExprState,
156         T_ScalarArrayOpExprState,
157         T_BoolExprState,
158         T_SubPlanState,
159         T_FieldSelectState,
160         T_FieldStoreState,
161         T_ConvertRowtypeExprState,
162         T_CaseExprState,
163         T_CaseWhenState,
164         T_ArrayExprState,
165         T_RowExprState,
166         T_RowCompareExprState,
167         T_CoalesceExprState,
168         T_MinMaxExprState,
169         T_XmlExprState,
170         T_NullTestState,
171         T_CoerceToDomainState,
172         T_DomainConstraintState,
173
174         /*
175          * TAGS FOR PLANNER NODES (relation.h)
176          */
177         T_PlannerInfo = 500,
178         T_RelOptInfo,
179         T_IndexOptInfo,
180         T_Path,
181         T_IndexPath,
182         T_BitmapHeapPath,
183         T_BitmapAndPath,
184         T_BitmapOrPath,
185         T_NestPath,
186         T_MergePath,
187         T_HashPath,
188         T_TidPath,
189         T_AppendPath,
190         T_ResultPath,
191         T_MaterialPath,
192         T_UniquePath,
193         T_EquivalenceClass,
194         T_EquivalenceMember,
195         T_PathKey,
196         T_RestrictInfo,
197         T_InnerIndexscanInfo,
198         T_OuterJoinInfo,
199         T_InClauseInfo,
200         T_AppendRelInfo,
201
202         /*
203          * TAGS FOR MEMORY NODES (memnodes.h)
204          */
205         T_MemoryContext = 600,
206         T_AllocSetContext,
207
208         /*
209          * TAGS FOR VALUE NODES (value.h)
210          */
211         T_Value = 650,
212         T_Integer,
213         T_Float,
214         T_String,
215         T_BitString,
216         T_Null,
217
218         /*
219          * TAGS FOR LIST NODES (pg_list.h)
220          */
221         T_List,
222         T_IntList,
223         T_OidList,
224
225         /*
226          * TAGS FOR PARSE TREE NODES (parsenodes.h)
227          */
228         T_Query = 700,
229         T_InsertStmt,
230         T_DeleteStmt,
231         T_UpdateStmt,
232         T_SelectStmt,
233         T_AlterTableStmt,
234         T_AlterTableCmd,
235         T_AlterDomainStmt,
236         T_SetOperationStmt,
237         T_GrantStmt,
238         T_GrantRoleStmt,
239         T_ClosePortalStmt,
240         T_ClusterStmt,
241         T_CopyStmt,
242         T_CreateStmt,
243         T_DefineStmt,
244         T_DropStmt,
245         T_TruncateStmt,
246         T_CommentStmt,
247         T_FetchStmt,
248         T_IndexStmt,
249         T_CreateFunctionStmt,
250         T_AlterFunctionStmt,
251         T_RemoveFuncStmt,
252         T_RenameStmt,
253         T_RuleStmt,
254         T_NotifyStmt,
255         T_ListenStmt,
256         T_UnlistenStmt,
257         T_TransactionStmt,
258         T_ViewStmt,
259         T_LoadStmt,
260         T_CreateDomainStmt,
261         T_CreatedbStmt,
262         T_DropdbStmt,
263         T_VacuumStmt,
264         T_ExplainStmt,
265         T_CreateSeqStmt,
266         T_AlterSeqStmt,
267         T_VariableSetStmt,
268         T_VariableShowStmt,
269         T_VariableResetStmt,
270         T_CreateTrigStmt,
271         T_DropPropertyStmt,
272         T_CreatePLangStmt,
273         T_DropPLangStmt,
274         T_CreateRoleStmt,
275         T_AlterRoleStmt,
276         T_DropRoleStmt,
277         T_LockStmt,
278         T_ConstraintsSetStmt,
279         T_ReindexStmt,
280         T_CheckPointStmt,
281         T_CreateSchemaStmt,
282         T_AlterDatabaseStmt,
283         T_AlterDatabaseSetStmt,
284         T_AlterRoleSetStmt,
285         T_CreateConversionStmt,
286         T_CreateCastStmt,
287         T_DropCastStmt,
288         T_CreateOpClassStmt,
289         T_CreateOpFamilyStmt,
290         T_AlterOpFamilyStmt,
291         T_RemoveOpClassStmt,
292         T_RemoveOpFamilyStmt,
293         T_PrepareStmt,
294         T_ExecuteStmt,
295         T_DeallocateStmt,
296         T_DeclareCursorStmt,
297         T_CreateTableSpaceStmt,
298         T_DropTableSpaceStmt,
299         T_AlterObjectSchemaStmt,
300         T_AlterOwnerStmt,
301         T_DropOwnedStmt,
302         T_ReassignOwnedStmt,
303
304         T_A_Expr = 800,
305         T_ColumnRef,
306         T_ParamRef,
307         T_A_Const,
308         T_FuncCall,
309         T_A_Indices,
310         T_A_Indirection,
311         T_ResTarget,
312         T_TypeCast,
313         T_SortBy,
314         T_RangeSubselect,
315         T_RangeFunction,
316         T_TypeName,
317         T_ColumnDef,
318         T_IndexElem,
319         T_Constraint,
320         T_DefElem,
321         T_RangeTblEntry,
322         T_SortClause,
323         T_GroupClause,
324         T_FkConstraint,
325         T_PrivGrantee,
326         T_FuncWithArgs,
327         T_PrivTarget,
328         T_CreateOpClassItem,
329         T_CompositeTypeStmt,
330         T_InhRelation,
331         T_FunctionParameter,
332         T_LockingClause,
333         T_RowMarkClause,
334         T_XmlSerialize,
335
336         /*
337          * TAGS FOR RANDOM OTHER STUFF
338          *
339          * These are objects that aren't part of parse/plan/execute node tree
340          * structures, but we give them NodeTags anyway for identification
341          * purposes (usually because they are involved in APIs where we want to
342          * pass multiple object types through the same pointer).
343          */
344         T_TriggerData = 900,            /* in commands/trigger.h */
345         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
346         T_TIDBitmap                                     /* in nodes/tidbitmap.h */
347 } NodeTag;
348
349 /*
350  * The first field of a node of any type is guaranteed to be the NodeTag.
351  * Hence the type of any node can be gotten by casting it to Node. Declaring
352  * a variable to be of Node * (instead of void *) can also facilitate
353  * debugging.
354  */
355 typedef struct Node
356 {
357         NodeTag         type;
358 } Node;
359
360 #define nodeTag(nodeptr)                (((Node*)(nodeptr))->type)
361
362 /*
363  * newNode -
364  *        create a new node of the specified size and tag the node with the
365  *        specified tag.
366  *
367  * !WARNING!: Avoid using newNode directly. You should be using the
368  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
369  *
370  *      There is no way to dereference the palloc'ed pointer to assign the
371  *      tag, and also return the pointer itself, so we need a holder variable.
372  *      Fortunately, this macro isn't recursive so we just define
373  *      a global variable for this purpose.
374  */
375 extern DLLIMPORT Node *newNodeMacroHolder;
376
377 #define newNode(size, tag) \
378 ( \
379         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
380         newNodeMacroHolder = (Node *) palloc0fast(size), \
381         newNodeMacroHolder->type = (tag), \
382         newNodeMacroHolder \
383 )
384
385
386 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
387 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
388
389 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
390
391 /* ----------------------------------------------------------------
392  *                                        extern declarations follow
393  * ----------------------------------------------------------------
394  */
395
396 /*
397  * nodes/{outfuncs.c,print.c}
398  */
399 extern char *nodeToString(void *obj);
400
401 /*
402  * nodes/{readfuncs.c,read.c}
403  */
404 extern void *stringToNode(char *str);
405
406 /*
407  * nodes/copyfuncs.c
408  */
409 extern void *copyObject(void *obj);
410
411 /*
412  * nodes/equalfuncs.c
413  */
414 extern bool equal(void *a, void *b);
415
416
417 /*
418  * Typedefs for identifying qualifier selectivities and plan costs as such.
419  * These are just plain "double"s, but declaring a variable as Selectivity
420  * or Cost makes the intent more obvious.
421  *
422  * These could have gone into plannodes.h or some such, but many files
423  * depend on them...
424  */
425 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
426 typedef double Cost;                    /* execution cost (in page-access units) */
427
428
429 /*
430  * CmdType -
431  *        enums for type of operation represented by a Query
432  *
433  * ??? could have put this in parsenodes.h but many files not in the
434  *        optimizer also need this...
435  */
436 typedef enum CmdType
437 {
438         CMD_UNKNOWN,
439         CMD_SELECT,                                     /* select stmt */
440         CMD_UPDATE,                                     /* update stmt */
441         CMD_INSERT,                                     /* insert stmt */
442         CMD_DELETE,
443         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
444                                                                  * etc. */
445         CMD_NOTHING                                     /* dummy command for instead nothing rules
446                                                                  * with qual */
447 } CmdType;
448
449
450 /*
451  * JoinType -
452  *        enums for types of relation joins
453  *
454  * JoinType determines the exact semantics of joining two relations using
455  * a matching qualification.  For example, it tells what to do with a tuple
456  * that has no match in the other relation.
457  *
458  * This is needed in both parsenodes.h and plannodes.h, so put it here...
459  */
460 typedef enum JoinType
461 {
462         /*
463          * The canonical kinds of joins
464          */
465         JOIN_INNER,                                     /* matching tuple pairs only */
466         JOIN_LEFT,                                      /* pairs + unmatched outer tuples */
467         JOIN_FULL,                                      /* pairs + unmatched outer + unmatched inner */
468         JOIN_RIGHT,                                     /* pairs + unmatched inner tuples */
469
470         /*
471          * These are used for queries like WHERE foo IN (SELECT bar FROM ...).
472          * Only JOIN_IN is actually implemented in the executor; the others are
473          * defined for internal use in the planner.
474          */
475         JOIN_IN,                                        /* at most one result per outer row */
476         JOIN_REVERSE_IN,                        /* at most one result per inner row */
477         JOIN_UNIQUE_OUTER,                      /* outer path must be made unique */
478         JOIN_UNIQUE_INNER                       /* inner path must be made unique */
479
480         /*
481          * We might need additional join types someday.
482          */
483 } JoinType;
484
485 #define IS_OUTER_JOIN(jointype) \
486         ((jointype) == JOIN_LEFT || \
487          (jointype) == JOIN_FULL || \
488          (jointype) == JOIN_RIGHT)
489
490 #endif   /* NODES_H */