relation.h 6.9 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
 *
9
 * $Id: relation.h,v 1.5 1997/09/07 04:58:48 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 27

/*
 * Rel
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 50
 *		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
 *					space of this Rel or not.  -- JMH, 11/11/92
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 64 65 66 67 68
 *		clauseinfo - List of ClauseInfo nodes, containing info about each
 *					 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
 */

74 75 76 77 78 79 80 81 82 83 84 85 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
typedef struct Rel
{
	NodeTag			type;

	/* all relations: */
	Relid			relids;

	/* catalog statistics information */
	bool			indexed;
	int				pages;
	int				tuples;
	int				size;
	int				width;

	/* materialization information */
	List		   *targetlist;
	List		   *pathlist;
	struct Path    *unorderedpath;
	struct Path    *cheapestpath;
	bool			pruneable;

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

	Oid				indproc;
	List		   *indpred;

	/* used by various scans and joins: */
	Oid			   *ordering;	/* OID of operators in sort order */
	List		   *clauseinfo; /* restriction clauses */
	List		   *joininfo;	/* join clauses */
	List		   *innerjoin;
	List		   *superrels;
}				Rel;

extern Var	   *get_expr(TargetEntry * foo);

typedef struct MergeOrder
{
	NodeTag			type;
	Oid				join_operator;
	Oid				left_operator;
	Oid				right_operator;
	Oid				left_type;
	Oid				right_type;
}				MergeOrder;

typedef enum OrderType
{
	MERGE_ORDER, SORTOP_ORDER
}				OrderType;

typedef struct PathOrder
{
	OrderType		ordtype;
	union
	{
		Oid			   *sortop;
		MergeOrder	   *merge;
	}				ord;
}				PathOrder;

typedef struct Path
{
	NodeTag			type;

	Rel			   *parent;
	Cost			path_cost;

	NodeTag			pathtype;

	PathOrder		p_ordering;

	List		   *keys;
	Cost			outerjoincost;
	Relid			joinid;
	List		   *locclauseinfo;
}				Path;

typedef struct IndexPath
{
	Path			path;
	List		   *indexid;
	List		   *indexqual;
	int			   *indexkeys;	/* to transform heap attnos into index
								 * ones */
}				IndexPath;

typedef struct JoinPath
{
	Path			path;
	List		   *pathclauseinfo;
	Path		   *outerjoinpath;
	Path		   *innerjoinpath;
}				JoinPath;

typedef struct MergePath
{
	JoinPath		jpath;
	List		   *path_mergeclauses;
	List		   *outersortkeys;
	List		   *innersortkeys;
}				MergePath;

typedef struct HashPath
{
	JoinPath		jpath;
	List		   *path_hashclauses;
	List		   *outerhashkeys;
	List		   *innerhashkeys;
}				HashPath;
187 188 189 190 191

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

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

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

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

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
typedef struct CInfo
{
	NodeTag			type;
	Expr		   *clause;		/* should be an OP clause */
	Cost			selectivity;
	bool			notclause;
	List		   *indexids;

	/* mergesort only */
	MergeOrder	   *mergesortorder;

	/* hashjoin only */
	Oid				hashjoinoperator;
	Relid			cinfojoinid;
}				CInfo;

typedef struct JoinMethod
{
	NodeTag			type;
	List		   *jmkeys;
	List		   *clauses;
}				JoinMethod;

typedef struct HInfo
{
	JoinMethod		jmethod;
	Oid				hashop;
}				HInfo;

typedef struct MInfo
{
	JoinMethod		jmethod;
	MergeOrder	   *m_ordering;
}				MInfo;

typedef struct JInfo
{
	NodeTag			type;
	List		   *otherrels;
	List		   *jinfoclauseinfo;
	bool			mergesortable;
	bool			hashjoinable;
	bool			inactive;
}				JInfo;

typedef struct Iter
{
	NodeTag			type;
	Node		   *iterexpr;
	Oid				itertype;	/* type of the iter expr (use for type
								 * checking) */
}				Iter;
262 263 264

/*
** Stream:
265
**	 A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
266
** JoinPaths and Paths).  The stream includes pointers to all Path nodes,
267
** as well as to any clauses that reside above Path nodes.	This structure
268 269 270
** is used to make Path nodes and clauses look similar, so that Predicate
** Migration can run.
**
271 272 273 274 275 276 277 278 279 280
**	   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.
**	clausetype -- whether cinfo is in locclauseinfo or pathclauseinfo in the
**				  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
281 282 283
*/
typedef struct Stream *StreamPtr;

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

#endif							/* RELATION_H */