]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
SQL/MED catalog manipulation facilities
[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.216 2008/12/19 16:25:19 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_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         T_CreateFdwStmt,
329         T_AlterFdwStmt,
330         T_DropFdwStmt,
331         T_CreateForeignServerStmt,
332         T_AlterForeignServerStmt,
333         T_DropForeignServerStmt,
334         T_CreateUserMappingStmt,
335         T_AlterUserMappingStmt,
336         T_DropUserMappingStmt,
337
338         /*
339          * TAGS FOR PARSE TREE NODES (parsenodes.h)
340          */
341         T_A_Expr = 900,
342         T_ColumnRef,
343         T_ParamRef,
344         T_A_Const,
345         T_FuncCall,
346         T_A_Star,
347         T_A_Indices,
348         T_A_Indirection,
349         T_A_ArrayExpr,
350         T_ResTarget,
351         T_TypeCast,
352         T_SortBy,
353         T_RangeSubselect,
354         T_RangeFunction,
355         T_TypeName,
356         T_ColumnDef,
357         T_IndexElem,
358         T_Constraint,
359         T_DefElem,
360         T_OptionDefElem,
361         T_RangeTblEntry,
362         T_SortGroupClause,
363         T_FkConstraint,
364         T_PrivGrantee,
365         T_FuncWithArgs,
366         T_PrivTarget,
367         T_CreateOpClassItem,
368         T_InhRelation,
369         T_FunctionParameter,
370         T_LockingClause,
371         T_RowMarkClause,
372         T_XmlSerialize,
373         T_WithClause,
374         T_CommonTableExpr,
375
376         /*
377          * TAGS FOR RANDOM OTHER STUFF
378          *
379          * These are objects that aren't part of parse/plan/execute node tree
380          * structures, but we give them NodeTags anyway for identification
381          * purposes (usually because they are involved in APIs where we want to
382          * pass multiple object types through the same pointer).
383          */
384         T_TriggerData = 950,            /* in commands/trigger.h */
385         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
386         T_TIDBitmap                                     /* in nodes/tidbitmap.h */
387 } NodeTag;
388
389 /*
390  * The first field of a node of any type is guaranteed to be the NodeTag.
391  * Hence the type of any node can be gotten by casting it to Node. Declaring
392  * a variable to be of Node * (instead of void *) can also facilitate
393  * debugging.
394  */
395 typedef struct Node
396 {
397         NodeTag         type;
398 } Node;
399
400 #define nodeTag(nodeptr)                (((Node*)(nodeptr))->type)
401
402 /*
403  * newNode -
404  *        create a new node of the specified size and tag the node with the
405  *        specified tag.
406  *
407  * !WARNING!: Avoid using newNode directly. You should be using the
408  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
409  *
410  * Note: the size argument should always be a compile-time constant, so the
411  * apparent risk of multiple evaluation doesn't matter in practice.
412  */
413 #ifdef __GNUC__
414
415 /* With GCC, we can use a compound statement within an expression */
416 #define newNode(size, tag) \
417 ({      Node   *_result; \
418         AssertMacro((size) >= sizeof(Node));            /* need the tag, at least */ \
419         _result = (Node *) palloc0fast(size); \
420         _result->type = (tag); \
421         _result; \
422 })
423
424 #else
425
426 /*
427  *      There is no way to dereference the palloc'ed pointer to assign the
428  *      tag, and also return the pointer itself, so we need a holder variable.
429  *      Fortunately, this macro isn't recursive so we just define
430  *      a global variable for this purpose.
431  */
432 extern PGDLLIMPORT Node *newNodeMacroHolder;
433
434 #define newNode(size, tag) \
435 ( \
436         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
437         newNodeMacroHolder = (Node *) palloc0fast(size), \
438         newNodeMacroHolder->type = (tag), \
439         newNodeMacroHolder \
440 )
441
442 #endif   /* __GNUC__ */
443
444
445 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
446 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
447
448 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
449
450 /* ----------------------------------------------------------------
451  *                                        extern declarations follow
452  * ----------------------------------------------------------------
453  */
454
455 /*
456  * nodes/{outfuncs.c,print.c}
457  */
458 extern char *nodeToString(void *obj);
459
460 /*
461  * nodes/{readfuncs.c,read.c}
462  */
463 extern void *stringToNode(char *str);
464
465 /*
466  * nodes/copyfuncs.c
467  */
468 extern void *copyObject(void *obj);
469
470 /*
471  * nodes/equalfuncs.c
472  */
473 extern bool equal(void *a, void *b);
474
475
476 /*
477  * Typedefs for identifying qualifier selectivities and plan costs as such.
478  * These are just plain "double"s, but declaring a variable as Selectivity
479  * or Cost makes the intent more obvious.
480  *
481  * These could have gone into plannodes.h or some such, but many files
482  * depend on them...
483  */
484 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
485 typedef double Cost;                    /* execution cost (in page-access units) */
486
487
488 /*
489  * CmdType -
490  *        enums for type of operation represented by a Query or PlannedStmt
491  *
492  * This is needed in both parsenodes.h and plannodes.h, so put it here...
493  */
494 typedef enum CmdType
495 {
496         CMD_UNKNOWN,
497         CMD_SELECT,                                     /* select stmt */
498         CMD_UPDATE,                                     /* update stmt */
499         CMD_INSERT,                                     /* insert stmt */
500         CMD_DELETE,
501         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
502                                                                  * etc. */
503         CMD_NOTHING                                     /* dummy command for instead nothing rules
504                                                                  * with qual */
505 } CmdType;
506
507
508 /*
509  * JoinType -
510  *        enums for types of relation joins
511  *
512  * JoinType determines the exact semantics of joining two relations using
513  * a matching qualification.  For example, it tells what to do with a tuple
514  * that has no match in the other relation.
515  *
516  * This is needed in both parsenodes.h and plannodes.h, so put it here...
517  */
518 typedef enum JoinType
519 {
520         /*
521          * The canonical kinds of joins according to the SQL JOIN syntax.
522          * Only these codes can appear in parser output (e.g., JoinExpr nodes).
523          */
524         JOIN_INNER,                                     /* matching tuple pairs only */
525         JOIN_LEFT,                                      /* pairs + unmatched LHS tuples */
526         JOIN_FULL,                                      /* pairs + unmatched LHS + unmatched RHS */
527         JOIN_RIGHT,                                     /* pairs + unmatched RHS tuples */
528
529         /*
530          * Semijoins and anti-semijoins (as defined in relational theory) do
531          * not appear in the SQL JOIN syntax, but there are standard idioms for
532          * representing them (e.g., using EXISTS).  The planner recognizes these
533          * cases and converts them to joins.  So the planner and executor must
534          * support these codes.  NOTE: in JOIN_SEMI output, it is unspecified
535          * which matching RHS row is joined to.  In JOIN_ANTI output, the row
536          * is guaranteed to be null-extended.
537          */
538         JOIN_SEMI,                                      /* 1 copy of each LHS row that has match(es) */
539         JOIN_ANTI,                                      /* 1 copy of each LHS row that has no match */
540
541         /*
542          * These codes are used internally in the planner, but are not supported
543          * by the executor (nor, indeed, by most of the planner).
544          */
545         JOIN_UNIQUE_OUTER,                      /* LHS path must be made unique */
546         JOIN_UNIQUE_INNER                       /* RHS path must be made unique */
547
548         /*
549          * We might need additional join types someday.
550          */
551 } JoinType;
552
553 /*
554  * OUTER joins are those for which pushed-down quals must behave differently
555  * from the join's own quals.  This is in fact everything except INNER and
556  * SEMI joins.  However, this macro must also exclude the JOIN_UNIQUE symbols
557  * since those are temporary proxies for what will eventually be an INNER
558  * join.
559  *
560  * Note: semijoins are a hybrid case, but we choose to treat them as not
561  * being outer joins.  This is okay principally because the SQL syntax makes
562  * it impossible to have a pushed-down qual that refers to the inner relation
563  * of a semijoin; so there is no strong need to distinguish join quals from
564  * pushed-down quals.  This is convenient because for almost all purposes,
565  * quals attached to a semijoin can be treated the same as innerjoin quals.
566  */
567 #define IS_OUTER_JOIN(jointype) \
568         (((1 << (jointype)) & \
569           ((1 << JOIN_LEFT) | \
570            (1 << JOIN_FULL) | \
571            (1 << JOIN_RIGHT) | \
572            (1 << JOIN_ANTI))) != 0)
573
574 #endif   /* NODES_H */