nodes.h 8.17 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * nodes.h
4
 *	  Definitions for tagged nodes.
5 6
 *
 *
Bruce Momjian's avatar
Bruce Momjian committed
7
 * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
Bruce Momjian's avatar
Add:  
Bruce Momjian committed
8
 * Portions Copyright (c) 1994, Regents of the University of California
9
 *
10
 * $Id: nodes.h,v 1.130 2002/12/12 15:49:40 tgl Exp $
11 12 13 14
 *
 *-------------------------------------------------------------------------
 */
#ifndef NODES_H
15
#define NODES_H
16 17 18 19 20

/*
 * The first field of every node is NodeTag. Each node created (with makeNode)
 * 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 24
 * (Since node tag numbers never exist outside backend memory, there's no
 * real harm in renumbering, it just costs a full rebuild ...)
25
 */
26 27
typedef enum NodeTag
{
28
	T_Invalid = 0,
29

30 31 32 33 34 35 36 37 38 39 40
	/*
	 * TAGS FOR EXECUTOR NODES (execnodes.h)
	 */
	T_IndexInfo = 10,
	T_ResultRelInfo,
	T_TupleTableSlot,
	T_ExprContext,
	T_ProjectionInfo,
	T_JunkFilter,
	T_EState,

41
	/*
42 43
	 * TAGS FOR PLAN NODES (plannodes.h)
	 */
44
	T_Plan = 100,
45 46 47 48 49
	T_Result,
	T_Append,
	T_Scan,
	T_SeqScan,
	T_IndexScan,
50 51 52
	T_TidScan,
	T_SubqueryScan,
	T_FunctionScan,
53 54 55 56 57 58
	T_Join,
	T_NestLoop,
	T_MergeJoin,
	T_HashJoin,
	T_Material,
	T_Sort,
59
	T_Group,
60 61 62 63
	T_Agg,
	T_Unique,
	T_Hash,
	T_SetOp,
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
	T_Limit,

	/*
	 * TAGS FOR PLAN STATE NODES (execnodes.h)
	 *
	 * These should correspond one-to-one with Plan node types.
	 */
	T_PlanState = 200,
	T_ResultState,
	T_AppendState,
	T_ScanState,
	T_SeqScanState,
	T_IndexScanState,
	T_TidScanState,
	T_SubqueryScanState,
	T_FunctionScanState,
	T_JoinState,
	T_NestLoopState,
	T_MergeJoinState,
	T_HashJoinState,
	T_MaterialState,
	T_SortState,
	T_GroupState,
	T_AggState,
	T_UniqueState,
	T_HashState,
	T_SetOpState,
	T_LimitState,
	T_SubPlanState,
93

94
	/*
95 96
	 * TAGS FOR PRIMITIVE NODES (primnodes.h)
	 */
97
	T_Resdom = 300,
98 99
	T_Alias,
	T_RangeVar,
100 101 102 103 104
	T_Expr,
	T_Var,
	T_Const,
	T_Param,
	T_Aggref,
105 106 107 108 109
	T_ArrayRef,
	T_FuncExpr,
	T_OpExpr,
	T_DistinctExpr,
	T_BoolExpr,
110
	T_SubLink,
111
	T_SubPlanExpr,
112 113
	T_FieldSelect,
	T_RelabelType,
114 115 116 117 118 119 120
	T_CaseExpr,
	T_CaseWhen,
	T_NullTest,
	T_BooleanTest,
	T_ConstraintTest,
	T_ConstraintTestValue,
	T_TargetEntry,
121 122
	T_RangeTblRef,
	T_JoinExpr,
123
	T_FromExpr,
124

125
	/*
126
	 * TAGS FOR PLANNER NODES (relation.h)
127
	 */
128
	T_RelOptInfo = 400,
129
	T_IndexOptInfo,
130 131 132 133 134 135 136
	T_Path,
	T_IndexPath,
	T_NestPath,
	T_MergePath,
	T_HashPath,
	T_TidPath,
	T_AppendPath,
137
	T_ResultPath,
138
	T_MaterialPath,
139 140 141
	T_PathKeyItem,
	T_RestrictInfo,
	T_JoinInfo,
142
	T_InnerIndexscanInfo,
143

144
	/*
145 146
	 * TAGS FOR MEMORY NODES (memnodes.h)
	 */
147
	T_MemoryContext = 500,
148
	T_AllocSetContext,
149

150
	/*
151 152
	 * TAGS FOR VALUE NODES (pg_list.h)
	 */
153
	T_Value = 600,
154 155 156 157 158 159
	T_List,
	T_Integer,
	T_Float,
	T_String,
	T_BitString,
	T_Null,
160

161
	/*
162
	 * TAGS FOR PARSE TREE NODES (parsenodes.h)
163
	 */
164
	T_Query = 700,
165 166 167 168 169
	T_InsertStmt,
	T_DeleteStmt,
	T_UpdateStmt,
	T_SelectStmt,
	T_AlterTableStmt,
170
	T_AlterDomainStmt,
171 172 173 174 175 176 177 178 179 180 181 182
	T_SetOperationStmt,
	T_GrantStmt,
	T_ClosePortalStmt,
	T_ClusterStmt,
	T_CopyStmt,
	T_CreateStmt,
	T_DefineStmt,
	T_DropStmt,
	T_TruncateStmt,
	T_CommentStmt,
	T_FetchStmt,
	T_IndexStmt,
183
	T_CreateFunctionStmt,
184 185 186 187 188 189 190 191 192 193 194
	T_RemoveAggrStmt,
	T_RemoveFuncStmt,
	T_RemoveOperStmt,
	T_RenameStmt,
	T_RuleStmt,
	T_NotifyStmt,
	T_ListenStmt,
	T_UnlistenStmt,
	T_TransactionStmt,
	T_ViewStmt,
	T_LoadStmt,
195
	T_CreateDomainStmt,
196 197 198 199 200 201 202 203 204
	T_CreatedbStmt,
	T_DropdbStmt,
	T_VacuumStmt,
	T_ExplainStmt,
	T_CreateSeqStmt,
	T_VariableSetStmt,
	T_VariableShowStmt,
	T_VariableResetStmt,
	T_CreateTrigStmt,
205
	T_DropPropertyStmt,
206 207 208 209 210 211 212 213 214 215 216 217
	T_CreatePLangStmt,
	T_DropPLangStmt,
	T_CreateUserStmt,
	T_AlterUserStmt,
	T_DropUserStmt,
	T_LockStmt,
	T_ConstraintsSetStmt,
	T_CreateGroupStmt,
	T_AlterGroupStmt,
	T_DropGroupStmt,
	T_ReindexStmt,
	T_CheckPointStmt,
218
	T_CreateSchemaStmt,
219 220
	T_AlterDatabaseSetStmt,
	T_AlterUserSetStmt,
221
	T_CreateConversionStmt,
222 223
	T_CreateCastStmt,
	T_DropCastStmt,
224 225
	T_CreateOpClassStmt,
	T_RemoveOpClassStmt,
226 227 228
	T_PrepareStmt,
	T_ExecuteStmt,
	T_DeallocateStmt,
229

230
	T_A_Expr = 800,
231 232 233
	T_ColumnRef,
	T_ParamRef,
	T_A_Const,
234 235
	T_FuncCall,
	T_A_Indices,
236
	T_ExprFieldSelect,
237 238 239
	T_ResTarget,
	T_TypeCast,
	T_SortGroupBy,
240
	T_RangeSubselect,
241
	T_RangeFunction,
242 243
	T_TypeName,
	T_ColumnDef,
244
	T_IndexElem,
245 246 247 248 249 250 251
	T_Constraint,
	T_DefElem,
	T_RangeTblEntry,
	T_SortClause,
	T_GroupClause,
	T_FkConstraint,
	T_PrivGrantee,
252 253
	T_FuncWithArgs,
	T_PrivTarget,
Bruce Momjian's avatar
Bruce Momjian committed
254
	T_InsertDefault,
255
	T_DomainConstraintValue,
256
	T_CreateOpClassItem,
Bruce Momjian's avatar
Bruce Momjian committed
257
	T_CompositeTypeStmt,
258

259
	/*
260
	 * TAGS FOR FUNCTION-CALL CONTEXT AND RESULTINFO NODES (see fmgr.h)
261
	 */
262
	T_TriggerData = 900,		/* in commands/trigger.h */
263
	T_ReturnSetInfo				/* in nodes/execnodes.h */
264

265
} NodeTag;
266 267

/*
268
 * The first field of a node of any type is guaranteed to be the NodeTag.
269 270 271 272
 * Hence the type of any node can be gotten by casting it to Node. Declaring
 * a variable to be of Node * (instead of void *) can also facilitate
 * debugging.
 */
273 274
typedef struct Node
{
275
	NodeTag		type;
276
} Node;
277

278
#define nodeTag(nodeptr)		(((Node*)(nodeptr))->type)
279

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
/*
 *	There is no way to dereference the palloc'ed pointer to assign the
 *	tag, and return the pointer itself, so we need a holder variable.
 *	Fortunately, this function isn't recursive so we just define
 *	a global variable for this purpose.
 */
extern Node *newNodeMacroHolder;

#define newNode(size, tag) \
( \
	AssertMacro((size) >= sizeof(Node)),		/* need the tag, at least */ \
\
	newNodeMacroHolder = (Node *) palloc0(size), \
	newNodeMacroHolder->type = (tag), \
	newNodeMacroHolder \
)


298 299
#define makeNode(_type_)		((_type_ *) newNode(sizeof(_type_),T_##_type_))
#define NodeSetTag(nodeptr,t)	(((Node*)(nodeptr))->type = (t))
300

301
#define IsA(nodeptr,_type_)		(nodeTag(nodeptr) == T_##_type_)
302 303

/* ----------------------------------------------------------------
304
 *					  extern declarations follow
305 306 307
 * ----------------------------------------------------------------
 */

308 309 310
/*
 * nodes/{outfuncs.c,print.c}
 */
311
extern char *nodeToString(void *obj);
312 313 314 315

/*
 * nodes/{readfuncs.c,read.c}
 */
316
extern void *stringToNode(char *str);
317 318 319 320

/*
 * nodes/copyfuncs.c
 */
321
extern void *copyObject(void *obj);
322 323 324 325

/*
 * nodes/equalfuncs.c
 */
326
extern bool equal(void *a, void *b);
327 328


329 330 331 332 333 334 335
/*
 * Typedefs for identifying qualifier selectivities and plan costs as such.
 * These are just plain "double"s, but declaring a variable as Selectivity
 * or Cost makes the intent more obvious.
 *
 * These could have gone into plannodes.h or some such, but many files
 * depend on them...
336
 */
337 338
typedef double Selectivity;		/* fraction of tuples a qualifier will
								 * pass */
339 340
typedef double Cost;			/* execution cost (in page-access units) */

341 342 343

/*
 * CmdType -
344
 *	  enums for type of operation represented by a Query
345 346
 *
 * ??? could have put this in parsenodes.h but many files not in the
347
 *	  optimizer also need this...
348
 */
349 350
typedef enum CmdType
{
351 352 353 354 355 356
	CMD_UNKNOWN,
	CMD_SELECT,					/* select stmt (formerly retrieve) */
	CMD_UPDATE,					/* update stmt (formerly replace) */
	CMD_INSERT,					/* insert stmt (formerly append) */
	CMD_DELETE,
	CMD_UTILITY,				/* cmds like create, destroy, copy,
357
								 * vacuum, etc. */
358
	CMD_NOTHING					/* dummy command for instead nothing rules
359
								 * with qual */
360
} CmdType;
361

362

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
/*
 * JoinType -
 *	  enums for types of relation joins
 *
 * JoinType determines the exact semantics of joining two relations using
 * a matching qualification.  For example, it tells what to do with a tuple
 * that has no match in the other relation.
 *
 * This is needed in both parsenodes.h and plannodes.h, so put it here...
 */
typedef enum JoinType
{
	/*
	 * The canonical kinds of joins
	 */
378 379 380
	JOIN_INNER,					/* matching tuple pairs only */
	JOIN_LEFT,					/* pairs + unmatched outer tuples */
	JOIN_FULL,					/* pairs + unmatched outer + unmatched
381
								 * inner */
382
	JOIN_RIGHT,					/* pairs + unmatched inner tuples */
383

384
	/*
385 386 387 388
	 * SQL92 considers UNION JOIN to be a kind of join, so list it here
	 * for parser convenience, even though it's not implemented like a
	 * join in the executor.  (The planner must convert it to an Append
	 * plan.)
389
	 */
390
	JOIN_UNION
391

392 393 394 395 396 397 398 399 400 401
	/*
	 * Eventually we will have some additional join types for efficient
	 * support of queries like WHERE foo IN (SELECT bar FROM ...).
	 */
} JoinType;

#define IS_OUTER_JOIN(jointype) \
	((jointype) == JOIN_LEFT || \
	 (jointype) == JOIN_FULL || \
	 (jointype) == JOIN_RIGHT)
402

403
#endif   /* NODES_H */