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