nodes.h 6.28 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * nodes.h
4
 *	  Definitions for tagged nodes.
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: nodes.h,v 1.61 2000/01/16 20:04:58 petere Exp $
10 11 12 13
 *
 *-------------------------------------------------------------------------
 */
#ifndef NODES_H
14
#define NODES_H
15 16 17 18 19 20 21 22

/*
 * 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.
 *
 * Note that the number of the node tags are not contiguous. We left holes
 * here so that we can add more tags without changing the existing enum's.
 */
23 24 25
typedef enum NodeTag
{
	T_Invalid = 0,
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40
	/*---------------------
	 * TAGS FOR PLAN NODES (plannodes.h)
	 *---------------------
	 */
	T_Plan = 10,
	T_Result,
	T_Append,
	T_Scan,
	T_SeqScan,
	T_IndexScan,
	T_Join,
	T_NestLoop,
	T_MergeJoin,
	T_HashJoin,
41
	T_Noname,
42 43 44 45 46 47 48
	T_Material,
	T_Sort,
	T_Agg,
	T_Unique,
	T_Hash,
	T_Choose,
	T_Group,
49
	T_SubPlan,
50
	T_TidScan,
51

52 53 54 55 56 57 58 59 60 61 62
	/*---------------------
	 * TAGS FOR PRIMITIVE NODES (primnodes.h)
	 *---------------------
	 */
	T_Resdom = 100,
	T_Fjoin,
	T_Expr,
	T_Var,
	T_Oper,
	T_Const,
	T_Param,
Bruce Momjian's avatar
Bruce Momjian committed
63
	T_Aggref,
64
	T_SubLink,
65 66 67
	T_Func,
	T_Array,
	T_ArrayRef,
68
	T_Iter,
69

70
	/*---------------------
71
	 * TAGS FOR PLANNER NODES (relation.h)
72 73
	 *---------------------
	 */
Bruce Momjian's avatar
Bruce Momjian committed
74
	T_RelOptInfo = 200,
75 76
	T_Path,
	T_IndexPath,
77
	T_NestPath,
78 79
	T_MergePath,
	T_HashPath,
80
	T_PathKeyItem,
81
	T_RestrictInfo,
82
	T_JoinInfo,
83
	T_Stream,
84
	T_TidPath,
85
	T_IndexOptInfo,
86

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
	/*---------------------
	 * TAGS FOR EXECUTOR NODES (execnodes.h)
	 *---------------------
	 */
	T_IndexInfo = 300,
	T_RelationInfo,
	T_TupleCount,
	T_TupleTableSlot,
	T_ExprContext,
	T_ProjectionInfo,
	T_JunkFilter,
	T_EState,
	T_BaseNode,
	T_CommonState,
	T_ResultState,
	T_AppendState,
	T_CommonScanState,
	T_ScanState,
	T_IndexScanState,
	T_JoinState,
	T_NestLoopState,
	T_MergeJoinState,
	T_HashJoinState,
	T_MaterialState,
	T_AggState,
	T_GroupState,
	T_SortState,
	T_UniqueState,
	T_HashState,
116
	T_TidScanState,
117

118 119 120 121 122 123 124 125 126
	/*---------------------
	 * TAGS FOR MEMORY NODES (memnodes.h)
	 *---------------------
	 */
	T_MemoryContext = 400,
	T_GlobalMemory,
	T_PortalMemoryContext,
	T_PortalVariableMemory,
	T_PortalHeapMemory,
127

128 129 130 131 132 133 134 135 136 137
	/*---------------------
	 * TAGS FOR VALUE NODES (pg_list.h)
	 *---------------------
	 */
	T_Value = 500,
	T_List,
	T_Integer,
	T_Float,
	T_String,
	T_Null,
138

139 140 141 142 143
	/*---------------------
	 * TAGS FOR PARSE TREE NODES (parsenode.h)
	 *---------------------
	 */
	T_Query = 600,
Bruce Momjian's avatar
Bruce Momjian committed
144
	T_InsertStmt,
145
	T_DeleteStmt,
Bruce Momjian's avatar
Bruce Momjian committed
146 147
	T_UpdateStmt,
	T_SelectStmt,
148
    T_AlterTableStmt,
149 150 151 152 153 154 155 156
	T_AggregateStmt,
	T_ChangeACLStmt,
	T_ClosePortalStmt,
	T_ClusterStmt,
	T_CopyStmt,
	T_CreateStmt,
	T_VersionStmt,
	T_DefineStmt,
157
	T_DropStmt,
158
	T_TruncateStmt,
159
	T_CommentStmt,
160 161 162 163 164 165 166 167 168 169 170 171
	T_ExtendStmt,
	T_FetchStmt,
	T_IndexStmt,
	T_ProcedureStmt,
	T_RemoveAggrStmt,
	T_RemoveFuncStmt,
	T_RemoveOperStmt,
	T_RemoveStmt,
	T_RenameStmt,
	T_RuleStmt,
	T_NotifyStmt,
	T_ListenStmt,
172
	T_UnlistenStmt,
173 174 175 176
	T_TransactionStmt,
	T_ViewStmt,
	T_LoadStmt,
	T_CreatedbStmt,
177
	T_DropdbStmt,
178 179 180 181 182 183 184 185
	T_VacuumStmt,
	T_ExplainStmt,
	T_CreateSeqStmt,
	T_VariableSetStmt,
	T_VariableShowStmt,
	T_VariableResetStmt,
	T_CreateTrigStmt,
	T_DropTrigStmt,
186 187
	T_CreatePLangStmt,
	T_DropPLangStmt,
188 189 190
	T_CreateUserStmt,
	T_AlterUserStmt,
	T_DropUserStmt,
191
	T_LockStmt,
192
	T_ConstraintsSetStmt,
193 194 195
    T_CreateGroupStmt,
    T_AlterGroupStmt,
    T_DropGroupStmt,
196 197 198 199 200 201 202 203 204

	T_A_Expr = 700,
	T_Attr,
	T_A_Const,
	T_ParamNo,
	T_Ident,
	T_FuncCall,
	T_A_Indices,
	T_ResTarget,
205
	T_ParamString,		/* not used anymore */
206 207 208 209 210 211
	T_RelExpr,
	T_SortGroupBy,
	T_RangeVar,
	T_TypeName,
	T_IndexElem,
	T_ColumnDef,
212
	T_Constraint,
213 214 215 216 217
	T_DefElem,
	T_TargetEntry,
	T_RangeTblEntry,
	T_SortClause,
	T_GroupClause,
218
	T_SubSelect,
219
	T_JoinExpr,
220
	T_CaseExpr,
221
	T_CaseWhen,
Jan Wieck's avatar
Jan Wieck committed
222 223
	T_RowMark,
	T_FkConstraint
224
} NodeTag;
225 226

/*
227
 * The first field of a node of any type is guaranteed to be the NodeTag.
228 229 230 231
 * 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.
 */
232 233
typedef struct Node
{
234
	NodeTag		type;
235
} Node;
236

237
#define nodeTag(nodeptr)		(((Node*)(nodeptr))->type)
238

239 240
#define makeNode(_type_)		((_type_ *) newNode(sizeof(_type_),T_##_type_))
#define NodeSetTag(nodeptr,t)	(((Node*)(nodeptr))->type = (t))
241

242
#define IsA(nodeptr,_type_)		(nodeTag(nodeptr) == T_##_type_)
243 244

/* ----------------------------------------------------------------
245
 *					  IsA functions (no inheritance any more)
246 247 248
 * ----------------------------------------------------------------
 */
#define IsA_JoinPath(jp) \
249
	(IsA(jp, NestPath) || IsA(jp, MergePath) || IsA(jp, HashPath))
250

251 252 253
#define IsA_Join(jp) \
	(IsA(jp, Join) || IsA(jp, NestLoop) || \
	 IsA(jp, MergeJoin) || IsA(jp, HashJoin))
254

255
#define IsA_Noname(t) \
256 257
	(IsA(t, Noname) || IsA(t, Material) || IsA(t, Sort) || \
	 IsA(t, Unique))
258 259

/* ----------------------------------------------------------------
260
 *					  extern declarations follow
261 262 263 264 265 266
 * ----------------------------------------------------------------
 */

/*
 * nodes/nodes.c
 */
267
extern Node *newNode(Size size, NodeTag tag);
268

269 270 271
/*
 * nodes/{outfuncs.c,print.c}
 */
272
extern char *nodeToString(void *obj);
273 274 275 276

/*
 * nodes/{readfuncs.c,read.c}
 */
277
extern void *stringToNode(char *str);
278 279 280 281

/*
 * nodes/copyfuncs.c
 */
282
extern void *copyObject(void *obj);
283 284 285 286

/*
 * nodes/equalfuncs.c
 */
287
extern bool equal(void *a, void *b);
288 289


290 291 292 293 294 295 296
/*
 * 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...
297
 */
298 299 300
typedef double Selectivity;		/* fraction of tuples a qualifier will pass */
typedef double Cost;			/* execution cost (in page-access units) */

301 302 303

/*
 * CmdType -
304
 *	  enums for type of operation to aid debugging
305 306
 *
 * ??? could have put this in parsenodes.h but many files not in the
307
 *	  optimizer also need this...
308
 */
309 310 311 312 313 314 315
typedef enum CmdType
{
	CMD_UNKNOWN,
	CMD_SELECT,					/* select stmt (formerly retrieve) */
	CMD_UPDATE,					/* update stmt (formerly replace) */
	CMD_INSERT,					/* insert stmt (formerly append) */
	CMD_DELETE,
316
	CMD_UTILITY,				/* cmds like create, destroy, copy,
317
								 * vacuum, etc. */
318 319
	CMD_NOTHING					/* dummy command for instead nothing rules
								 * with qual */
320
} CmdType;
321

322

323
#endif	 /* NODES_H */