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