]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
be151ac9f306b64083b81defdacf30354a78b939
[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.191 2007/01/05 22:19:55 momjian 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_PathKeyItem,
194         T_RestrictInfo,
195         T_InnerIndexscanInfo,
196         T_OuterJoinInfo,
197         T_InClauseInfo,
198         T_AppendRelInfo,
199
200         /*
201          * TAGS FOR MEMORY NODES (memnodes.h)
202          */
203         T_MemoryContext = 600,
204         T_AllocSetContext,
205
206         /*
207          * TAGS FOR VALUE NODES (value.h)
208          */
209         T_Value = 650,
210         T_Integer,
211         T_Float,
212         T_String,
213         T_BitString,
214         T_Null,
215
216         /*
217          * TAGS FOR LIST NODES (pg_list.h)
218          */
219         T_List,
220         T_IntList,
221         T_OidList,
222
223         /*
224          * TAGS FOR PARSE TREE NODES (parsenodes.h)
225          */
226         T_Query = 700,
227         T_InsertStmt,
228         T_DeleteStmt,
229         T_UpdateStmt,
230         T_SelectStmt,
231         T_AlterTableStmt,
232         T_AlterTableCmd,
233         T_AlterDomainStmt,
234         T_SetOperationStmt,
235         T_GrantStmt,
236         T_GrantRoleStmt,
237         T_ClosePortalStmt,
238         T_ClusterStmt,
239         T_CopyStmt,
240         T_CreateStmt,
241         T_DefineStmt,
242         T_DropStmt,
243         T_TruncateStmt,
244         T_CommentStmt,
245         T_FetchStmt,
246         T_IndexStmt,
247         T_CreateFunctionStmt,
248         T_AlterFunctionStmt,
249         T_RemoveFuncStmt,
250         T_RenameStmt,
251         T_RuleStmt,
252         T_NotifyStmt,
253         T_ListenStmt,
254         T_UnlistenStmt,
255         T_TransactionStmt,
256         T_ViewStmt,
257         T_LoadStmt,
258         T_CreateDomainStmt,
259         T_CreatedbStmt,
260         T_DropdbStmt,
261         T_VacuumStmt,
262         T_ExplainStmt,
263         T_CreateSeqStmt,
264         T_AlterSeqStmt,
265         T_VariableSetStmt,
266         T_VariableShowStmt,
267         T_VariableResetStmt,
268         T_CreateTrigStmt,
269         T_DropPropertyStmt,
270         T_CreatePLangStmt,
271         T_DropPLangStmt,
272         T_CreateRoleStmt,
273         T_AlterRoleStmt,
274         T_DropRoleStmt,
275         T_LockStmt,
276         T_ConstraintsSetStmt,
277         T_ReindexStmt,
278         T_CheckPointStmt,
279         T_CreateSchemaStmt,
280         T_AlterDatabaseStmt,
281         T_AlterDatabaseSetStmt,
282         T_AlterRoleSetStmt,
283         T_CreateConversionStmt,
284         T_CreateCastStmt,
285         T_DropCastStmt,
286         T_CreateOpClassStmt,
287         T_RemoveOpClassStmt,
288         T_PrepareStmt,
289         T_ExecuteStmt,
290         T_DeallocateStmt,
291         T_DeclareCursorStmt,
292         T_CreateTableSpaceStmt,
293         T_DropTableSpaceStmt,
294         T_AlterObjectSchemaStmt,
295         T_AlterOwnerStmt,
296         T_DropOwnedStmt,
297         T_ReassignOwnedStmt,
298
299         T_A_Expr = 800,
300         T_ColumnRef,
301         T_ParamRef,
302         T_A_Const,
303         T_FuncCall,
304         T_A_Indices,
305         T_A_Indirection,
306         T_ResTarget,
307         T_TypeCast,
308         T_SortBy,
309         T_RangeSubselect,
310         T_RangeFunction,
311         T_TypeName,
312         T_ColumnDef,
313         T_IndexElem,
314         T_Constraint,
315         T_DefElem,
316         T_RangeTblEntry,
317         T_SortClause,
318         T_GroupClause,
319         T_FkConstraint,
320         T_PrivGrantee,
321         T_FuncWithArgs,
322         T_PrivTarget,
323         T_CreateOpClassItem,
324         T_CompositeTypeStmt,
325         T_InhRelation,
326         T_FunctionParameter,
327         T_LockingClause,
328         T_RowMarkClause,
329
330         /*
331          * TAGS FOR RANDOM OTHER STUFF
332          *
333          * These are objects that aren't part of parse/plan/execute node tree
334          * structures, but we give them NodeTags anyway for identification
335          * purposes (usually because they are involved in APIs where we want to
336          * pass multiple object types through the same pointer).
337          */
338         T_TriggerData = 900,            /* in commands/trigger.h */
339         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
340         T_TIDBitmap                                     /* in nodes/tidbitmap.h */
341 } NodeTag;
342
343 /*
344  * The first field of a node of any type is guaranteed to be the NodeTag.
345  * Hence the type of any node can be gotten by casting it to Node. Declaring
346  * a variable to be of Node * (instead of void *) can also facilitate
347  * debugging.
348  */
349 typedef struct Node
350 {
351         NodeTag         type;
352 } Node;
353
354 #define nodeTag(nodeptr)                (((Node*)(nodeptr))->type)
355
356 /*
357  * newNode -
358  *        create a new node of the specified size and tag the node with the
359  *        specified tag.
360  *
361  * !WARNING!: Avoid using newNode directly. You should be using the
362  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
363  *
364  *      There is no way to dereference the palloc'ed pointer to assign the
365  *      tag, and also return the pointer itself, so we need a holder variable.
366  *      Fortunately, this macro isn't recursive so we just define
367  *      a global variable for this purpose.
368  */
369 extern DLLIMPORT Node *newNodeMacroHolder;
370
371 #define newNode(size, tag) \
372 ( \
373         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
374         newNodeMacroHolder = (Node *) palloc0fast(size), \
375         newNodeMacroHolder->type = (tag), \
376         newNodeMacroHolder \
377 )
378
379
380 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
381 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
382
383 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
384
385 /* ----------------------------------------------------------------
386  *                                        extern declarations follow
387  * ----------------------------------------------------------------
388  */
389
390 /*
391  * nodes/{outfuncs.c,print.c}
392  */
393 extern char *nodeToString(void *obj);
394
395 /*
396  * nodes/{readfuncs.c,read.c}
397  */
398 extern void *stringToNode(char *str);
399
400 /*
401  * nodes/copyfuncs.c
402  */
403 extern void *copyObject(void *obj);
404
405 /*
406  * nodes/equalfuncs.c
407  */
408 extern bool equal(void *a, void *b);
409
410
411 /*
412  * Typedefs for identifying qualifier selectivities and plan costs as such.
413  * These are just plain "double"s, but declaring a variable as Selectivity
414  * or Cost makes the intent more obvious.
415  *
416  * These could have gone into plannodes.h or some such, but many files
417  * depend on them...
418  */
419 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
420 typedef double Cost;                    /* execution cost (in page-access units) */
421
422
423 /*
424  * CmdType -
425  *        enums for type of operation represented by a Query
426  *
427  * ??? could have put this in parsenodes.h but many files not in the
428  *        optimizer also need this...
429  */
430 typedef enum CmdType
431 {
432         CMD_UNKNOWN,
433         CMD_SELECT,                                     /* select stmt */
434         CMD_UPDATE,                                     /* update stmt */
435         CMD_INSERT,                                     /* insert stmt */
436         CMD_DELETE,
437         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
438                                                                  * etc. */
439         CMD_NOTHING                                     /* dummy command for instead nothing rules
440                                                                  * with qual */
441 } CmdType;
442
443
444 /*
445  * JoinType -
446  *        enums for types of relation joins
447  *
448  * JoinType determines the exact semantics of joining two relations using
449  * a matching qualification.  For example, it tells what to do with a tuple
450  * that has no match in the other relation.
451  *
452  * This is needed in both parsenodes.h and plannodes.h, so put it here...
453  */
454 typedef enum JoinType
455 {
456         /*
457          * The canonical kinds of joins
458          */
459         JOIN_INNER,                                     /* matching tuple pairs only */
460         JOIN_LEFT,                                      /* pairs + unmatched outer tuples */
461         JOIN_FULL,                                      /* pairs + unmatched outer + unmatched inner */
462         JOIN_RIGHT,                                     /* pairs + unmatched inner tuples */
463
464         /*
465          * These are used for queries like WHERE foo IN (SELECT bar FROM ...).
466          * Only JOIN_IN is actually implemented in the executor; the others are
467          * defined for internal use in the planner.
468          */
469         JOIN_IN,                                        /* at most one result per outer row */
470         JOIN_REVERSE_IN,                        /* at most one result per inner row */
471         JOIN_UNIQUE_OUTER,                      /* outer path must be made unique */
472         JOIN_UNIQUE_INNER                       /* inner path must be made unique */
473
474         /*
475          * We might need additional join types someday.
476          */
477 } JoinType;
478
479 #define IS_OUTER_JOIN(jointype) \
480         ((jointype) == JOIN_LEFT || \
481          (jointype) == JOIN_FULL || \
482          (jointype) == JOIN_RIGHT)
483
484 #endif   /* NODES_H */