Fix pg_dump bug in the database-level collation patch. "datcollate" and
[PostgreSQL.git] / src / include / nodes / nodes.h
blobd51a26353bdcea34d4465851422d7f5d1ba75364
1 /*-------------------------------------------------------------------------
3 * nodes.h
4 * Definitions for tagged nodes.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
10 * $PostgreSQL$
12 *-------------------------------------------------------------------------
14 #ifndef NODES_H
15 #define NODES_H
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.
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 ...)
26 typedef enum NodeTag
28 T_Invalid = 0,
31 * TAGS FOR EXECUTOR NODES (execnodes.h)
33 T_IndexInfo = 10,
34 T_ExprContext,
35 T_ProjectionInfo,
36 T_JunkFilter,
37 T_ResultRelInfo,
38 T_EState,
39 T_TupleTableSlot,
42 * TAGS FOR PLAN NODES (plannodes.h)
44 T_Plan = 100,
45 T_Result,
46 T_Append,
47 T_BitmapAnd,
48 T_BitmapOr,
49 T_Scan,
50 T_SeqScan,
51 T_IndexScan,
52 T_BitmapIndexScan,
53 T_BitmapHeapScan,
54 T_TidScan,
55 T_SubqueryScan,
56 T_FunctionScan,
57 T_ValuesScan,
58 T_Join,
59 T_NestLoop,
60 T_MergeJoin,
61 T_HashJoin,
62 T_Material,
63 T_Sort,
64 T_Group,
65 T_Agg,
66 T_Unique,
67 T_Hash,
68 T_SetOp,
69 T_Limit,
70 /* this one isn't a subclass of Plan: */
71 T_PlanInvalItem,
74 * TAGS FOR PLAN STATE NODES (execnodes.h)
76 * These should correspond one-to-one with Plan node types.
78 T_PlanState = 200,
79 T_ResultState,
80 T_AppendState,
81 T_BitmapAndState,
82 T_BitmapOrState,
83 T_ScanState,
84 T_SeqScanState,
85 T_IndexScanState,
86 T_BitmapIndexScanState,
87 T_BitmapHeapScanState,
88 T_TidScanState,
89 T_SubqueryScanState,
90 T_FunctionScanState,
91 T_ValuesScanState,
92 T_JoinState,
93 T_NestLoopState,
94 T_MergeJoinState,
95 T_HashJoinState,
96 T_MaterialState,
97 T_SortState,
98 T_GroupState,
99 T_AggState,
100 T_UniqueState,
101 T_HashState,
102 T_SetOpState,
103 T_LimitState,
106 * TAGS FOR PRIMITIVE NODES (primnodes.h)
108 T_Alias = 300,
109 T_RangeVar,
110 T_Expr,
111 T_Var,
112 T_Const,
113 T_Param,
114 T_Aggref,
115 T_ArrayRef,
116 T_FuncExpr,
117 T_OpExpr,
118 T_DistinctExpr,
119 T_ScalarArrayOpExpr,
120 T_BoolExpr,
121 T_SubLink,
122 T_SubPlan,
123 T_AlternativeSubPlan,
124 T_FieldSelect,
125 T_FieldStore,
126 T_RelabelType,
127 T_CoerceViaIO,
128 T_ArrayCoerceExpr,
129 T_ConvertRowtypeExpr,
130 T_CaseExpr,
131 T_CaseWhen,
132 T_CaseTestExpr,
133 T_ArrayExpr,
134 T_RowExpr,
135 T_RowCompareExpr,
136 T_CoalesceExpr,
137 T_MinMaxExpr,
138 T_XmlExpr,
139 T_NullIfExpr,
140 T_NullTest,
141 T_BooleanTest,
142 T_CoerceToDomain,
143 T_CoerceToDomainValue,
144 T_SetToDefault,
145 T_CurrentOfExpr,
146 T_TargetEntry,
147 T_RangeTblRef,
148 T_JoinExpr,
149 T_FromExpr,
150 T_IntoClause,
153 * TAGS FOR EXPRESSION STATE NODES (execnodes.h)
155 * These correspond (not always one-for-one) to primitive nodes derived
156 * from Expr.
158 T_ExprState = 400,
159 T_GenericExprState,
160 T_AggrefExprState,
161 T_ArrayRefExprState,
162 T_FuncExprState,
163 T_ScalarArrayOpExprState,
164 T_BoolExprState,
165 T_SubPlanState,
166 T_AlternativeSubPlanState,
167 T_FieldSelectState,
168 T_FieldStoreState,
169 T_CoerceViaIOState,
170 T_ArrayCoerceExprState,
171 T_ConvertRowtypeExprState,
172 T_CaseExprState,
173 T_CaseWhenState,
174 T_ArrayExprState,
175 T_RowExprState,
176 T_RowCompareExprState,
177 T_CoalesceExprState,
178 T_MinMaxExprState,
179 T_XmlExprState,
180 T_NullTestState,
181 T_CoerceToDomainState,
182 T_DomainConstraintState,
185 * TAGS FOR PLANNER NODES (relation.h)
187 T_PlannerInfo = 500,
188 T_PlannerGlobal,
189 T_RelOptInfo,
190 T_IndexOptInfo,
191 T_Path,
192 T_IndexPath,
193 T_BitmapHeapPath,
194 T_BitmapAndPath,
195 T_BitmapOrPath,
196 T_NestPath,
197 T_MergePath,
198 T_HashPath,
199 T_TidPath,
200 T_AppendPath,
201 T_ResultPath,
202 T_MaterialPath,
203 T_UniquePath,
204 T_EquivalenceClass,
205 T_EquivalenceMember,
206 T_PathKey,
207 T_RestrictInfo,
208 T_InnerIndexscanInfo,
209 T_FlattenedSubLink,
210 T_SpecialJoinInfo,
211 T_AppendRelInfo,
212 T_PlannerParamItem,
215 * TAGS FOR MEMORY NODES (memnodes.h)
217 T_MemoryContext = 600,
218 T_AllocSetContext,
221 * TAGS FOR VALUE NODES (value.h)
223 T_Value = 650,
224 T_Integer,
225 T_Float,
226 T_String,
227 T_BitString,
228 T_Null,
231 * TAGS FOR LIST NODES (pg_list.h)
233 T_List,
234 T_IntList,
235 T_OidList,
238 * TAGS FOR STATEMENT NODES (mostly in parsenodes.h)
240 T_Query = 700,
241 T_PlannedStmt,
242 T_InsertStmt,
243 T_DeleteStmt,
244 T_UpdateStmt,
245 T_SelectStmt,
246 T_AlterTableStmt,
247 T_AlterTableCmd,
248 T_AlterDomainStmt,
249 T_SetOperationStmt,
250 T_GrantStmt,
251 T_GrantRoleStmt,
252 T_ClosePortalStmt,
253 T_ClusterStmt,
254 T_CopyStmt,
255 T_CreateStmt,
256 T_DefineStmt,
257 T_DropStmt,
258 T_TruncateStmt,
259 T_CommentStmt,
260 T_FetchStmt,
261 T_IndexStmt,
262 T_CreateFunctionStmt,
263 T_AlterFunctionStmt,
264 T_RemoveFuncStmt,
265 T_RenameStmt,
266 T_RuleStmt,
267 T_NotifyStmt,
268 T_ListenStmt,
269 T_UnlistenStmt,
270 T_TransactionStmt,
271 T_ViewStmt,
272 T_LoadStmt,
273 T_CreateDomainStmt,
274 T_CreatedbStmt,
275 T_DropdbStmt,
276 T_VacuumStmt,
277 T_ExplainStmt,
278 T_CreateSeqStmt,
279 T_AlterSeqStmt,
280 T_VariableSetStmt,
281 T_VariableShowStmt,
282 T_DiscardStmt,
283 T_CreateTrigStmt,
284 T_DropPropertyStmt,
285 T_CreatePLangStmt,
286 T_DropPLangStmt,
287 T_CreateRoleStmt,
288 T_AlterRoleStmt,
289 T_DropRoleStmt,
290 T_LockStmt,
291 T_ConstraintsSetStmt,
292 T_ReindexStmt,
293 T_CheckPointStmt,
294 T_CreateSchemaStmt,
295 T_AlterDatabaseStmt,
296 T_AlterDatabaseSetStmt,
297 T_AlterRoleSetStmt,
298 T_CreateConversionStmt,
299 T_CreateCastStmt,
300 T_DropCastStmt,
301 T_CreateOpClassStmt,
302 T_CreateOpFamilyStmt,
303 T_AlterOpFamilyStmt,
304 T_RemoveOpClassStmt,
305 T_RemoveOpFamilyStmt,
306 T_PrepareStmt,
307 T_ExecuteStmt,
308 T_DeallocateStmt,
309 T_DeclareCursorStmt,
310 T_CreateTableSpaceStmt,
311 T_DropTableSpaceStmt,
312 T_AlterObjectSchemaStmt,
313 T_AlterOwnerStmt,
314 T_DropOwnedStmt,
315 T_ReassignOwnedStmt,
316 T_CompositeTypeStmt,
317 T_CreateEnumStmt,
318 T_AlterTSDictionaryStmt,
319 T_AlterTSConfigurationStmt,
322 * TAGS FOR PARSE TREE NODES (parsenodes.h)
324 T_A_Expr = 900,
325 T_ColumnRef,
326 T_ParamRef,
327 T_A_Const,
328 T_FuncCall,
329 T_A_Star,
330 T_A_Indices,
331 T_A_Indirection,
332 T_A_ArrayExpr,
333 T_ResTarget,
334 T_TypeCast,
335 T_SortBy,
336 T_RangeSubselect,
337 T_RangeFunction,
338 T_TypeName,
339 T_ColumnDef,
340 T_IndexElem,
341 T_Constraint,
342 T_DefElem,
343 T_RangeTblEntry,
344 T_SortGroupClause,
345 T_FkConstraint,
346 T_PrivGrantee,
347 T_FuncWithArgs,
348 T_PrivTarget,
349 T_CreateOpClassItem,
350 T_InhRelation,
351 T_FunctionParameter,
352 T_LockingClause,
353 T_RowMarkClause,
354 T_XmlSerialize,
357 * TAGS FOR RANDOM OTHER STUFF
359 * These are objects that aren't part of parse/plan/execute node tree
360 * structures, but we give them NodeTags anyway for identification
361 * purposes (usually because they are involved in APIs where we want to
362 * pass multiple object types through the same pointer).
364 T_TriggerData = 950, /* in commands/trigger.h */
365 T_ReturnSetInfo, /* in nodes/execnodes.h */
366 T_TIDBitmap /* in nodes/tidbitmap.h */
367 } NodeTag;
370 * The first field of a node of any type is guaranteed to be the NodeTag.
371 * Hence the type of any node can be gotten by casting it to Node. Declaring
372 * a variable to be of Node * (instead of void *) can also facilitate
373 * debugging.
375 typedef struct Node
377 NodeTag type;
378 } Node;
380 #define nodeTag(nodeptr) (((Node*)(nodeptr))->type)
383 * newNode -
384 * create a new node of the specified size and tag the node with the
385 * specified tag.
387 * !WARNING!: Avoid using newNode directly. You should be using the
388 * macro makeNode. eg. to create a Query node, use makeNode(Query)
390 * Note: the size argument should always be a compile-time constant, so the
391 * apparent risk of multiple evaluation doesn't matter in practice.
393 #ifdef __GNUC__
395 /* With GCC, we can use a compound statement within an expression */
396 #define newNode(size, tag) \
397 ({ Node *_result; \
398 AssertMacro((size) >= sizeof(Node)); /* need the tag, at least */ \
399 _result = (Node *) palloc0fast(size); \
400 _result->type = (tag); \
401 _result; \
404 #else
407 * There is no way to dereference the palloc'ed pointer to assign the
408 * tag, and also return the pointer itself, so we need a holder variable.
409 * Fortunately, this macro isn't recursive so we just define
410 * a global variable for this purpose.
412 extern PGDLLIMPORT Node *newNodeMacroHolder;
414 #define newNode(size, tag) \
416 AssertMacro((size) >= sizeof(Node)), /* need the tag, at least */ \
417 newNodeMacroHolder = (Node *) palloc0fast(size), \
418 newNodeMacroHolder->type = (tag), \
419 newNodeMacroHolder \
422 #endif /* __GNUC__ */
425 #define makeNode(_type_) ((_type_ *) newNode(sizeof(_type_),T_##_type_))
426 #define NodeSetTag(nodeptr,t) (((Node*)(nodeptr))->type = (t))
428 #define IsA(nodeptr,_type_) (nodeTag(nodeptr) == T_##_type_)
430 /* ----------------------------------------------------------------
431 * extern declarations follow
432 * ----------------------------------------------------------------
436 * nodes/{outfuncs.c,print.c}
438 extern char *nodeToString(void *obj);
441 * nodes/{readfuncs.c,read.c}
443 extern void *stringToNode(char *str);
446 * nodes/copyfuncs.c
448 extern void *copyObject(void *obj);
451 * nodes/equalfuncs.c
453 extern bool equal(void *a, void *b);
457 * Typedefs for identifying qualifier selectivities and plan costs as such.
458 * These are just plain "double"s, but declaring a variable as Selectivity
459 * or Cost makes the intent more obvious.
461 * These could have gone into plannodes.h or some such, but many files
462 * depend on them...
464 typedef double Selectivity; /* fraction of tuples a qualifier will pass */
465 typedef double Cost; /* execution cost (in page-access units) */
469 * CmdType -
470 * enums for type of operation represented by a Query or PlannedStmt
472 * This is needed in both parsenodes.h and plannodes.h, so put it here...
474 typedef enum CmdType
476 CMD_UNKNOWN,
477 CMD_SELECT, /* select stmt */
478 CMD_UPDATE, /* update stmt */
479 CMD_INSERT, /* insert stmt */
480 CMD_DELETE,
481 CMD_UTILITY, /* cmds like create, destroy, copy, vacuum,
482 * etc. */
483 CMD_NOTHING /* dummy command for instead nothing rules
484 * with qual */
485 } CmdType;
489 * JoinType -
490 * enums for types of relation joins
492 * JoinType determines the exact semantics of joining two relations using
493 * a matching qualification. For example, it tells what to do with a tuple
494 * that has no match in the other relation.
496 * This is needed in both parsenodes.h and plannodes.h, so put it here...
498 typedef enum JoinType
501 * The canonical kinds of joins according to the SQL JOIN syntax.
502 * Only these codes can appear in parser output (e.g., JoinExpr nodes).
504 JOIN_INNER, /* matching tuple pairs only */
505 JOIN_LEFT, /* pairs + unmatched LHS tuples */
506 JOIN_FULL, /* pairs + unmatched LHS + unmatched RHS */
507 JOIN_RIGHT, /* pairs + unmatched RHS tuples */
510 * Semijoins and anti-semijoins (as defined in relational theory) do
511 * not appear in the SQL JOIN syntax, but there are standard idioms for
512 * representing them (e.g., using EXISTS). The planner recognizes these
513 * cases and converts them to joins. So the planner and executor must
514 * support these codes. NOTE: in JOIN_SEMI output, it is unspecified
515 * which matching RHS row is joined to. In JOIN_ANTI output, the row
516 * is guaranteed to be null-extended.
518 JOIN_SEMI, /* 1 copy of each LHS row that has match(es) */
519 JOIN_ANTI, /* 1 copy of each LHS row that has no match */
522 * These codes are used internally in the planner, but are not supported
523 * by the executor (nor, indeed, by most of the planner).
525 JOIN_UNIQUE_OUTER, /* LHS path must be made unique */
526 JOIN_UNIQUE_INNER /* RHS path must be made unique */
529 * We might need additional join types someday.
531 } JoinType;
534 * OUTER joins are those for which pushed-down quals must behave differently
535 * from the join's own quals. This is in fact everything except INNER joins.
536 * However, this macro must also exclude the JOIN_UNIQUE symbols since those
537 * are temporary proxies for what will eventually be an INNER join.
539 * Note: in some places it is preferable to treat JOIN_SEMI as not being
540 * an outer join, since it doesn't produce null-extended rows. Be aware
541 * of that distinction when deciding whether to use this macro.
543 #define IS_OUTER_JOIN(jointype) \
544 ((jointype) > JOIN_INNER && (jointype) < JOIN_UNIQUE_OUTER)
546 #endif /* NODES_H */