nodes.h 6.0 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.41 1999/02/09 17:03:11 momjian 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 49
	T_Material,
	T_Sort,
	T_Agg,
	T_Unique,
	T_Hash,
	T_Choose,
	T_Tee,
	T_Group,
50
	T_SubPlan,
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,
B
Bruce Momjian 已提交
63
	T_Aggref,
64
	T_SubLink,
65 66 67
	T_Func,
	T_Array,
	T_ArrayRef,
68

69 70 71 72
	/*---------------------
	 * TAGS FOR INNER PLAN NODES (relation.h)
	 *---------------------
	 */
B
Bruce Momjian 已提交
73
	T_RelOptInfo = 200,
74
	T_PathOrder,
75 76 77 78 79 80 81 82
	T_Path,
	T_IndexPath,
	T_JoinPath,
	T_MergePath,
	T_HashPath,
	T_OrderKey,
	T_JoinKey,
	T_MergeOrder,
83
	T_RestrictInfo,
84
	T_JoinMethod,
85
	T_HashInfo,
B
Bruce Momjian 已提交
86
	T_MergeInfo,
87
	T_JoinInfo,
88 89
	T_Iter,
	T_Stream,
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 116 117 118 119 120
	/*---------------------
	 * 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,
	T_TeeState,
121

122 123 124 125 126 127 128 129 130
	/*---------------------
	 * TAGS FOR MEMORY NODES (memnodes.h)
	 *---------------------
	 */
	T_MemoryContext = 400,
	T_GlobalMemory,
	T_PortalMemoryContext,
	T_PortalVariableMemory,
	T_PortalHeapMemory,
131

132 133 134 135 136 137 138 139 140 141
	/*---------------------
	 * TAGS FOR VALUE NODES (pg_list.h)
	 *---------------------
	 */
	T_Value = 500,
	T_List,
	T_Integer,
	T_Float,
	T_String,
	T_Null,
142

143 144 145 146 147
	/*---------------------
	 * TAGS FOR PARSE TREE NODES (parsenode.h)
	 *---------------------
	 */
	T_Query = 600,
B
Bruce Momjian 已提交
148
	T_InsertStmt,
149
	T_DeleteStmt,
B
Bruce Momjian 已提交
150 151
	T_UpdateStmt,
	T_SelectStmt,
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
	T_AddAttrStmt,
	T_AggregateStmt,
	T_ChangeACLStmt,
	T_ClosePortalStmt,
	T_ClusterStmt,
	T_CopyStmt,
	T_CreateStmt,
	T_VersionStmt,
	T_DefineStmt,
	T_DestroyStmt,
	T_ExtendStmt,
	T_FetchStmt,
	T_IndexStmt,
	T_ProcedureStmt,
	T_RecipeStmt,
	T_RemoveAggrStmt,
	T_RemoveFuncStmt,
	T_RemoveOperStmt,
	T_RemoveStmt,
	T_RenameStmt,
	T_RuleStmt,
	T_NotifyStmt,
	T_ListenStmt,
M
 
Marc G. Fournier 已提交
175
	T_UnlistenStmt,
176 177 178 179 180 181 182 183 184 185 186 187 188
	T_TransactionStmt,
	T_ViewStmt,
	T_LoadStmt,
	T_CreatedbStmt,
	T_DestroydbStmt,
	T_VacuumStmt,
	T_ExplainStmt,
	T_CreateSeqStmt,
	T_VariableSetStmt,
	T_VariableShowStmt,
	T_VariableResetStmt,
	T_CreateTrigStmt,
	T_DropTrigStmt,
189 190
	T_CreatePLangStmt,
	T_DropPLangStmt,
191 192 193
	T_CreateUserStmt,
	T_AlterUserStmt,
	T_DropUserStmt,
194
	T_LockStmt,
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210

	T_A_Expr = 700,
	T_Attr,
	T_A_Const,
	T_ParamNo,
	T_Ident,
	T_FuncCall,
	T_A_Indices,
	T_ResTarget,
	T_ParamString,
	T_RelExpr,
	T_SortGroupBy,
	T_RangeVar,
	T_TypeName,
	T_IndexElem,
	T_ColumnDef,
T
Thomas G. Lockhart 已提交
211
	T_Constraint,
212 213 214 215 216
	T_DefElem,
	T_TargetEntry,
	T_RangeTblEntry,
	T_SortClause,
	T_GroupClause,
M
 
Marc G. Fournier 已提交
217
	T_SubSelect,
T
Thomas G. Lockhart 已提交
218 219
	T_JoinUsing,
	T_CaseExpr,
220 221
	T_CaseWhen,
	T_RowMark
222
} NodeTag;
223 224

/*
T
Thomas G. Lockhart 已提交
225
 * The first field of a node of any type is guaranteed to be the NodeTag.
226 227 228 229
 * 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.
 */
230 231
typedef struct Node
{
232
	NodeTag		type;
233
} Node;
234

235
#define nodeTag(_node_)			((Node*)_node_)->type
236

237 238
#define makeNode(_node_)		(_node_*)newNode(sizeof(_node_),T_##_node_)
#define NodeSetTag(n, t)		((Node *)n)->type = t
239

240
#define IsA(_node_,_tag_)		(nodeTag(_node_) == T_##_tag_)
241 242

/* ----------------------------------------------------------------
243
 *					  IsA functions (no inheritence any more)
244 245 246
 * ----------------------------------------------------------------
 */
#define IsA_JoinPath(jp) \
247 248
	(nodeTag(jp)==T_JoinPath || nodeTag(jp)==T_MergePath || \
	 nodeTag(jp)==T_HashPath)
249 250

#define IsA_Join(j) \
251 252
	(nodeTag(j)==T_Join || nodeTag(j)==T_NestLoop || \
	 nodeTag(j)==T_MergeJoin || nodeTag(j)==T_HashJoin)
253

254 255
#define IsA_Noname(t) \
	(nodeTag(t)==T_Noname || nodeTag(t)==T_Material || nodeTag(t)==T_Sort || \
256
	 nodeTag(t)==T_Unique)
257 258

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

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

/*
 * nodes/{outfuncs.c,print.c}
 */
271
#define nodeDisplay		pprint
272

273 274
extern char *nodeToString(void *obj);
extern void print(void *obj);
275 276 277 278

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

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

286 287 288 289 290
/*
 * nodes/freefuncs.c
 */
extern void freeObject(void *obj);

291 292 293
/*
 * nodes/equalfuncs.c
 */
294
extern bool equal(void *a, void *b);
295 296 297


/* ----------------
298 299
 *		I don't know why this is here.  Most likely a hack..
 *		-cim 6/3/90
300 301
 * ----------------
 */
302
typedef float Cost;
303 304 305

/*
 * CmdType -
306
 *	  enums for type of operation to aid debugging
307 308
 *
 * ??? could have put this in parsenodes.h but many files not in the
309
 *	  optimizer also need this...
310
 */
311 312 313 314 315 316 317
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,
318
	CMD_UTILITY,				/* cmds like create, destroy, copy,
319
								 * vacuum, etc. */
320 321
	CMD_NOTHING					/* dummy command for instead nothing rules
								 * with qual */
322
} CmdType;
323

324

325
#endif	 /* NODES_H */