]> granicus.if.org Git - postgresql/blob - src/include/nodes/relation.h
Optimizer rename ClauseInfo -> RestrictInfo. Update optimizer README.
[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.12 1999/02/03 20:15:46 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.  -- JMH, 11/11/92
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;
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;               /* restriction clauses */
106         List       *joininfo;           /* join clauses */
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       p_ordering;
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
161                                                                  * ones */
162 } IndexPath;
163
164 typedef struct JoinPath
165 {
166         Path            path;
167         List       *pathinfo;
168         Path       *outerjoinpath;
169         Path       *innerjoinpath;
170 } JoinPath;
171
172 typedef struct MergePath
173 {
174         JoinPath        jpath;
175         List       *path_mergeclauses;
176         List       *outersortkeys;
177         List       *innersortkeys;
178 } MergePath;
179
180 typedef struct HashPath
181 {
182         JoinPath        jpath;
183         List       *path_hashclauses;
184         List       *outerhashkeys;
185         List       *innerhashkeys;
186 } HashPath;
187
188 /******
189  * Keys
190  ******/
191
192 typedef struct OrderKey
193 {
194         NodeTag         type;
195         int                     attribute_number;
196         Index           array_index;
197 } OrderKey;
198
199 typedef struct JoinKey
200 {
201         NodeTag         type;
202         Var                *outer;
203         Var                *inner;
204 } JoinKey;
205
206 /*******
207  * clause info
208  *******/
209
210 typedef struct RestrictInfo
211 {
212         NodeTag         type;
213         Expr       *clause;                     /* should be an OP clause */
214         Cost            selectivity;
215         bool            notclause;
216         List       *indexids;
217
218         /* mergejoin only */
219         MergeOrder *mergejoinorder;
220
221         /* hashjoin only */
222         Oid                     hashjoinoperator;
223         Relid           cinfojoinid;
224 } RestrictInfo;
225
226 typedef struct JoinMethod
227 {
228         NodeTag         type;
229         List       *jmkeys;
230         List       *clauses;
231 } JoinMethod;
232
233 typedef struct HInfo
234 {
235         JoinMethod      jmethod;
236         Oid                     hashop;
237 } HInfo;
238
239 typedef struct MInfo
240 {
241         JoinMethod      jmethod;
242         MergeOrder *m_ordering;
243 } MInfo;
244
245 typedef struct JoinInfo
246 {
247         NodeTag         type;
248         List       *otherrels;
249         List       *jinfo_restrictinfo;
250         bool            mergejoinable;
251         bool            hashjoinable;
252         bool            inactive;
253 }                       JoinInfo;
254
255 typedef struct Iter
256 {
257         NodeTag         type;
258         Node       *iterexpr;
259         Oid                     itertype;               /* type of the iter expr (use for type
260                                                                  * checking) */
261 } 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 ** is used to make Path nodes and clauses look similar, so that Predicate
269 ** Migration can run.
270 **
271 **         pathptr -- pointer to the current path node
272 **               cinfo -- if NULL, this stream node referes to the path node.
273 **                                Otherwise this is a pointer to the current clause.
274 **      clausetype -- whether cinfo is in loc_restrictinfo or pathinfo in the
275 **                                path node
276 **        upstream -- linked list pointer upwards
277 **      downstream -- ditto, downwards
278 **         groupup -- whether or not this node is in a group with the node upstream
279 **       groupcost -- total cost of the group that node is in
280 **        groupsel -- total selectivity of the group that node is in
281 */
282 typedef struct Stream *StreamPtr;
283
284 typedef struct Stream
285 {
286         NodeTag         type;
287         Path       *pathptr;
288         RestrictInfo *cinfo;
289         int                *clausetype;
290         struct Stream *upstream;
291         struct Stream *downstream;
292         bool            groupup;
293         Cost            groupcost;
294         Cost            groupsel;
295 } Stream;
296
297 #endif   /* RELATION_H */