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