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