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