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