primnodes.h 11.7 KB
Newer Older
1 2
/*-------------------------------------------------------------------------
 *
3
 * primnodes.h
4
 *	  Definitions for parse tree/query tree ("primitive") nodes.
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
9
 * $Id: primnodes.h,v 1.33 1999/08/16 02:17:39 tgl Exp $
10 11 12 13
 *
 *-------------------------------------------------------------------------
 */
#ifndef PRIMNODES_H
14
#define PRIMNODES_H
15

16 17
#include "access/attnum.h"
#include "nodes/pg_list.h"
B
Bruce Momjian 已提交
18
#include "utils/fcache.h"
19 20

/* ----------------------------------------------------------------
21
 *						node definitions
22 23 24 25 26
 * ----------------------------------------------------------------
 */

/* ----------------
 * Resdom (Result Domain)
27 28
 *		resno			- attribute number
 *		restype			- type of the resdom
29
 *		restypmod		- type-specific modifier of the result
30 31 32
 *		resname			- name of the resdom (could be NULL)
 *		reskey			- order of key in a sort (for those > 0)
 *		reskeyop		- sort operator Oid
33
 *		resgroupref		- set to nonzero if referenced from a group by clause
B
Bruce Momjian 已提交
34 35
 *		resjunk			- set to true to eliminate the attribute
 *						  from final target list
36 37 38
 *
 * ----------------
 */
39 40
typedef struct Resdom
{
41 42 43
	NodeTag		type;
	AttrNumber	resno;
	Oid			restype;
44
	int32		restypmod;
45 46 47
	char	   *resname;
	Index		reskey;
	Oid			reskeyop;
48
	Index		resgroupref;
B
Bruce Momjian 已提交
49
	bool		resjunk;
50
} Resdom;
51 52 53

/* -------------
 * Fjoin
54 55 56 57 58 59 60 61 62 63 64 65 66 67
 *		initialized		- true if the Fjoin has already been initialized for
 *						  the current target list evaluation
 *		nNodes			- The number of Iter nodes returning sets that the
 *						  node will flatten
 *		outerList		- 1 or more Iter nodes
 *		inner			- exactly one Iter node.  We eval every node in the
 *						  outerList once then eval the inner node to completion
 *						  pair the outerList result vector with each inner
 *						  result to form the full result.  When the inner has
 *						  been exhausted, we get the next outer result vector
 *						  and reset the inner.
 *		results			- The complete (flattened) result vector
 *		alwaysNull		- a null vector to indicate sets with a cardinality of
 *						  0, we treat them as the set {NULL}.
68
 */
69 70
typedef struct Fjoin
{
71 72 73 74 75 76
	NodeTag		type;
	bool		fj_initialized;
	int			fj_nNodes;
	List	   *fj_innerNode;
	DatumPtr	fj_results;
	BoolPtr		fj_alwaysDone;
77
} Fjoin;
78 79 80

/* ----------------
 * Expr
81 82 83 84 85
 *		typeOid			- oid of the type of this expression
 *		opType			- type of this expression
 *		oper			- the Oper node if it is an OPER_EXPR or the
 *						  Func node if it is a FUNC_EXPR
 *		args			- arguments to this expression
86 87
 * ----------------
 */
88 89
typedef enum OpType
{
90
	OP_EXPR, FUNC_EXPR, OR_EXPR, AND_EXPR, NOT_EXPR, SUBPLAN_EXPR
91
} OpType;
92

93 94
typedef struct Expr
{
95 96 97
	NodeTag		type;
	Oid			typeOid;		/* oid of the type of this expr */
	OpType		opType;			/* type of the op */
98
	Node	   *oper;			/* could be Oper or Func or SubPlan */
99
	List	   *args;			/* list of argument nodes */
100
} Expr;
101 102 103

/* ----------------
 * Var
104 105 106 107
 *		varno			- index of this var's relation in the range table
 *						  (could be INNER or OUTER)
 *		varattno		- attribute number of this var, or zero for all
 *		vartype			- pg_type tuple oid for the type of this var
108
 *		vartypmod		- pg_attribute typmod value
109
 *		varlevelsup		- for subquery variables referencing outer relations
110 111 112 113
 *		varnoold		- keep varno around in case it got changed to INNER/
 *						  OUTER (see match_varid)
 *		varoattno		- attribute number of this var
 *						  [ '(varnoold varoattno) was varid   -ay 2/95]
114 115
 * ----------------
 */
116 117
#define    INNER		65000
#define    OUTER		65001
118

119 120
#define    PRS2_CURRENT_VARNO			1
#define    PRS2_NEW_VARNO				2
121

122 123
typedef struct Var
{
124 125 126 127
	NodeTag		type;
	Index		varno;
	AttrNumber	varattno;
	Oid			vartype;
128
	int32		vartypmod;
129
	Index		varlevelsup;	/* erased by upper optimizer */
130 131
	Index		varnoold;		/* only used by optimizer */
	AttrNumber	varoattno;		/* only used by optimizer */
132
} Var;
133 134 135

/* ----------------
 * Oper
136 137 138 139 140
 *		opno			- PG_OPERATOR OID of the operator
 *		opid			- PG_PROC OID for the operator
 *		opresulttype	- PG_TYPE OID of the operator's return value
 *		opsize			- size of return result (cached by executor)
 *		op_fcache		- XXX comment me.
141 142 143
 *
 * ----
 * NOTE: in the good old days 'opno' used to be both (or either, or
144
 * neither) the pg_operator oid, and/or the pg_proc oid depending
145 146 147 148 149 150
 * on the postgres module in question (parser->pg_operator,
 * executor->pg_proc, planner->both), the mood of the programmer,
 * and the phase of the moon (rumors that it was also depending on the day
 * of the week are probably false). To make things even more postgres-like
 * (i.e. a mess) some comments were referring to 'opno' using the name
 * 'opid'. Anyway, now we have two separate fields, and of course that
151
 * immediately removes all bugs from the code...		[ sp :-) ].
152 153
 * ----------------
 */
154 155
typedef struct Oper
{
156 157 158 159 160
	NodeTag		type;
	Oid			opno;
	Oid			opid;
	Oid			opresulttype;
	int			opsize;
161
	FunctionCachePtr op_fcache;
162
} Oper;
163 164 165 166


/* ----------------
 * Const
167 168 169 170 171 172 173 174 175 176 177 178
 *		consttype - PG_TYPE OID of the constant's value
 *		constlen - length in bytes of the constant's value
 *		constvalue - the constant's value
 *		constisnull - whether the constant is null
 *				(if true, the other fields are undefined)
 *		constbyval - whether the information in constvalue
 *				if passed by value.  If true, then all the information
 *				is stored in the datum. If false, then the datum
 *				contains a pointer to the information.
 *		constisset - whether the const represents a set.  The const
 *				value corresponding will be the query that defines
 *				the set.
179 180
 * ----------------
 */
181 182
typedef struct Const
{
183 184
	NodeTag		type;
	Oid			consttype;
185
	int			constlen;
186 187 188 189 190
	Datum		constvalue;
	bool		constisnull;
	bool		constbyval;
	bool		constisset;
	bool		constiscast;
191
} Const;
192 193 194

/* ----------------
 * Param
195 196
 *		paramkind - specifies the kind of parameter. The possible values
 *		for this field are specified in "params.h", and they are:
197
 *
198 199 200
 *		PARAM_NAMED: The parameter has a name, i.e. something
 *				like `$.salary' or `$.foobar'.
 *				In this case field `paramname' must be a valid Name.
201
 *
202 203 204
 *		PARAM_NUM:	 The parameter has only a numeric identifier,
 *				i.e. something like `$1', `$2' etc.
 *				The number is contained in the `paramid' field.
205
 *
206 207 208 209
 *		PARAM_NEW:	 Used in PRS2 rule, similar to PARAM_NAMED.
 *					 The `paramname' and `paramid' refer to the "NEW" tuple
 *					 The `pramname' is the attribute name and `paramid'
 *					 is the attribute number.
210
 *
211 212
 *		PARAM_OLD:	 Same as PARAM_NEW, but in this case we refer to
 *				the "OLD" tuple.
213
 *
214 215 216 217
 *		paramid - numeric identifier for literal-constant parameters ("$1")
 *		paramname - attribute name for tuple-substitution parameters ("$.foo")
 *		paramtype - PG_TYPE OID of the parameter's value
 *		param_tlist - allows for projection in a param node.
218 219
 * ----------------
 */
220 221
typedef struct Param
{
222 223 224 225 226 227
	NodeTag		type;
	int			paramkind;
	AttrNumber	paramid;
	char	   *paramname;
	Oid			paramtype;
	List	   *param_tlist;
228
} Param;
229 230 231 232


/* ----------------
 * Func
233 234 235 236 237 238 239 240 241 242 243
 *		funcid			- PG_FUNCTION OID of the function
 *		functype		- PG_TYPE OID of the function's return value
 *		funcisindex		- the function can be evaluated by scanning an index
 *						  (set during query optimization)
 *		funcsize		- size of return result (cached by executor)
 *		func_fcache		- runtime state while running this function.  Where
 *						  we are in the execution of the function if it
 *						  returns more than one value, etc.
 *						  See utils/fcache.h
 *		func_tlist		- projection of functions returning tuples
 *		func_planlist	- result of planning this func, if it's a PQ func
244 245
 * ----------------
 */
246 247
typedef struct Func
{
248 249 250 251 252
	NodeTag		type;
	Oid			funcid;
	Oid			functype;
	bool		funcisindex;
	int			funcsize;
253
	FunctionCachePtr func_fcache;
254 255
	List	   *func_tlist;
	List	   *func_planlist;
256
} Func;
257

258 259 260 261 262 263 264 265 266 267 268 269 270 271
/* ----------------
 * Iter
 *		can anyone explain what this is for?  Seems to have something to do
 *		with evaluation of functions that return sets...
 * ----------------
 */
typedef struct Iter
{
	NodeTag		type;
	Node	   *iterexpr;
	Oid			itertype;		/* type of the iter expr (use for type
								 * checking) */
} Iter;

272
/* ----------------
B
Bruce Momjian 已提交
273
 * Aggref
274 275 276
 *		aggname			- name of the aggregate
 *		basetype		- base type Oid of the aggregate
 *		aggtype			- type Oid of final result of the aggregate
277 278
 *		target			- attribute or expression we are aggregating on
 *		aggno			- index to ecxt_values
279 280
 * ----------------
 */
B
Bruce Momjian 已提交
281
typedef struct Aggref
282
{
283 284
	NodeTag		type;
	char	   *aggname;
285 286
	Oid			basetype;
	Oid			aggtype;
287
	Node	   *target;
288 289
	int			aggno;
	bool		usenulls;
290
} Aggref;
291

292 293 294 295 296 297 298 299 300 301 302
/* ----------------
 * SubLink
 *		subLinkType		- EXISTS, ALL, ANY, EXPR
 *		useor			- TRUE for <>
 *		lefthand		- list of Var/Const nodes on the left
 *		oper			- list of Oper nodes
 *		subselect		- subselect as Query* or parsetree
 * ----------------
 */
typedef enum SubLinkType
{
303
	EXISTS_SUBLINK, ALL_SUBLINK, ANY_SUBLINK, EXPR_SUBLINK
304 305 306 307 308 309
} SubLinkType;


typedef struct SubLink
{
	NodeTag		type;
310
	SubLinkType subLinkType;
311
	bool		useor;
312 313 314
	List	   *lefthand;
	List	   *oper;
	Node	   *subselect;
315 316
} SubLink;

317 318
/* ----------------
 * Array
319
 *		arrayelemtype	- type of the array's elements (homogenous!)
320
 *		arrayelemlength - length of that type
321
 *		arrayelembyval	- is the element type pass-by-value?
322 323 324
 *		arrayndim		- number of dimensions of the array
 *		arraylow		- base for array indexing
 *		arrayhigh		- limit for array indexing
325
 *		arraylen		- total length of array object
326 327
 * ----------------
 *
328 329 330
 *	memo from mao:	the array support we inherited from 3.1 is just
 *	wrong.	when time exists, we should redesign this stuff to get
 *	around a bunch of unfortunate implementation decisions made there.
331
 */
332 333
typedef struct Array
{
334 335 336 337 338 339 340 341
	NodeTag		type;
	Oid			arrayelemtype;
	int			arrayelemlength;
	bool		arrayelembyval;
	int			arrayndim;
	IntArray	arraylow;
	IntArray	arrayhigh;
	int			arraylen;
B
Bruce Momjian 已提交
342
} Array;
343 344

/* ----------------
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
 *	ArrayRef: describes an array subscripting operation
 *
 * An ArrayRef can describe fetching a single element from an array,
 * fetching a subarray (array slice), storing a single element into
 * an array, or storing a slice.  The "store" cases work with an
 * initial array value and a source value that is inserted into the
 * appropriate part of the array.
 *
 *		refattrlength	- total length of array object
 *		refelemtype		- type of the result of the subscript operation
 *		refelemlength	- length of the array element type
 *		refelembyval	- is the element type pass-by-value?
 *		refupperindexpr - expressions that evaluate to upper array indexes
 *		reflowerindexpr	- expressions that evaluate to lower array indexes
 *		refexpr			- the expression that evaluates to an array value
 *		refassgnexpr	- expression for the source value, or NULL if fetch
 *
 * If reflowerindexpr = NIL, then we are fetching or storing a single array
 * element at the subscripts given by refupperindexpr.  Otherwise we are
 * fetching or storing an array slice, that is a rectangular subarray
 * with lower and upper bounds given by the index expressions.
 * reflowerindexpr must be the same length as refupperindexpr when it
 * is not NIL.
 *
 * Note: array types can be fixed-length (refattrlength > 0), but only
 * when the element type is itself fixed-length.  Otherwise they are
 * varlena structures and have refattrlength = -1.  In any case,
 * an array type is never pass-by-value.
 *
 * Note: currently, refelemtype is NOT the element type, but the array type,
 * when doing subarray fetch or either type of store.  It would be cleaner
 * to add more fields so we can distinguish the array element type from the
 * result type of the subscript operator...
378 379
 * ----------------
 */
380 381
typedef struct ArrayRef
{
382 383 384 385 386 387 388 389 390
	NodeTag		type;
	int			refattrlength;
	int			refelemlength;
	Oid			refelemtype;
	bool		refelembyval;
	List	   *refupperindexpr;
	List	   *reflowerindexpr;
	Node	   *refexpr;
	Node	   *refassgnexpr;
B
Bruce Momjian 已提交
391
} ArrayRef;
392

393
#endif	 /* PRIMNODES_H */