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