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