]> granicus.if.org Git - postgresql/blob - src/include/nodes/relation.h
aaee1637cf3eefa10e0fdeda3802378f00a2724a
[postgresql] / src / include / nodes / relation.h
1 /*-------------------------------------------------------------------------
2  *
3  * relation.h--
4  *        Definitions for internal planner nodes.
5  *
6  *
7  * Copyright (c) 1994, Regents of the University of California
8  *
9  * $Id: relation.h,v 1.16 1999/02/08 04:29:25 momjian Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef RELATION_H
14 #define RELATION_H
15
16 #include <nodes/parsenodes.h>
17 #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  * RelOptInfo
28  *              Per-base-relation information
29  *
30  *              Parts of this data structure are specific to various scan and join
31  *              mechanisms.  It didn't seem worth creating new node types for them.
32  *
33  *              relids - List of relation indentifiers
34  *              indexed - true if the relation has secondary indices
35  *              pages - number of pages in the relation
36  *              tuples - number of tuples in the relation
37  *              size - number of tuples in the relation after restrictions clauses
38  *                         have been applied
39  *              width - number of bytes per tuple in the relation after the
40  *                              appropriate projections have been done
41  *              targetlist - List of TargetList nodes
42  *              pathlist - List of Path nodes, one for each possible method of
43  *                                 generating the relation
44  *              unorderedpath - a Path node generating this relation whose resulting
45  *                                              tuples are unordered (this isn't necessarily a
46  *                                              sequential scan path, e.g., scanning with a hash index
47  *                                              leaves the tuples unordered)
48  *              cheapestpath -  least expensive Path (regardless of final order)
49  *              pruneable - flag to let the planner know whether it can prune the plan
50  *                                      space of this RelOptInfo or not.
51  *
52  *       * If the relation is a (secondary) index it will have the following
53  *              three fields:
54  *
55  *              classlist - List of PG_AMOPCLASS OIDs for the index
56  *              indexkeys - List of base-relation attribute numbers that are index keys
57  *              ordering - List of PG_OPERATOR OIDs which order the indexscan result
58  *              relam     - the OID of the pg_am of the index
59  *
60  *       * The presence of the remaining fields depends on the restrictions
61  *              and joins which the relation participates in:
62  *
63  *              restrictinfo - List of RestrictInfo nodes, containing info about each
64  *                                       qualification clause in which this relation participates
65  *              joininfo  - List of JoinInfo nodes, containing info about each join
66  *                                      clause in which this relation participates
67  *              innerjoin - List of Path nodes that represent indices that may be used
68  *                                      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 typedef struct RelOptInfo
75 {
76         NodeTag         type;
77
78         /* all relations: */
79         Relid           relids;
80
81         /* catalog statistics information */
82         bool            indexed;
83         int                     pages;
84         int                     tuples;
85         int                     size;
86         int                     width;
87
88         /* materialization information */
89         List       *targetlist;
90         List       *pathlist;           /* Path structures */
91         struct Path *unorderedpath;
92         struct Path *cheapestpath;
93         bool            pruneable;
94
95         /* used solely by indices: */
96         Oid                *classlist;          /* classes of AM operators */
97         int                *indexkeys;          /* keys over which we're indexing */
98         Oid                     relam;                  /* OID of the access method (in pg_am) */
99
100         Oid                     indproc;
101         List       *indpred;
102
103         /* used by various scans and joins: */
104         Oid                *ordering;           /* OID of operators in sort order */
105         List       *restrictinfo;       /* RestrictInfo structures */
106         List       *joininfo;           /* JoinInfo structures */
107         List       *innerjoin;
108         List       *superrels;
109 } RelOptInfo;
110
111 extern Var *get_expr(TargetEntry *foo);
112
113 typedef struct MergeOrder
114 {
115         NodeTag         type;
116         Oid                     join_operator;
117         Oid                     left_operator;
118         Oid                     right_operator;
119         Oid                     left_type;
120         Oid                     right_type;
121 } MergeOrder;
122
123 typedef enum OrderType
124 {
125         MERGE_ORDER, SORTOP_ORDER
126 } OrderType;
127
128 typedef struct PathOrder
129 {
130         OrderType       ordtype;
131         union
132         {
133                 Oid                *sortop;
134                 MergeOrder *merge;
135         } ord;
136 } PathOrder;
137
138 typedef struct Path
139 {
140         NodeTag         type;
141
142         RelOptInfo *parent;
143         Cost            path_cost;
144
145         NodeTag         pathtype;
146
147         PathOrder       path_order;
148
149         List       *keys;
150         Cost            outerjoincost;
151         Relid           joinid;
152         List       *loc_restrictinfo;
153 } Path;
154
155 typedef struct IndexPath
156 {
157         Path            path;
158         List       *indexid;
159         List       *indexqual;
160         int                *indexkeys;  /* to transform heap attnos into index ones */
161 } IndexPath;
162
163 typedef struct JoinPath
164 {
165         Path            path;
166         List       *pathinfo;
167         Path       *outerjoinpath;
168         Path       *innerjoinpath;
169 } JoinPath;
170
171 typedef struct MergePath
172 {
173         JoinPath        jpath;
174         List       *path_mergeclauses;
175         List       *outersortkeys;
176         List       *innersortkeys;
177 } MergePath;
178
179 typedef struct HashPath
180 {
181         JoinPath        jpath;
182         List       *path_hashclauses;
183         List       *outerhashkeys;
184         List       *innerhashkeys;
185 } HashPath;
186
187 /******
188  * Keys
189  ******/
190
191 typedef struct OrderKey
192 {
193         NodeTag         type;
194         int                     attribute_number;
195         Index           array_index;
196 } OrderKey;
197
198 typedef struct JoinKey
199 {
200         NodeTag         type;
201         Var                *outer;
202         Var                *inner;
203 } JoinKey;
204
205 /*******
206  * clause info
207  *******/
208
209 typedef struct RestrictInfo
210 {
211         NodeTag         type;
212         Expr       *clause;                     /* should be an OP clause */
213         Cost            selectivity;
214         bool            notclause;
215         List       *indexids;
216
217         /* mergejoin only */
218         MergeOrder *mergejoinorder;
219
220         /* hashjoin only */
221         Oid                     hashjoinoperator;
222         Relid           restrictinfojoinid;
223 } RestrictInfo;
224
225 typedef struct JoinMethod
226 {
227         NodeTag         type;
228         List       *jmkeys;
229         List       *clauses;
230 } JoinMethod;
231
232 typedef struct HashInfo
233 {
234         JoinMethod      jmethod;
235         Oid                     hashop;
236 } HashInfo;
237
238 typedef struct MergeInfo
239 {
240         JoinMethod      jmethod;
241         MergeOrder *m_ordering;
242 } MergeInfo;
243
244 typedef struct JoinInfo
245 {
246         NodeTag         type;
247         List       *otherrels;
248         List       *jinfo_restrictinfo;
249         bool            mergejoinable;
250         bool            hashjoinable;
251         bool            inactive;
252 } JoinInfo;
253
254 typedef struct Iter
255 {
256         NodeTag         type;
257         Node       *iterexpr;
258         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 ** is used to make Path nodes and clauses look similar, so that Predicate
268 ** Migration can run.
269 **
270 **         pathptr -- pointer to the current path node
271 **               cinfo -- if NULL, this stream node referes to the path node.
272 **                                Otherwise this is a pointer to the current clause.
273 **      clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the
274 **                                path node
275 **        upstream -- linked list pointer upwards
276 **      downstream -- ditto, downwards
277 **         groupup -- whether or not this node is in a group with the node upstream
278 **       groupcost -- total cost of the group that node is in
279 **        groupsel -- total selectivity of the group that node is in
280 */
281 typedef struct Stream *StreamPtr;
282
283 typedef struct Stream
284 {
285         NodeTag         type;
286         Path       *pathptr;
287         RestrictInfo *cinfo;
288         int                *clausetype;
289         struct Stream *upstream;
290         struct Stream *downstream;
291         bool            groupup;
292         Cost            groupcost;
293         Cost            groupsel;
294 } Stream;
295
296 #endif   /* RELATION_H */