]> granicus.if.org Git - postgresql/blob - src/include/nodes/relation.h
Patches for Vadim's multikey indexing...
[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.4 1997/03/18 18:41:37 scrappy 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  * Rel
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 Rel 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  *      clauseinfo - List of ClauseInfo 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 Rel {
75     NodeTag     type;
76
77     /* all relations: */
78     Relid       relids;
79
80     /* catalog statistics information */
81     bool        indexed;
82     int         pages;
83     int         tuples;
84     int         size;
85     int         width;
86
87     /* materialization information */
88     List        *targetlist;
89     List        *pathlist;
90     struct Path *unorderedpath;
91     struct Path *cheapestpath;
92     bool        pruneable;
93
94     /* used solely by indices: */
95     Oid         *classlist;             /* classes of AM operators */
96     int         *indexkeys;             /* keys over which we're indexing */
97     Oid         relam;  /* OID of the access method (in pg_am) */
98                                    
99     Oid         indproc;
100     List        *indpred;
101
102     /* used by various scans and joins: */
103     Oid         *ordering;              /* OID of operators in sort order */
104     List        *clauseinfo;            /* restriction clauses */
105     List        *joininfo;              /* join clauses */
106     List        *innerjoin;
107     List        *superrels;
108 } Rel;
109
110 extern Var *get_expr(TargetEntry *foo);
111
112 typedef struct MergeOrder {
113     NodeTag     type;
114     Oid         join_operator;
115     Oid         left_operator;
116     Oid         right_operator;
117     Oid         left_type;
118     Oid         right_type;
119 } MergeOrder;
120
121 typedef enum OrderType {
122     MERGE_ORDER, SORTOP_ORDER
123 } OrderType;
124
125 typedef struct PathOrder {
126     OrderType   ordtype;
127     union {
128         Oid             *sortop;
129         MergeOrder      *merge;
130     } ord;
131 } PathOrder;
132
133 typedef struct Path {
134     NodeTag     type;
135
136     Rel         *parent;
137     Cost        path_cost;
138
139     NodeTag     pathtype;
140
141     PathOrder   p_ordering;
142
143     List        *keys;
144     Cost        outerjoincost;
145     Relid       joinid;
146     List        *locclauseinfo;
147 } Path;
148
149 typedef struct IndexPath {
150     Path        path;
151     List        *indexid;
152     List        *indexqual;
153     int         *indexkeys;     /* to transform heap attnos into index ones */
154 } IndexPath;
155
156 typedef struct JoinPath {
157     Path        path;
158     List        *pathclauseinfo;
159     Path        *outerjoinpath;
160     Path        *innerjoinpath;
161 } JoinPath;
162
163 typedef struct MergePath {
164     JoinPath    jpath;
165     List        *path_mergeclauses;
166     List        *outersortkeys;
167     List        *innersortkeys;
168 } MergePath;
169
170 typedef struct HashPath {
171     JoinPath    jpath;
172     List        *path_hashclauses;
173     List        *outerhashkeys;
174     List        *innerhashkeys;
175 } HashPath;
176
177 /******
178  * Keys
179  ******/
180
181 typedef struct OrderKey {
182     NodeTag     type;
183     int         attribute_number;
184     Index       array_index;
185 } OrderKey;
186
187 typedef struct JoinKey {
188     NodeTag     type;
189     Var         *outer;
190     Var         *inner;
191 } JoinKey;
192
193 /*******
194  * clause info
195  *******/
196
197 typedef struct CInfo {
198     NodeTag     type;
199     Expr        *clause;        /* should be an OP clause */
200     Cost        selectivity;
201     bool        notclause;
202     List        *indexids;
203
204     /* mergesort only */
205     MergeOrder  *mergesortorder;
206
207     /* hashjoin only */
208     Oid         hashjoinoperator;
209     Relid       cinfojoinid;
210 } CInfo;
211
212 typedef struct JoinMethod {
213     NodeTag     type;
214     List        *jmkeys;
215     List        *clauses;
216 } JoinMethod;
217
218 typedef struct HInfo {
219     JoinMethod  jmethod;
220     Oid         hashop;
221 } HInfo;
222
223 typedef struct MInfo {
224     JoinMethod  jmethod;
225     MergeOrder  *m_ordering;
226 } MInfo;
227
228 typedef struct JInfo {
229     NodeTag     type;
230     List        *otherrels;
231     List        *jinfoclauseinfo;
232     bool        mergesortable;
233     bool        hashjoinable;
234     bool        inactive;
235 } JInfo;
236
237 typedef struct Iter {
238     NodeTag     type;
239     Node        *iterexpr;
240     Oid         itertype;       /* type of the iter expr (use for type
241                                    checking) */
242 } Iter;
243
244 /*
245 ** Stream:
246 **   A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
247 ** JoinPaths and Paths).  The stream includes pointers to all Path nodes,
248 ** as well as to any clauses that reside above Path nodes.  This structure
249 ** is used to make Path nodes and clauses look similar, so that Predicate
250 ** Migration can run.
251 **
252 **     pathptr -- pointer to the current path node
253 **       cinfo -- if NULL, this stream node referes to the path node.
254 **                Otherwise this is a pointer to the current clause.
255 **  clausetype -- whether cinfo is in locclauseinfo or pathclauseinfo in the 
256 **                path node
257 **    upstream -- linked list pointer upwards
258 **  downstream -- ditto, downwards
259 **     groupup -- whether or not this node is in a group with the node upstream
260 **   groupcost -- total cost of the group that node is in
261 **    groupsel -- total selectivity of the group that node is in
262 */
263 typedef struct Stream *StreamPtr;
264
265 typedef struct Stream {
266     NodeTag     type;
267     Path        *pathptr;
268     CInfo       *cinfo;
269     int         *clausetype;
270     struct Stream *upstream;
271     struct Stream *downstream;
272     bool        groupup;
273     Cost        groupcost;
274     Cost         groupsel;
275 } Stream;
276
277 #endif /* RELATION_H */