]> granicus.if.org Git - postgresql/blob - src/include/nodes/relation.h
remove:
[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.2 1996/10/31 09:49:18 scrappy Exp $
10  *
11  *-------------------------------------------------------------------------
12  */
13 #ifndef RELATION_H
14 #define RELATION_H
15
16 #include "nodes/pg_list.h"
17 #include "nodes/primnodes.h"
18 #include "nodes/parsenodes.h"
19 #include "nodes/nodes.h"
20
21 /*
22  * Relid
23  *      List of relation identifiers (indexes into the rangetable).
24  */
25
26 typedef List    *Relid;
27
28 /*
29  * Rel
30  *      Per-base-relation information
31  *
32  *      Parts of this data structure are specific to various scan and join
33  *      mechanisms.  It didn't seem worth creating new node types for them.
34  *
35  *      relids - List of relation indentifiers
36  *      indexed - true if the relation has secondary indices
37  *      pages - number of pages in the relation
38  *      tuples - number of tuples in the relation
39  *      size - number of tuples in the relation after restrictions clauses
40  *             have been applied
41  *      width - number of bytes per tuple in the relation after the
42  *              appropriate projections have been done
43  *      targetlist - List of TargetList nodes
44  *      pathlist - List of Path nodes, one for each possible method of
45  *                 generating the relation
46  *      unorderedpath - a Path node generating this relation whose resulting
47  *                      tuples are unordered (this isn't necessarily a
48  *                      sequential scan path, e.g., scanning with a hash index
49  *                      leaves the tuples unordered)
50  *      cheapestpath -  least expensive Path (regardless of final order)
51  *      pruneable - flag to let the planner know whether it can prune the plan
52  *                  space of this Rel or not.  -- JMH, 11/11/92
53  *
54  *   * If the relation is a (secondary) index it will have the following
55  *      three fields:
56  *
57  *      classlist - List of PG_AMOPCLASS OIDs for the index
58  *      indexkeys - List of base-relation attribute numbers that are index keys
59  *      ordering - List of PG_OPERATOR OIDs which order the indexscan result
60  *      relam     - the OID of the pg_am of the index
61  *
62  *   * The presence of the remaining fields depends on the restrictions
63  *      and joins which the relation participates in:
64  *
65  *      clauseinfo - List of ClauseInfo nodes, containing info about each
66  *                   qualification clause in which this relation participates
67  *      joininfo  - List of JoinInfo nodes, containing info about each join
68  *                  clause in which this relation participates
69  *      innerjoin - List of Path nodes that represent indices that may be used
70  *                  as inner paths of nestloop joins
71  *
72  * NB. the last element of the arrays classlist, indexkeys and ordering
73  *     is always 0.                             2/95 - ay
74  */
75
76 typedef struct Rel {
77     NodeTag     type;
78
79     /* all relations: */
80     Relid       relids;
81
82     /* catalog statistics information */
83     bool        indexed;
84     int         pages;
85     int         tuples;
86     int         size;
87     int         width;
88
89     /* materialization information */
90     List        *targetlist;
91     List        *pathlist;
92     struct Path *unorderedpath;
93     struct Path *cheapestpath;
94     bool        pruneable;
95
96     /* used solely by indices: */
97     Oid         *classlist;             /* classes of AM operators */
98     int         *indexkeys;             /* keys over which we're indexing */
99     Oid         relam;  /* OID of the access method (in pg_am) */
100                                    
101     Oid         indproc;
102     List        *indpred;
103
104     /* used by various scans and joins: */
105     Oid         *ordering;              /* OID of operators in sort order */
106     List        *clauseinfo;            /* restriction clauses */
107     List        *joininfo;              /* join clauses */
108     List        *innerjoin;
109     List        *superrels;
110 } Rel;
111
112 extern Var *get_expr(TargetEntry *foo);
113
114 typedef struct MergeOrder {
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     MERGE_ORDER, SORTOP_ORDER
125 } OrderType;
126
127 typedef struct PathOrder {
128     OrderType   ordtype;
129     union {
130         Oid             *sortop;
131         MergeOrder      *merge;
132     } ord;
133 } PathOrder;
134
135 typedef struct Path {
136     NodeTag     type;
137
138     Rel         *parent;
139     Cost        path_cost;
140
141     NodeTag     pathtype;
142
143     PathOrder   p_ordering;
144
145     List        *keys;
146     Cost        outerjoincost;
147     Relid       joinid;
148     List        *locclauseinfo;
149 } Path;
150
151 typedef struct IndexPath {
152     Path        path;
153     List        *indexid;
154     List        *indexqual;
155 } IndexPath;
156
157 typedef struct JoinPath {
158     Path        path;
159     List        *pathclauseinfo;
160     Path        *outerjoinpath;
161     Path        *innerjoinpath;
162 } JoinPath;
163
164 typedef struct MergePath {
165     JoinPath    jpath;
166     List        *path_mergeclauses;
167     List        *outersortkeys;
168     List        *innersortkeys;
169 } MergePath;
170
171 typedef struct HashPath {
172     JoinPath    jpath;
173     List        *path_hashclauses;
174     List        *outerhashkeys;
175     List        *innerhashkeys;
176 } HashPath;
177
178 /******
179  * Keys
180  ******/
181
182 typedef struct OrderKey {
183     NodeTag     type;
184     int         attribute_number;
185     Index       array_index;
186 } OrderKey;
187
188 typedef struct JoinKey {
189     NodeTag     type;
190     Var         *outer;
191     Var         *inner;
192 } JoinKey;
193
194 /*******
195  * clause info
196  *******/
197
198 typedef struct CInfo {
199     NodeTag     type;
200     Expr        *clause;        /* should be an OP clause */
201     Cost        selectivity;
202     bool        notclause;
203     List        *indexids;
204
205     /* mergesort only */
206     MergeOrder  *mergesortorder;
207
208     /* hashjoin only */
209     Oid         hashjoinoperator;
210     Relid       cinfojoinid;
211 } CInfo;
212
213 typedef struct JoinMethod {
214     NodeTag     type;
215     List        *jmkeys;
216     List        *clauses;
217 } JoinMethod;
218
219 typedef struct HInfo {
220     JoinMethod  jmethod;
221     Oid         hashop;
222 } HInfo;
223
224 typedef struct MInfo {
225     JoinMethod  jmethod;
226     MergeOrder  *m_ordering;
227 } MInfo;
228
229 typedef struct JInfo {
230     NodeTag     type;
231     List        *otherrels;
232     List        *jinfoclauseinfo;
233     bool        mergesortable;
234     bool        hashjoinable;
235     bool        inactive;
236 } JInfo;
237
238 typedef struct Iter {
239     NodeTag     type;
240     Node        *iterexpr;
241     Oid         itertype;       /* type of the iter expr (use for type
242                                    checking) */
243 } Iter;
244
245 /*
246 ** Stream:
247 **   A stream represents a root-to-leaf path in a plan tree (i.e. a tree of
248 ** JoinPaths and Paths).  The stream includes pointers to all Path nodes,
249 ** as well as to any clauses that reside above Path nodes.  This structure
250 ** is used to make Path nodes and clauses look similar, so that Predicate
251 ** Migration can run.
252 **
253 **     pathptr -- pointer to the current path node
254 **       cinfo -- if NULL, this stream node referes to the path node.
255 **                Otherwise this is a pointer to the current clause.
256 **  clausetype -- whether cinfo is in locclauseinfo or pathclauseinfo in the 
257 **                path node
258 **    upstream -- linked list pointer upwards
259 **  downstream -- ditto, downwards
260 **     groupup -- whether or not this node is in a group with the node upstream
261 **   groupcost -- total cost of the group that node is in
262 **    groupsel -- total selectivity of the group that node is in
263 */
264 typedef struct Stream *StreamPtr;
265
266 typedef struct Stream {
267     NodeTag     type;
268     Path        *pathptr;
269     CInfo       *cinfo;
270     int         *clausetype;
271     struct Stream *upstream;
272     struct Stream *downstream;
273     bool        groupup;
274     Cost        groupcost;
275     Cost         groupsel;
276 } Stream;
277
278 #endif /* RELATION_H */