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