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