relation.h 6.8 KB
Newer Older
1 2 3
/*-------------------------------------------------------------------------
 *
 * relation.h--
4
 *	  Definitions for internal planner nodes.
5 6 7 8
 *
 *
 * Copyright (c) 1994, Regents of the University of California
 *
B
Bruce Momjian 已提交
9
 * $Id: relation.h,v 1.16 1999/02/08 04:29:25 momjian Exp $
10 11 12 13 14 15
 *
 *-------------------------------------------------------------------------
 */
#ifndef RELATION_H
#define RELATION_H

M
Marc G. Fournier 已提交
16 17
#include <nodes/parsenodes.h>
#include <nodes/primnodes.h>
18 19 20

/*
 * Relid
21
 *		List of relation identifiers (indexes into the rangetable).
22 23
 */

24
typedef List *Relid;
25 26

/*
B
Bruce Momjian 已提交
27
 * RelOptInfo
28
 *		Per-base-relation information
29
 *
30 31
 *		Parts of this data structure are specific to various scan and join
 *		mechanisms.  It didn't seem worth creating new node types for them.
32
 *
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
 *		relids - List of relation indentifiers
 *		indexed - true if the relation has secondary indices
 *		pages - number of pages in the relation
 *		tuples - number of tuples in the relation
 *		size - number of tuples in the relation after restrictions clauses
 *			   have been applied
 *		width - number of bytes per tuple in the relation after the
 *				appropriate projections have been done
 *		targetlist - List of TargetList nodes
 *		pathlist - List of Path nodes, one for each possible method of
 *				   generating the relation
 *		unorderedpath - a Path node generating this relation whose resulting
 *						tuples are unordered (this isn't necessarily a
 *						sequential scan path, e.g., scanning with a hash index
 *						leaves the tuples unordered)
 *		cheapestpath -	least expensive Path (regardless of final order)
 *		pruneable - flag to let the planner know whether it can prune the plan
B
Bruce Momjian 已提交
50
 *					space of this RelOptInfo or not.
51
 *
52 53
 *	 * If the relation is a (secondary) index it will have the following
 *		three fields:
54
 *
55 56 57 58
 *		classlist - List of PG_AMOPCLASS OIDs for the index
 *		indexkeys - List of base-relation attribute numbers that are index keys
 *		ordering - List of PG_OPERATOR OIDs which order the indexscan result
 *		relam	  - the OID of the pg_am of the index
59
 *
60 61
 *	 * The presence of the remaining fields depends on the restrictions
 *		and joins which the relation participates in:
62
 *
63
 *		restrictinfo - List of RestrictInfo nodes, containing info about each
64 65 66 67 68
 *					 qualification clause in which this relation participates
 *		joininfo  - List of JoinInfo nodes, containing info about each join
 *					clause in which this relation participates
 *		innerjoin - List of Path nodes that represent indices that may be used
 *					as inner paths of nestloop joins
69 70
 *
 * NB. the last element of the arrays classlist, indexkeys and ordering
71
 *	   is always 0.								2/95 - ay
72 73
 */

B
Bruce Momjian 已提交
74
typedef struct RelOptInfo
75
{
76
	NodeTag		type;
77 78

	/* all relations: */
79
	Relid		relids;
80 81

	/* catalog statistics information */
82 83 84 85 86
	bool		indexed;
	int			pages;
	int			tuples;
	int			size;
	int			width;
87 88

	/* materialization information */
89
	List	   *targetlist;
90
	List	   *pathlist;		/* Path structures */
91 92 93
	struct Path *unorderedpath;
	struct Path *cheapestpath;
	bool		pruneable;
94 95

	/* used solely by indices: */
96 97 98
	Oid		   *classlist;		/* classes of AM operators */
	int		   *indexkeys;		/* keys over which we're indexing */
	Oid			relam;			/* OID of the access method (in pg_am) */
99

100 101
	Oid			indproc;
	List	   *indpred;
102 103

	/* used by various scans and joins: */
104
	Oid		   *ordering;		/* OID of operators in sort order */
105 106
	List	   *restrictinfo;	/* RestrictInfo structures */
	List	   *joininfo;		/* JoinInfo structures */
107 108
	List	   *innerjoin;
	List	   *superrels;
109
} RelOptInfo;
110

111
extern Var *get_expr(TargetEntry *foo);
112 113 114

typedef struct MergeOrder
{
115 116 117 118 119 120
	NodeTag		type;
	Oid			join_operator;
	Oid			left_operator;
	Oid			right_operator;
	Oid			left_type;
	Oid			right_type;
121
} MergeOrder;
122 123 124 125

typedef enum OrderType
{
	MERGE_ORDER, SORTOP_ORDER
126
} OrderType;
127 128 129

typedef struct PathOrder
{
130
	OrderType	ordtype;
131 132
	union
	{
133 134
		Oid		   *sortop;
		MergeOrder *merge;
135
	} ord;
136
} PathOrder;
137 138 139

typedef struct Path
{
140
	NodeTag		type;
141

142
	RelOptInfo *parent;
143
	Cost		path_cost;
144

145
	NodeTag		pathtype;
146

B
Bruce Momjian 已提交
147
	PathOrder	path_order;
148

149 150 151
	List	   *keys;
	Cost		outerjoincost;
	Relid		joinid;
152
	List	   *loc_restrictinfo;
153
} Path;
154 155 156

typedef struct IndexPath
{
157 158 159
	Path		path;
	List	   *indexid;
	List	   *indexqual;
B
Bruce Momjian 已提交
160
	int		   *indexkeys;	/* to transform heap attnos into index ones */
161
} IndexPath;
162 163 164

typedef struct JoinPath
{
165
	Path		path;
166
	List	   *pathinfo;
167 168
	Path	   *outerjoinpath;
	Path	   *innerjoinpath;
169
} JoinPath;
170 171 172

typedef struct MergePath
{
173 174 175 176
	JoinPath	jpath;
	List	   *path_mergeclauses;
	List	   *outersortkeys;
	List	   *innersortkeys;
177
} MergePath;
178 179 180

typedef struct HashPath
{
181 182 183 184
	JoinPath	jpath;
	List	   *path_hashclauses;
	List	   *outerhashkeys;
	List	   *innerhashkeys;
185
} HashPath;
186 187 188 189 190

/******
 * Keys
 ******/

191 192
typedef struct OrderKey
{
193 194 195
	NodeTag		type;
	int			attribute_number;
	Index		array_index;
196
} OrderKey;
197

198 199
typedef struct JoinKey
{
200 201 202
	NodeTag		type;
	Var		   *outer;
	Var		   *inner;
203
} JoinKey;
204 205 206 207 208

/*******
 * clause info
 *******/

209
typedef struct RestrictInfo
210
{
211 212 213 214 215
	NodeTag		type;
	Expr	   *clause;			/* should be an OP clause */
	Cost		selectivity;
	bool		notclause;
	List	   *indexids;
216

217 218
	/* mergejoin only */
	MergeOrder *mergejoinorder;
219 220

	/* hashjoin only */
221
	Oid			hashjoinoperator;
B
Bruce Momjian 已提交
222
	Relid		restrictinfojoinid;
223
} RestrictInfo;
224 225 226

typedef struct JoinMethod
{
227 228 229
	NodeTag		type;
	List	   *jmkeys;
	List	   *clauses;
230
} JoinMethod;
231

232
typedef struct HashInfo
233
{
234 235
	JoinMethod	jmethod;
	Oid			hashop;
236
} HashInfo;
237

B
Bruce Momjian 已提交
238
typedef struct MergeInfo
239
{
240 241
	JoinMethod	jmethod;
	MergeOrder *m_ordering;
B
Bruce Momjian 已提交
242
} MergeInfo;
243

244
typedef struct JoinInfo
245
{
246 247
	NodeTag		type;
	List	   *otherrels;
248
	List	   *jinfo_restrictinfo;
249
	bool		mergejoinable;
250 251
	bool		hashjoinable;
	bool		inactive;
252
} JoinInfo;
253 254 255

typedef struct Iter
{
256 257 258
	NodeTag		type;
	Node	   *iterexpr;
	Oid			itertype;		/* type of the iter expr (use for type
259
								 * checking) */
260
} Iter;
261 262 263

/*
** Stream:
264
**	 A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
265
** JoinPaths and Paths).  The stream includes pointers to all Path nodes,
266
** as well as to any clauses that reside above Path nodes.	This structure
267 268 269
** is used to make Path nodes and clauses look similar, so that Predicate
** Migration can run.
**
270 271 272
**	   pathptr -- pointer to the current path node
**		 cinfo -- if NULL, this stream node referes to the path node.
**				  Otherwise this is a pointer to the current clause.
273
**	clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the
274 275 276 277 278 279
**				  path node
**	  upstream -- linked list pointer upwards
**	downstream -- ditto, downwards
**	   groupup -- whether or not this node is in a group with the node upstream
**	 groupcost -- total cost of the group that node is in
**	  groupsel -- total selectivity of the group that node is in
280 281 282
*/
typedef struct Stream *StreamPtr;

283 284
typedef struct Stream
{
285 286
	NodeTag		type;
	Path	   *pathptr;
287
	RestrictInfo *cinfo;
288 289 290 291 292 293
	int		   *clausetype;
	struct Stream *upstream;
	struct Stream *downstream;
	bool		groupup;
	Cost		groupcost;
	Cost		groupsel;
294
} Stream;
295

296
#endif	 /* RELATION_H */