PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
relation.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * relation.h
4  * Definitions for planner's internal data structures.
5  *
6  *
7  * Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
8  * Portions Copyright (c) 1994, Regents of the University of California
9  *
10  * src/include/nodes/relation.h
11  *
12  *-------------------------------------------------------------------------
13  */
14 #ifndef RELATION_H
15 #define RELATION_H
16 
17 #include "access/sdir.h"
18 #include "lib/stringinfo.h"
19 #include "nodes/params.h"
20 #include "nodes/parsenodes.h"
21 #include "storage/block.h"
22 
23 
24 /*
25  * Relids
26  * Set of relation identifiers (indexes into the rangetable).
27  */
28 typedef Bitmapset *Relids;
29 
30 /*
31  * When looking for a "cheapest path", this enum specifies whether we want
32  * cheapest startup cost or cheapest total cost.
33  */
34 typedef enum CostSelector
35 {
37 } CostSelector;
38 
39 /*
40  * The cost estimate produced by cost_qual_eval() includes both a one-time
41  * (startup) cost, and a per-tuple cost.
42  */
43 typedef struct QualCost
44 {
45  Cost startup; /* one-time cost */
46  Cost per_tuple; /* per-evaluation cost */
47 } QualCost;
48 
49 /*
50  * Costing aggregate function execution requires these statistics about
51  * the aggregates to be executed by a given Agg node. Note that the costs
52  * include the execution costs of the aggregates' argument expressions as
53  * well as the aggregate functions themselves. Also, the fields must be
54  * defined so that initializing the struct to zeroes with memset is correct.
55  */
56 typedef struct AggClauseCosts
57 {
58  int numAggs; /* total number of aggregate functions */
59  int numOrderedAggs; /* number w/ DISTINCT/ORDER BY/WITHIN GROUP */
60  bool hasNonPartial; /* does any agg not support partial mode? */
61  bool hasNonSerial; /* is any partial agg non-serializable? */
62  QualCost transCost; /* total per-input-row execution costs */
63  Cost finalCost; /* total per-aggregated-row costs */
64  Size transitionSpace; /* space for pass-by-ref transition data */
66 
67 /*
68  * This enum identifies the different types of "upper" (post-scan/join)
69  * relations that we might deal with during planning.
70  */
71 typedef enum UpperRelationKind
72 {
73  UPPERREL_SETOP, /* result of UNION/INTERSECT/EXCEPT, if any */
74  UPPERREL_GROUP_AGG, /* result of grouping/aggregation, if any */
75  UPPERREL_WINDOW, /* result of window functions, if any */
76  UPPERREL_DISTINCT, /* result of "SELECT DISTINCT", if any */
77  UPPERREL_ORDERED, /* result of ORDER BY, if any */
78  UPPERREL_FINAL /* result of any remaining top-level actions */
79  /* NB: UPPERREL_FINAL must be last enum entry; it's used to size arrays */
81 
82 
83 /*----------
84  * PlannerGlobal
85  * Global information for planning/optimization
86  *
87  * PlannerGlobal holds state for an entire planner invocation; this state
88  * is shared across all levels of sub-Queries that exist in the command being
89  * planned.
90  *----------
91  */
92 typedef struct PlannerGlobal
93 {
95 
96  ParamListInfo boundParams; /* Param values provided to planner() */
97 
98  List *subplans; /* Plans for SubPlan nodes */
99 
100  List *subroots; /* PlannerInfos for SubPlan nodes */
101 
102  Bitmapset *rewindPlanIDs; /* indices of subplans that require REWIND */
103 
104  List *finalrtable; /* "flat" rangetable for executor */
105 
106  List *finalrowmarks; /* "flat" list of PlanRowMarks */
107 
108  List *resultRelations; /* "flat" list of integer RT indexes */
109 
110  List *nonleafResultRelations; /* "flat" list of integer RT indexes */
111 
112  List *relationOids; /* OIDs of relations the plan depends on */
113 
114  List *invalItems; /* other dependencies, as PlanInvalItems */
115 
116  int nParamExec; /* number of PARAM_EXEC Params used */
117 
118  Index lastPHId; /* highest PlaceHolderVar ID assigned */
119 
120  Index lastRowMarkId; /* highest PlanRowMark ID assigned */
121 
122  int lastPlanNodeId; /* highest plan node ID assigned */
123 
124  bool transientPlan; /* redo plan when TransactionXmin changes? */
125 
126  bool dependsOnRole; /* is plan specific to current role? */
127 
128  bool parallelModeOK; /* parallel mode potentially OK? */
129 
130  bool parallelModeNeeded; /* parallel mode actually required? */
131 
132  char maxParallelHazard; /* worst PROPARALLEL hazard level */
133 } PlannerGlobal;
134 
135 /* macro for fetching the Plan associated with a SubPlan node */
136 #define planner_subplan_get_plan(root, subplan) \
137  ((Plan *) list_nth((root)->glob->subplans, (subplan)->plan_id - 1))
138 
139 
140 /*----------
141  * PlannerInfo
142  * Per-query information for planning/optimization
143  *
144  * This struct is conventionally called "root" in all the planner routines.
145  * It holds links to all of the planner's working state, in addition to the
146  * original Query. Note that at present the planner extensively modifies
147  * the passed-in Query data structure; someday that should stop.
148  *----------
149  */
150 typedef struct PlannerInfo
151 {
153 
154  Query *parse; /* the Query being planned */
155 
156  PlannerGlobal *glob; /* global info for current planner run */
157 
158  Index query_level; /* 1 at the outermost Query */
159 
160  struct PlannerInfo *parent_root; /* NULL at outermost Query */
161 
162  /*
163  * plan_params contains the expressions that this query level needs to
164  * make available to a lower query level that is currently being planned.
165  * outer_params contains the paramIds of PARAM_EXEC Params that outer
166  * query levels will make available to this query level.
167  */
168  List *plan_params; /* list of PlannerParamItems, see below */
170 
171  /*
172  * simple_rel_array holds pointers to "base rels" and "other rels" (see
173  * comments for RelOptInfo for more info). It is indexed by rangetable
174  * index (so entry 0 is always wasted). Entries can be NULL when an RTE
175  * does not correspond to a base relation, such as a join RTE or an
176  * unreferenced view RTE; or if the RelOptInfo hasn't been made yet.
177  */
178  struct RelOptInfo **simple_rel_array; /* All 1-rel RelOptInfos */
179  int simple_rel_array_size; /* allocated size of array */
180 
181  /*
182  * simple_rte_array is the same length as simple_rel_array and holds
183  * pointers to the associated rangetable entries. This lets us avoid
184  * rt_fetch(), which can be a bit slow once large inheritance sets have
185  * been expanded.
186  */
187  RangeTblEntry **simple_rte_array; /* rangetable as an array */
188 
189  /*
190  * all_baserels is a Relids set of all base relids (but not "other"
191  * relids) in the query; that is, the Relids identifier of the final join
192  * we need to form. This is computed in make_one_rel, just before we
193  * start making Paths.
194  */
196 
197  /*
198  * nullable_baserels is a Relids set of base relids that are nullable by
199  * some outer join in the jointree; these are rels that are potentially
200  * nullable below the WHERE clause, SELECT targetlist, etc. This is
201  * computed in deconstruct_jointree.
202  */
204 
205  /*
206  * join_rel_list is a list of all join-relation RelOptInfos we have
207  * considered in this planning run. For small problems we just scan the
208  * list to do lookups, but when there are many join relations we build a
209  * hash table for faster lookups. The hash table is present and valid
210  * when join_rel_hash is not NULL. Note that we still maintain the list
211  * even when using the hash table for lookups; this simplifies life for
212  * GEQO.
213  */
214  List *join_rel_list; /* list of join-relation RelOptInfos */
215  struct HTAB *join_rel_hash; /* optional hashtable for join relations */
216 
217  /*
218  * When doing a dynamic-programming-style join search, join_rel_level[k]
219  * is a list of all join-relation RelOptInfos of level k, and
220  * join_cur_level is the current level. New join-relation RelOptInfos are
221  * automatically added to the join_rel_level[join_cur_level] list.
222  * join_rel_level is NULL if not in use.
223  */
224  List **join_rel_level; /* lists of join-relation RelOptInfos */
225  int join_cur_level; /* index of list being extended */
226 
227  List *init_plans; /* init SubPlans for query */
228 
229  List *cte_plan_ids; /* per-CTE-item list of subplan IDs */
230 
231  List *multiexpr_params; /* List of Lists of Params for
232  * MULTIEXPR subquery outputs */
233 
234  List *eq_classes; /* list of active EquivalenceClasses */
235 
236  List *canon_pathkeys; /* list of "canonical" PathKeys */
237 
238  List *left_join_clauses; /* list of RestrictInfos for
239  * mergejoinable outer join clauses
240  * w/nonnullable var on left */
241 
242  List *right_join_clauses; /* list of RestrictInfos for
243  * mergejoinable outer join clauses
244  * w/nonnullable var on right */
245 
246  List *full_join_clauses; /* list of RestrictInfos for
247  * mergejoinable full join clauses */
248 
249  List *join_info_list; /* list of SpecialJoinInfos */
250 
251  List *append_rel_list; /* list of AppendRelInfos */
252 
253  List *pcinfo_list; /* list of PartitionedChildRelInfos */
254 
255  List *rowMarks; /* list of PlanRowMarks */
256 
257  List *placeholder_list; /* list of PlaceHolderInfos */
258 
259  List *fkey_list; /* list of ForeignKeyOptInfos */
260 
261  List *query_pathkeys; /* desired pathkeys for query_planner() */
262 
263  List *group_pathkeys; /* groupClause pathkeys, if any */
264  List *window_pathkeys; /* pathkeys of bottom window, if any */
265  List *distinct_pathkeys; /* distinctClause pathkeys, if any */
266  List *sort_pathkeys; /* sortClause pathkeys, if any */
267 
268  List *initial_rels; /* RelOptInfos we are now trying to join */
269 
270  /* Use fetch_upper_rel() to get any particular upper rel */
271  List *upper_rels[UPPERREL_FINAL + 1]; /* upper-rel RelOptInfos */
272 
273  /* Result tlists chosen by grouping_planner for upper-stage processing */
275 
276  /*
277  * grouping_planner passes back its final processed targetlist here, for
278  * use in relabeling the topmost tlist of the finished Plan.
279  */
281 
282  /* Fields filled during create_plan() for use in setrefs.c */
283  AttrNumber *grouping_map; /* for GroupingFunc fixup */
284  List *minmax_aggs; /* List of MinMaxAggInfos */
285 
286  MemoryContext planner_cxt; /* context holding PlannerInfo */
287 
288  double total_table_pages; /* # of pages in all tables of query */
289 
290  double tuple_fraction; /* tuple_fraction passed to query_planner */
291  double limit_tuples; /* limit_tuples passed to query_planner */
292 
293  Index qual_security_level; /* minimum security_level for quals */
294  /* Note: qual_security_level is zero if there are no securityQuals */
295 
296  bool hasInheritedTarget; /* true if parse->resultRelation is an
297  * inheritance child rel */
298  bool hasJoinRTEs; /* true if any RTEs are RTE_JOIN kind */
299  bool hasLateralRTEs; /* true if any RTEs are marked LATERAL */
300  bool hasDeletedRTEs; /* true if any RTE was deleted from jointree */
301  bool hasHavingQual; /* true if havingQual was non-null */
302  bool hasPseudoConstantQuals; /* true if any RestrictInfo has
303  * pseudoconstant = true */
304  bool hasRecursion; /* true if planning a recursive WITH item */
305 
306  /* These fields are used only when hasRecursion is true: */
307  int wt_param_id; /* PARAM_EXEC ID for the work table */
308  struct Path *non_recursive_path; /* a path for non-recursive term */
309 
310  /* These fields are workspace for createplan.c */
311  Relids curOuterRels; /* outer rels above current node */
312  List *curOuterParams; /* not-yet-assigned NestLoopParams */
313 
314  /* optional private data for join_search_hook, e.g., GEQO */
316 } PlannerInfo;
317 
318 
319 /*
320  * In places where it's known that simple_rte_array[] must have been prepared
321  * already, we just index into it to fetch RTEs. In code that might be
322  * executed before or after entering query_planner(), use this macro.
323  */
324 #define planner_rt_fetch(rti, root) \
325  ((root)->simple_rte_array ? (root)->simple_rte_array[rti] : \
326  rt_fetch(rti, (root)->parse->rtable))
327 
328 
329 /*----------
330  * RelOptInfo
331  * Per-relation information for planning/optimization
332  *
333  * For planning purposes, a "base rel" is either a plain relation (a table)
334  * or the output of a sub-SELECT or function that appears in the range table.
335  * In either case it is uniquely identified by an RT index. A "joinrel"
336  * is the joining of two or more base rels. A joinrel is identified by
337  * the set of RT indexes for its component baserels. We create RelOptInfo
338  * nodes for each baserel and joinrel, and store them in the PlannerInfo's
339  * simple_rel_array and join_rel_list respectively.
340  *
341  * Note that there is only one joinrel for any given set of component
342  * baserels, no matter what order we assemble them in; so an unordered
343  * set is the right datatype to identify it with.
344  *
345  * We also have "other rels", which are like base rels in that they refer to
346  * single RT indexes; but they are not part of the join tree, and are given
347  * a different RelOptKind to identify them.
348  * Currently the only kind of otherrels are those made for member relations
349  * of an "append relation", that is an inheritance set or UNION ALL subquery.
350  * An append relation has a parent RTE that is a base rel, which represents
351  * the entire append relation. The member RTEs are otherrels. The parent
352  * is present in the query join tree but the members are not. The member
353  * RTEs and otherrels are used to plan the scans of the individual tables or
354  * subqueries of the append set; then the parent baserel is given Append
355  * and/or MergeAppend paths comprising the best paths for the individual
356  * member rels. (See comments for AppendRelInfo for more information.)
357  *
358  * At one time we also made otherrels to represent join RTEs, for use in
359  * handling join alias Vars. Currently this is not needed because all join
360  * alias Vars are expanded to non-aliased form during preprocess_expression.
361  *
362  * There is also a RelOptKind for "upper" relations, which are RelOptInfos
363  * that describe post-scan/join processing steps, such as aggregation.
364  * Many of the fields in these RelOptInfos are meaningless, but their Path
365  * fields always hold Paths showing ways to do that processing step.
366  *
367  * Lastly, there is a RelOptKind for "dead" relations, which are base rels
368  * that we have proven we don't need to join after all.
369  *
370  * Parts of this data structure are specific to various scan and join
371  * mechanisms. It didn't seem worth creating new node types for them.
372  *
373  * relids - Set of base-relation identifiers; it is a base relation
374  * if there is just one, a join relation if more than one
375  * rows - estimated number of tuples in the relation after restriction
376  * clauses have been applied (ie, output rows of a plan for it)
377  * consider_startup - true if there is any value in keeping plain paths for
378  * this rel on the basis of having cheap startup cost
379  * consider_param_startup - the same for parameterized paths
380  * reltarget - Default Path output tlist for this rel; normally contains
381  * Var and PlaceHolderVar nodes for the values we need to
382  * output from this relation.
383  * List is in no particular order, but all rels of an
384  * appendrel set must use corresponding orders.
385  * NOTE: in an appendrel child relation, may contain
386  * arbitrary expressions pulled up from a subquery!
387  * pathlist - List of Path nodes, one for each potentially useful
388  * method of generating the relation
389  * ppilist - ParamPathInfo nodes for parameterized Paths, if any
390  * cheapest_startup_path - the pathlist member with lowest startup cost
391  * (regardless of ordering) among the unparameterized paths;
392  * or NULL if there is no unparameterized path
393  * cheapest_total_path - the pathlist member with lowest total cost
394  * (regardless of ordering) among the unparameterized paths;
395  * or if there is no unparameterized path, the path with lowest
396  * total cost among the paths with minimum parameterization
397  * cheapest_unique_path - for caching cheapest path to produce unique
398  * (no duplicates) output from relation; NULL if not yet requested
399  * cheapest_parameterized_paths - best paths for their parameterizations;
400  * always includes cheapest_total_path, even if that's unparameterized
401  * direct_lateral_relids - rels this rel has direct LATERAL references to
402  * lateral_relids - required outer rels for LATERAL, as a Relids set
403  * (includes both direct and indirect lateral references)
404  *
405  * If the relation is a base relation it will have these fields set:
406  *
407  * relid - RTE index (this is redundant with the relids field, but
408  * is provided for convenience of access)
409  * rtekind - distinguishes plain relation, subquery, or function RTE
410  * min_attr, max_attr - range of valid AttrNumbers for rel
411  * attr_needed - array of bitmapsets indicating the highest joinrel
412  * in which each attribute is needed; if bit 0 is set then
413  * the attribute is needed as part of final targetlist
414  * attr_widths - cache space for per-attribute width estimates;
415  * zero means not computed yet
416  * lateral_vars - lateral cross-references of rel, if any (list of
417  * Vars and PlaceHolderVars)
418  * lateral_referencers - relids of rels that reference this one laterally
419  * (includes both direct and indirect lateral references)
420  * indexlist - list of IndexOptInfo nodes for relation's indexes
421  * (always NIL if it's not a table)
422  * pages - number of disk pages in relation (zero if not a table)
423  * tuples - number of tuples in relation (not considering restrictions)
424  * allvisfrac - fraction of disk pages that are marked all-visible
425  * subroot - PlannerInfo for subquery (NULL if it's not a subquery)
426  * subplan_params - list of PlannerParamItems to be passed to subquery
427  *
428  * Note: for a subquery, tuples and subroot are not set immediately
429  * upon creation of the RelOptInfo object; they are filled in when
430  * set_subquery_pathlist processes the object.
431  *
432  * For otherrels that are appendrel members, these fields are filled
433  * in just as for a baserel, except we don't bother with lateral_vars.
434  *
435  * If the relation is either a foreign table or a join of foreign tables that
436  * all belong to the same foreign server and are assigned to the same user to
437  * check access permissions as (cf checkAsUser), these fields will be set:
438  *
439  * serverid - OID of foreign server, if foreign table (else InvalidOid)
440  * userid - OID of user to check access as (InvalidOid means current user)
441  * useridiscurrent - we've assumed that userid equals current user
442  * fdwroutine - function hooks for FDW, if foreign table (else NULL)
443  * fdw_private - private state for FDW, if foreign table (else NULL)
444  *
445  * The presence of the remaining fields depends on the restrictions
446  * and joins that the relation participates in:
447  *
448  * baserestrictinfo - List of RestrictInfo nodes, containing info about
449  * each non-join qualification clause in which this relation
450  * participates (only used for base rels)
451  * baserestrictcost - Estimated cost of evaluating the baserestrictinfo
452  * clauses at a single tuple (only used for base rels)
453  * baserestrict_min_security - Smallest security_level found among
454  * clauses in baserestrictinfo
455  * joininfo - List of RestrictInfo nodes, containing info about each
456  * join clause in which this relation participates (but
457  * note this excludes clauses that might be derivable from
458  * EquivalenceClasses)
459  * has_eclass_joins - flag that EquivalenceClass joins are possible
460  *
461  * Note: Keeping a restrictinfo list in the RelOptInfo is useful only for
462  * base rels, because for a join rel the set of clauses that are treated as
463  * restrict clauses varies depending on which sub-relations we choose to join.
464  * (For example, in a 3-base-rel join, a clause relating rels 1 and 2 must be
465  * treated as a restrictclause if we join {1} and {2 3} to make {1 2 3}; but
466  * if we join {1 2} and {3} then that clause will be a restrictclause in {1 2}
467  * and should not be processed again at the level of {1 2 3}.) Therefore,
468  * the restrictinfo list in the join case appears in individual JoinPaths
469  * (field joinrestrictinfo), not in the parent relation. But it's OK for
470  * the RelOptInfo to store the joininfo list, because that is the same
471  * for a given rel no matter how we form it.
472  *
473  * We store baserestrictcost in the RelOptInfo (for base relations) because
474  * we know we will need it at least once (to price the sequential scan)
475  * and may need it multiple times to price index scans.
476  *----------
477  */
478 typedef enum RelOptKind
479 {
485 } RelOptKind;
486 
487 typedef struct RelOptInfo
488 {
490 
492 
493  /* all relations included in this RelOptInfo */
494  Relids relids; /* set of base relids (rangetable indexes) */
495 
496  /* size estimates generated by planner */
497  double rows; /* estimated number of result tuples */
498 
499  /* per-relation planner control flags */
500  bool consider_startup; /* keep cheap-startup-cost paths? */
501  bool consider_param_startup; /* ditto, for parameterized paths? */
502  bool consider_parallel; /* consider parallel paths? */
503 
504  /* default result targetlist for Paths scanning this relation */
505  struct PathTarget *reltarget; /* list of Vars/Exprs, cost, width */
506 
507  /* materialization information */
508  List *pathlist; /* Path structures */
509  List *ppilist; /* ParamPathInfos used in pathlist */
510  List *partial_pathlist; /* partial Paths */
515 
516  /* parameterization information needed for both base rels and join rels */
517  /* (see also lateral_vars and lateral_referencers) */
518  Relids direct_lateral_relids; /* rels directly laterally referenced */
519  Relids lateral_relids; /* minimum parameterization of rel */
520 
521  /* information about a base rel (not set for join rels!) */
523  Oid reltablespace; /* containing tablespace */
524  RTEKind rtekind; /* RELATION, SUBQUERY, or FUNCTION */
525  AttrNumber min_attr; /* smallest attrno of rel (often <0) */
526  AttrNumber max_attr; /* largest attrno of rel */
527  Relids *attr_needed; /* array indexed [min_attr .. max_attr] */
528  int32 *attr_widths; /* array indexed [min_attr .. max_attr] */
529  List *lateral_vars; /* LATERAL Vars and PHVs referenced by rel */
530  Relids lateral_referencers; /* rels that reference me laterally */
531  List *indexlist; /* list of IndexOptInfo */
532  BlockNumber pages; /* size estimates derived from pg_class */
533  double tuples;
534  double allvisfrac;
535  PlannerInfo *subroot; /* if subquery */
536  List *subplan_params; /* if subquery */
537  int rel_parallel_workers; /* wanted number of parallel workers */
538 
539  /* Information about foreign tables and foreign joins */
540  Oid serverid; /* identifies server for the table or join */
541  Oid userid; /* identifies user to check access as */
542  bool useridiscurrent; /* join is only valid for current user */
543  /* use "struct FdwRoutine" to avoid including fdwapi.h here */
545  void *fdw_private;
546 
547  /* used by various scans and joins: */
548  List *baserestrictinfo; /* RestrictInfo structures (if base
549  * rel) */
550  QualCost baserestrictcost; /* cost of evaluating the above */
551  Index baserestrict_min_security; /* min security_level found in
552  * baserestrictinfo */
553  List *joininfo; /* RestrictInfo structures for join clauses
554  * involving this rel */
555  bool has_eclass_joins; /* T means joininfo is incomplete */
556 } RelOptInfo;
557 
558 /*
559  * IndexOptInfo
560  * Per-index information for planning/optimization
561  *
562  * indexkeys[], indexcollations[], opfamily[], and opcintype[]
563  * each have ncolumns entries.
564  *
565  * sortopfamily[], reverse_sort[], and nulls_first[] likewise have
566  * ncolumns entries, if the index is ordered; but if it is unordered,
567  * those pointers are NULL.
568  *
569  * Zeroes in the indexkeys[] array indicate index columns that are
570  * expressions; there is one element in indexprs for each such column.
571  *
572  * For an ordered index, reverse_sort[] and nulls_first[] describe the
573  * sort ordering of a forward indexscan; we can also consider a backward
574  * indexscan, which will generate the reverse ordering.
575  *
576  * The indexprs and indpred expressions have been run through
577  * prepqual.c and eval_const_expressions() for ease of matching to
578  * WHERE clauses. indpred is in implicit-AND form.
579  *
580  * indextlist is a TargetEntry list representing the index columns.
581  * It provides an equivalent base-relation Var for each simple column,
582  * and links to the matching indexprs element for each expression column.
583  *
584  * While most of these fields are filled when the IndexOptInfo is created
585  * (by plancat.c), indrestrictinfo and predOK are set later, in
586  * check_index_predicates().
587  */
588 typedef struct IndexOptInfo
589 {
591 
592  Oid indexoid; /* OID of the index relation */
593  Oid reltablespace; /* tablespace of index (not table) */
594  RelOptInfo *rel; /* back-link to index's table */
595 
596  /* index-size statistics (from pg_class and elsewhere) */
597  BlockNumber pages; /* number of disk pages in index */
598  double tuples; /* number of index tuples in index */
599  int tree_height; /* index tree height, or -1 if unknown */
600 
601  /* index descriptor information */
602  int ncolumns; /* number of columns in index */
603  int *indexkeys; /* column numbers of index's keys, or 0 */
604  Oid *indexcollations; /* OIDs of collations of index columns */
605  Oid *opfamily; /* OIDs of operator families for columns */
606  Oid *opcintype; /* OIDs of opclass declared input data types */
607  Oid *sortopfamily; /* OIDs of btree opfamilies, if orderable */
608  bool *reverse_sort; /* is sort order descending? */
609  bool *nulls_first; /* do NULLs come first in the sort order? */
610  bool *canreturn; /* which index cols can be returned in an
611  * index-only scan? */
612  Oid relam; /* OID of the access method (in pg_am) */
613 
614  List *indexprs; /* expressions for non-simple index columns */
615  List *indpred; /* predicate if a partial index, else NIL */
616 
617  List *indextlist; /* targetlist representing index columns */
618 
619  List *indrestrictinfo;/* parent relation's baserestrictinfo list,
620  * less any conditions implied by the index's
621  * predicate (unless it's a target rel, see
622  * comments in check_index_predicates()) */
623 
624  bool predOK; /* true if index predicate matches query */
625  bool unique; /* true if a unique index */
626  bool immediate; /* is uniqueness enforced immediately? */
627  bool hypothetical; /* true if index doesn't really exist */
628 
629  /* Remaining fields are copied from the index AM's API struct: */
630  bool amcanorderbyop; /* does AM support order by operator result? */
631  bool amoptionalkey; /* can query omit key for the first column? */
632  bool amsearcharray; /* can AM handle ScalarArrayOpExpr quals? */
633  bool amsearchnulls; /* can AM search for NULL/NOT NULL entries? */
634  bool amhasgettuple; /* does AM have amgettuple interface? */
635  bool amhasgetbitmap; /* does AM have amgetbitmap interface? */
636  bool amcanparallel; /* does AM support parallel scan? */
637  /* Rather than include amapi.h here, we declare amcostestimate like this */
638  void (*amcostestimate) (); /* AM's cost estimator */
639 } IndexOptInfo;
640 
641 /*
642  * ForeignKeyOptInfo
643  * Per-foreign-key information for planning/optimization
644  *
645  * The per-FK-column arrays can be fixed-size because we allow at most
646  * INDEX_MAX_KEYS columns in a foreign key constraint. Each array has
647  * nkeys valid entries.
648  */
649 typedef struct ForeignKeyOptInfo
650 {
652 
653  /* Basic data about the foreign key (fetched from catalogs): */
654  Index con_relid; /* RT index of the referencing table */
655  Index ref_relid; /* RT index of the referenced table */
656  int nkeys; /* number of columns in the foreign key */
657  AttrNumber conkey[INDEX_MAX_KEYS]; /* cols in referencing table */
658  AttrNumber confkey[INDEX_MAX_KEYS]; /* cols in referenced table */
659  Oid conpfeqop[INDEX_MAX_KEYS]; /* PK = FK operator OIDs */
660 
661  /* Derived info about whether FK's equality conditions match the query: */
662  int nmatched_ec; /* # of FK cols matched by ECs */
663  int nmatched_rcols; /* # of FK cols matched by non-EC rinfos */
664  int nmatched_ri; /* total # of non-EC rinfos matched to FK */
665  /* Pointer to eclass matching each column's condition, if there is one */
667  /* List of non-EC RestrictInfos matching each column's condition */
670 
671 
672 /*
673  * EquivalenceClasses
674  *
675  * Whenever we can determine that a mergejoinable equality clause A = B is
676  * not delayed by any outer join, we create an EquivalenceClass containing
677  * the expressions A and B to record this knowledge. If we later find another
678  * equivalence B = C, we add C to the existing EquivalenceClass; this may
679  * require merging two existing EquivalenceClasses. At the end of the qual
680  * distribution process, we have sets of values that are known all transitively
681  * equal to each other, where "equal" is according to the rules of the btree
682  * operator family(s) shown in ec_opfamilies, as well as the collation shown
683  * by ec_collation. (We restrict an EC to contain only equalities whose
684  * operators belong to the same set of opfamilies. This could probably be
685  * relaxed, but for now it's not worth the trouble, since nearly all equality
686  * operators belong to only one btree opclass anyway. Similarly, we suppose
687  * that all or none of the input datatypes are collatable, so that a single
688  * collation value is sufficient.)
689  *
690  * We also use EquivalenceClasses as the base structure for PathKeys, letting
691  * us represent knowledge about different sort orderings being equivalent.
692  * Since every PathKey must reference an EquivalenceClass, we will end up
693  * with single-member EquivalenceClasses whenever a sort key expression has
694  * not been equivalenced to anything else. It is also possible that such an
695  * EquivalenceClass will contain a volatile expression ("ORDER BY random()"),
696  * which is a case that can't arise otherwise since clauses containing
697  * volatile functions are never considered mergejoinable. We mark such
698  * EquivalenceClasses specially to prevent them from being merged with
699  * ordinary EquivalenceClasses. Also, for volatile expressions we have
700  * to be careful to match the EquivalenceClass to the correct targetlist
701  * entry: consider SELECT random() AS a, random() AS b ... ORDER BY b,a.
702  * So we record the SortGroupRef of the originating sort clause.
703  *
704  * We allow equality clauses appearing below the nullable side of an outer join
705  * to form EquivalenceClasses, but these have a slightly different meaning:
706  * the included values might be all NULL rather than all the same non-null
707  * values. See src/backend/optimizer/README for more on that point.
708  *
709  * NB: if ec_merged isn't NULL, this class has been merged into another, and
710  * should be ignored in favor of using the pointed-to class.
711  */
712 typedef struct EquivalenceClass
713 {
715 
716  List *ec_opfamilies; /* btree operator family OIDs */
717  Oid ec_collation; /* collation, if datatypes are collatable */
718  List *ec_members; /* list of EquivalenceMembers */
719  List *ec_sources; /* list of generating RestrictInfos */
720  List *ec_derives; /* list of derived RestrictInfos */
721  Relids ec_relids; /* all relids appearing in ec_members, except
722  * for child members (see below) */
723  bool ec_has_const; /* any pseudoconstants in ec_members? */
724  bool ec_has_volatile; /* the (sole) member is a volatile expr */
725  bool ec_below_outer_join; /* equivalence applies below an OJ */
726  bool ec_broken; /* failed to generate needed clauses? */
727  Index ec_sortref; /* originating sortclause label, or 0 */
728  Index ec_min_security; /* minimum security_level in ec_sources */
729  Index ec_max_security; /* maximum security_level in ec_sources */
730  struct EquivalenceClass *ec_merged; /* set if merged into another EC */
732 
733 /*
734  * If an EC contains a const and isn't below-outer-join, any PathKey depending
735  * on it must be redundant, since there's only one possible value of the key.
736  */
737 #define EC_MUST_BE_REDUNDANT(eclass) \
738  ((eclass)->ec_has_const && !(eclass)->ec_below_outer_join)
739 
740 /*
741  * EquivalenceMember - one member expression of an EquivalenceClass
742  *
743  * em_is_child signifies that this element was built by transposing a member
744  * for an appendrel parent relation to represent the corresponding expression
745  * for an appendrel child. These members are used for determining the
746  * pathkeys of scans on the child relation and for explicitly sorting the
747  * child when necessary to build a MergeAppend path for the whole appendrel
748  * tree. An em_is_child member has no impact on the properties of the EC as a
749  * whole; in particular the EC's ec_relids field does NOT include the child
750  * relation. An em_is_child member should never be marked em_is_const nor
751  * cause ec_has_const or ec_has_volatile to be set, either. Thus, em_is_child
752  * members are not really full-fledged members of the EC, but just reflections
753  * or doppelgangers of real members. Most operations on EquivalenceClasses
754  * should ignore em_is_child members, and those that don't should test
755  * em_relids to make sure they only consider relevant members.
756  *
757  * em_datatype is usually the same as exprType(em_expr), but can be
758  * different when dealing with a binary-compatible opfamily; in particular
759  * anyarray_ops would never work without this. Use em_datatype when
760  * looking up a specific btree operator to work with this expression.
761  */
762 typedef struct EquivalenceMember
763 {
765 
766  Expr *em_expr; /* the expression represented */
767  Relids em_relids; /* all relids appearing in em_expr */
768  Relids em_nullable_relids; /* nullable by lower outer joins */
769  bool em_is_const; /* expression is pseudoconstant? */
770  bool em_is_child; /* derived version for a child relation? */
771  Oid em_datatype; /* the "nominal type" used by the opfamily */
773 
774 /*
775  * PathKeys
776  *
777  * The sort ordering of a path is represented by a list of PathKey nodes.
778  * An empty list implies no known ordering. Otherwise the first item
779  * represents the primary sort key, the second the first secondary sort key,
780  * etc. The value being sorted is represented by linking to an
781  * EquivalenceClass containing that value and including pk_opfamily among its
782  * ec_opfamilies. The EquivalenceClass tells which collation to use, too.
783  * This is a convenient method because it makes it trivial to detect
784  * equivalent and closely-related orderings. (See optimizer/README for more
785  * information.)
786  *
787  * Note: pk_strategy is either BTLessStrategyNumber (for ASC) or
788  * BTGreaterStrategyNumber (for DESC). We assume that all ordering-capable
789  * index types will use btree-compatible strategy numbers.
790  */
791 typedef struct PathKey
792 {
794 
795  EquivalenceClass *pk_eclass; /* the value that is ordered */
796  Oid pk_opfamily; /* btree opfamily defining the ordering */
797  int pk_strategy; /* sort direction (ASC or DESC) */
798  bool pk_nulls_first; /* do NULLs come before normal values? */
799 } PathKey;
800 
801 
802 /*
803  * PathTarget
804  *
805  * This struct contains what we need to know during planning about the
806  * targetlist (output columns) that a Path will compute. Each RelOptInfo
807  * includes a default PathTarget, which its individual Paths may simply
808  * reference. However, in some cases a Path may compute outputs different
809  * from other Paths, and in that case we make a custom PathTarget for it.
810  * For example, an indexscan might return index expressions that would
811  * otherwise need to be explicitly calculated. (Note also that "upper"
812  * relations generally don't have useful default PathTargets.)
813  *
814  * exprs contains bare expressions; they do not have TargetEntry nodes on top,
815  * though those will appear in finished Plans.
816  *
817  * sortgrouprefs[] is an array of the same length as exprs, containing the
818  * corresponding sort/group refnos, or zeroes for expressions not referenced
819  * by sort/group clauses. If sortgrouprefs is NULL (which it generally is in
820  * RelOptInfo.reltarget targets; only upper-level Paths contain this info),
821  * we have not identified sort/group columns in this tlist. This allows us to
822  * deal with sort/group refnos when needed with less expense than including
823  * TargetEntry nodes in the exprs list.
824  */
825 typedef struct PathTarget
826 {
828  List *exprs; /* list of expressions to be computed */
829  Index *sortgrouprefs; /* corresponding sort/group refnos, or 0 */
830  QualCost cost; /* cost of evaluating the expressions */
831  int width; /* estimated avg width of result tuples */
832 } PathTarget;
833 
834 /* Convenience macro to get a sort/group refno from a PathTarget */
835 #define get_pathtarget_sortgroupref(target, colno) \
836  ((target)->sortgrouprefs ? (target)->sortgrouprefs[colno] : (Index) 0)
837 
838 
839 /*
840  * ParamPathInfo
841  *
842  * All parameterized paths for a given relation with given required outer rels
843  * link to a single ParamPathInfo, which stores common information such as
844  * the estimated rowcount for this parameterization. We do this partly to
845  * avoid recalculations, but mostly to ensure that the estimated rowcount
846  * is in fact the same for every such path.
847  *
848  * Note: ppi_clauses is only used in ParamPathInfos for base relation paths;
849  * in join cases it's NIL because the set of relevant clauses varies depending
850  * on how the join is formed. The relevant clauses will appear in each
851  * parameterized join path's joinrestrictinfo list, instead.
852  */
853 typedef struct ParamPathInfo
854 {
856 
857  Relids ppi_req_outer; /* rels supplying parameters used by path */
858  double ppi_rows; /* estimated number of result tuples */
859  List *ppi_clauses; /* join clauses available from outer rels */
860 } ParamPathInfo;
861 
862 
863 /*
864  * Type "Path" is used as-is for sequential-scan paths, as well as some other
865  * simple plan types that we don't need any extra information in the path for.
866  * For other path types it is the first component of a larger struct.
867  *
868  * "pathtype" is the NodeTag of the Plan node we could build from this Path.
869  * It is partially redundant with the Path's NodeTag, but allows us to use
870  * the same Path type for multiple Plan types when there is no need to
871  * distinguish the Plan type during path processing.
872  *
873  * "parent" identifies the relation this Path scans, and "pathtarget"
874  * describes the precise set of output columns the Path would compute.
875  * In simple cases all Paths for a given rel share the same targetlist,
876  * which we represent by having path->pathtarget equal to parent->reltarget.
877  *
878  * "param_info", if not NULL, links to a ParamPathInfo that identifies outer
879  * relation(s) that provide parameter values to each scan of this path.
880  * That means this path can only be joined to those rels by means of nestloop
881  * joins with this path on the inside. Also note that a parameterized path
882  * is responsible for testing all "movable" joinclauses involving this rel
883  * and the specified outer rel(s).
884  *
885  * "rows" is the same as parent->rows in simple paths, but in parameterized
886  * paths and UniquePaths it can be less than parent->rows, reflecting the
887  * fact that we've filtered by extra join conditions or removed duplicates.
888  *
889  * "pathkeys" is a List of PathKey nodes (see above), describing the sort
890  * ordering of the path's output rows.
891  */
892 typedef struct Path
893 {
895 
896  NodeTag pathtype; /* tag identifying scan/join method */
897 
898  RelOptInfo *parent; /* the relation this path can build */
899  PathTarget *pathtarget; /* list of Vars/Exprs, cost, width */
900 
901  ParamPathInfo *param_info; /* parameterization info, or NULL if none */
902 
903  bool parallel_aware; /* engage parallel-aware logic? */
904  bool parallel_safe; /* OK to use as part of parallel plan? */
905  int parallel_workers; /* desired # of workers; 0 = not
906  * parallel */
907 
908  /* estimated size/costs for path (see costsize.c for more info) */
909  double rows; /* estimated number of result tuples */
910  Cost startup_cost; /* cost expended before fetching any tuples */
911  Cost total_cost; /* total cost (assuming all tuples fetched) */
912 
913  List *pathkeys; /* sort ordering of path's output */
914  /* pathkeys is a List of PathKey nodes; see above */
915 } Path;
916 
917 /* Macro for extracting a path's parameterization relids; beware double eval */
918 #define PATH_REQ_OUTER(path) \
919  ((path)->param_info ? (path)->param_info->ppi_req_outer : (Relids) NULL)
920 
921 /*----------
922  * IndexPath represents an index scan over a single index.
923  *
924  * This struct is used for both regular indexscans and index-only scans;
925  * path.pathtype is T_IndexScan or T_IndexOnlyScan to show which is meant.
926  *
927  * 'indexinfo' is the index to be scanned.
928  *
929  * 'indexclauses' is a list of index qualification clauses, with implicit
930  * AND semantics across the list. Each clause is a RestrictInfo node from
931  * the query's WHERE or JOIN conditions. An empty list implies a full
932  * index scan.
933  *
934  * 'indexquals' has the same structure as 'indexclauses', but it contains
935  * the actual index qual conditions that can be used with the index.
936  * In simple cases this is identical to 'indexclauses', but when special
937  * indexable operators appear in 'indexclauses', they are replaced by the
938  * derived indexscannable conditions in 'indexquals'.
939  *
940  * 'indexqualcols' is an integer list of index column numbers (zero-based)
941  * of the same length as 'indexquals', showing which index column each qual
942  * is meant to be used with. 'indexquals' is required to be ordered by
943  * index column, so 'indexqualcols' must form a nondecreasing sequence.
944  * (The order of multiple quals for the same index column is unspecified.)
945  *
946  * 'indexorderbys', if not NIL, is a list of ORDER BY expressions that have
947  * been found to be usable as ordering operators for an amcanorderbyop index.
948  * The list must match the path's pathkeys, ie, one expression per pathkey
949  * in the same order. These are not RestrictInfos, just bare expressions,
950  * since they generally won't yield booleans. Also, unlike the case for
951  * quals, it's guaranteed that each expression has the index key on the left
952  * side of the operator.
953  *
954  * 'indexorderbycols' is an integer list of index column numbers (zero-based)
955  * of the same length as 'indexorderbys', showing which index column each
956  * ORDER BY expression is meant to be used with. (There is no restriction
957  * on which index column each ORDER BY can be used with.)
958  *
959  * 'indexscandir' is one of:
960  * ForwardScanDirection: forward scan of an ordered index
961  * BackwardScanDirection: backward scan of an ordered index
962  * NoMovementScanDirection: scan of an unordered index, or don't care
963  * (The executor doesn't care whether it gets ForwardScanDirection or
964  * NoMovementScanDirection for an indexscan, but the planner wants to
965  * distinguish ordered from unordered indexes for building pathkeys.)
966  *
967  * 'indextotalcost' and 'indexselectivity' are saved in the IndexPath so that
968  * we need not recompute them when considering using the same index in a
969  * bitmap index/heap scan (see BitmapHeapPath). The costs of the IndexPath
970  * itself represent the costs of an IndexScan or IndexOnlyScan plan type.
971  *----------
972  */
973 typedef struct IndexPath
974 {
985 } IndexPath;
986 
987 /*
988  * BitmapHeapPath represents one or more indexscans that generate TID bitmaps
989  * instead of directly accessing the heap, followed by AND/OR combinations
990  * to produce a single bitmap, followed by a heap scan that uses the bitmap.
991  * Note that the output is always considered unordered, since it will come
992  * out in physical heap order no matter what the underlying indexes did.
993  *
994  * The individual indexscans are represented by IndexPath nodes, and any
995  * logic on top of them is represented by a tree of BitmapAndPath and
996  * BitmapOrPath nodes. Notice that we can use the same IndexPath node both
997  * to represent a regular (or index-only) index scan plan, and as the child
998  * of a BitmapHeapPath that represents scanning the same index using a
999  * BitmapIndexScan. The startup_cost and total_cost figures of an IndexPath
1000  * always represent the costs to use it as a regular (or index-only)
1001  * IndexScan. The costs of a BitmapIndexScan can be computed using the
1002  * IndexPath's indextotalcost and indexselectivity.
1003  */
1004 typedef struct BitmapHeapPath
1005 {
1007  Path *bitmapqual; /* IndexPath, BitmapAndPath, BitmapOrPath */
1008 } BitmapHeapPath;
1009 
1010 /*
1011  * BitmapAndPath represents a BitmapAnd plan node; it can only appear as
1012  * part of the substructure of a BitmapHeapPath. The Path structure is
1013  * a bit more heavyweight than we really need for this, but for simplicity
1014  * we make it a derivative of Path anyway.
1015  */
1016 typedef struct BitmapAndPath
1017 {
1019  List *bitmapquals; /* IndexPaths and BitmapOrPaths */
1021 } BitmapAndPath;
1022 
1023 /*
1024  * BitmapOrPath represents a BitmapOr plan node; it can only appear as
1025  * part of the substructure of a BitmapHeapPath. The Path structure is
1026  * a bit more heavyweight than we really need for this, but for simplicity
1027  * we make it a derivative of Path anyway.
1028  */
1029 typedef struct BitmapOrPath
1030 {
1032  List *bitmapquals; /* IndexPaths and BitmapAndPaths */
1034 } BitmapOrPath;
1035 
1036 /*
1037  * TidPath represents a scan by TID
1038  *
1039  * tidquals is an implicitly OR'ed list of qual expressions of the form
1040  * "CTID = pseudoconstant" or "CTID = ANY(pseudoconstant_array)".
1041  * Note they are bare expressions, not RestrictInfos.
1042  */
1043 typedef struct TidPath
1044 {
1046  List *tidquals; /* qual(s) involving CTID = something */
1047 } TidPath;
1048 
1049 /*
1050  * SubqueryScanPath represents a scan of an unflattened subquery-in-FROM
1051  *
1052  * Note that the subpath comes from a different planning domain; for example
1053  * RTE indexes within it mean something different from those known to the
1054  * SubqueryScanPath. path.parent->subroot is the planning context needed to
1055  * interpret the subpath.
1056  */
1057 typedef struct SubqueryScanPath
1058 {
1060  Path *subpath; /* path representing subquery execution */
1062 
1063 /*
1064  * ForeignPath represents a potential scan of a foreign table, foreign join
1065  * or foreign upper-relation.
1066  *
1067  * fdw_private stores FDW private data about the scan. While fdw_private is
1068  * not actually touched by the core code during normal operations, it's
1069  * generally a good idea to use a representation that can be dumped by
1070  * nodeToString(), so that you can examine the structure during debugging
1071  * with tools like pprint().
1072  */
1073 typedef struct ForeignPath
1074 {
1078 } ForeignPath;
1079 
1080 /*
1081  * CustomPath represents a table scan done by some out-of-core extension.
1082  *
1083  * We provide a set of hooks here - which the provider must take care to set
1084  * up correctly - to allow extensions to supply their own methods of scanning
1085  * a relation. For example, a provider might provide GPU acceleration, a
1086  * cache-based scan, or some other kind of logic we haven't dreamed up yet.
1087  *
1088  * CustomPaths can be injected into the planning process for a relation by
1089  * set_rel_pathlist_hook functions.
1090  *
1091  * Core code must avoid assuming that the CustomPath is only as large as
1092  * the structure declared here; providers are allowed to make it the first
1093  * element in a larger structure. (Since the planner never copies Paths,
1094  * this doesn't add any complication.) However, for consistency with the
1095  * FDW case, we provide a "custom_private" field in CustomPath; providers
1096  * may prefer to use that rather than define another struct type.
1097  */
1098 
1099 struct CustomPathMethods;
1100 
1101 typedef struct CustomPath
1102 {
1104  uint32 flags; /* mask of CUSTOMPATH_* flags, see
1105  * nodes/extensible.h */
1106  List *custom_paths; /* list of child Path nodes, if any */
1109 } CustomPath;
1110 
1111 /*
1112  * AppendPath represents an Append plan, ie, successive execution of
1113  * several member plans.
1114  *
1115  * Note: it is possible for "subpaths" to contain only one, or even no,
1116  * elements. These cases are optimized during create_append_plan.
1117  * In particular, an AppendPath with no subpaths is a "dummy" path that
1118  * is created to represent the case that a relation is provably empty.
1119  */
1120 typedef struct AppendPath
1121 {
1123  /* RT indexes of non-leaf tables in a partition tree */
1125  List *subpaths; /* list of component Paths */
1126 } AppendPath;
1127 
1128 #define IS_DUMMY_PATH(p) \
1129  (IsA((p), AppendPath) && ((AppendPath *) (p))->subpaths == NIL)
1130 
1131 /* A relation that's been proven empty will have one path that is dummy */
1132 #define IS_DUMMY_REL(r) \
1133  ((r)->cheapest_total_path != NULL && \
1134  IS_DUMMY_PATH((r)->cheapest_total_path))
1135 
1136 /*
1137  * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted
1138  * results from several member plans to produce similarly-sorted output.
1139  */
1140 typedef struct MergeAppendPath
1141 {
1143  /* RT indexes of non-leaf tables in a partition tree */
1145  List *subpaths; /* list of component Paths */
1146  double limit_tuples; /* hard limit on output tuples, or -1 */
1147 } MergeAppendPath;
1148 
1149 /*
1150  * ResultPath represents use of a Result plan node to compute a variable-free
1151  * targetlist with no underlying tables (a "SELECT expressions" query).
1152  * The query could have a WHERE clause, too, represented by "quals".
1153  *
1154  * Note that quals is a list of bare clauses, not RestrictInfos.
1155  */
1156 typedef struct ResultPath
1157 {
1160 } ResultPath;
1161 
1162 /*
1163  * MaterialPath represents use of a Material plan node, i.e., caching of
1164  * the output of its subpath. This is used when the subpath is expensive
1165  * and needs to be scanned repeatedly, or when we need mark/restore ability
1166  * and the subpath doesn't have it.
1167  */
1168 typedef struct MaterialPath
1169 {
1172 } MaterialPath;
1173 
1174 /*
1175  * UniquePath represents elimination of distinct rows from the output of
1176  * its subpath.
1177  *
1178  * This can represent significantly different plans: either hash-based or
1179  * sort-based implementation, or a no-op if the input path can be proven
1180  * distinct already. The decision is sufficiently localized that it's not
1181  * worth having separate Path node types. (Note: in the no-op case, we could
1182  * eliminate the UniquePath node entirely and just return the subpath; but
1183  * it's convenient to have a UniquePath in the path tree to signal upper-level
1184  * routines that the input is known distinct.)
1185  */
1186 typedef enum
1187 {
1188  UNIQUE_PATH_NOOP, /* input is known unique already */
1189  UNIQUE_PATH_HASH, /* use hashing */
1190  UNIQUE_PATH_SORT /* use sorting */
1192 
1193 typedef struct UniquePath
1194 {
1198  List *in_operators; /* equality operators of the IN clause */
1199  List *uniq_exprs; /* expressions to be made unique */
1200 } UniquePath;
1201 
1202 /*
1203  * GatherPath runs several copies of a plan in parallel and collects the
1204  * results. The parallel leader may also execute the plan, unless the
1205  * single_copy flag is set.
1206  */
1207 typedef struct GatherPath
1208 {
1210  Path *subpath; /* path for each worker */
1211  bool single_copy; /* don't execute path more than once */
1212 } GatherPath;
1213 
1214 /*
1215  * GatherMergePath runs several copies of a plan in parallel and
1216  * collects the results. For gather merge parallel leader always execute the
1217  * plan.
1218  */
1219 typedef struct GatherMergePath
1220 {
1222  Path *subpath; /* path for each worker */
1223  int num_workers; /* number of workers sought to help */
1224 } GatherMergePath;
1225 
1226 
1227 /*
1228  * All join-type paths share these fields.
1229  */
1230 
1231 typedef struct JoinPath
1232 {
1234 
1236 
1237  Path *outerjoinpath; /* path for the outer side of the join */
1238  Path *innerjoinpath; /* path for the inner side of the join */
1239 
1240  List *joinrestrictinfo; /* RestrictInfos to apply to join */
1241 
1242  /*
1243  * See the notes for RelOptInfo and ParamPathInfo to understand why
1244  * joinrestrictinfo is needed in JoinPath, and can't be merged into the
1245  * parent RelOptInfo.
1246  */
1247 } JoinPath;
1248 
1249 /*
1250  * A nested-loop path needs no special fields.
1251  */
1252 
1254 
1255 /*
1256  * A mergejoin path has these fields.
1257  *
1258  * Unlike other path types, a MergePath node doesn't represent just a single
1259  * run-time plan node: it can represent up to four. Aside from the MergeJoin
1260  * node itself, there can be a Sort node for the outer input, a Sort node
1261  * for the inner input, and/or a Material node for the inner input. We could
1262  * represent these nodes by separate path nodes, but considering how many
1263  * different merge paths are investigated during a complex join problem,
1264  * it seems better to avoid unnecessary palloc overhead.
1265  *
1266  * path_mergeclauses lists the clauses (in the form of RestrictInfos)
1267  * that will be used in the merge.
1268  *
1269  * Note that the mergeclauses are a subset of the parent relation's
1270  * restriction-clause list. Any join clauses that are not mergejoinable
1271  * appear only in the parent's restrict list, and must be checked by a
1272  * qpqual at execution time.
1273  *
1274  * outersortkeys (resp. innersortkeys) is NIL if the outer path
1275  * (resp. inner path) is already ordered appropriately for the
1276  * mergejoin. If it is not NIL then it is a PathKeys list describing
1277  * the ordering that must be created by an explicit Sort node.
1278  *
1279  * materialize_inner is TRUE if a Material node should be placed atop the
1280  * inner input. This may appear with or without an inner Sort step.
1281  */
1282 
1283 typedef struct MergePath
1284 {
1286  List *path_mergeclauses; /* join clauses to be used for merge */
1287  List *outersortkeys; /* keys for explicit sort, if any */
1288  List *innersortkeys; /* keys for explicit sort, if any */
1289  bool materialize_inner; /* add Materialize to inner? */
1290 } MergePath;
1291 
1292 /*
1293  * A hashjoin path has these fields.
1294  *
1295  * The remarks above for mergeclauses apply for hashclauses as well.
1296  *
1297  * Hashjoin does not care what order its inputs appear in, so we have
1298  * no need for sortkeys.
1299  */
1300 
1301 typedef struct HashPath
1302 {
1304  List *path_hashclauses; /* join clauses used for hashing */
1305  int num_batches; /* number of batches expected */
1306 } HashPath;
1307 
1308 /*
1309  * ProjectionPath represents a projection (that is, targetlist computation)
1310  *
1311  * Nominally, this path node represents using a Result plan node to do a
1312  * projection step. However, if the input plan node supports projection,
1313  * we can just modify its output targetlist to do the required calculations
1314  * directly, and not need a Result. In some places in the planner we can just
1315  * jam the desired PathTarget into the input path node (and adjust its cost
1316  * accordingly), so we don't need a ProjectionPath. But in other places
1317  * it's necessary to not modify the input path node, so we need a separate
1318  * ProjectionPath node, which is marked dummy to indicate that we intend to
1319  * assign the work to the input plan node. The estimated cost for the
1320  * ProjectionPath node will account for whether a Result will be used or not.
1321  */
1322 typedef struct ProjectionPath
1323 {
1325  Path *subpath; /* path representing input source */
1326  bool dummypp; /* true if no separate Result is needed */
1327 } ProjectionPath;
1328 
1329 /*
1330  * ProjectSetPath represents evaluation of a targetlist that includes
1331  * set-returning function(s), which will need to be implemented by a
1332  * ProjectSet plan node.
1333  */
1334 typedef struct ProjectSetPath
1335 {
1337  Path *subpath; /* path representing input source */
1338 } ProjectSetPath;
1339 
1340 /*
1341  * SortPath represents an explicit sort step
1342  *
1343  * The sort keys are, by definition, the same as path.pathkeys.
1344  *
1345  * Note: the Sort plan node cannot project, so path.pathtarget must be the
1346  * same as the input's pathtarget.
1347  */
1348 typedef struct SortPath
1349 {
1351  Path *subpath; /* path representing input source */
1352 } SortPath;
1353 
1354 /*
1355  * GroupPath represents grouping (of presorted input)
1356  *
1357  * groupClause represents the columns to be grouped on; the input path
1358  * must be at least that well sorted.
1359  *
1360  * We can also apply a qual to the grouped rows (equivalent of HAVING)
1361  */
1362 typedef struct GroupPath
1363 {
1365  Path *subpath; /* path representing input source */
1366  List *groupClause; /* a list of SortGroupClause's */
1367  List *qual; /* quals (HAVING quals), if any */
1368 } GroupPath;
1369 
1370 /*
1371  * UpperUniquePath represents adjacent-duplicate removal (in presorted input)
1372  *
1373  * The columns to be compared are the first numkeys columns of the path's
1374  * pathkeys. The input is presumed already sorted that way.
1375  */
1376 typedef struct UpperUniquePath
1377 {
1379  Path *subpath; /* path representing input source */
1380  int numkeys; /* number of pathkey columns to compare */
1381 } UpperUniquePath;
1382 
1383 /*
1384  * AggPath represents generic computation of aggregate functions
1385  *
1386  * This may involve plain grouping (but not grouping sets), using either
1387  * sorted or hashed grouping; for the AGG_SORTED case, the input must be
1388  * appropriately presorted.
1389  */
1390 typedef struct AggPath
1391 {
1393  Path *subpath; /* path representing input source */
1394  AggStrategy aggstrategy; /* basic strategy, see nodes.h */
1395  AggSplit aggsplit; /* agg-splitting mode, see nodes.h */
1396  double numGroups; /* estimated number of groups in input */
1397  List *groupClause; /* a list of SortGroupClause's */
1398  List *qual; /* quals (HAVING quals), if any */
1399 } AggPath;
1400 
1401 /*
1402  * GroupingSetsPath represents a GROUPING SETS aggregation
1403  *
1404  * Currently we only support this in sorted not hashed form, so the input
1405  * must always be appropriately presorted.
1406  */
1407 typedef struct GroupingSetsPath
1408 {
1410  Path *subpath; /* path representing input source */
1411  List *rollup_groupclauses; /* list of lists of SortGroupClause's */
1412  List *rollup_lists; /* parallel list of lists of grouping sets */
1413  List *qual; /* quals (HAVING quals), if any */
1415 
1416 /*
1417  * MinMaxAggPath represents computation of MIN/MAX aggregates from indexes
1418  */
1419 typedef struct MinMaxAggPath
1420 {
1422  List *mmaggregates; /* list of MinMaxAggInfo */
1423  List *quals; /* HAVING quals, if any */
1424 } MinMaxAggPath;
1425 
1426 /*
1427  * WindowAggPath represents generic computation of window functions
1428  *
1429  * Note: winpathkeys is separate from path.pathkeys because the actual sort
1430  * order might be an extension of winpathkeys; but createplan.c needs to
1431  * know exactly how many pathkeys match the window clause.
1432  */
1433 typedef struct WindowAggPath
1434 {
1436  Path *subpath; /* path representing input source */
1437  WindowClause *winclause; /* WindowClause we'll be using */
1438  List *winpathkeys; /* PathKeys for PARTITION keys + ORDER keys */
1439 } WindowAggPath;
1440 
1441 /*
1442  * SetOpPath represents a set-operation, that is INTERSECT or EXCEPT
1443  */
1444 typedef struct SetOpPath
1445 {
1447  Path *subpath; /* path representing input source */
1448  SetOpCmd cmd; /* what to do, see nodes.h */
1449  SetOpStrategy strategy; /* how to do it, see nodes.h */
1450  List *distinctList; /* SortGroupClauses identifying target cols */
1451  AttrNumber flagColIdx; /* where is the flag column, if any */
1452  int firstFlag; /* flag value for first input relation */
1453  double numGroups; /* estimated number of groups in input */
1454 } SetOpPath;
1455 
1456 /*
1457  * RecursiveUnionPath represents a recursive UNION node
1458  */
1459 typedef struct RecursiveUnionPath
1460 {
1462  Path *leftpath; /* paths representing input sources */
1464  List *distinctList; /* SortGroupClauses identifying target cols */
1465  int wtParam; /* ID of Param representing work table */
1466  double numGroups; /* estimated number of groups in input */
1468 
1469 /*
1470  * LockRowsPath represents acquiring row locks for SELECT FOR UPDATE/SHARE
1471  */
1472 typedef struct LockRowsPath
1473 {
1475  Path *subpath; /* path representing input source */
1476  List *rowMarks; /* a list of PlanRowMark's */
1477  int epqParam; /* ID of Param for EvalPlanQual re-eval */
1478 } LockRowsPath;
1479 
1480 /*
1481  * ModifyTablePath represents performing INSERT/UPDATE/DELETE modifications
1482  *
1483  * We represent most things that will be in the ModifyTable plan node
1484  * literally, except we have child Path(s) not Plan(s). But analysis of the
1485  * OnConflictExpr is deferred to createplan.c, as is collection of FDW data.
1486  */
1487 typedef struct ModifyTablePath
1488 {
1490  CmdType operation; /* INSERT, UPDATE, or DELETE */
1491  bool canSetTag; /* do we set the command tag/es_processed? */
1492  Index nominalRelation; /* Parent RT index for use of EXPLAIN */
1493  /* RT indexes of non-leaf tables in a partition tree */
1495  List *resultRelations; /* integer list of RT indexes */
1496  List *subpaths; /* Path(s) producing source data */
1497  List *subroots; /* per-target-table PlannerInfos */
1498  List *withCheckOptionLists; /* per-target-table WCO lists */
1499  List *returningLists; /* per-target-table RETURNING tlists */
1500  List *rowMarks; /* PlanRowMarks (non-locking only) */
1501  OnConflictExpr *onconflict; /* ON CONFLICT clause, or NULL */
1502  int epqParam; /* ID of Param for EvalPlanQual re-eval */
1503 } ModifyTablePath;
1504 
1505 /*
1506  * LimitPath represents applying LIMIT/OFFSET restrictions
1507  */
1508 typedef struct LimitPath
1509 {
1511  Path *subpath; /* path representing input source */
1512  Node *limitOffset; /* OFFSET parameter, or NULL if none */
1513  Node *limitCount; /* COUNT parameter, or NULL if none */
1514 } LimitPath;
1515 
1516 
1517 /*
1518  * Restriction clause info.
1519  *
1520  * We create one of these for each AND sub-clause of a restriction condition
1521  * (WHERE or JOIN/ON clause). Since the restriction clauses are logically
1522  * ANDed, we can use any one of them or any subset of them to filter out
1523  * tuples, without having to evaluate the rest. The RestrictInfo node itself
1524  * stores data used by the optimizer while choosing the best query plan.
1525  *
1526  * If a restriction clause references a single base relation, it will appear
1527  * in the baserestrictinfo list of the RelOptInfo for that base rel.
1528  *
1529  * If a restriction clause references more than one base rel, it will
1530  * appear in the joininfo list of every RelOptInfo that describes a strict
1531  * subset of the base rels mentioned in the clause. The joininfo lists are
1532  * used to drive join tree building by selecting plausible join candidates.
1533  * The clause cannot actually be applied until we have built a join rel
1534  * containing all the base rels it references, however.
1535  *
1536  * When we construct a join rel that includes all the base rels referenced
1537  * in a multi-relation restriction clause, we place that clause into the
1538  * joinrestrictinfo lists of paths for the join rel, if neither left nor
1539  * right sub-path includes all base rels referenced in the clause. The clause
1540  * will be applied at that join level, and will not propagate any further up
1541  * the join tree. (Note: the "predicate migration" code was once intended to
1542  * push restriction clauses up and down the plan tree based on evaluation
1543  * costs, but it's dead code and is unlikely to be resurrected in the
1544  * foreseeable future.)
1545  *
1546  * Note that in the presence of more than two rels, a multi-rel restriction
1547  * might reach different heights in the join tree depending on the join
1548  * sequence we use. So, these clauses cannot be associated directly with
1549  * the join RelOptInfo, but must be kept track of on a per-join-path basis.
1550  *
1551  * RestrictInfos that represent equivalence conditions (i.e., mergejoinable
1552  * equalities that are not outerjoin-delayed) are handled a bit differently.
1553  * Initially we attach them to the EquivalenceClasses that are derived from
1554  * them. When we construct a scan or join path, we look through all the
1555  * EquivalenceClasses and generate derived RestrictInfos representing the
1556  * minimal set of conditions that need to be checked for this particular scan
1557  * or join to enforce that all members of each EquivalenceClass are in fact
1558  * equal in all rows emitted by the scan or join.
1559  *
1560  * When dealing with outer joins we have to be very careful about pushing qual
1561  * clauses up and down the tree. An outer join's own JOIN/ON conditions must
1562  * be evaluated exactly at that join node, unless they are "degenerate"
1563  * conditions that reference only Vars from the nullable side of the join.
1564  * Quals appearing in WHERE or in a JOIN above the outer join cannot be pushed
1565  * down below the outer join, if they reference any nullable Vars.
1566  * RestrictInfo nodes contain a flag to indicate whether a qual has been
1567  * pushed down to a lower level than its original syntactic placement in the
1568  * join tree would suggest. If an outer join prevents us from pushing a qual
1569  * down to its "natural" semantic level (the level associated with just the
1570  * base rels used in the qual) then we mark the qual with a "required_relids"
1571  * value including more than just the base rels it actually uses. By
1572  * pretending that the qual references all the rels required to form the outer
1573  * join, we prevent it from being evaluated below the outer join's joinrel.
1574  * When we do form the outer join's joinrel, we still need to distinguish
1575  * those quals that are actually in that join's JOIN/ON condition from those
1576  * that appeared elsewhere in the tree and were pushed down to the join rel
1577  * because they used no other rels. That's what the is_pushed_down flag is
1578  * for; it tells us that a qual is not an OUTER JOIN qual for the set of base
1579  * rels listed in required_relids. A clause that originally came from WHERE
1580  * or an INNER JOIN condition will *always* have its is_pushed_down flag set.
1581  * It's possible for an OUTER JOIN clause to be marked is_pushed_down too,
1582  * if we decide that it can be pushed down into the nullable side of the join.
1583  * In that case it acts as a plain filter qual for wherever it gets evaluated.
1584  * (In short, is_pushed_down is only false for non-degenerate outer join
1585  * conditions. Possibly we should rename it to reflect that meaning?)
1586  *
1587  * RestrictInfo nodes also contain an outerjoin_delayed flag, which is true
1588  * if the clause's applicability must be delayed due to any outer joins
1589  * appearing below it (ie, it has to be postponed to some join level higher
1590  * than the set of relations it actually references).
1591  *
1592  * There is also an outer_relids field, which is NULL except for outer join
1593  * clauses; for those, it is the set of relids on the outer side of the
1594  * clause's outer join. (These are rels that the clause cannot be applied to
1595  * in parameterized scans, since pushing it into the join's outer side would
1596  * lead to wrong answers.)
1597  *
1598  * There is also a nullable_relids field, which is the set of rels the clause
1599  * references that can be forced null by some outer join below the clause.
1600  *
1601  * outerjoin_delayed = true is subtly different from nullable_relids != NULL:
1602  * a clause might reference some nullable rels and yet not be
1603  * outerjoin_delayed because it also references all the other rels of the
1604  * outer join(s). A clause that is not outerjoin_delayed can be enforced
1605  * anywhere it is computable.
1606  *
1607  * To handle security-barrier conditions efficiently, we mark RestrictInfo
1608  * nodes with a security_level field, in which higher values identify clauses
1609  * coming from less-trusted sources. The exact semantics are that a clause
1610  * cannot be evaluated before another clause with a lower security_level value
1611  * unless the first clause is leakproof. As with outer-join clauses, this
1612  * creates a reason for clauses to sometimes need to be evaluated higher in
1613  * the join tree than their contents would suggest; and even at a single plan
1614  * node, this rule constrains the order of application of clauses.
1615  *
1616  * In general, the referenced clause might be arbitrarily complex. The
1617  * kinds of clauses we can handle as indexscan quals, mergejoin clauses,
1618  * or hashjoin clauses are limited (e.g., no volatile functions). The code
1619  * for each kind of path is responsible for identifying the restrict clauses
1620  * it can use and ignoring the rest. Clauses not implemented by an indexscan,
1621  * mergejoin, or hashjoin will be placed in the plan qual or joinqual field
1622  * of the finished Plan node, where they will be enforced by general-purpose
1623  * qual-expression-evaluation code. (But we are still entitled to count
1624  * their selectivity when estimating the result tuple count, if we
1625  * can guess what it is...)
1626  *
1627  * When the referenced clause is an OR clause, we generate a modified copy
1628  * in which additional RestrictInfo nodes are inserted below the top-level
1629  * OR/AND structure. This is a convenience for OR indexscan processing:
1630  * indexquals taken from either the top level or an OR subclause will have
1631  * associated RestrictInfo nodes.
1632  *
1633  * The can_join flag is set true if the clause looks potentially useful as
1634  * a merge or hash join clause, that is if it is a binary opclause with
1635  * nonoverlapping sets of relids referenced in the left and right sides.
1636  * (Whether the operator is actually merge or hash joinable isn't checked,
1637  * however.)
1638  *
1639  * The pseudoconstant flag is set true if the clause contains no Vars of
1640  * the current query level and no volatile functions. Such a clause can be
1641  * pulled out and used as a one-time qual in a gating Result node. We keep
1642  * pseudoconstant clauses in the same lists as other RestrictInfos so that
1643  * the regular clause-pushing machinery can assign them to the correct join
1644  * level, but they need to be treated specially for cost and selectivity
1645  * estimates. Note that a pseudoconstant clause can never be an indexqual
1646  * or merge or hash join clause, so it's of no interest to large parts of
1647  * the planner.
1648  *
1649  * When join clauses are generated from EquivalenceClasses, there may be
1650  * several equally valid ways to enforce join equivalence, of which we need
1651  * apply only one. We mark clauses of this kind by setting parent_ec to
1652  * point to the generating EquivalenceClass. Multiple clauses with the same
1653  * parent_ec in the same join are redundant.
1654  */
1655 
1656 typedef struct RestrictInfo
1657 {
1659 
1660  Expr *clause; /* the represented clause of WHERE or JOIN */
1661 
1662  bool is_pushed_down; /* TRUE if clause was pushed down in level */
1663 
1664  bool outerjoin_delayed; /* TRUE if delayed by lower outer join */
1665 
1666  bool can_join; /* see comment above */
1667 
1668  bool pseudoconstant; /* see comment above */
1669 
1670  bool leakproof; /* TRUE if known to contain no leaked Vars */
1671 
1672  Index security_level; /* see comment above */
1673 
1674  /* The set of relids (varnos) actually referenced in the clause: */
1676 
1677  /* The set of relids required to evaluate the clause: */
1679 
1680  /* If an outer-join clause, the outer-side relations, else NULL: */
1682 
1683  /* The relids used in the clause that are nullable by lower outer joins: */
1685 
1686  /* These fields are set for any binary opclause: */
1687  Relids left_relids; /* relids in left side of clause */
1688  Relids right_relids; /* relids in right side of clause */
1689 
1690  /* This field is NULL unless clause is an OR clause: */
1691  Expr *orclause; /* modified clause with RestrictInfos */
1692 
1693  /* This field is NULL unless clause is potentially redundant: */
1694  EquivalenceClass *parent_ec; /* generating EquivalenceClass */
1695 
1696  /* cache space for cost and selectivity */
1697  QualCost eval_cost; /* eval cost of clause; -1 if not yet set */
1698  Selectivity norm_selec; /* selectivity for "normal" (JOIN_INNER)
1699  * semantics; -1 if not yet set; >1 means a
1700  * redundant clause */
1701  Selectivity outer_selec; /* selectivity for outer join semantics; -1 if
1702  * not yet set */
1703 
1704  /* valid if clause is mergejoinable, else NIL */
1705  List *mergeopfamilies; /* opfamilies containing clause operator */
1706 
1707  /* cache space for mergeclause processing; NULL if not yet set */
1708  EquivalenceClass *left_ec; /* EquivalenceClass containing lefthand */
1709  EquivalenceClass *right_ec; /* EquivalenceClass containing righthand */
1710  EquivalenceMember *left_em; /* EquivalenceMember for lefthand */
1711  EquivalenceMember *right_em; /* EquivalenceMember for righthand */
1712  List *scansel_cache; /* list of MergeScanSelCache structs */
1713 
1714  /* transient workspace for use while considering a specific join path */
1715  bool outer_is_left; /* T = outer var on left, F = on right */
1716 
1717  /* valid if clause is hashjoinable, else InvalidOid: */
1718  Oid hashjoinoperator; /* copy of clause operator */
1719 
1720  /* cache space for hashclause processing; -1 if not yet set */
1721  Selectivity left_bucketsize; /* avg bucketsize of left side */
1722  Selectivity right_bucketsize; /* avg bucketsize of right side */
1723 } RestrictInfo;
1724 
1725 /*
1726  * Since mergejoinscansel() is a relatively expensive function, and would
1727  * otherwise be invoked many times while planning a large join tree,
1728  * we go out of our way to cache its results. Each mergejoinable
1729  * RestrictInfo carries a list of the specific sort orderings that have
1730  * been considered for use with it, and the resulting selectivities.
1731  */
1732 typedef struct MergeScanSelCache
1733 {
1734  /* Ordering details (cache lookup key) */
1735  Oid opfamily; /* btree opfamily defining the ordering */
1736  Oid collation; /* collation for the ordering */
1737  int strategy; /* sort direction (ASC or DESC) */
1738  bool nulls_first; /* do NULLs come before normal values? */
1739  /* Results */
1740  Selectivity leftstartsel; /* first-join fraction for clause left side */
1741  Selectivity leftendsel; /* last-join fraction for clause left side */
1742  Selectivity rightstartsel; /* first-join fraction for clause right side */
1743  Selectivity rightendsel; /* last-join fraction for clause right side */
1745 
1746 /*
1747  * Placeholder node for an expression to be evaluated below the top level
1748  * of a plan tree. This is used during planning to represent the contained
1749  * expression. At the end of the planning process it is replaced by either
1750  * the contained expression or a Var referring to a lower-level evaluation of
1751  * the contained expression. Typically the evaluation occurs below an outer
1752  * join, and Var references above the outer join might thereby yield NULL
1753  * instead of the expression value.
1754  *
1755  * Although the planner treats this as an expression node type, it is not
1756  * recognized by the parser or executor, so we declare it here rather than
1757  * in primnodes.h.
1758  */
1759 
1760 typedef struct PlaceHolderVar
1761 {
1763  Expr *phexpr; /* the represented expression */
1764  Relids phrels; /* base relids syntactically within expr src */
1765  Index phid; /* ID for PHV (unique within planner run) */
1766  Index phlevelsup; /* > 0 if PHV belongs to outer query */
1767 } PlaceHolderVar;
1768 
1769 /*
1770  * "Special join" info.
1771  *
1772  * One-sided outer joins constrain the order of joining partially but not
1773  * completely. We flatten such joins into the planner's top-level list of
1774  * relations to join, but record information about each outer join in a
1775  * SpecialJoinInfo struct. These structs are kept in the PlannerInfo node's
1776  * join_info_list.
1777  *
1778  * Similarly, semijoins and antijoins created by flattening IN (subselect)
1779  * and EXISTS(subselect) clauses create partial constraints on join order.
1780  * These are likewise recorded in SpecialJoinInfo structs.
1781  *
1782  * We make SpecialJoinInfos for FULL JOINs even though there is no flexibility
1783  * of planning for them, because this simplifies make_join_rel()'s API.
1784  *
1785  * min_lefthand and min_righthand are the sets of base relids that must be
1786  * available on each side when performing the special join. lhs_strict is
1787  * true if the special join's condition cannot succeed when the LHS variables
1788  * are all NULL (this means that an outer join can commute with upper-level
1789  * outer joins even if it appears in their RHS). We don't bother to set
1790  * lhs_strict for FULL JOINs, however.
1791  *
1792  * It is not valid for either min_lefthand or min_righthand to be empty sets;
1793  * if they were, this would break the logic that enforces join order.
1794  *
1795  * syn_lefthand and syn_righthand are the sets of base relids that are
1796  * syntactically below this special join. (These are needed to help compute
1797  * min_lefthand and min_righthand for higher joins.)
1798  *
1799  * delay_upper_joins is set TRUE if we detect a pushed-down clause that has
1800  * to be evaluated after this join is formed (because it references the RHS).
1801  * Any outer joins that have such a clause and this join in their RHS cannot
1802  * commute with this join, because that would leave noplace to check the
1803  * pushed-down clause. (We don't track this for FULL JOINs, either.)
1804  *
1805  * For a semijoin, we also extract the join operators and their RHS arguments
1806  * and set semi_operators, semi_rhs_exprs, semi_can_btree, and semi_can_hash.
1807  * This is done in support of possibly unique-ifying the RHS, so we don't
1808  * bother unless at least one of semi_can_btree and semi_can_hash can be set
1809  * true. (You might expect that this information would be computed during
1810  * join planning; but it's helpful to have it available during planning of
1811  * parameterized table scans, so we store it in the SpecialJoinInfo structs.)
1812  *
1813  * jointype is never JOIN_RIGHT; a RIGHT JOIN is handled by switching
1814  * the inputs to make it a LEFT JOIN. So the allowed values of jointype
1815  * in a join_info_list member are only LEFT, FULL, SEMI, or ANTI.
1816  *
1817  * For purposes of join selectivity estimation, we create transient
1818  * SpecialJoinInfo structures for regular inner joins; so it is possible
1819  * to have jointype == JOIN_INNER in such a structure, even though this is
1820  * not allowed within join_info_list. We also create transient
1821  * SpecialJoinInfos with jointype == JOIN_INNER for outer joins, since for
1822  * cost estimation purposes it is sometimes useful to know the join size under
1823  * plain innerjoin semantics. Note that lhs_strict, delay_upper_joins, and
1824  * of course the semi_xxx fields are not set meaningfully within such structs.
1825  */
1826 
1827 typedef struct SpecialJoinInfo
1828 {
1830  Relids min_lefthand; /* base relids in minimum LHS for join */
1831  Relids min_righthand; /* base relids in minimum RHS for join */
1832  Relids syn_lefthand; /* base relids syntactically within LHS */
1833  Relids syn_righthand; /* base relids syntactically within RHS */
1834  JoinType jointype; /* always INNER, LEFT, FULL, SEMI, or ANTI */
1835  bool lhs_strict; /* joinclause is strict for some LHS rel */
1836  bool delay_upper_joins; /* can't commute with upper RHS */
1837  /* Remaining fields are set only for JOIN_SEMI jointype: */
1838  bool semi_can_btree; /* true if semi_operators are all btree */
1839  bool semi_can_hash; /* true if semi_operators are all hash */
1840  List *semi_operators; /* OIDs of equality join operators */
1841  List *semi_rhs_exprs; /* righthand-side expressions of these ops */
1842 } SpecialJoinInfo;
1843 
1844 /*
1845  * Append-relation info.
1846  *
1847  * When we expand an inheritable table or a UNION-ALL subselect into an
1848  * "append relation" (essentially, a list of child RTEs), we build an
1849  * AppendRelInfo for each non-partitioned child RTE. The list of
1850  * AppendRelInfos indicates which child RTEs must be included when expanding
1851  * the parent, and each node carries information needed to translate Vars
1852  * referencing the parent into Vars referencing that child.
1853  *
1854  * These structs are kept in the PlannerInfo node's append_rel_list.
1855  * Note that we just throw all the structs into one list, and scan the
1856  * whole list when desiring to expand any one parent. We could have used
1857  * a more complex data structure (eg, one list per parent), but this would
1858  * be harder to update during operations such as pulling up subqueries,
1859  * and not really any easier to scan. Considering that typical queries
1860  * will not have many different append parents, it doesn't seem worthwhile
1861  * to complicate things.
1862  *
1863  * Note: after completion of the planner prep phase, any given RTE is an
1864  * append parent having entries in append_rel_list if and only if its
1865  * "inh" flag is set. We clear "inh" for plain tables that turn out not
1866  * to have inheritance children, and (in an abuse of the original meaning
1867  * of the flag) we set "inh" for subquery RTEs that turn out to be
1868  * flattenable UNION ALL queries. This lets us avoid useless searches
1869  * of append_rel_list.
1870  *
1871  * Note: the data structure assumes that append-rel members are single
1872  * baserels. This is OK for inheritance, but it prevents us from pulling
1873  * up a UNION ALL member subquery if it contains a join. While that could
1874  * be fixed with a more complex data structure, at present there's not much
1875  * point because no improvement in the plan could result.
1876  */
1877 
1878 typedef struct AppendRelInfo
1879 {
1881 
1882  /*
1883  * These fields uniquely identify this append relationship. There can be
1884  * (in fact, always should be) multiple AppendRelInfos for the same
1885  * parent_relid, but never more than one per child_relid, since a given
1886  * RTE cannot be a child of more than one append parent.
1887  */
1888  Index parent_relid; /* RT index of append parent rel */
1889  Index child_relid; /* RT index of append child rel */
1890 
1891  /*
1892  * For an inheritance appendrel, the parent and child are both regular
1893  * relations, and we store their rowtype OIDs here for use in translating
1894  * whole-row Vars. For a UNION-ALL appendrel, the parent and child are
1895  * both subqueries with no named rowtype, and we store InvalidOid here.
1896  */
1897  Oid parent_reltype; /* OID of parent's composite type */
1898  Oid child_reltype; /* OID of child's composite type */
1899 
1900  /*
1901  * The N'th element of this list is a Var or expression representing the
1902  * child column corresponding to the N'th column of the parent. This is
1903  * used to translate Vars referencing the parent rel into references to
1904  * the child. A list element is NULL if it corresponds to a dropped
1905  * column of the parent (this is only possible for inheritance cases, not
1906  * UNION ALL). The list elements are always simple Vars for inheritance
1907  * cases, but can be arbitrary expressions in UNION ALL cases.
1908  *
1909  * Notice we only store entries for user columns (attno > 0). Whole-row
1910  * Vars are special-cased, and system columns (attno < 0) need no special
1911  * translation since their attnos are the same for all tables.
1912  *
1913  * Caution: the Vars have varlevelsup = 0. Be careful to adjust as needed
1914  * when copying into a subquery.
1915  */
1916  List *translated_vars; /* Expressions in the child's Vars */
1917 
1918  /*
1919  * We store the parent table's OID here for inheritance, or InvalidOid for
1920  * UNION ALL. This is only needed to help in generating error messages if
1921  * an attempt is made to reference a dropped parent column.
1922  */
1923  Oid parent_reloid; /* OID of parent relation */
1924 } AppendRelInfo;
1925 
1926 /*
1927  * For a partitioned table, this maps its RT index to the list of RT indexes
1928  * of the partitioned child tables in the partition tree. We need to
1929  * separately store this information, because we do not create AppendRelInfos
1930  * for the partitioned child tables of a parent table, since AppendRelInfos
1931  * contain information that is unnecessary for the partitioned child tables.
1932  * The child_rels list must contain at least one element, because the parent
1933  * partitioned table is itself counted as a child.
1934  *
1935  * These structs are kept in the PlannerInfo node's pcinfo_list.
1936  */
1938 {
1940 
1944 
1945 /*
1946  * For each distinct placeholder expression generated during planning, we
1947  * store a PlaceHolderInfo node in the PlannerInfo node's placeholder_list.
1948  * This stores info that is needed centrally rather than in each copy of the
1949  * PlaceHolderVar. The phid fields identify which PlaceHolderInfo goes with
1950  * each PlaceHolderVar. Note that phid is unique throughout a planner run,
1951  * not just within a query level --- this is so that we need not reassign ID's
1952  * when pulling a subquery into its parent.
1953  *
1954  * The idea is to evaluate the expression at (only) the ph_eval_at join level,
1955  * then allow it to bubble up like a Var until the ph_needed join level.
1956  * ph_needed has the same definition as attr_needed for a regular Var.
1957  *
1958  * The PlaceHolderVar's expression might contain LATERAL references to vars
1959  * coming from outside its syntactic scope. If so, those rels are *not*
1960  * included in ph_eval_at, but they are recorded in ph_lateral.
1961  *
1962  * Notice that when ph_eval_at is a join rather than a single baserel, the
1963  * PlaceHolderInfo may create constraints on join order: the ph_eval_at join
1964  * has to be formed below any outer joins that should null the PlaceHolderVar.
1965  *
1966  * We create a PlaceHolderInfo only after determining that the PlaceHolderVar
1967  * is actually referenced in the plan tree, so that unreferenced placeholders
1968  * don't result in unnecessary constraints on join order.
1969  */
1970 
1971 typedef struct PlaceHolderInfo
1972 {
1974 
1975  Index phid; /* ID for PH (unique within planner run) */
1976  PlaceHolderVar *ph_var; /* copy of PlaceHolderVar tree */
1977  Relids ph_eval_at; /* lowest level we can evaluate value at */
1978  Relids ph_lateral; /* relids of contained lateral refs, if any */
1979  Relids ph_needed; /* highest level the value is needed at */
1980  int32 ph_width; /* estimated attribute width */
1981 } PlaceHolderInfo;
1982 
1983 /*
1984  * This struct describes one potentially index-optimizable MIN/MAX aggregate
1985  * function. MinMaxAggPath contains a list of these, and if we accept that
1986  * path, the list is stored into root->minmax_aggs for use during setrefs.c.
1987  */
1988 typedef struct MinMaxAggInfo
1989 {
1991 
1992  Oid aggfnoid; /* pg_proc Oid of the aggregate */
1993  Oid aggsortop; /* Oid of its sort operator */
1994  Expr *target; /* expression we are aggregating on */
1995  PlannerInfo *subroot; /* modified "root" for planning the subquery */
1996  Path *path; /* access path for subquery */
1997  Cost pathcost; /* estimated cost to fetch first row */
1998  Param *param; /* param for subplan's output */
1999 } MinMaxAggInfo;
2000 
2001 /*
2002  * At runtime, PARAM_EXEC slots are used to pass values around from one plan
2003  * node to another. They can be used to pass values down into subqueries (for
2004  * outer references in subqueries), or up out of subqueries (for the results
2005  * of a subplan), or from a NestLoop plan node into its inner relation (when
2006  * the inner scan is parameterized with values from the outer relation).
2007  * The planner is responsible for assigning nonconflicting PARAM_EXEC IDs to
2008  * the PARAM_EXEC Params it generates.
2009  *
2010  * Outer references are managed via root->plan_params, which is a list of
2011  * PlannerParamItems. While planning a subquery, each parent query level's
2012  * plan_params contains the values required from it by the current subquery.
2013  * During create_plan(), we use plan_params to track values that must be
2014  * passed from outer to inner sides of NestLoop plan nodes.
2015  *
2016  * The item a PlannerParamItem represents can be one of three kinds:
2017  *
2018  * A Var: the slot represents a variable of this level that must be passed
2019  * down because subqueries have outer references to it, or must be passed
2020  * from a NestLoop node to its inner scan. The varlevelsup value in the Var
2021  * will always be zero.
2022  *
2023  * A PlaceHolderVar: this works much like the Var case, except that the
2024  * entry is a PlaceHolderVar node with a contained expression. The PHV
2025  * will have phlevelsup = 0, and the contained expression is adjusted
2026  * to match in level.
2027  *
2028  * An Aggref (with an expression tree representing its argument): the slot
2029  * represents an aggregate expression that is an outer reference for some
2030  * subquery. The Aggref itself has agglevelsup = 0, and its argument tree
2031  * is adjusted to match in level.
2032  *
2033  * Note: we detect duplicate Var and PlaceHolderVar parameters and coalesce
2034  * them into one slot, but we do not bother to do that for Aggrefs.
2035  * The scope of duplicate-elimination only extends across the set of
2036  * parameters passed from one query level into a single subquery, or for
2037  * nestloop parameters across the set of nestloop parameters used in a single
2038  * query level. So there is no possibility of a PARAM_EXEC slot being used
2039  * for conflicting purposes.
2040  *
2041  * In addition, PARAM_EXEC slots are assigned for Params representing outputs
2042  * from subplans (values that are setParam items for those subplans). These
2043  * IDs need not be tracked via PlannerParamItems, since we do not need any
2044  * duplicate-elimination nor later processing of the represented expressions.
2045  * Instead, we just record the assignment of the slot number by incrementing
2046  * root->glob->nParamExec.
2047  */
2048 typedef struct PlannerParamItem
2049 {
2051 
2052  Node *item; /* the Var, PlaceHolderVar, or Aggref */
2053  int paramId; /* its assigned PARAM_EXEC slot number */
2055 
2056 /*
2057  * When making cost estimates for a SEMI or ANTI join, there are some
2058  * correction factors that are needed in both nestloop and hash joins
2059  * to account for the fact that the executor can stop scanning inner rows
2060  * as soon as it finds a match to the current outer row. These numbers
2061  * depend only on the selected outer and inner join relations, not on the
2062  * particular paths used for them, so it's worthwhile to calculate them
2063  * just once per relation pair not once per considered path. This struct
2064  * is filled by compute_semi_anti_join_factors and must be passed along
2065  * to the join cost estimation functions.
2066  *
2067  * outer_match_frac is the fraction of the outer tuples that are
2068  * expected to have at least one match.
2069  * match_count is the average number of matches expected for
2070  * outer tuples that have at least one match.
2071  */
2072 typedef struct SemiAntiJoinFactors
2073 {
2077 
2078 /*
2079  * Struct for extra information passed to subroutines of add_paths_to_joinrel
2080  *
2081  * restrictlist contains all of the RestrictInfo nodes for restriction
2082  * clauses that apply to this join
2083  * mergeclause_list is a list of RestrictInfo nodes for available
2084  * mergejoin clauses in this join
2085  * sjinfo is extra info about special joins for selectivity estimation
2086  * semifactors is as shown above (only valid for SEMI or ANTI joins)
2087  * param_source_rels are OK targets for parameterization of result paths
2088  */
2089 typedef struct JoinPathExtraData
2090 {
2097 
2098 /*
2099  * For speed reasons, cost estimation for join paths is performed in two
2100  * phases: the first phase tries to quickly derive a lower bound for the
2101  * join cost, and then we check if that's sufficient to reject the path.
2102  * If not, we come back for a more refined cost estimate. The first phase
2103  * fills a JoinCostWorkspace struct with its preliminary cost estimates
2104  * and possibly additional intermediate values. The second phase takes
2105  * these values as inputs to avoid repeating work.
2106  *
2107  * (Ideally we'd declare this in cost.h, but it's also needed in pathnode.h,
2108  * so seems best to put it here.)
2109  */
2110 typedef struct JoinCostWorkspace
2111 {
2112  /* Preliminary cost estimates --- must not be larger than final ones! */
2113  Cost startup_cost; /* cost expended before fetching any tuples */
2114  Cost total_cost; /* total cost (assuming all tuples fetched) */
2115 
2116  /* Fields below here should be treated as private to costsize.c */
2117  Cost run_cost; /* non-startup cost components */
2118 
2119  /* private for cost_nestloop code */
2120  Cost inner_run_cost; /* also used by cost_mergejoin code */
2122 
2123  /* private for cost_mergejoin code */
2124  double outer_rows;
2125  double inner_rows;
2128 
2129  /* private for cost_hashjoin code */
2133 
2134 #endif /* RELATION_H */
QualCost eval_cost
Definition: relation.h:1697
bool has_eclass_joins
Definition: relation.h:555
struct ModifyTablePath ModifyTablePath
struct Path * cheapest_unique_path
Definition: relation.h:513
List * indexorderbycols
Definition: relation.h:981
char maxParallelHazard
Definition: relation.h:132
List * group_pathkeys
Definition: relation.h:263
struct MinMaxAggPath MinMaxAggPath
List * rowMarks
Definition: relation.h:255
struct ForeignKeyOptInfo ForeignKeyOptInfo
Relids ph_needed
Definition: relation.h:1979
List * qual
Definition: relation.h:1367
bool semi_can_btree
Definition: relation.h:1838
Selectivity leftendsel
Definition: relation.h:1741
List * path_mergeclauses
Definition: relation.h:1286
int join_cur_level
Definition: relation.h:225
List * outersortkeys
Definition: relation.h:1287
List * distinctList
Definition: relation.h:1450
JoinPath jpath
Definition: relation.h:1303
PathTarget * pathtarget
Definition: relation.h:899
Query * parse
Definition: relation.h:154
List * returningLists
Definition: relation.h:1499
struct PathTarget PathTarget
Index security_level
Definition: relation.h:1672
OnConflictExpr * onconflict
Definition: relation.h:1501
bool predOK
Definition: relation.h:624
Node * limitOffset
Definition: relation.h:1512
Path * subpath
Definition: relation.h:1379
struct PlaceHolderInfo PlaceHolderInfo
Path path
Definition: relation.h:975
NodeTag type
Definition: relation.h:1880
Path * subpath
Definition: relation.h:1351
Relids ph_eval_at
Definition: relation.h:1977
List * plan_params
Definition: relation.h:168
PlaceHolderVar * ph_var
Definition: relation.h:1976
IndexOptInfo * indexinfo
Definition: relation.h:976
SemiAntiJoinFactors semifactors
Definition: relation.h:2094
Index nominalRelation
Definition: relation.h:1492
Oid * indexcollations
Definition: relation.h:604
bool hasJoinRTEs
Definition: relation.h:298
Path * fdw_outerpath
Definition: relation.h:1076
RelOptKind reloptkind
Definition: relation.h:491
Relids * attr_needed
Definition: relation.h:527
List * custom_paths
Definition: relation.h:1106
List * query_pathkeys
Definition: relation.h:261
int num_batches
Definition: relation.h:1305
List * join_info_list
Definition: relation.h:249
Relids required_relids
Definition: relation.h:1678
SetOpStrategy strategy
Definition: relation.h:1449
Relids min_righthand
Definition: relation.h:1831
AggStrategy aggstrategy
Definition: relation.h:1394
bool materialize_inner
Definition: relation.h:1289
void * join_search_private
Definition: relation.h:315
Relids curOuterRels
Definition: relation.h:311
List * qual
Definition: relation.h:1398
bool leakproof
Definition: relation.h:1670
Index ec_min_security
Definition: relation.h:728
Expr * orclause
Definition: relation.h:1691
Selectivity outer_match_frac
Definition: relation.h:2074
Path * innerjoinpath
Definition: relation.h:1238
struct BitmapOrPath BitmapOrPath
List * indextlist
Definition: relation.h:617
struct AppendPath AppendPath
struct Path * cheapest_startup_path
Definition: relation.h:511
struct LockRowsPath LockRowsPath
Oid userid
Definition: relation.h:541
struct IndexPath IndexPath
struct CustomPath CustomPath
Relids em_nullable_relids
Definition: relation.h:768
int lastPlanNodeId
Definition: relation.h:122
double tuples
Definition: relation.h:533
Oid reltablespace
Definition: relation.h:523
Path * subpath
Definition: relation.h:1447
List * baserestrictinfo
Definition: relation.h:548
NodeTag type
Definition: relation.h:894
List * ec_derives
Definition: relation.h:720
struct UniquePath UniquePath
List * rowMarks
Definition: relation.h:1500
NodeTag type
Definition: relation.h:1829
struct SpecialJoinInfo SpecialJoinInfo
Relids clause_relids
Definition: relation.h:1675
Param * param
Definition: relation.h:1998
struct JoinPathExtraData JoinPathExtraData
int parallel_workers
Definition: relation.h:905
bool pseudoconstant
Definition: relation.h:1668
RelOptKind
Definition: relation.h:478
bool consider_param_startup
Definition: relation.h:501
struct PlannerInfo PlannerInfo
List * resultRelations
Definition: relation.h:108
ParamPathInfo * param_info
Definition: relation.h:901
struct EquivalenceMember EquivalenceMember
Index ec_sortref
Definition: relation.h:727
Definition: nodes.h:518
Oid * sortopfamily
Definition: relation.h:607
struct SubqueryScanPath SubqueryScanPath
List * partial_pathlist
Definition: relation.h:510
Oid reltablespace
Definition: relation.h:593
Relids left_relids
Definition: relation.h:1687
List * join_rel_list
Definition: relation.h:214
bool ec_below_outer_join
Definition: relation.h:725
uint32 flags
Definition: relation.h:1104
bool hasNonSerial
Definition: relation.h:61
uint32 BlockNumber
Definition: block.h:31
EquivalenceClass * right_ec
Definition: relation.h:1709
List * cheapest_parameterized_paths
Definition: relation.h:514
List * minmax_aggs
Definition: relation.h:284
bool single_copy
Definition: relation.h:1211
bool hypothetical
Definition: relation.h:627
Index baserestrict_min_security
Definition: relation.h:551
UniquePathMethod umethod
Definition: relation.h:1197
struct WindowAggPath WindowAggPath
Path * subpath
Definition: relation.h:1171
List * indexclauses
Definition: relation.h:977
NodeTag type
Definition: relation.h:489
double Selectivity
Definition: nodes.h:641
NodeTag type
Definition: relation.h:1973
Index ec_max_security
Definition: relation.h:729
bool hasNonPartial
Definition: relation.h:60
bool useridiscurrent
Definition: relation.h:542
AggSplit aggsplit
Definition: relation.h:1395
bool immediate
Definition: relation.h:626
QualCost transCost
Definition: relation.h:62
List * partitioned_rels
Definition: relation.h:1144
struct ProjectSetPath ProjectSetPath
Selectivity bitmapselectivity
Definition: relation.h:1020
double tuples
Definition: relation.h:598
unsigned int Oid
Definition: postgres_ext.h:31
NodeTag
Definition: nodes.h:26
List * quals
Definition: relation.h:1423
UpperRelationKind
Definition: relation.h:71
struct ResultPath ResultPath
AttrNumber * grouping_map
Definition: relation.h:283
List * fkey_list
Definition: relation.h:259
int tree_height
Definition: relation.h:599
struct GatherMergePath GatherMergePath
bool hasRecursion
Definition: relation.h:304
double numGroups
Definition: relation.h:1396
double numGroups
Definition: relation.h:1453
List * mergeopfamilies
Definition: relation.h:1705
List * translated_vars
Definition: relation.h:1916
SetOpStrategy
Definition: nodes.h:788
Cost inner_rescan_run_cost
Definition: relation.h:2121
Oid parent_reltype
Definition: relation.h:1897
Relids syn_lefthand
Definition: relation.h:1832
List * rowMarks
Definition: relation.h:1476
int pk_strategy
Definition: relation.h:797
List * winpathkeys
Definition: relation.h:1438
struct PlaceHolderVar PlaceHolderVar
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:534
Relids outer_relids
Definition: relation.h:1681
signed int int32
Definition: c.h:256
List * bitmapquals
Definition: relation.h:1019
Selectivity norm_selec
Definition: relation.h:1698
Path path
Definition: relation.h:1122
List * custom_private
Definition: relation.h:1107
JoinType
Definition: nodes.h:675
struct PlannerGlobal PlannerGlobal
WindowClause * winclause
Definition: relation.h:1437
struct RelOptInfo ** simple_rel_array
Definition: relation.h:178
List * bitmapquals
Definition: relation.h:1032
List * multiexpr_params
Definition: relation.h:231
bool unique
Definition: relation.h:625
BlockNumber pages
Definition: relation.h:597
NodeTag pathtype
Definition: relation.h:896
Relids syn_righthand
Definition: relation.h:1833
List * subpaths
Definition: relation.h:1125
PlannerInfo * subroot
Definition: relation.h:535
NodeTag type
Definition: relation.h:793
SetOpCmd cmd
Definition: relation.h:1448
bool dependsOnRole
Definition: relation.h:126
struct AggPath AggPath
bool consider_startup
Definition: relation.h:500
Definition: dynahash.c:193
struct MaterialPath MaterialPath
Relids lateral_relids
Definition: relation.h:519
Cost per_tuple
Definition: relation.h:46
const struct CustomPathMethods * methods
Definition: relation.h:1108
List * indexquals
Definition: relation.h:978
int wt_param_id
Definition: relation.h:307
double tuple_fraction
Definition: relation.h:290
Path * subpath
Definition: relation.h:1436
RelOptInfo * rel
Definition: relation.h:594
bool amoptionalkey
Definition: relation.h:631
SpecialJoinInfo * sjinfo
Definition: relation.h:2093
bool parallelModeNeeded
Definition: relation.h:130
Path path
Definition: relation.h:1158
struct AppendRelInfo AppendRelInfo
Relids phrels
Definition: relation.h:1764
Relids all_baserels
Definition: relation.h:195
bool pk_nulls_first
Definition: relation.h:798
Path * path
Definition: relation.h:1996
bool hasDeletedRTEs
Definition: relation.h:300
Expr * phexpr
Definition: relation.h:1763
Relids param_source_rels
Definition: relation.h:2095
NodeTag type
Definition: relation.h:855
double limit_tuples
Definition: relation.h:291
EquivalenceMember * left_em
Definition: relation.h:1710
Cost indextotalcost
Definition: relation.h:983
Cost startup_cost
Definition: relation.h:910
List * semi_rhs_exprs
Definition: relation.h:1841
NodeTag type
Definition: relation.h:827
Oid conpfeqop[INDEX_MAX_KEYS]
Definition: relation.h:659
bool semi_can_hash
Definition: relation.h:1839
bool hasLateralRTEs
Definition: relation.h:299
Path * subpath
Definition: relation.h:1511
struct PlannerParamItem PlannerParamItem
List * joinrestrictinfo
Definition: relation.h:1240
bool parallelModeOK
Definition: relation.h:128
EquivalenceClass * parent_ec
Definition: relation.h:1694
bool can_join
Definition: relation.h:1666
RTEKind
Definition: parsenodes.h:901
List * subroots
Definition: relation.h:1497
Bitmapset * rewindPlanIDs
Definition: relation.h:102
RelOptInfo * parent
Definition: relation.h:898
List * uniq_exprs
Definition: relation.h:1199
Path * bitmapqual
Definition: relation.h:1007
bool outerjoin_delayed
Definition: relation.h:1664
Path path
Definition: relation.h:1364
List * rollup_lists
Definition: relation.h:1412
List * ec_sources
Definition: relation.h:719
struct Path * cheapest_total_path
Definition: relation.h:512
Selectivity rightstartsel
Definition: relation.h:1742
List * curOuterParams
Definition: relation.h:312
struct SetOpPath SetOpPath
struct IndexOptInfo IndexOptInfo
Selectivity indexselectivity
Definition: relation.h:984
List * subplans
Definition: relation.h:98
bool amcanorderbyop
Definition: relation.h:630
List * joininfo
Definition: relation.h:553
struct GroupPath GroupPath
Relids ec_relids
Definition: relation.h:721
PlannerGlobal * glob
Definition: relation.h:156
bool outer_is_left
Definition: relation.h:1715
struct FdwRoutine * fdwroutine
Definition: relation.h:544
List * left_join_clauses
Definition: relation.h:238
ScanDirection
Definition: sdir.h:22
List * full_join_clauses
Definition: relation.h:246
struct GroupingSetsPath GroupingSetsPath
List * subpaths
Definition: relation.h:1496
List * groupClause
Definition: relation.h:1397
Index * sortgrouprefs
Definition: relation.h:829
List * mergeclause_list
Definition: relation.h:2092
unsigned int uint32
Definition: c.h:268
AttrNumber flagColIdx
Definition: relation.h:1451
Relids relids
Definition: relation.h:494
Selectivity outer_selec
Definition: relation.h:1701
Path * subpath
Definition: relation.h:1210
struct TidPath TidPath
double total_table_pages
Definition: relation.h:288
struct LimitPath LimitPath
Selectivity bitmapselectivity
Definition: relation.h:1033
struct RecursiveUnionPath RecursiveUnionPath
int simple_rel_array_size
Definition: relation.h:179
int ncolumns
Definition: relation.h:602
bool amhasgetbitmap
Definition: relation.h:635
List * canon_pathkeys
Definition: relation.h:236
List * ppilist
Definition: relation.h:509
Path path
Definition: relation.h:1103
Index relid
Definition: relation.h:522
Bitmapset * Relids
Definition: relation.h:28
List * sort_pathkeys
Definition: relation.h:266
RangeTblEntry ** simple_rte_array
Definition: relation.h:187
struct PlannerInfo * parent_root
Definition: relation.h:160
EquivalenceMember * right_em
Definition: relation.h:1711
Relids lateral_referencers
Definition: relation.h:530
Expr * clause
Definition: relation.h:1660
int numOrderedAggs
Definition: relation.h:59
Path * subpath
Definition: relation.h:1475
struct EquivalenceClass * eclass[INDEX_MAX_KEYS]
Definition: relation.h:666
Oid serverid
Definition: relation.h:540
List * ec_opfamilies
Definition: relation.h:716
List * exprs
Definition: relation.h:828
struct ParamPathInfo ParamPathInfo
struct Path Path
List * window_pathkeys
Definition: relation.h:264
List * indrestrictinfo
Definition: relation.h:619
Relids direct_lateral_relids
Definition: relation.h:518
Path * outerjoinpath
Definition: relation.h:1237
List * invalItems
Definition: relation.h:114
NodeTag type
Definition: relation.h:152
struct MinMaxAggInfo MinMaxAggInfo
Relids nullable_relids
Definition: relation.h:1684
bool delay_upper_joins
Definition: relation.h:1836
struct QualCost QualCost
List * rollup_groupclauses
Definition: relation.h:1411
List * indexorderbys
Definition: relation.h:980
AttrNumber conkey[INDEX_MAX_KEYS]
Definition: relation.h:657
int rel_parallel_workers
Definition: relation.h:537
List * groupClause
Definition: relation.h:1366
List * append_rel_list
Definition: relation.h:251
Index lastPHId
Definition: relation.h:118
List * cte_plan_ids
Definition: relation.h:229
List * mmaggregates
Definition: relation.h:1422
Relids ph_lateral
Definition: relation.h:1978
List * partitioned_rels
Definition: relation.h:1494
Relids em_relids
Definition: relation.h:767
List * tidquals
Definition: relation.h:1046
List * restrictlist
Definition: relation.h:2091
Path * subpath
Definition: relation.h:1365
unsigned int Index
Definition: c.h:365
struct ForeignPath ForeignPath
RTEKind rtekind
Definition: relation.h:524
List * indexlist
Definition: relation.h:531
List * init_plans
Definition: relation.h:227
List * in_operators
Definition: relation.h:1198
struct SemiAntiJoinFactors SemiAntiJoinFactors
struct MergeScanSelCache MergeScanSelCache
struct RestrictInfo RestrictInfo
double rows
Definition: relation.h:497
bool hasPseudoConstantQuals
Definition: relation.h:302
bool amhasgettuple
Definition: relation.h:634
Cost finalCost
Definition: relation.h:63
List * distinct_pathkeys
Definition: relation.h:265
bool is_pushed_down
Definition: relation.h:1662
void * fdw_private
Definition: relation.h:545
Cost total_cost
Definition: relation.h:911
NodeTag type
Definition: relation.h:590
Selectivity left_bucketsize
Definition: relation.h:1721
int firstFlag
Definition: relation.h:1452
double outer_skip_rows
Definition: relation.h:2126
List * pathkeys
Definition: relation.h:913
struct GatherPath GatherPath
List * nonleafResultRelations
Definition: relation.h:110
Relids right_relids
Definition: relation.h:1688
BlockNumber pages
Definition: relation.h:532
Path path
Definition: relation.h:1233
ParamListInfo boundParams
Definition: relation.h:96
struct AggClauseCosts AggClauseCosts
Expr * target
Definition: relation.h:1994
List * pcinfo_list
Definition: relation.h:253
List * eq_classes
Definition: relation.h:234
List ** join_rel_level
Definition: relation.h:224
NodeTag type
Definition: relation.h:94
JoinPath NestPath
Definition: relation.h:1253
Path * subpath
Definition: relation.h:1337
double rows
Definition: relation.h:909
bool parallel_safe
Definition: relation.h:904
List * lateral_vars
Definition: relation.h:529
bool hasInheritedTarget
Definition: relation.h:296
List * quals
Definition: relation.h:1159
JoinType jointype
Definition: relation.h:1834
EquivalenceClass * pk_eclass
Definition: relation.h:795
Bitmapset * outer_params
Definition: relation.h:169
List * ppi_clauses
Definition: relation.h:859
struct Path * non_recursive_path
Definition: relation.h:308
#define INDEX_MAX_KEYS
size_t Size
Definition: c.h:356
Oid hashjoinoperator
Definition: relation.h:1718
NodeTag type
Definition: relation.h:1658
QualCost cost
Definition: relation.h:830
AggSplit
Definition: nodes.h:758
bool ec_has_volatile
Definition: relation.h:724
List * relationOids
Definition: relation.h:112
struct HashPath HashPath
List * subroots
Definition: relation.h:100
bool amsearcharray
Definition: relation.h:632
struct HTAB * join_rel_hash
Definition: relation.h:215
CostSelector
Definition: relation.h:34
struct JoinPath JoinPath
Index qual_security_level
Definition: relation.h:293
bool consider_parallel
Definition: relation.h:502
List * innersortkeys
Definition: relation.h:1288
Path * subpath
Definition: relation.h:1393
Oid * opcintype
Definition: relation.h:606
struct EquivalenceClass EquivalenceClass
List * partitioned_rels
Definition: relation.h:1124
Index query_level
Definition: relation.h:158
Oid pk_opfamily
Definition: relation.h:796
struct JoinCostWorkspace JoinCostWorkspace
Path * subpath
Definition: relation.h:1222
struct SortPath SortPath
double ppi_rows
Definition: relation.h:858
Path path
Definition: relation.h:1510
Path path
Definition: relation.h:1045
struct PartitionedChildRelInfo PartitionedChildRelInfo
Oid child_reltype
Definition: relation.h:1898
Oid * opfamily
Definition: relation.h:605
List * withCheckOptionLists
Definition: relation.h:1498
List * indexqualcols
Definition: relation.h:979
List * finalrtable
Definition: relation.h:104
int width
Definition: relation.h:831
AggStrategy
Definition: nodes.h:737
Index phlevelsup
Definition: relation.h:1766
Index lastRowMarkId
Definition: relation.h:120
AttrNumber max_attr
Definition: relation.h:526
Selectivity match_count
Definition: relation.h:2075
Selectivity right_bucketsize
Definition: relation.h:1722
EquivalenceClass * left_ec
Definition: relation.h:1708
Relids nullable_baserels
Definition: relation.h:203
struct MergeAppendPath MergeAppendPath
List * fdw_private
Definition: relation.h:1077
SetOpCmd
Definition: nodes.h:780
JoinType jointype
Definition: relation.h:1235
List * semi_operators
Definition: relation.h:1840
ScanDirection indexscandir
Definition: relation.h:982
CmdType operation
Definition: relation.h:1490
List * placeholder_list
Definition: relation.h:257
List * resultRelations
Definition: relation.h:1495
int nParamExec
Definition: relation.h:116
Size transitionSpace
Definition: relation.h:64
struct BitmapHeapPath BitmapHeapPath
bool hasHavingQual
Definition: relation.h:301
struct PathKey PathKey
JoinPath jpath
Definition: relation.h:1285
NodeTag type
Definition: relation.h:714
bool parallel_aware
Definition: relation.h:903
int * indexkeys
Definition: relation.h:603
List * path_hashclauses
Definition: relation.h:1304
struct ProjectionPath ProjectionPath
UniquePathMethod
Definition: relation.h:1186
struct UpperUniquePath UpperUniquePath
List * initial_rels
Definition: relation.h:268
List * pathlist
Definition: relation.h:508
List * subpaths
Definition: relation.h:1145
Relids ppi_req_outer
Definition: relation.h:857
MemoryContext planner_cxt
Definition: relation.h:286
struct MergePath MergePath
List * right_join_clauses
Definition: relation.h:242
Oid indexoid
Definition: relation.h:592
Index child_relid
Definition: relation.h:1889
bool * canreturn
Definition: relation.h:610
bool amsearchnulls
Definition: relation.h:633
Oid parent_reloid
Definition: relation.h:1923
void(* amcostestimate)()
Definition: relation.h:638
bool * nulls_first
Definition: relation.h:609
Path * subpath
Definition: relation.h:1325
Path path
Definition: relation.h:1209
Index parent_relid
Definition: relation.h:1888
bool * reverse_sort
Definition: relation.h:608
double inner_skip_rows
Definition: relation.h:2127
List * processed_tlist
Definition: relation.h:280
List * indpred
Definition: relation.h:615
int32 * attr_widths
Definition: relation.h:528
Node * limitCount
Definition: relation.h:1513
List * finalrowmarks
Definition: relation.h:106
Definition: pg_list.h:45
AttrNumber confkey[INDEX_MAX_KEYS]
Definition: relation.h:658
Path path
Definition: relation.h:1350
struct PathTarget * reltarget
Definition: relation.h:505
Relids min_lefthand
Definition: relation.h:1830
int16 AttrNumber
Definition: attnum.h:21
QualCost baserestrictcost
Definition: relation.h:550
List * rinfos[INDEX_MAX_KEYS]
Definition: relation.h:668
List * subplan_params
Definition: relation.h:536
Path path
Definition: relation.h:1446
NodeTag type
Definition: relation.h:1990
Path path
Definition: relation.h:1195
CmdType
Definition: nodes.h:651
Path path
Definition: relation.h:1392
struct RelOptInfo RelOptInfo
Definition: relation.h:892
double limit_tuples
Definition: relation.h:1146
struct EquivalenceClass * ec_merged
Definition: relation.h:730
Selectivity rightendsel
Definition: relation.h:1743
bool amcanparallel
Definition: relation.h:636
double Cost
Definition: nodes.h:642
List * scansel_cache
Definition: relation.h:1712
Selectivity leftstartsel
Definition: relation.h:1740
List * ec_members
Definition: relation.h:718
List * indexprs
Definition: relation.h:614
bool transientPlan
Definition: relation.h:124
struct PathTarget * upper_targets[UPPERREL_FINAL+1]
Definition: relation.h:274
Path * subpath
Definition: relation.h:1196
PlannerInfo * subroot
Definition: relation.h:1995
struct BitmapAndPath BitmapAndPath
List * upper_rels[UPPERREL_FINAL+1]
Definition: relation.h:271
AttrNumber min_attr
Definition: relation.h:525