]> granicus.if.org Git - postgresql/blob - src/include/nodes/relation.h
Phase 1 of read-only-plans project: cause executor state nodes to point
[postgresql] / src / include / nodes / relation.h
1 /*-------------------------------------------------------------------------
2  *
3  * relation.h
4  *        Definitions for planner's internal data structures.
5  *
6  *
7  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * $Id: relation.h,v 1.73 2002/12/05 15:50:39 tgl Exp $
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELATION_H
15 #define RELATION_H
16
17 #include "access/sdir.h"
18 #include "nodes/parsenodes.h"
19
20 /*
21  * Relids
22  *              List of relation identifiers (indexes into the rangetable).
23  *
24  *              Note: these are lists of integers, not Nodes.
25  */
26
27 typedef List *Relids;
28
29 /*
30  * When looking for a "cheapest path", this enum specifies whether we want
31  * cheapest startup cost or cheapest total cost.
32  */
33 typedef enum CostSelector
34 {
35         STARTUP_COST, TOTAL_COST
36 } CostSelector;
37
38 /*----------
39  * RelOptInfo
40  *              Per-relation information for planning/optimization
41  *
42  * For planning purposes, a "base rel" is either a plain relation (a table)
43  * or the output of a sub-SELECT that appears in the range table.
44  * In either case it is uniquely identified by an RT index.  A "joinrel"
45  * is the joining of two or more base rels.  A joinrel is identified by
46  * the set of RT indexes for its component baserels.  We create RelOptInfo
47  * nodes for each baserel and joinrel, and store them in the Query's
48  * base_rel_list and join_rel_list respectively.
49  *
50  * Note that there is only one joinrel for any given set of component
51  * baserels, no matter what order we assemble them in; so an unordered
52  * set is the right datatype to identify it with.
53  *
54  * We also have "other rels", which are like base rels in that they refer to
55  * single RT indexes; but they are not part of the join tree, and are stored
56  * in other_rel_list not base_rel_list.  An otherrel is created for each
57  * join RTE as an aid in processing Vars that refer to the join's outputs,
58  * but it serves no other purpose in planning.  It is important not to
59  * confuse this otherrel with the joinrel that represents the matching set
60  * of base relations.
61  *
62  * A second category of otherrels are those made for child relations of an
63  * inheritance scan (SELECT FROM foo*).  The parent table's RTE and
64  * corresponding baserel represent the whole result of the inheritance scan.
65  * The planner creates separate RTEs and associated RelOptInfos for each child
66  * table (including the parent table, in its capacity as a member of the
67  * inheritance set).  These RelOptInfos are physically identical to baserels,
68  * but are otherrels because they are not in the main join tree.  These added
69  * RTEs and otherrels are used to plan the scans of the individual tables in
70  * the inheritance set; then the parent baserel is given an Append plan
71  * comprising the best plans for the individual child tables.
72  *
73  * Parts of this data structure are specific to various scan and join
74  * mechanisms.  It didn't seem worth creating new node types for them.
75  *
76  *              relids - List of base-relation identifiers; it is a base relation
77  *                              if there is just one, a join relation if more than one
78  *              rows - estimated number of tuples in the relation after restriction
79  *                         clauses have been applied (ie, output rows of a plan for it)
80  *              width - avg. number of bytes per tuple in the relation after the
81  *                              appropriate projections have been done (ie, output width)
82  *              targetlist - List of TargetEntry nodes for the attributes we need
83  *                                       to output from this relation
84  *              pathlist - List of Path nodes, one for each potentially useful
85  *                                 method of generating the relation
86  *              cheapest_startup_path - the pathlist member with lowest startup cost
87  *                                                              (regardless of its ordering)
88  *              cheapest_total_path - the pathlist member with lowest total cost
89  *                                                        (regardless of its ordering)
90  *              pruneable - flag to let the planner know whether it can prune the
91  *                                      pathlist of this RelOptInfo or not.
92  *
93  * If the relation is a base relation it will have these fields set:
94  *
95  *              rtekind - distinguishes plain relation, subquery, or function RTE
96  *              indexlist - list of IndexOptInfo nodes for relation's indexes
97  *                                      (always NIL if it's not a table)
98  *              pages - number of disk pages in relation (zero if not a table)
99  *              tuples - number of tuples in relation (not considering restrictions)
100  *              subplan - plan for subquery (NULL if it's not a subquery)
101  *
102  *              Note: for a subquery, tuples and subplan are not set immediately
103  *              upon creation of the RelOptInfo object; they are filled in when
104  *              set_base_rel_pathlist processes the object.
105  *
106  *              For otherrels that are inheritance children, these fields are filled
107  *              in just as for a baserel.  In otherrels for join RTEs, these fields
108  *              are empty --- the only useful field of a join otherrel is its
109  *              outerjoinset.
110  *
111  * If the relation is a join relation it will have these fields set:
112  *
113  *              joinrti - RT index of corresponding JOIN RTE, if any; 0 if none
114  *              joinrteids - List of RT indexes of JOIN RTEs included in this join
115  *                                       (including joinrti)
116  *
117  * The presence of the remaining fields depends on the restrictions
118  * and joins that the relation participates in:
119  *
120  *              baserestrictinfo - List of RestrictInfo nodes, containing info about
121  *                                      each qualification clause in which this relation
122  *                                      participates (only used for base rels)
123  *              baserestrictcost - Estimated cost of evaluating the baserestrictinfo
124  *                                      clauses at a single tuple (only used for base rels)
125  *              outerjoinset - For a base rel: if the rel appears within the nullable
126  *                                      side of an outer join, the list of all relids
127  *                                      participating in the highest such outer join; else NIL.
128  *                                      For a join otherrel: the list of all baserel relids
129  *                                      syntactically within the join.  Otherwise, unused.
130  *              joininfo  - List of JoinInfo nodes, containing info about each join
131  *                                      clause in which this relation participates
132  *              index_outer_relids - only used for base rels; list of outer relids
133  *                                      that participate in indexable joinclauses for this rel
134  *              index_inner_paths - only used for base rels; list of InnerIndexscanInfo
135  *                                      nodes showing best indexpaths for various subsets of
136  *                                      index_outer_relids.
137  *
138  * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for
139  * base rels, because for a join rel the set of clauses that are treated as
140  * restrict clauses varies depending on which sub-relations we choose to join.
141  * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be
142  * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but
143  * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2}
144  * and should not be processed again at the level of {1 2 3}.)  Therefore,
145  * the restrictinfo list in the join case appears in individual JoinPaths
146  * (field joinrestrictinfo), not in the parent relation.  But it's OK for
147  * the RelOptInfo to store the joininfo lists, because those are the same
148  * for a given rel no matter how we form it.
149  *
150  * We store baserestrictcost in the RelOptInfo (for base relations) because
151  * we know we will need it at least once (to price the sequential scan)
152  * and may need it multiple times to price index scans.
153  *
154  * outerjoinset is used to ensure correct placement of WHERE clauses that
155  * apply to outer-joined relations; we must not apply such WHERE clauses
156  * until after the outer join is performed.
157  *----------
158  */
159 typedef enum RelOptKind
160 {
161         RELOPT_BASEREL,
162         RELOPT_JOINREL,
163         RELOPT_OTHER_JOIN_REL,
164         RELOPT_OTHER_CHILD_REL
165 } RelOptKind;
166
167 typedef struct RelOptInfo
168 {
169         NodeTag         type;
170
171         RelOptKind      reloptkind;
172
173         /* all relations included in this RelOptInfo */
174         Relids          relids;                 /* integer list of base relids (rangetable
175                                                                  * indexes) */
176
177         /* size estimates generated by planner */
178         double          rows;                   /* estimated number of result tuples */
179         int                     width;                  /* estimated avg width of result tuples */
180
181         /* materialization information */
182         List       *targetlist;
183         List       *pathlist;           /* Path structures */
184         struct Path *cheapest_startup_path;
185         struct Path *cheapest_total_path;
186         bool            pruneable;
187
188         /* information about a base rel (not set for join rels!) */
189         RTEKind         rtekind;                /* RELATION, SUBQUERY, or FUNCTION */
190         List       *indexlist;
191         long            pages;
192         double          tuples;
193         struct Plan *subplan;           /* if subquery */
194
195         /* information about a join rel (not set for base rels!) */
196         Index           joinrti;
197         List       *joinrteids;
198
199         /* used by various scans and joins: */
200         List       *baserestrictinfo;           /* RestrictInfo structures (if
201                                                                                  * base rel) */
202         Cost            baserestrictcost;               /* cost of evaluating the above */
203         Relids          outerjoinset;   /* integer list of base relids */
204         List       *joininfo;           /* JoinInfo structures */
205
206         /* cached info about inner indexscan paths for relation: */
207         Relids          index_outer_relids;             /* other relids in indexable join
208                                                                                  * clauses */
209         List       *index_inner_paths;          /* InnerIndexscanInfo nodes */
210         /*
211          * Inner indexscans are not in the main pathlist because they are
212          * not usable except in specific join contexts.  We use the
213          * index_inner_paths list just to avoid recomputing the best inner
214          * indexscan repeatedly for similar outer relations.  See comments
215          * for InnerIndexscanInfo.
216          */
217 } RelOptInfo;
218
219 /*
220  * IndexOptInfo
221  *              Per-index information for planning/optimization
222  *
223  *              Prior to Postgres 7.0, RelOptInfo was used to describe both relations
224  *              and indexes, but that created confusion without actually doing anything
225  *              useful.  So now we have a separate IndexOptInfo struct for indexes.
226  *
227  *              ncolumns and nkeys are the same except for a functional index,
228  *              wherein ncolumns is 1 (the single function output) while nkeys
229  *              is the number of table columns passed to the function. classlist[]
230  *              and ordering[] have ncolumns entries, while indexkeys[] has nkeys
231  *              entries.
232  *
233  *              Note: for historical reasons, the arrays classlist, indexkeys and
234  *              ordering have an extra entry that is always zero.  Some code scans
235  *              until it sees a zero rather than looking at ncolumns or nkeys.
236  */
237
238 typedef struct IndexOptInfo
239 {
240         NodeTag         type;
241
242         Oid                     indexoid;               /* OID of the index relation */
243
244         /* statistics from pg_class */
245         long            pages;                  /* number of disk pages in index */
246         double          tuples;                 /* number of index tuples in index */
247
248         /* index descriptor information */
249         int                     ncolumns;               /* number of columns in index */
250         int                     nkeys;                  /* number of keys used by index */
251         Oid                *classlist;          /* OIDs of operator classes for columns */
252         int                *indexkeys;          /* column numbers of index's keys */
253         Oid                *ordering;           /* OIDs of sort operators for each column */
254         Oid                     relam;                  /* OID of the access method (in pg_am) */
255
256         RegProcedure amcostestimate;    /* OID of the access method's cost fcn */
257
258         Oid                     indproc;                /* OID of func if functional index, else 0 */
259         List       *indpred;            /* predicate if a partial index, else NIL */
260         bool            unique;                 /* true if a unique index */
261
262         /* cached info about inner indexscan paths for index */
263         Relids          outer_relids;   /* other relids in usable join clauses */
264         List       *inner_paths;        /* List of InnerIndexscanInfo nodes */
265 } IndexOptInfo;
266
267
268 /*
269  * A Var is considered to belong to a relation if it's either from one
270  * of the actual base rels making up the relation, or it's a join alias
271  * var that is included in the relation.
272  */
273 #define VARISRELMEMBER(varno,rel) (intMember((varno), (rel)->relids) || \
274                                                                    intMember((varno), (rel)->joinrteids))
275
276
277 /*
278  * PathKeys
279  *
280  *      The sort ordering of a path is represented by a list of sublists of
281  *      PathKeyItem nodes.      An empty list implies no known ordering.  Otherwise
282  *      the first sublist represents the primary sort key, the second the
283  *      first secondary sort key, etc.  Each sublist contains one or more
284  *      PathKeyItem nodes, each of which can be taken as the attribute that
285  *      appears at that sort position.  (See the top of optimizer/path/pathkeys.c
286  *      for more information.)
287  */
288
289 typedef struct PathKeyItem
290 {
291         NodeTag         type;
292
293         Node       *key;                        /* the item that is ordered */
294         Oid                     sortop;                 /* the ordering operator ('<' op) */
295
296         /*
297          * key typically points to a Var node, ie a relation attribute, but it
298          * can also point to a Func clause representing the value indexed by a
299          * functional index.  Someday we might allow arbitrary expressions as
300          * path keys, so don't assume more than you must.
301          */
302 } PathKeyItem;
303
304 /*
305  * Type "Path" is used as-is for sequential-scan paths.  For other
306  * path types it is the first component of a larger struct.
307  *
308  * Note: "pathtype" is the NodeTag of the Plan node we could build from this
309  * Path.  It is partially redundant with the Path's NodeTag, but allows us
310  * to use the same Path type for multiple Plan types where there is no need
311  * to distinguish the Plan type during path processing.
312  */
313
314 typedef struct Path
315 {
316         NodeTag         type;
317
318         RelOptInfo *parent;                     /* the relation this path can build */
319
320         /* estimated execution costs for path (see costsize.c for more info) */
321         Cost            startup_cost;   /* cost expended before fetching any
322                                                                  * tuples */
323         Cost            total_cost;             /* total cost (assuming all tuples
324                                                                  * fetched) */
325
326         NodeTag         pathtype;               /* tag identifying scan/join method */
327
328         List       *pathkeys;           /* sort ordering of path's output */
329         /* pathkeys is a List of Lists of PathKeyItem nodes; see above */
330 } Path;
331
332 /*----------
333  * IndexPath represents an index scan.  Although an indexscan can only read
334  * a single relation, it can scan it more than once, potentially using a
335  * different index during each scan.  The result is the union (OR) of all the
336  * tuples matched during any scan.      (The executor is smart enough not to return
337  * the same tuple more than once, even if it is matched in multiple scans.)
338  *
339  * 'indexinfo' is a list of IndexOptInfo nodes, one per scan to be performed.
340  *
341  * 'indexqual' is a list of index qualifications, also one per scan.
342  * Each entry in 'indexqual' is a sublist of qualification expressions with
343  * implicit AND semantics across the sublist items.  Only expressions that
344  * are usable as indexquals (as determined by indxpath.c) may appear here.
345  * NOTE that the semantics of the top-level list in 'indexqual' is OR
346  * combination, while the sublists are implicitly AND combinations!
347  * Also note that indexquals lists do not contain RestrictInfo nodes,
348  * just bare clause expressions.
349  *
350  * 'indexscandir' is one of:
351  *              ForwardScanDirection: forward scan of an ordered index
352  *              BackwardScanDirection: backward scan of an ordered index
353  *              NoMovementScanDirection: scan of an unordered index, or don't care
354  * (The executor doesn't care whether it gets ForwardScanDirection or
355  * NoMovementScanDirection for an indexscan, but the planner wants to
356  * distinguish ordered from unordered indexes for building pathkeys.)
357  *
358  * 'rows' is the estimated result tuple count for the indexscan.  This
359  * is the same as path.parent->rows for a simple indexscan, but it is
360  * different for a nestloop inner scan, because the additional indexquals
361  * coming from join clauses make the scan more selective than the parent
362  * rel's restrict clauses alone would do.
363  *----------
364  */
365 typedef struct IndexPath
366 {
367         Path            path;
368         List       *indexinfo;
369         List       *indexqual;
370         ScanDirection indexscandir;
371         double          rows;                   /* estimated number of result tuples */
372 } IndexPath;
373
374 /*
375  * TidPath represents a scan by TID
376  */
377 typedef struct TidPath
378 {
379         Path            path;
380         List       *tideval;            /* qual(s) involving CTID = something */
381 } TidPath;
382
383 /*
384  * AppendPath represents an Append plan, ie, successive execution of
385  * several member plans.  Currently it is only used to handle expansion
386  * of inheritance trees.
387  */
388 typedef struct AppendPath
389 {
390         Path            path;
391         List       *subpaths;           /* list of component Paths */
392 } AppendPath;
393
394 /*
395  * ResultPath represents use of a Result plan node, either to compute a
396  * variable-free targetlist or to gate execution of a subplan with a
397  * one-time (variable-free) qual condition.  Note that in the former case
398  * path.parent will be NULL; in the latter case it is copied from the subpath.
399  */
400 typedef struct ResultPath
401 {
402         Path            path;
403         Path       *subpath;
404         List       *constantqual;
405 } ResultPath;
406
407 /*
408  * MaterialPath represents use of a Material plan node, i.e., caching of
409  * the output of its subpath.  This is used when the subpath is expensive
410  * and needs to be scanned repeatedly, or when we need mark/restore ability
411  * and the subpath doesn't have it.
412  */
413 typedef struct MaterialPath
414 {
415         Path            path;
416         Path       *subpath;
417 } MaterialPath;
418
419 /*
420  * All join-type paths share these fields.
421  */
422
423 typedef struct JoinPath
424 {
425         Path            path;
426
427         JoinType        jointype;
428
429         Path       *outerjoinpath;      /* path for the outer side of the join */
430         Path       *innerjoinpath;      /* path for the inner side of the join */
431
432         List       *joinrestrictinfo;           /* RestrictInfos to apply to join */
433
434         /*
435          * See the notes for RelOptInfo to understand why joinrestrictinfo is
436          * needed in JoinPath, and can't be merged into the parent RelOptInfo.
437          */
438 } JoinPath;
439
440 /*
441  * A nested-loop path needs no special fields.
442  */
443
444 typedef JoinPath NestPath;
445
446 /*
447  * A mergejoin path has these fields.
448  *
449  * path_mergeclauses lists the clauses (in the form of RestrictInfos)
450  * that will be used in the merge.      (Before 7.0, this was a list of bare
451  * clause expressions, but we can save on list memory and cost_qual_eval
452  * work by leaving it in the form of a RestrictInfo list.)
453  *
454  * Note that the mergeclauses are a subset of the parent relation's
455  * restriction-clause list.  Any join clauses that are not mergejoinable
456  * appear only in the parent's restrict list, and must be checked by a
457  * qpqual at execution time.
458  *
459  * outersortkeys (resp. innersortkeys) is NIL if the outer path
460  * (resp. inner path) is already ordered appropriately for the
461  * mergejoin.  If it is not NIL then it is a PathKeys list describing
462  * the ordering that must be created by an explicit sort step.
463  */
464
465 typedef struct MergePath
466 {
467         JoinPath        jpath;
468         List       *path_mergeclauses;          /* join clauses to be used for
469                                                                                  * merge */
470         List       *outersortkeys;      /* keys for explicit sort, if any */
471         List       *innersortkeys;      /* keys for explicit sort, if any */
472 } MergePath;
473
474 /*
475  * A hashjoin path has these fields.
476  *
477  * The remarks above for mergeclauses apply for hashclauses as well.
478  *
479  * Hashjoin does not care what order its inputs appear in, so we have
480  * no need for sortkeys.
481  */
482
483 typedef struct HashPath
484 {
485         JoinPath        jpath;
486         List       *path_hashclauses;           /* join clauses used for hashing */
487 } HashPath;
488
489 /*
490  * Restriction clause info.
491  *
492  * We create one of these for each AND sub-clause of a restriction condition
493  * (WHERE or JOIN/ON clause).  Since the restriction clauses are logically
494  * ANDed, we can use any one of them or any subset of them to filter out
495  * tuples, without having to evaluate the rest.  The RestrictInfo node itself
496  * stores data used by the optimizer while choosing the best query plan.
497  *
498  * If a restriction clause references a single base relation, it will appear
499  * in the baserestrictinfo list of the RelOptInfo for that base rel.
500  *
501  * If a restriction clause references more than one base rel, it will
502  * appear in the JoinInfo lists of every RelOptInfo that describes a strict
503  * subset of the base rels mentioned in the clause.  The JoinInfo lists are
504  * used to drive join tree building by selecting plausible join candidates.
505  * The clause cannot actually be applied until we have built a join rel
506  * containing all the base rels it references, however.
507  *
508  * When we construct a join rel that includes all the base rels referenced
509  * in a multi-relation restriction clause, we place that clause into the
510  * joinrestrictinfo lists of paths for the join rel, if neither left nor
511  * right sub-path includes all base rels referenced in the clause.      The clause
512  * will be applied at that join level, and will not propagate any further up
513  * the join tree.  (Note: the "predicate migration" code was once intended to
514  * push restriction clauses up and down the plan tree based on evaluation
515  * costs, but it's dead code and is unlikely to be resurrected in the
516  * foreseeable future.)
517  *
518  * Note that in the presence of more than two rels, a multi-rel restriction
519  * might reach different heights in the join tree depending on the join
520  * sequence we use.  So, these clauses cannot be associated directly with
521  * the join RelOptInfo, but must be kept track of on a per-join-path basis.
522  *
523  * When dealing with outer joins we have to be very careful about pushing qual
524  * clauses up and down the tree.  An outer join's own JOIN/ON conditions must
525  * be evaluated exactly at that join node, and any quals appearing in WHERE or
526  * in a JOIN above the outer join cannot be pushed down below the outer join.
527  * Otherwise the outer join will produce wrong results because it will see the
528  * wrong sets of input rows.  All quals are stored as RestrictInfo nodes
529  * during planning, but there's a flag to indicate whether a qual has been
530  * pushed down to a lower level than its original syntactic placement in the
531  * join tree would suggest.  If an outer join prevents us from pushing a qual
532  * down to its "natural" semantic level (the level associated with just the
533  * base rels used in the qual) then the qual will appear in JoinInfo lists
534  * that reference more than just the base rels it actually uses.  By
535  * pretending that the qual references all the rels appearing in the outer
536  * join, we prevent it from being evaluated below the outer join's joinrel.
537  * When we do form the outer join's joinrel, we still need to distinguish
538  * those quals that are actually in that join's JOIN/ON condition from those
539  * that appeared higher in the tree and were pushed down to the join rel
540  * because they used no other rels.  That's what the ispusheddown flag is for;
541  * it tells us that a qual came from a point above the join of the specific
542  * set of base rels that it uses (or that the JoinInfo structures claim it
543  * uses).  A clause that originally came from WHERE will *always* have its
544  * ispusheddown flag set; a clause that came from an INNER JOIN condition,
545  * but doesn't use all the rels being joined, will also have ispusheddown set
546  * because it will get attached to some lower joinrel.
547  *
548  * In general, the referenced clause might be arbitrarily complex.      The
549  * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
550  * or hashjoin clauses are fairly limited --- the code for each kind of
551  * path is responsible for identifying the restrict clauses it can use
552  * and ignoring the rest.  Clauses not implemented by an indexscan,
553  * mergejoin, or hashjoin will be placed in the plan qual or joinqual field
554  * of the finished Plan node, where they will be enforced by general-purpose
555  * qual-expression-evaluation code.  (But we are still entitled to count
556  * their selectivity when estimating the result tuple count, if we
557  * can guess what it is...)
558  */
559
560 typedef struct RestrictInfo
561 {
562         NodeTag         type;
563
564         Expr       *clause;                     /* the represented clause of WHERE or JOIN */
565
566         bool            ispusheddown;   /* TRUE if clause was pushed down in level */
567
568         /* only used if clause is an OR clause: */
569         List       *subclauseindices;           /* indexes matching subclauses */
570         /* subclauseindices is a List of Lists of IndexOptInfos */
571
572         /* cache space for costs (currently only used for join clauses) */
573         Cost            eval_cost;              /* eval cost of clause; -1 if not yet set */
574         Selectivity this_selec;         /* selectivity; -1 if not yet set */
575
576         /* valid if clause is mergejoinable, else InvalidOid: */
577         Oid                     mergejoinoperator;              /* copy of clause operator */
578         Oid                     left_sortop;    /* leftside sortop needed for mergejoin */
579         Oid                     right_sortop;   /* rightside sortop needed for mergejoin */
580
581         /* cache space for mergeclause processing; NIL if not yet set */
582         List       *left_pathkey;       /* canonical pathkey for left side */
583         List       *right_pathkey;      /* canonical pathkey for right side */
584
585         /* cache space for mergeclause processing; -1 if not yet set */
586         Selectivity left_mergescansel;          /* fraction of left side to scan */
587         Selectivity right_mergescansel;         /* fraction of right side to scan */
588
589         /* valid if clause is hashjoinable, else InvalidOid: */
590         Oid                     hashjoinoperator;               /* copy of clause operator */
591
592         /* cache space for hashclause processing; -1 if not yet set */
593         Selectivity left_bucketsize;    /* avg bucketsize of left side */
594         Selectivity right_bucketsize;           /* avg bucketsize of right side */
595 } RestrictInfo;
596
597 /*
598  * Join clause info.
599  *
600  * We make a list of these for each RelOptInfo, containing info about
601  * all the join clauses this RelOptInfo participates in.  (For this
602  * purpose, a "join clause" is a WHERE clause that mentions both vars
603  * belonging to this relation and vars belonging to relations not yet
604  * joined to it.)  We group these clauses according to the set of
605  * other base relations (unjoined relations) mentioned in them.
606  * There is one JoinInfo for each distinct set of unjoined_relids,
607  * and its jinfo_restrictinfo lists the clause(s) that use that set
608  * of other relations.
609  */
610
611 typedef struct JoinInfo
612 {
613         NodeTag         type;
614         Relids          unjoined_relids;        /* some rels not yet part of my RelOptInfo */
615         List       *jinfo_restrictinfo;         /* relevant RestrictInfos */
616 } JoinInfo;
617
618 /*
619  * Inner indexscan info.
620  *
621  * An inner indexscan is one that uses one or more joinclauses as index
622  * conditions (perhaps in addition to plain restriction clauses).  So it
623  * can only be used as the inner path of a nestloop join where the outer
624  * relation includes all other relids appearing in those joinclauses.
625  * The set of usable joinclauses, and thus the best inner indexscan,
626  * thus varies depending on which outer relation we consider; so we have
627  * to recompute the best such path for every join.  To avoid lots of
628  * redundant computation, we cache the results of such searches.  For
629  * each index we compute the set of possible otherrelids (all relids
630  * appearing in joinquals that could become indexquals for this index).
631  * Two outer relations whose relids have the same intersection with this
632  * set will have the same set of available joinclauses and thus the same
633  * best inner indexscan for that index.  Similarly, for each base relation,
634  * we form the union of the per-index otherrelids sets.  Two outer relations
635  * with the same intersection with that set will have the same best overall
636  * inner indexscan for the base relation.  We use lists of InnerIndexscanInfo
637  * nodes to cache the results of these searches at both the index and
638  * relation level.
639  *
640  * The search key also includes a bool showing whether the join being
641  * considered is an outer join.  Since we constrain the join order for
642  * outer joins, I believe that this bool can only have one possible value
643  * for any particular base relation; but store it anyway to avoid confusion.
644  */
645
646 typedef struct InnerIndexscanInfo
647 {
648         NodeTag         type;
649         /* The lookup key: */
650         Relids          other_relids;   /* a set of relevant other relids */
651         bool            isouterjoin;    /* true if join is outer */
652         /* Best path for this lookup key: */
653         Path       *best_innerpath;     /* best inner indexscan, or NULL if none */
654 } InnerIndexscanInfo;
655
656 #endif   /* RELATION_H */