]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
Fix whole-row Var evaluation to cope with resjunk columns (again).
[postgresql] / src / include / nodes / nodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * nodes.h
4  *        Definitions for tagged nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2012, 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_Join,
66         T_NestLoop,
67         T_MergeJoin,
68         T_HashJoin,
69         T_Material,
70         T_Sort,
71         T_Group,
72         T_Agg,
73         T_WindowAgg,
74         T_Unique,
75         T_Hash,
76         T_SetOp,
77         T_LockRows,
78         T_Limit,
79         /* these aren't subclasses of Plan: */
80         T_NestLoopParam,
81         T_PlanRowMark,
82         T_PlanInvalItem,
83
84         /*
85          * TAGS FOR PLAN STATE NODES (execnodes.h)
86          *
87          * These should correspond one-to-one with Plan node types.
88          */
89         T_PlanState = 200,
90         T_ResultState,
91         T_ModifyTableState,
92         T_AppendState,
93         T_MergeAppendState,
94         T_RecursiveUnionState,
95         T_BitmapAndState,
96         T_BitmapOrState,
97         T_ScanState,
98         T_SeqScanState,
99         T_IndexScanState,
100         T_IndexOnlyScanState,
101         T_BitmapIndexScanState,
102         T_BitmapHeapScanState,
103         T_TidScanState,
104         T_SubqueryScanState,
105         T_FunctionScanState,
106         T_ValuesScanState,
107         T_CteScanState,
108         T_WorkTableScanState,
109         T_ForeignScanState,
110         T_JoinState,
111         T_NestLoopState,
112         T_MergeJoinState,
113         T_HashJoinState,
114         T_MaterialState,
115         T_SortState,
116         T_GroupState,
117         T_AggState,
118         T_WindowAggState,
119         T_UniqueState,
120         T_HashState,
121         T_SetOpState,
122         T_LockRowsState,
123         T_LimitState,
124
125         /*
126          * TAGS FOR PRIMITIVE NODES (primnodes.h)
127          */
128         T_Alias = 300,
129         T_RangeVar,
130         T_Expr,
131         T_Var,
132         T_Const,
133         T_Param,
134         T_Aggref,
135         T_WindowFunc,
136         T_ArrayRef,
137         T_FuncExpr,
138         T_NamedArgExpr,
139         T_OpExpr,
140         T_DistinctExpr,
141         T_NullIfExpr,
142         T_ScalarArrayOpExpr,
143         T_BoolExpr,
144         T_SubLink,
145         T_SubPlan,
146         T_AlternativeSubPlan,
147         T_FieldSelect,
148         T_FieldStore,
149         T_RelabelType,
150         T_CoerceViaIO,
151         T_ArrayCoerceExpr,
152         T_ConvertRowtypeExpr,
153         T_CollateExpr,
154         T_CaseExpr,
155         T_CaseWhen,
156         T_CaseTestExpr,
157         T_ArrayExpr,
158         T_RowExpr,
159         T_RowCompareExpr,
160         T_CoalesceExpr,
161         T_MinMaxExpr,
162         T_XmlExpr,
163         T_NullTest,
164         T_BooleanTest,
165         T_CoerceToDomain,
166         T_CoerceToDomainValue,
167         T_SetToDefault,
168         T_CurrentOfExpr,
169         T_TargetEntry,
170         T_RangeTblRef,
171         T_JoinExpr,
172         T_FromExpr,
173         T_IntoClause,
174
175         /*
176          * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
177          *
178          * These correspond (not always one-for-one) to primitive nodes derived
179          * from Expr.
180          */
181         T_ExprState = 400,
182         T_GenericExprState,
183         T_WholeRowVarExprState,
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_ParamPathInfo,
217         T_Path,
218         T_IndexPath,
219         T_BitmapHeapPath,
220         T_BitmapAndPath,
221         T_BitmapOrPath,
222         T_NestPath,
223         T_MergePath,
224         T_HashPath,
225         T_TidPath,
226         T_ForeignPath,
227         T_AppendPath,
228         T_MergeAppendPath,
229         T_ResultPath,
230         T_MaterialPath,
231         T_UniquePath,
232         T_EquivalenceClass,
233         T_EquivalenceMember,
234         T_PathKey,
235         T_RestrictInfo,
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_CreateTableAsStmt,
309         T_CreateSeqStmt,
310         T_AlterSeqStmt,
311         T_VariableSetStmt,
312         T_VariableShowStmt,
313         T_DiscardStmt,
314         T_CreateTrigStmt,
315         T_CreatePLangStmt,
316         T_CreateRoleStmt,
317         T_AlterRoleStmt,
318         T_DropRoleStmt,
319         T_LockStmt,
320         T_ConstraintsSetStmt,
321         T_ReindexStmt,
322         T_CheckPointStmt,
323         T_CreateSchemaStmt,
324         T_AlterDatabaseStmt,
325         T_AlterDatabaseSetStmt,
326         T_AlterRoleSetStmt,
327         T_CreateConversionStmt,
328         T_CreateCastStmt,
329         T_CreateOpClassStmt,
330         T_CreateOpFamilyStmt,
331         T_AlterOpFamilyStmt,
332         T_PrepareStmt,
333         T_ExecuteStmt,
334         T_DeallocateStmt,
335         T_DeclareCursorStmt,
336         T_CreateTableSpaceStmt,
337         T_DropTableSpaceStmt,
338         T_AlterObjectSchemaStmt,
339         T_AlterOwnerStmt,
340         T_DropOwnedStmt,
341         T_ReassignOwnedStmt,
342         T_CompositeTypeStmt,
343         T_CreateEnumStmt,
344         T_CreateRangeStmt,
345         T_AlterEnumStmt,
346         T_AlterTSDictionaryStmt,
347         T_AlterTSConfigurationStmt,
348         T_CreateFdwStmt,
349         T_AlterFdwStmt,
350         T_CreateForeignServerStmt,
351         T_AlterForeignServerStmt,
352         T_CreateUserMappingStmt,
353         T_AlterUserMappingStmt,
354         T_DropUserMappingStmt,
355         T_AlterTableSpaceOptionsStmt,
356         T_SecLabelStmt,
357         T_CreateForeignTableStmt,
358         T_CreateExtensionStmt,
359         T_AlterExtensionStmt,
360         T_AlterExtensionContentsStmt,
361         T_CreateEventTrigStmt,
362         T_AlterEventTrigStmt,
363
364         /*
365          * TAGS FOR PARSE TREE NODES (parsenodes.h)
366          */
367         T_A_Expr = 900,
368         T_ColumnRef,
369         T_ParamRef,
370         T_A_Const,
371         T_FuncCall,
372         T_A_Star,
373         T_A_Indices,
374         T_A_Indirection,
375         T_A_ArrayExpr,
376         T_ResTarget,
377         T_TypeCast,
378         T_CollateClause,
379         T_SortBy,
380         T_WindowDef,
381         T_RangeSubselect,
382         T_RangeFunction,
383         T_TypeName,
384         T_ColumnDef,
385         T_IndexElem,
386         T_Constraint,
387         T_DefElem,
388         T_RangeTblEntry,
389         T_SortGroupClause,
390         T_WindowClause,
391         T_PrivGrantee,
392         T_FuncWithArgs,
393         T_AccessPriv,
394         T_CreateOpClassItem,
395         T_TableLikeClause,
396         T_FunctionParameter,
397         T_LockingClause,
398         T_RowMarkClause,
399         T_XmlSerialize,
400         T_WithClause,
401         T_CommonTableExpr,
402
403         /*
404          * TAGS FOR REPLICATION GRAMMAR PARSE NODES (replnodes.h)
405          */
406         T_IdentifySystemCmd,
407         T_BaseBackupCmd,
408         T_StartReplicationCmd,
409
410         /*
411          * TAGS FOR RANDOM OTHER STUFF
412          *
413          * These are objects that aren't part of parse/plan/execute node tree
414          * structures, but we give them NodeTags anyway for identification
415          * purposes (usually because they are involved in APIs where we want to
416          * pass multiple object types through the same pointer).
417          */
418         T_TriggerData = 950,            /* in commands/trigger.h */
419         T_EventTriggerData,                     /* in commands/event_trigger.h */
420         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
421         T_WindowObjectData,                     /* private in nodeWindowAgg.c */
422         T_TIDBitmap,                            /* in nodes/tidbitmap.h */
423         T_InlineCodeBlock,                      /* in nodes/parsenodes.h */
424         T_FdwRoutine                            /* in foreign/fdwapi.h */
425 } NodeTag;
426
427 /*
428  * The first field of a node of any type is guaranteed to be the NodeTag.
429  * Hence the type of any node can be gotten by casting it to Node. Declaring
430  * a variable to be of Node * (instead of void *) can also facilitate
431  * debugging.
432  */
433 typedef struct Node
434 {
435         NodeTag         type;
436 } Node;
437
438 #define nodeTag(nodeptr)                (((const Node*)(nodeptr))->type)
439
440 /*
441  * newNode -
442  *        create a new node of the specified size and tag the node with the
443  *        specified tag.
444  *
445  * !WARNING!: Avoid using newNode directly. You should be using the
446  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
447  *
448  * Note: the size argument should always be a compile-time constant, so the
449  * apparent risk of multiple evaluation doesn't matter in practice.
450  */
451 #ifdef __GNUC__
452
453 /* With GCC, we can use a compound statement within an expression */
454 #define newNode(size, tag) \
455 ({      Node   *_result; \
456         AssertMacro((size) >= sizeof(Node));            /* need the tag, at least */ \
457         _result = (Node *) palloc0fast(size); \
458         _result->type = (tag); \
459         _result; \
460 })
461 #else
462
463 /*
464  *      There is no way to dereference the palloc'ed pointer to assign the
465  *      tag, and also return the pointer itself, so we need a holder variable.
466  *      Fortunately, this macro isn't recursive so we just define
467  *      a global variable for this purpose.
468  */
469 extern PGDLLIMPORT Node *newNodeMacroHolder;
470
471 #define newNode(size, tag) \
472 ( \
473         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
474         newNodeMacroHolder = (Node *) palloc0fast(size), \
475         newNodeMacroHolder->type = (tag), \
476         newNodeMacroHolder \
477 )
478 #endif   /* __GNUC__ */
479
480
481 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
482 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
483
484 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
485
486 /* ----------------------------------------------------------------
487  *                                        extern declarations follow
488  * ----------------------------------------------------------------
489  */
490
491 /*
492  * nodes/{outfuncs.c,print.c}
493  */
494 extern char *nodeToString(const void *obj);
495
496 /*
497  * nodes/{readfuncs.c,read.c}
498  */
499 extern void *stringToNode(char *str);
500
501 /*
502  * nodes/copyfuncs.c
503  */
504 extern void *copyObject(const void *obj);
505
506 /*
507  * nodes/equalfuncs.c
508  */
509 extern bool equal(const void *a, const void *b);
510
511
512 /*
513  * Typedefs for identifying qualifier selectivities and plan costs as such.
514  * These are just plain "double"s, but declaring a variable as Selectivity
515  * or Cost makes the intent more obvious.
516  *
517  * These could have gone into plannodes.h or some such, but many files
518  * depend on them...
519  */
520 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
521 typedef double Cost;                    /* execution cost (in page-access units) */
522
523
524 /*
525  * CmdType -
526  *        enums for type of operation represented by a Query or PlannedStmt
527  *
528  * This is needed in both parsenodes.h and plannodes.h, so put it here...
529  */
530 typedef enum CmdType
531 {
532         CMD_UNKNOWN,
533         CMD_SELECT,                                     /* select stmt */
534         CMD_UPDATE,                                     /* update stmt */
535         CMD_INSERT,                                     /* insert stmt */
536         CMD_DELETE,
537         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
538                                                                  * etc. */
539         CMD_NOTHING                                     /* dummy command for instead nothing rules
540                                                                  * with qual */
541 } CmdType;
542
543
544 /*
545  * JoinType -
546  *        enums for types of relation joins
547  *
548  * JoinType determines the exact semantics of joining two relations using
549  * a matching qualification.  For example, it tells what to do with a tuple
550  * that has no match in the other relation.
551  *
552  * This is needed in both parsenodes.h and plannodes.h, so put it here...
553  */
554 typedef enum JoinType
555 {
556         /*
557          * The canonical kinds of joins according to the SQL JOIN syntax. Only
558          * these codes can appear in parser output (e.g., JoinExpr nodes).
559          */
560         JOIN_INNER,                                     /* matching tuple pairs only */
561         JOIN_LEFT,                                      /* pairs + unmatched LHS tuples */
562         JOIN_FULL,                                      /* pairs + unmatched LHS + unmatched RHS */
563         JOIN_RIGHT,                                     /* pairs + unmatched RHS tuples */
564
565         /*
566          * Semijoins and anti-semijoins (as defined in relational theory) do not
567          * appear in the SQL JOIN syntax, but there are standard idioms for
568          * representing them (e.g., using EXISTS).      The planner recognizes these
569          * cases and converts them to joins.  So the planner and executor must
570          * support these codes.  NOTE: in JOIN_SEMI output, it is unspecified
571          * which matching RHS row is joined to.  In JOIN_ANTI output, the row is
572          * guaranteed to be null-extended.
573          */
574         JOIN_SEMI,                                      /* 1 copy of each LHS row that has match(es) */
575         JOIN_ANTI,                                      /* 1 copy of each LHS row that has no match */
576
577         /*
578          * These codes are used internally in the planner, but are not supported
579          * by the executor (nor, indeed, by most of the planner).
580          */
581         JOIN_UNIQUE_OUTER,                      /* LHS path must be made unique */
582         JOIN_UNIQUE_INNER                       /* RHS path must be made unique */
583
584         /*
585          * We might need additional join types someday.
586          */
587 } JoinType;
588
589 /*
590  * OUTER joins are those for which pushed-down quals must behave differently
591  * from the join's own quals.  This is in fact everything except INNER and
592  * SEMI joins.  However, this macro must also exclude the JOIN_UNIQUE symbols
593  * since those are temporary proxies for what will eventually be an INNER
594  * join.
595  *
596  * Note: semijoins are a hybrid case, but we choose to treat them as not
597  * being outer joins.  This is okay principally because the SQL syntax makes
598  * it impossible to have a pushed-down qual that refers to the inner relation
599  * of a semijoin; so there is no strong need to distinguish join quals from
600  * pushed-down quals.  This is convenient because for almost all purposes,
601  * quals attached to a semijoin can be treated the same as innerjoin quals.
602  */
603 #define IS_OUTER_JOIN(jointype) \
604         (((1 << (jointype)) & \
605           ((1 << JOIN_LEFT) | \
606            (1 << JOIN_FULL) | \
607            (1 << JOIN_RIGHT) | \
608            (1 << JOIN_ANTI))) != 0)
609
610 #endif   /* NODES_H */