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