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