plannodes.h 8.4 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * plannodes.h
4
 *	  definitions for query plan nodes
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: plannodes.h,v 1.23 1999/03/01 00:10:36 tgl Exp $
10 11 12 13
 *
 *-------------------------------------------------------------------------
 */
#ifndef PLANNODES_H
14
#define PLANNODES_H
15

16
#include <nodes/execnodes.h>
17 18

/* ----------------------------------------------------------------
19 20
 *	Executor State types are used in the plannode structures
 *	so we have to include their definitions too.
21
 *
22
 *		Node Type				node information used by executor
23 24 25
 *
 * control nodes
 *
26
 *		Result					ResultState				resstate;
27
 *		Append					AppendState				appendstate;
28 29 30
 *
 * scan nodes
 *
31 32
 *		Scan ***				CommonScanState			scanstate;
 *		IndexScan				IndexScanState			indxstate;
33
 *
34
 *		  (*** nodes which inherit Scan also inherit scanstate)
35 36 37
 *
 * join nodes
 *
38 39 40
 *		NestLoop				NestLoopState			nlstate;
 *		MergeJoin				MergeJoinState			mergestate;
 *		HashJoin				HashJoinState			hashjoinstate;
41 42 43
 *
 * materialize nodes
 *
44 45 46 47
 *		Material				MaterialState			matstate;
 *		Sort					SortState				sortstate;
 *		Unique					UniqueState				uniquestate;
 *		Hash					HashState				hashstate;
48 49 50 51 52 53
 *
 * ----------------------------------------------------------------
 */


/* ----------------------------------------------------------------
54
 *						node definitions
55 56 57 58
 * ----------------------------------------------------------------
 */

/* ----------------
59
 *		Plan node
60 61 62
 * ----------------
 */

63 64
typedef struct Plan
{
65 66 67 68 69 70
	NodeTag		type;
	Cost		cost;
	int			plan_size;
	int			plan_width;
	int			plan_tupperpage;
	EState	   *state;			/* at execution time, state's of
71 72
								 * individual nodes point to one EState
								 * for the whole top-level plan */
73 74 75 76
	List	   *targetlist;
	List	   *qual;			/* Node* or List* ?? */
	struct Plan *lefttree;
	struct Plan *righttree;
77 78 79 80 81 82
	List	   *extParam;		/* indices of _all_ _external_ PARAM_EXEC
								 * for this plan in global
								 * es_param_exec_vals. Params from
								 * setParam from initPlan-s are not
								 * included, but their execParam-s are
								 * here!!! */
83 84
	List	   *locParam;		/* someones from setParam-s */
	List	   *chgParam;		/* list of changed ones from the above */
85 86
	List	   *initPlan;		/* Init Plan nodes (un-correlated expr
								 * subselects) */
87
	List	   *subPlan;		/* Other SubPlan nodes */
88 89

	/*
90
	 * We really need in some TopPlan node to store range table and
91 92
	 * resultRelation from Query there and get rid of Query itself from
	 * Executor. Some other stuff like below could be put there, too.
93 94 95 96
	 */
	int			nParamExec;		/* Number of them in entire query. This is
								 * to get Executor know about how many
								 * param_exec there are in query plan. */
97
} Plan;
98 99

/* ----------------
100 101 102 103
 *	these are are defined to avoid confusion problems with "left"
 *	and "right" and "inner" and "outer".  The convention is that
 *	the "left" plan is the "outer" plan and the "right" plan is
 *	the inner plan, but these make the code more readable.
104 105
 * ----------------
 */
106 107
#define innerPlan(node)			(((Plan *)(node))->righttree)
#define outerPlan(node)			(((Plan *)(node))->lefttree)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122


/*
 * ===============
 * Top-level nodes
 * ===============
 */

/* all plan nodes "derive" from the Plan structure by having the
   Plan structure as the first field.  This ensures that everything works
   when nodes are cast to Plan's.  (node pointers are frequently cast to Plan*
   when passed around generically in the executor */


/* ----------------
123 124
 *	 result node -
 *		returns tuples from outer plan that satisfy the qualifications
125 126
 * ----------------
 */
127 128
typedef struct Result
{
129 130 131
	Plan		plan;
	Node	   *resconstantqual;
	ResultState *resstate;
132
} Result;
133 134

/* ----------------
135
 *		append node
136 137
 * ----------------
 */
138 139
typedef struct Append
{
140
	Plan		plan;
141
	List	   *appendplans;
142 143 144 145
	List	   *unionrtables;	/* List of range tables, one for each
								 * union query. */
	Index		inheritrelid;	/* The range table has to be changed for
								 * inheritance. */
146 147
	List	   *inheritrtable;
	AppendState *appendstate;
B
Bruce Momjian 已提交
148
} Append;
149 150 151 152 153 154

/*
 * ==========
 * Scan nodes
 * ==========
 */
155 156
typedef struct Scan
{
157 158
	Plan		plan;
	Index		scanrelid;		/* relid is index into the range table */
159
	CommonScanState *scanstate;
160
} Scan;
161 162

/* ----------------
163
 *		sequential scan node
164 165
 * ----------------
 */
166
typedef Scan SeqScan;
167 168

/* ----------------
169
 *		index scan node
170 171
 * ----------------
 */
172 173
typedef struct IndexScan
{
174 175 176
	Scan		scan;
	List	   *indxid;
	List	   *indxqual;
177
	List	   *indxqualorig;
178
	IndexScanState *indxstate;
179
} IndexScan;
180 181 182 183 184 185 186 187

/*
 * ==========
 * Join nodes
 * ==========
 */

/* ----------------
188
 *		Join node
189 190
 * ----------------
 */
191
typedef Plan Join;
192 193

/* ----------------
194
 *		nest loop join node
195 196
 * ----------------
 */
197 198
typedef struct NestLoop
{
199 200
	Join		join;
	NestLoopState *nlstate;
201
} NestLoop;
202 203

/* ----------------
204
 *		merge join node
205 206
 * ----------------
 */
207 208
typedef struct MergeJoin
{
209 210
	Join		join;
	List	   *mergeclauses;
211
	MergeJoinState *mergestate;
212
} MergeJoin;
213 214

/* ----------------
215
 *		hash join (probe) node
216 217
 * ----------------
 */
218 219
typedef struct HashJoin
{
220 221 222 223 224 225 226 227
	Join		join;
	List	   *hashclauses;
	Oid			hashjoinop;
	HashJoinState *hashjoinstate;
	HashJoinTable hashjointable;
	IpcMemoryKey hashjointablekey;
	int			hashjointablesize;
	bool		hashdone;
228
} HashJoin;
229 230

/* ---------------
231
 *		aggregate node
232 233
 * ---------------
 */
234 235
typedef struct Agg
{
236
	Plan		plan;
237
	List	   *aggs;
238
	AggState   *aggstate;
B
Bruce Momjian 已提交
239
} Agg;
240 241

/* ---------------
242 243
 *	 group node -
 *		use for queries with GROUP BY specified.
244
 *
245 246 247 248
 *		If tuplePerGroup is true, one tuple (with group columns only) is
 *		returned for each group and NULL is returned when there are no more
 *		groups. Otherwise, all the tuples of a group are returned with a
 *		NULL returned at the end of each group. (see nodeGroup.c for details)
249 250
 * ---------------
 */
251 252
typedef struct Group
{
253 254 255 256 257
	Plan		plan;
	bool		tuplePerGroup;	/* what tuples to return (see above) */
	int			numCols;		/* number of group columns */
	AttrNumber *grpColIdx;		/* index into the target list */
	GroupState *grpstate;
258
} Group;
259 260 261

/*
 * ==========
262
 * Noname nodes
263 264
 * ==========
 */
265
typedef struct Noname
266
{
267
	Plan		plan;
268
	Oid			nonameid;
269
	int			keycount;
270
} Noname;
271 272

/* ----------------
273
 *		materialization node
274 275
 * ----------------
 */
276 277
typedef struct Material
{
278 279
	Plan		plan;			/* noname node flattened out */
	Oid			nonameid;
280 281
	int			keycount;
	MaterialState *matstate;
282
} Material;
283 284

/* ----------------
285
 *		sort node
286 287
 * ----------------
 */
288 289
typedef struct Sort
{
290 291
	Plan		plan;			/* noname node flattened out */
	Oid			nonameid;
292 293 294 295
	int			keycount;
	SortState  *sortstate;
	void	   *psortstate;
	bool		cleaned;
296
} Sort;
297 298

/* ----------------
299
 *		unique node
300 301
 * ----------------
 */
302 303
typedef struct Unique
{
304 305
	Plan		plan;			/* noname node flattened out */
	Oid			nonameid;
306 307
	int			keycount;
	char	   *uniqueAttr;		/* NULL if all attrs, or unique attribute
308
								 * name */
309 310 311
	AttrNumber	uniqueAttrNum;	/* attribute number of attribute to select
								 * distinct on */
	UniqueState *uniquestate;
312
} Unique;
313 314

/* ----------------
315
 *		hash build node
316 317
 * ----------------
 */
318 319
typedef struct Hash
{
320 321 322 323 324 325
	Plan		plan;
	Var		   *hashkey;
	HashState  *hashstate;
	HashJoinTable hashtable;
	IpcMemoryKey hashtablekey;
	int			hashtablesize;
326
} Hash;
327 328

/* -------------------
329
 *		Tee node information
330
 *
331 332
 *	  leftParent :				the left parent of this node
 *	  rightParent:				the right parent of this node
333 334
 * -------------------
*/
335 336
typedef struct Tee
{
337 338 339 340 341 342 343
	Plan		plan;
	Plan	   *leftParent;
	Plan	   *rightParent;
	TeeState   *teestate;
	char	   *teeTableName;	/* the name of the table to materialize
								 * the tee into */
	List	   *rtentries;		/* the range table for the plan below the
344 345
								 * Tee may be different than the parent
								 * plans */
346
} Tee;
347

348 349 350 351 352 353
/* ---------------------
 *		SubPlan node
 * ---------------------
 */
typedef struct SubPlan
{
354 355 356 357 358
	NodeTag		type;
	Plan	   *plan;			/* subselect plan itself */
	int			plan_id;		/* dummy thing because of we haven't equal
								 * funcs for plan nodes... actually, we
								 * could put *plan itself somewhere else
359
								 * (TopPlan node ?)... */
360 361
	List	   *rtable;			/* range table */
	List	   *setParam;		/* non-correlated EXPR & EXISTS subqueries
362
								 * have to set some Params for paren Plan */
363 364 365 366
	List	   *parParam;		/* indices of corr. Vars from parent plan */
	SubLink    *sublink;		/* SubLink node for subselects in WHERE
								 * and HAVING */
	bool		shutdown;		/* shutdown plan if TRUE */
367 368
} SubPlan;

369
#endif	 /* PLANNODES_H */