]> granicus.if.org Git - postgresql/blob - src/include/nodes/nodes.h
Add an "argisrow" field to NullTest nodes, following a plan made way back in
[postgresql] / src / include / nodes / nodes.h
1 /*-------------------------------------------------------------------------
2  *
3  * nodes.h
4  *        Definitions for tagged nodes.
5  *
6  *
7  * Portions Copyright (c) 1996-2009, 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.231 2009/10/26 02:26:41 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_PlanRowMark,
78         T_PlanInvalItem,
79
80         /*
81          * TAGS FOR PLAN STATE NODES (execnodes.h)
82          *
83          * These should correspond one-to-one with Plan node types.
84          */
85         T_PlanState = 200,
86         T_ResultState,
87         T_ModifyTableState,
88         T_AppendState,
89         T_RecursiveUnionState,
90         T_BitmapAndState,
91         T_BitmapOrState,
92         T_ScanState,
93         T_SeqScanState,
94         T_IndexScanState,
95         T_BitmapIndexScanState,
96         T_BitmapHeapScanState,
97         T_TidScanState,
98         T_SubqueryScanState,
99         T_FunctionScanState,
100         T_ValuesScanState,
101         T_CteScanState,
102         T_WorkTableScanState,
103         T_JoinState,
104         T_NestLoopState,
105         T_MergeJoinState,
106         T_HashJoinState,
107         T_MaterialState,
108         T_SortState,
109         T_GroupState,
110         T_AggState,
111         T_WindowAggState,
112         T_UniqueState,
113         T_HashState,
114         T_SetOpState,
115         T_LockRowsState,
116         T_LimitState,
117
118         /*
119          * TAGS FOR PRIMITIVE NODES (primnodes.h)
120          */
121         T_Alias = 300,
122         T_RangeVar,
123         T_Expr,
124         T_Var,
125         T_Const,
126         T_Param,
127         T_Aggref,
128         T_WindowFunc,
129         T_ArrayRef,
130         T_FuncExpr,
131         T_NamedArgExpr,
132         T_OpExpr,
133         T_DistinctExpr,
134         T_ScalarArrayOpExpr,
135         T_BoolExpr,
136         T_SubLink,
137         T_SubPlan,
138         T_AlternativeSubPlan,
139         T_FieldSelect,
140         T_FieldStore,
141         T_RelabelType,
142         T_CoerceViaIO,
143         T_ArrayCoerceExpr,
144         T_ConvertRowtypeExpr,
145         T_CaseExpr,
146         T_CaseWhen,
147         T_CaseTestExpr,
148         T_ArrayExpr,
149         T_RowExpr,
150         T_RowCompareExpr,
151         T_CoalesceExpr,
152         T_MinMaxExpr,
153         T_XmlExpr,
154         T_NullIfExpr,
155         T_NullTest,
156         T_BooleanTest,
157         T_CoerceToDomain,
158         T_CoerceToDomainValue,
159         T_SetToDefault,
160         T_CurrentOfExpr,
161         T_TargetEntry,
162         T_RangeTblRef,
163         T_JoinExpr,
164         T_FromExpr,
165         T_IntoClause,
166
167         /*
168          * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
169          *
170          * These correspond (not always one-for-one) to primitive nodes derived
171          * from Expr.
172          */
173         T_ExprState = 400,
174         T_GenericExprState,
175         T_AggrefExprState,
176         T_WindowFuncExprState,
177         T_ArrayRefExprState,
178         T_FuncExprState,
179         T_ScalarArrayOpExprState,
180         T_BoolExprState,
181         T_SubPlanState,
182         T_AlternativeSubPlanState,
183         T_FieldSelectState,
184         T_FieldStoreState,
185         T_CoerceViaIOState,
186         T_ArrayCoerceExprState,
187         T_ConvertRowtypeExprState,
188         T_CaseExprState,
189         T_CaseWhenState,
190         T_ArrayExprState,
191         T_RowExprState,
192         T_RowCompareExprState,
193         T_CoalesceExprState,
194         T_MinMaxExprState,
195         T_XmlExprState,
196         T_NullTestState,
197         T_CoerceToDomainState,
198         T_DomainConstraintState,
199
200         /*
201          * TAGS FOR PLANNER NODES (relation.h)
202          */
203         T_PlannerInfo = 500,
204         T_PlannerGlobal,
205         T_RelOptInfo,
206         T_IndexOptInfo,
207         T_Path,
208         T_IndexPath,
209         T_BitmapHeapPath,
210         T_BitmapAndPath,
211         T_BitmapOrPath,
212         T_NestPath,
213         T_MergePath,
214         T_HashPath,
215         T_TidPath,
216         T_AppendPath,
217         T_ResultPath,
218         T_MaterialPath,
219         T_UniquePath,
220         T_NoOpPath,
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
350         /*
351          * TAGS FOR PARSE TREE NODES (parsenodes.h)
352          */
353         T_A_Expr = 900,
354         T_ColumnRef,
355         T_ParamRef,
356         T_A_Const,
357         T_FuncCall,
358         T_A_Star,
359         T_A_Indices,
360         T_A_Indirection,
361         T_A_ArrayExpr,
362         T_ResTarget,
363         T_TypeCast,
364         T_SortBy,
365         T_WindowDef,
366         T_RangeSubselect,
367         T_RangeFunction,
368         T_TypeName,
369         T_ColumnDef,
370         T_IndexElem,
371         T_Constraint,
372         T_DefElem,
373         T_RangeTblEntry,
374         T_SortGroupClause,
375         T_WindowClause,
376         T_PrivGrantee,
377         T_FuncWithArgs,
378         T_AccessPriv,
379         T_CreateOpClassItem,
380         T_InhRelation,
381         T_FunctionParameter,
382         T_LockingClause,
383         T_RowMarkClause,
384         T_XmlSerialize,
385         T_WithClause,
386         T_CommonTableExpr,
387
388         /*
389          * TAGS FOR RANDOM OTHER STUFF
390          *
391          * These are objects that aren't part of parse/plan/execute node tree
392          * structures, but we give them NodeTags anyway for identification
393          * purposes (usually because they are involved in APIs where we want to
394          * pass multiple object types through the same pointer).
395          */
396         T_TriggerData = 950,            /* in commands/trigger.h */
397         T_ReturnSetInfo,                        /* in nodes/execnodes.h */
398         T_WindowObjectData,                     /* private in nodeWindowAgg.c */
399         T_TIDBitmap,                            /* in nodes/tidbitmap.h */
400         T_InlineCodeBlock                       /* in nodes/parsenodes.h */
401 } NodeTag;
402
403 /*
404  * The first field of a node of any type is guaranteed to be the NodeTag.
405  * Hence the type of any node can be gotten by casting it to Node. Declaring
406  * a variable to be of Node * (instead of void *) can also facilitate
407  * debugging.
408  */
409 typedef struct Node
410 {
411         NodeTag         type;
412 } Node;
413
414 #define nodeTag(nodeptr)                (((Node*)(nodeptr))->type)
415
416 /*
417  * newNode -
418  *        create a new node of the specified size and tag the node with the
419  *        specified tag.
420  *
421  * !WARNING!: Avoid using newNode directly. You should be using the
422  *        macro makeNode.  eg. to create a Query node, use makeNode(Query)
423  *
424  * Note: the size argument should always be a compile-time constant, so the
425  * apparent risk of multiple evaluation doesn't matter in practice.
426  */
427 #ifdef __GNUC__
428
429 /* With GCC, we can use a compound statement within an expression */
430 #define newNode(size, tag) \
431 ({      Node   *_result; \
432         AssertMacro((size) >= sizeof(Node));            /* need the tag, at least */ \
433         _result = (Node *) palloc0fast(size); \
434         _result->type = (tag); \
435         _result; \
436 })
437 #else
438
439 /*
440  *      There is no way to dereference the palloc'ed pointer to assign the
441  *      tag, and also return the pointer itself, so we need a holder variable.
442  *      Fortunately, this macro isn't recursive so we just define
443  *      a global variable for this purpose.
444  */
445 extern PGDLLIMPORT Node *newNodeMacroHolder;
446
447 #define newNode(size, tag) \
448 ( \
449         AssertMacro((size) >= sizeof(Node)),            /* need the tag, at least */ \
450         newNodeMacroHolder = (Node *) palloc0fast(size), \
451         newNodeMacroHolder->type = (tag), \
452         newNodeMacroHolder \
453 )
454 #endif   /* __GNUC__ */
455
456
457 #define makeNode(_type_)                ((_type_ *) newNode(sizeof(_type_),T_##_type_))
458 #define NodeSetTag(nodeptr,t)   (((Node*)(nodeptr))->type = (t))
459
460 #define IsA(nodeptr,_type_)             (nodeTag(nodeptr) == T_##_type_)
461
462 /* ----------------------------------------------------------------
463  *                                        extern declarations follow
464  * ----------------------------------------------------------------
465  */
466
467 /*
468  * nodes/{outfuncs.c,print.c}
469  */
470 extern char *nodeToString(void *obj);
471
472 /*
473  * nodes/{readfuncs.c,read.c}
474  */
475 extern void *stringToNode(char *str);
476
477 /*
478  * nodes/copyfuncs.c
479  */
480 extern void *copyObject(void *obj);
481
482 /*
483  * nodes/equalfuncs.c
484  */
485 extern bool equal(void *a, void *b);
486
487
488 /*
489  * Typedefs for identifying qualifier selectivities and plan costs as such.
490  * These are just plain "double"s, but declaring a variable as Selectivity
491  * or Cost makes the intent more obvious.
492  *
493  * These could have gone into plannodes.h or some such, but many files
494  * depend on them...
495  */
496 typedef double Selectivity;             /* fraction of tuples a qualifier will pass */
497 typedef double Cost;                    /* execution cost (in page-access units) */
498
499
500 /*
501  * CmdType -
502  *        enums for type of operation represented by a Query or PlannedStmt
503  *
504  * This is needed in both parsenodes.h and plannodes.h, so put it here...
505  */
506 typedef enum CmdType
507 {
508         CMD_UNKNOWN,
509         CMD_SELECT,                                     /* select stmt */
510         CMD_UPDATE,                                     /* update stmt */
511         CMD_INSERT,                                     /* insert stmt */
512         CMD_DELETE,
513         CMD_UTILITY,                            /* cmds like create, destroy, copy, vacuum,
514                                                                  * etc. */
515         CMD_NOTHING                                     /* dummy command for instead nothing rules
516                                                                  * with qual */
517 } CmdType;
518
519
520 /*
521  * JoinType -
522  *        enums for types of relation joins
523  *
524  * JoinType determines the exact semantics of joining two relations using
525  * a matching qualification.  For example, it tells what to do with a tuple
526  * that has no match in the other relation.
527  *
528  * This is needed in both parsenodes.h and plannodes.h, so put it here...
529  */
530 typedef enum JoinType
531 {
532         /*
533          * The canonical kinds of joins according to the SQL JOIN syntax. Only
534          * these codes can appear in parser output (e.g., JoinExpr nodes).
535          */
536         JOIN_INNER,                                     /* matching tuple pairs only */
537         JOIN_LEFT,                                      /* pairs + unmatched LHS tuples */
538         JOIN_FULL,                                      /* pairs + unmatched LHS + unmatched RHS */
539         JOIN_RIGHT,                                     /* pairs + unmatched RHS tuples */
540
541         /*
542          * Semijoins and anti-semijoins (as defined in relational theory) do not
543          * appear in the SQL JOIN syntax, but there are standard idioms for
544          * representing them (e.g., using EXISTS).      The planner recognizes these
545          * cases and converts them to joins.  So the planner and executor must
546          * support these codes.  NOTE: in JOIN_SEMI output, it is unspecified
547          * which matching RHS row is joined to.  In JOIN_ANTI output, the row is
548          * guaranteed to be null-extended.
549          */
550         JOIN_SEMI,                                      /* 1 copy of each LHS row that has match(es) */
551         JOIN_ANTI,                                      /* 1 copy of each LHS row that has no match */
552
553         /*
554          * These codes are used internally in the planner, but are not supported
555          * by the executor (nor, indeed, by most of the planner).
556          */
557         JOIN_UNIQUE_OUTER,                      /* LHS path must be made unique */
558         JOIN_UNIQUE_INNER                       /* RHS path must be made unique */
559
560         /*
561          * We might need additional join types someday.
562          */
563 } JoinType;
564
565 /*
566  * OUTER joins are those for which pushed-down quals must behave differently
567  * from the join's own quals.  This is in fact everything except INNER and
568  * SEMI joins.  However, this macro must also exclude the JOIN_UNIQUE symbols
569  * since those are temporary proxies for what will eventually be an INNER
570  * join.
571  *
572  * Note: semijoins are a hybrid case, but we choose to treat them as not
573  * being outer joins.  This is okay principally because the SQL syntax makes
574  * it impossible to have a pushed-down qual that refers to the inner relation
575  * of a semijoin; so there is no strong need to distinguish join quals from
576  * pushed-down quals.  This is convenient because for almost all purposes,
577  * quals attached to a semijoin can be treated the same as innerjoin quals.
578  */
579 #define IS_OUTER_JOIN(jointype) \
580         (((1 << (jointype)) & \
581           ((1 << JOIN_LEFT) | \
582            (1 << JOIN_FULL) | \
583            (1 << JOIN_RIGHT) | \
584            (1 << JOIN_ANTI))) != 0)
585
586 #endif   /* NODES_H */