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