PostgreSQL Source Code  git master
pathnode.c File Reference
#include "postgres.h"
#include <math.h>
#include "foreign/fdwapi.h"
#include "miscadmin.h"
#include "nodes/extensible.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/appendinfo.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/optimizer.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h"
#include "parser/parsetree.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/selfuncs.h"
Include dependency graph for pathnode.c:

Go to the source code of this file.

Macros

#define STD_FUZZ_FACTOR   1.01
 
#define CONSIDER_PATH_STARTUP_COST(p)   ((p)->param_info == NULL ? (p)->parent->consider_startup : (p)->parent->consider_param_startup)
 
#define FLAT_COPY_PATH(newnode, node, nodetype)
 
#define ADJUST_CHILD_ATTRS(node)
 
#define REPARAMETERIZE_CHILD_PATH(path)
 
#define REPARAMETERIZE_CHILD_PATH_LIST(pathlist)
 

Enumerations

enum  PathCostComparison { COSTS_EQUAL, COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT }
 

Functions

static Listtranslate_sub_tlist (List *tlist, int relid)
 
static int append_total_cost_compare (const ListCell *a, const ListCell *b)
 
static int append_startup_cost_compare (const ListCell *a, const ListCell *b)
 
static Listreparameterize_pathlist_by_child (PlannerInfo *root, List *pathlist, RelOptInfo *child_rel)
 
int compare_path_costs (Path *path1, Path *path2, CostSelector criterion)
 
int compare_fractional_path_costs (Path *path1, Path *path2, double fraction)
 
static PathCostComparison compare_path_costs_fuzzily (Path *path1, Path *path2, double fuzz_factor)
 
void set_cheapest (RelOptInfo *parent_rel)
 
void add_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_path_precheck (RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
 
void add_partial_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_partial_path_precheck (RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
 
Pathcreate_seqscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
 
Pathcreate_samplescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
IndexPathcreate_index_path (PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
 
BitmapHeapPathcreate_bitmap_heap_path (PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
 
BitmapAndPathcreate_bitmap_and_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
BitmapOrPathcreate_bitmap_or_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
TidPathcreate_tidscan_path (PlannerInfo *root, RelOptInfo *rel, List *tidquals, Relids required_outer)
 
TidRangePathcreate_tidrangescan_path (PlannerInfo *root, RelOptInfo *rel, List *tidrangequals, Relids required_outer)
 
AppendPathcreate_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, double rows)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer)
 
GroupResultPathcreate_group_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *havingqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
MemoizePathcreate_memoize_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *param_exprs, List *hash_operators, bool singlerow, double calls)
 
UniquePathcreate_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
 
GatherMergePathcreate_gather_merge_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, Relids required_outer, double *rows)
 
GatherPathcreate_gather_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
 
SubqueryScanPathcreate_subqueryscan_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
 
Pathcreate_functionscan_path (PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
 
Pathcreate_tablefuncscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_valuesscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_ctescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_namedtuplestorescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_resultscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_worktablescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
ForeignPathcreate_foreignscan_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
ForeignPathcreate_foreign_join_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
ForeignPathcreate_foreign_upper_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Path *fdw_outerpath, List *fdw_private)
 
Relids calc_nestloop_required_outer (Relids outerrelids, Relids outer_paramrels, Relids innerrelids, Relids inner_paramrels)
 
Relids calc_non_nestloop_required_outer (Path *outer_path, Path *inner_path)
 
NestPathcreate_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
 
MergePathcreate_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
 
HashPathcreate_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, bool parallel_hash, List *restrict_clauses, Relids required_outer, List *hashclauses)
 
ProjectionPathcreate_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
Pathapply_projection_to_path (PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
 
ProjectSetPathcreate_set_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
IncrementalSortPathcreate_incremental_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, int presorted_keys, double limit_tuples)
 
SortPathcreate_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
 
GroupPathcreate_group_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *groupClause, List *qual, double numGroups)
 
UpperUniquePathcreate_upper_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
 
AggPathcreate_agg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
 
GroupingSetsPathcreate_groupingsets_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs, double numGroups)
 
MinMaxAggPathcreate_minmaxagg_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *mmaggregates, List *quals)
 
WindowAggPathcreate_windowagg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, WindowClause *winclause)
 
SetOpPathcreate_setop_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SetOpCmd cmd, SetOpStrategy strategy, List *distinctList, AttrNumber flagColIdx, int firstFlag, double numGroups, double outputRows)
 
RecursiveUnionPathcreate_recursiveunion_path (PlannerInfo *root, RelOptInfo *rel, Path *leftpath, Path *rightpath, PathTarget *target, List *distinctList, int wtParam, double numGroups)
 
LockRowsPathcreate_lockrows_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
 
ModifyTablePathcreate_modifytable_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, CmdType operation, bool canSetTag, Index nominalRelation, Index rootRelation, bool partColsUpdated, List *resultRelations, List *updateColnosLists, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
LimitPathcreate_limit_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, LimitOption limitOption, int64 offset_est, int64 count_est)
 
void adjust_limit_rows_costs (double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
 
Pathreparameterize_path (PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
 
Pathreparameterize_path_by_child (PlannerInfo *root, Path *path, RelOptInfo *child_rel)
 

Macro Definition Documentation

◆ ADJUST_CHILD_ATTRS

#define ADJUST_CHILD_ATTRS (   node)
Value:
((node) = \
child_rel->relids, \
child_rel->top_parent_relids))
Definition: nodes.h:539
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:488
Definition: pg_list.h:50

Referenced by reparameterize_path_by_child().

◆ CONSIDER_PATH_STARTUP_COST

#define CONSIDER_PATH_STARTUP_COST (   p)    ((p)->param_info == NULL ? (p)->parent->consider_startup : (p)->parent->consider_param_startup)

◆ FLAT_COPY_PATH

#define FLAT_COPY_PATH (   newnode,
  node,
  nodetype 
)
Value:
( (newnode) = makeNode(nodetype), \
memcpy((newnode), (node), sizeof(nodetype)) )
#define makeNode(_type_)
Definition: nodes.h:587

Referenced by reparameterize_path_by_child().

◆ REPARAMETERIZE_CHILD_PATH

#define REPARAMETERIZE_CHILD_PATH (   path)
Value:
do { \
(path) = reparameterize_path_by_child(root, (path), child_rel); \
if ((path) == NULL) \
return NULL; \
} while(0)
Path * reparameterize_path_by_child(PlannerInfo *root, Path *path, RelOptInfo *child_rel)
Definition: pathnode.c:3972

Referenced by reparameterize_path_by_child().

◆ REPARAMETERIZE_CHILD_PATH_LIST

#define REPARAMETERIZE_CHILD_PATH_LIST (   pathlist)
Value:
do { \
if ((pathlist) != NIL) \
{ \
(pathlist) = reparameterize_pathlist_by_child(root, (pathlist), \
child_rel); \
if ((pathlist) == NIL) \
return NULL; \
} \
} while(0)
#define NIL
Definition: pg_list.h:65
static List * reparameterize_pathlist_by_child(PlannerInfo *root, List *pathlist, RelOptInfo *child_rel)
Definition: pathnode.c:4250

Referenced by reparameterize_path_by_child().

◆ STD_FUZZ_FACTOR

#define STD_FUZZ_FACTOR   1.01

Enumeration Type Documentation

◆ PathCostComparison

Enumerator
COSTS_EQUAL 
COSTS_BETTER1 
COSTS_BETTER2 
COSTS_DIFFERENT 

Definition at line 38 of file pathnode.c.

39 {
40  COSTS_EQUAL, /* path costs are fuzzily equal */
41  COSTS_BETTER1, /* first path is cheaper than second */
42  COSTS_BETTER2, /* second path is cheaper than first */
43  COSTS_DIFFERENT /* neither path dominates the other on cost */
PathCostComparison
Definition: pathnode.c:38

Function Documentation

◆ add_partial_path()

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 749 of file pathnode.c.

References Assert, CHECK_FOR_INTERRUPTS, compare_pathkeys(), RelOptInfo::consider_parallel, foreach_current_index, foreach_delete_current, lfirst, list_insert_nth(), Path::parallel_safe, RelOptInfo::partial_pathlist, Path::pathkeys, PATHKEYS_BETTER1, PATHKEYS_BETTER2, PATHKEYS_DIFFERENT, pfree(), STD_FUZZ_FACTOR, and Path::total_cost.

Referenced by add_paths_to_append_rel(), build_index_paths(), create_partial_bitmap_paths(), create_partial_grouping_paths(), create_plain_partial_paths(), grouping_planner(), recurse_set_operations(), set_subquery_pathlist(), try_partial_hashjoin_path(), try_partial_mergejoin_path(), and try_partial_nestloop_path().

750 {
751  bool accept_new = true; /* unless we find a superior old path */
752  int insert_at = 0; /* where to insert new item */
753  ListCell *p1;
754 
755  /* Check for query cancel. */
757 
758  /* Path to be added must be parallel safe. */
759  Assert(new_path->parallel_safe);
760 
761  /* Relation should be OK for parallelism, too. */
762  Assert(parent_rel->consider_parallel);
763 
764  /*
765  * As in add_path, throw out any paths which are dominated by the new
766  * path, but throw out the new path if some existing path dominates it.
767  */
768  foreach(p1, parent_rel->partial_pathlist)
769  {
770  Path *old_path = (Path *) lfirst(p1);
771  bool remove_old = false; /* unless new proves superior */
772  PathKeysComparison keyscmp;
773 
774  /* Compare pathkeys. */
775  keyscmp = compare_pathkeys(new_path->pathkeys, old_path->pathkeys);
776 
777  /* Unless pathkeys are incompatible, keep just one of the two paths. */
778  if (keyscmp != PATHKEYS_DIFFERENT)
779  {
780  if (new_path->total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
781  {
782  /* New path costs more; keep it only if pathkeys are better. */
783  if (keyscmp != PATHKEYS_BETTER1)
784  accept_new = false;
785  }
786  else if (old_path->total_cost > new_path->total_cost
787  * STD_FUZZ_FACTOR)
788  {
789  /* Old path costs more; keep it only if pathkeys are better. */
790  if (keyscmp != PATHKEYS_BETTER2)
791  remove_old = true;
792  }
793  else if (keyscmp == PATHKEYS_BETTER1)
794  {
795  /* Costs are about the same, new path has better pathkeys. */
796  remove_old = true;
797  }
798  else if (keyscmp == PATHKEYS_BETTER2)
799  {
800  /* Costs are about the same, old path has better pathkeys. */
801  accept_new = false;
802  }
803  else if (old_path->total_cost > new_path->total_cost * 1.0000000001)
804  {
805  /* Pathkeys are the same, and the old path costs more. */
806  remove_old = true;
807  }
808  else
809  {
810  /*
811  * Pathkeys are the same, and new path isn't materially
812  * cheaper.
813  */
814  accept_new = false;
815  }
816  }
817 
818  /*
819  * Remove current element from partial_pathlist if dominated by new.
820  */
821  if (remove_old)
822  {
823  parent_rel->partial_pathlist =
824  foreach_delete_current(parent_rel->partial_pathlist, p1);
825  pfree(old_path);
826  }
827  else
828  {
829  /* new belongs after this old path if it has cost >= old's */
830  if (new_path->total_cost >= old_path->total_cost)
831  insert_at = foreach_current_index(p1) + 1;
832  }
833 
834  /*
835  * If we found an old path that dominates new_path, we can quit
836  * scanning the partial_pathlist; we will not add new_path, and we
837  * assume new_path cannot dominate any later path.
838  */
839  if (!accept_new)
840  break;
841  }
842 
843  if (accept_new)
844  {
845  /* Accept the new path: insert it at proper place */
846  parent_rel->partial_pathlist =
847  list_insert_nth(parent_rel->partial_pathlist, insert_at, new_path);
848  }
849  else
850  {
851  /* Reject and recycle the new path */
852  pfree(new_path);
853  }
854 }
List * partial_pathlist
Definition: pathnodes.h:692
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:369
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:415
void pfree(void *pointer)
Definition: mcxt.c:1169
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
bool parallel_safe
Definition: pathnodes.h:1180
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
bool consider_parallel
Definition: pathnodes.h:684
PathKeysComparison
Definition: paths.h:195
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
#define foreach_current_index(cell)
Definition: pg_list.h:382

◆ add_partial_path_precheck()

bool add_partial_path_precheck ( RelOptInfo parent_rel,
Cost  total_cost,
List pathkeys 
)

Definition at line 867 of file pathnode.c.

References add_path_precheck(), compare_pathkeys(), lfirst, RelOptInfo::partial_pathlist, Path::pathkeys, PATHKEYS_BETTER1, PATHKEYS_BETTER2, PATHKEYS_DIFFERENT, STD_FUZZ_FACTOR, and Path::total_cost.

Referenced by try_partial_hashjoin_path(), try_partial_mergejoin_path(), and try_partial_nestloop_path().

869 {
870  ListCell *p1;
871 
872  /*
873  * Our goal here is twofold. First, we want to find out whether this path
874  * is clearly inferior to some existing partial path. If so, we want to
875  * reject it immediately. Second, we want to find out whether this path
876  * is clearly superior to some existing partial path -- at least, modulo
877  * final cost computations. If so, we definitely want to consider it.
878  *
879  * Unlike add_path(), we always compare pathkeys here. This is because we
880  * expect partial_pathlist to be very short, and getting a definitive
881  * answer at this stage avoids the need to call add_path_precheck.
882  */
883  foreach(p1, parent_rel->partial_pathlist)
884  {
885  Path *old_path = (Path *) lfirst(p1);
886  PathKeysComparison keyscmp;
887 
888  keyscmp = compare_pathkeys(pathkeys, old_path->pathkeys);
889  if (keyscmp != PATHKEYS_DIFFERENT)
890  {
891  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR &&
892  keyscmp != PATHKEYS_BETTER1)
893  return false;
894  if (old_path->total_cost > total_cost * STD_FUZZ_FACTOR &&
895  keyscmp != PATHKEYS_BETTER2)
896  return true;
897  }
898  }
899 
900  /*
901  * This path is neither clearly inferior to an existing partial path nor
902  * clearly good enough that it might replace one. Compare it to
903  * non-parallel plans. If it loses even before accounting for the cost of
904  * the Gather node, we should definitely reject it.
905  *
906  * Note that we pass the total_cost to add_path_precheck twice. This is
907  * because it's never advantageous to consider the startup cost of a
908  * partial path; the resulting plans, if run in parallel, will be run to
909  * completion.
910  */
911  if (!add_path_precheck(parent_rel, total_cost, total_cost, pathkeys,
912  NULL))
913  return false;
914 
915  return true;
916 }
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:644
List * partial_pathlist
Definition: pathnodes.h:692
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define lfirst(lc)
Definition: pg_list.h:169
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:195

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

References BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, bms_subset_compare(), CHECK_FOR_INTERRUPTS, compare_path_costs_fuzzily(), compare_pathkeys(), COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT, COSTS_EQUAL, foreach_current_index, foreach_delete_current, IsA, lfirst, list_insert_nth(), NIL, Path::parallel_safe, Path::param_info, PATH_REQ_OUTER, Path::pathkeys, PATHKEYS_BETTER1, PATHKEYS_BETTER2, PATHKEYS_DIFFERENT, RelOptInfo::pathlist, pfree(), Path::rows, STD_FUZZ_FACTOR, and Path::total_cost.

Referenced by add_foreign_final_paths(), add_foreign_grouping_paths(), add_foreign_ordered_paths(), add_paths_to_append_rel(), add_paths_to_grouping_rel(), add_paths_with_pathkeys_for_rel(), BuildParameterizedTidPaths(), consider_groupingsets_paths(), create_degenerate_grouping_paths(), create_distinct_paths(), create_index_paths(), create_one_window_path(), create_ordered_paths(), create_partial_grouping_paths(), create_tidscan_paths(), fileGetForeignPaths(), gather_grouping_paths(), generate_gather_paths(), generate_nonunion_paths(), generate_orderedappend_paths(), generate_recursion_path(), generate_union_paths(), generate_useful_gather_paths(), get_index_paths(), grouping_planner(), mark_dummy_rel(), postgresGetForeignJoinPaths(), postgresGetForeignPaths(), preprocess_minmax_aggregates(), query_planner(), recurse_set_operations(), set_cte_pathlist(), set_dummy_rel_pathlist(), set_function_pathlist(), set_namedtuplestore_pathlist(), set_plain_rel_pathlist(), set_result_pathlist(), set_subquery_pathlist(), set_tablefunc_pathlist(), set_tablesample_rel_pathlist(), set_values_pathlist(), set_worktable_pathlist(), try_hashjoin_path(), try_mergejoin_path(), and try_nestloop_path().

423 {
424  bool accept_new = true; /* unless we find a superior old path */
425  int insert_at = 0; /* where to insert new item */
426  List *new_path_pathkeys;
427  ListCell *p1;
428 
429  /*
430  * This is a convenient place to check for query cancel --- no part of the
431  * planner goes very long without calling add_path().
432  */
434 
435  /* Pretend parameterized paths have no pathkeys, per comment above */
436  new_path_pathkeys = new_path->param_info ? NIL : new_path->pathkeys;
437 
438  /*
439  * Loop to check proposed new path against old paths. Note it is possible
440  * for more than one old path to be tossed out because new_path dominates
441  * it.
442  */
443  foreach(p1, parent_rel->pathlist)
444  {
445  Path *old_path = (Path *) lfirst(p1);
446  bool remove_old = false; /* unless new proves superior */
447  PathCostComparison costcmp;
448  PathKeysComparison keyscmp;
449  BMS_Comparison outercmp;
450 
451  /*
452  * Do a fuzzy cost comparison with standard fuzziness limit.
453  */
454  costcmp = compare_path_costs_fuzzily(new_path, old_path,
456 
457  /*
458  * If the two paths compare differently for startup and total cost,
459  * then we want to keep both, and we can skip comparing pathkeys and
460  * required_outer rels. If they compare the same, proceed with the
461  * other comparisons. Row count is checked last. (We make the tests
462  * in this order because the cost comparison is most likely to turn
463  * out "different", and the pathkeys comparison next most likely. As
464  * explained above, row count very seldom makes a difference, so even
465  * though it's cheap to compare there's not much point in checking it
466  * earlier.)
467  */
468  if (costcmp != COSTS_DIFFERENT)
469  {
470  /* Similarly check to see if either dominates on pathkeys */
471  List *old_path_pathkeys;
472 
473  old_path_pathkeys = old_path->param_info ? NIL : old_path->pathkeys;
474  keyscmp = compare_pathkeys(new_path_pathkeys,
475  old_path_pathkeys);
476  if (keyscmp != PATHKEYS_DIFFERENT)
477  {
478  switch (costcmp)
479  {
480  case COSTS_EQUAL:
481  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
482  PATH_REQ_OUTER(old_path));
483  if (keyscmp == PATHKEYS_BETTER1)
484  {
485  if ((outercmp == BMS_EQUAL ||
486  outercmp == BMS_SUBSET1) &&
487  new_path->rows <= old_path->rows &&
488  new_path->parallel_safe >= old_path->parallel_safe)
489  remove_old = true; /* new dominates old */
490  }
491  else if (keyscmp == PATHKEYS_BETTER2)
492  {
493  if ((outercmp == BMS_EQUAL ||
494  outercmp == BMS_SUBSET2) &&
495  new_path->rows >= old_path->rows &&
496  new_path->parallel_safe <= old_path->parallel_safe)
497  accept_new = false; /* old dominates new */
498  }
499  else /* keyscmp == PATHKEYS_EQUAL */
500  {
501  if (outercmp == BMS_EQUAL)
502  {
503  /*
504  * Same pathkeys and outer rels, and fuzzily
505  * the same cost, so keep just one; to decide
506  * which, first check parallel-safety, then
507  * rows, then do a fuzzy cost comparison with
508  * very small fuzz limit. (We used to do an
509  * exact cost comparison, but that results in
510  * annoying platform-specific plan variations
511  * due to roundoff in the cost estimates.) If
512  * things are still tied, arbitrarily keep
513  * only the old path. Notice that we will
514  * keep only the old path even if the
515  * less-fuzzy comparison decides the startup
516  * and total costs compare differently.
517  */
518  if (new_path->parallel_safe >
519  old_path->parallel_safe)
520  remove_old = true; /* new dominates old */
521  else if (new_path->parallel_safe <
522  old_path->parallel_safe)
523  accept_new = false; /* old dominates new */
524  else if (new_path->rows < old_path->rows)
525  remove_old = true; /* new dominates old */
526  else if (new_path->rows > old_path->rows)
527  accept_new = false; /* old dominates new */
528  else if (compare_path_costs_fuzzily(new_path,
529  old_path,
530  1.0000000001) == COSTS_BETTER1)
531  remove_old = true; /* new dominates old */
532  else
533  accept_new = false; /* old equals or
534  * dominates new */
535  }
536  else if (outercmp == BMS_SUBSET1 &&
537  new_path->rows <= old_path->rows &&
538  new_path->parallel_safe >= old_path->parallel_safe)
539  remove_old = true; /* new dominates old */
540  else if (outercmp == BMS_SUBSET2 &&
541  new_path->rows >= old_path->rows &&
542  new_path->parallel_safe <= old_path->parallel_safe)
543  accept_new = false; /* old dominates new */
544  /* else different parameterizations, keep both */
545  }
546  break;
547  case COSTS_BETTER1:
548  if (keyscmp != PATHKEYS_BETTER2)
549  {
550  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
551  PATH_REQ_OUTER(old_path));
552  if ((outercmp == BMS_EQUAL ||
553  outercmp == BMS_SUBSET1) &&
554  new_path->rows <= old_path->rows &&
555  new_path->parallel_safe >= old_path->parallel_safe)
556  remove_old = true; /* new dominates old */
557  }
558  break;
559  case COSTS_BETTER2:
560  if (keyscmp != PATHKEYS_BETTER1)
561  {
562  outercmp = bms_subset_compare(PATH_REQ_OUTER(new_path),
563  PATH_REQ_OUTER(old_path));
564  if ((outercmp == BMS_EQUAL ||
565  outercmp == BMS_SUBSET2) &&
566  new_path->rows >= old_path->rows &&
567  new_path->parallel_safe <= old_path->parallel_safe)
568  accept_new = false; /* old dominates new */
569  }
570  break;
571  case COSTS_DIFFERENT:
572 
573  /*
574  * can't get here, but keep this case to keep compiler
575  * quiet
576  */
577  break;
578  }
579  }
580  }
581 
582  /*
583  * Remove current element from pathlist if dominated by new.
584  */
585  if (remove_old)
586  {
587  parent_rel->pathlist = foreach_delete_current(parent_rel->pathlist,
588  p1);
589 
590  /*
591  * Delete the data pointed-to by the deleted cell, if possible
592  */
593  if (!IsA(old_path, IndexPath))
594  pfree(old_path);
595  }
596  else
597  {
598  /* new belongs after this old path if it has cost >= old's */
599  if (new_path->total_cost >= old_path->total_cost)
600  insert_at = foreach_current_index(p1) + 1;
601  }
602 
603  /*
604  * If we found an old path that dominates new_path, we can quit
605  * scanning the pathlist; we will not add new_path, and we assume
606  * new_path cannot dominate any other elements of the pathlist.
607  */
608  if (!accept_new)
609  break;
610  }
611 
612  if (accept_new)
613  {
614  /* Accept the new path: insert it at proper place in pathlist */
615  parent_rel->pathlist =
616  list_insert_nth(parent_rel->pathlist, insert_at, new_path);
617  }
618  else
619  {
620  /* Reject and recycle the new path */
621  if (!IsA(new_path, IndexPath))
622  pfree(new_path);
623  }
624 }
#define NIL
Definition: pg_list.h:65
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
ParamPathInfo * param_info
Definition: pathnodes.h:1177
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:369
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:415
void pfree(void *pointer)
Definition: mcxt.c:1169
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
static PathCostComparison compare_path_costs_fuzzily(Path *path1, Path *path2, double fuzz_factor)
Definition: pathnode.c:166
PathCostComparison
Definition: pathnode.c:38
BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:352
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:195
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
List * pathlist
Definition: pathnodes.h:690
Definition: pg_list.h:50
BMS_Comparison
Definition: bitmapset.h:57
#define foreach_current_index(cell)
Definition: pg_list.h:382

◆ add_path_precheck()

bool add_path_precheck ( RelOptInfo parent_rel,
Cost  startup_cost,
Cost  total_cost,
List pathkeys,
Relids  required_outer 
)

Definition at line 644 of file pathnode.c.

References bms_equal(), compare_pathkeys(), RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, lfirst, NIL, Path::param_info, PATH_REQ_OUTER, Path::pathkeys, PATHKEYS_BETTER2, PATHKEYS_EQUAL, RelOptInfo::pathlist, Path::startup_cost, STD_FUZZ_FACTOR, and Path::total_cost.

Referenced by add_partial_path_precheck(), try_hashjoin_path(), try_mergejoin_path(), and try_nestloop_path().

647 {
648  List *new_path_pathkeys;
649  bool consider_startup;
650  ListCell *p1;
651 
652  /* Pretend parameterized paths have no pathkeys, per add_path policy */
653  new_path_pathkeys = required_outer ? NIL : pathkeys;
654 
655  /* Decide whether new path's startup cost is interesting */
656  consider_startup = required_outer ? parent_rel->consider_param_startup : parent_rel->consider_startup;
657 
658  foreach(p1, parent_rel->pathlist)
659  {
660  Path *old_path = (Path *) lfirst(p1);
661  PathKeysComparison keyscmp;
662 
663  /*
664  * We are looking for an old_path with the same parameterization (and
665  * by assumption the same rowcount) that dominates the new path on
666  * pathkeys as well as both cost metrics. If we find one, we can
667  * reject the new path.
668  *
669  * Cost comparisons here should match compare_path_costs_fuzzily.
670  */
671  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
672  {
673  /* new path can win on startup cost only if consider_startup */
674  if (startup_cost > old_path->startup_cost * STD_FUZZ_FACTOR ||
675  !consider_startup)
676  {
677  /* new path loses on cost, so check pathkeys... */
678  List *old_path_pathkeys;
679 
680  old_path_pathkeys = old_path->param_info ? NIL : old_path->pathkeys;
681  keyscmp = compare_pathkeys(new_path_pathkeys,
682  old_path_pathkeys);
683  if (keyscmp == PATHKEYS_EQUAL ||
684  keyscmp == PATHKEYS_BETTER2)
685  {
686  /* new path does not win on pathkeys... */
687  if (bms_equal(required_outer, PATH_REQ_OUTER(old_path)))
688  {
689  /* Found an old path that dominates the new one */
690  return false;
691  }
692  }
693  }
694  }
695  else
696  {
697  /*
698  * Since the pathlist is sorted by total_cost, we can stop looking
699  * once we reach a path with a total_cost larger than the new
700  * path's.
701  */
702  break;
703  }
704  }
705 
706  return true;
707 }
#define NIL
Definition: pg_list.h:65
bool consider_param_startup
Definition: pathnodes.h:683
ParamPathInfo * param_info
Definition: pathnodes.h:1177
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
bool consider_startup
Definition: pathnodes.h:682
Cost startup_cost
Definition: pathnodes.h:1185
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define lfirst(lc)
Definition: pg_list.h:169
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:195
List * pathlist
Definition: pathnodes.h:690
Definition: pg_list.h:50
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ adjust_limit_rows_costs()

void adjust_limit_rows_costs ( double *  rows,
Cost startup_cost,
Cost total_cost,
int64  offset_est,
int64  count_est 
)

Definition at line 3776 of file pathnode.c.

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

3781 {
3782  double input_rows = *rows;
3783  Cost input_startup_cost = *startup_cost;
3784  Cost input_total_cost = *total_cost;
3785 
3786  if (offset_est != 0)
3787  {
3788  double offset_rows;
3789 
3790  if (offset_est > 0)
3791  offset_rows = (double) offset_est;
3792  else
3793  offset_rows = clamp_row_est(input_rows * 0.10);
3794  if (offset_rows > *rows)
3795  offset_rows = *rows;
3796  if (input_rows > 0)
3797  *startup_cost +=
3798  (input_total_cost - input_startup_cost)
3799  * offset_rows / input_rows;
3800  *rows -= offset_rows;
3801  if (*rows < 1)
3802  *rows = 1;
3803  }
3804 
3805  if (count_est != 0)
3806  {
3807  double count_rows;
3808 
3809  if (count_est > 0)
3810  count_rows = (double) count_est;
3811  else
3812  count_rows = clamp_row_est(input_rows * 0.10);
3813  if (count_rows > *rows)
3814  count_rows = *rows;
3815  if (input_rows > 0)
3816  *total_cost = *startup_cost +
3817  (input_total_cost - input_startup_cost)
3818  * count_rows / input_rows;
3819  *rows = count_rows;
3820  if (*rows < 1)
3821  *rows = 1;
3822  }
3823 }
double clamp_row_est(double nrows)
Definition: costsize.c:199
double Cost
Definition: nodes.h:673

◆ append_startup_cost_compare()

static int append_startup_cost_compare ( const ListCell a,
const ListCell b 
)
static

Definition at line 1386 of file pathnode.c.

References bms_compare(), cmp(), compare_path_costs(), lfirst, Path::parent, RelOptInfo::relids, and STARTUP_COST.

Referenced by create_append_path().

1387 {
1388  Path *path1 = (Path *) lfirst(a);
1389  Path *path2 = (Path *) lfirst(b);
1390  int cmp;
1391 
1392  cmp = compare_path_costs(path1, path2, STARTUP_COST);
1393  if (cmp != 0)
1394  return -cmp;
1395  return bms_compare(path1->parent->relids, path2->parent->relids);
1396 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:147
RelOptInfo * parent
Definition: pathnodes.h:1174
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: pathnodes.h:676
#define lfirst(lc)
Definition: pg_list.h:169
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747

◆ append_total_cost_compare()

static int append_total_cost_compare ( const ListCell a,
const ListCell b 
)
static

Definition at line 1364 of file pathnode.c.

References bms_compare(), cmp(), compare_path_costs(), lfirst, Path::parent, RelOptInfo::relids, and TOTAL_COST.

Referenced by create_append_path().

1365 {
1366  Path *path1 = (Path *) lfirst(a);
1367  Path *path2 = (Path *) lfirst(b);
1368  int cmp;
1369 
1370  cmp = compare_path_costs(path1, path2, TOTAL_COST);
1371  if (cmp != 0)
1372  return -cmp;
1373  return bms_compare(path1->parent->relids, path2->parent->relids);
1374 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:147
RelOptInfo * parent
Definition: pathnodes.h:1174
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: pathnodes.h:676
#define lfirst(lc)
Definition: pg_list.h:169
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747

◆ apply_projection_to_path()

Path* apply_projection_to_path ( PlannerInfo root,
RelOptInfo rel,
Path path,
PathTarget target 
)

Definition at line 2734 of file pathnode.c.

References PathTarget::cost, create_projection_path(), PathTarget::exprs, is_parallel_safe(), is_projection_capable_path(), IsA, Path::parallel_safe, Path::parent, Path::pathtarget, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, GatherPath::subpath, GatherMergePath::subpath, and Path::total_cost.

Referenced by adjust_paths_for_srfs(), build_minmax_path(), create_ordered_paths(), and recurse_set_operations().

2738 {
2739  QualCost oldcost;
2740 
2741  /*
2742  * If given path can't project, we might need a Result node, so make a
2743  * separate ProjectionPath.
2744  */
2745  if (!is_projection_capable_path(path))
2746  return (Path *) create_projection_path(root, rel, path, target);
2747 
2748  /*
2749  * We can just jam the desired tlist into the existing path, being sure to
2750  * update its cost estimates appropriately.
2751  */
2752  oldcost = path->pathtarget->cost;
2753  path->pathtarget = target;
2754 
2755  path->startup_cost += target->cost.startup - oldcost.startup;
2756  path->total_cost += target->cost.startup - oldcost.startup +
2757  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2758 
2759  /*
2760  * If the path happens to be a Gather or GatherMerge path, we'd like to
2761  * arrange for the subpath to return the required target list so that
2762  * workers can help project. But if there is something that is not
2763  * parallel-safe in the target expressions, then we can't.
2764  */
2765  if ((IsA(path, GatherPath) || IsA(path, GatherMergePath)) &&
2766  is_parallel_safe(root, (Node *) target->exprs))
2767  {
2768  /*
2769  * We always use create_projection_path here, even if the subpath is
2770  * projection-capable, so as to avoid modifying the subpath in place.
2771  * It seems unlikely at present that there could be any other
2772  * references to the subpath, but better safe than sorry.
2773  *
2774  * Note that we don't change the parallel path's cost estimates; it
2775  * might be appropriate to do so, to reflect the fact that the bulk of
2776  * the target evaluation will happen in workers.
2777  */
2778  if (IsA(path, GatherPath))
2779  {
2780  GatherPath *gpath = (GatherPath *) path;
2781 
2782  gpath->subpath = (Path *)
2784  gpath->subpath->parent,
2785  gpath->subpath,
2786  target);
2787  }
2788  else
2789  {
2790  GatherMergePath *gmpath = (GatherMergePath *) path;
2791 
2792  gmpath->subpath = (Path *)
2794  gmpath->subpath->parent,
2795  gmpath->subpath,
2796  target);
2797  }
2798  }
2799  else if (path->parallel_safe &&
2800  !is_parallel_safe(root, (Node *) target->exprs))
2801  {
2802  /*
2803  * We're inserting a parallel-restricted target list into a path
2804  * currently marked parallel-safe, so we have to mark it as no longer
2805  * safe.
2806  */
2807  path->parallel_safe = false;
2808  }
2809 
2810  return path;
2811 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
PathTarget * pathtarget
Definition: pathnodes.h:1175
Definition: nodes.h:539
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2626
Cost startup
Definition: pathnodes.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:638
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * subpath
Definition: pathnodes.h:1552
List * exprs
Definition: pathnodes.h:1102
Cost total_cost
Definition: pathnodes.h:1186
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
bool is_projection_capable_path(Path *path)
Definition: createplan.c:7028

◆ calc_nestloop_required_outer()

Relids calc_nestloop_required_outer ( Relids  outerrelids,
Relids  outer_paramrels,
Relids  innerrelids,
Relids  inner_paramrels 
)

Definition at line 2340 of file pathnode.c.

References Assert, bms_copy(), bms_del_members(), bms_free(), bms_is_empty(), bms_overlap(), and bms_union().

Referenced by try_nestloop_path().

2344 {
2345  Relids required_outer;
2346 
2347  /* inner_path can require rels from outer path, but not vice versa */
2348  Assert(!bms_overlap(outer_paramrels, innerrelids));
2349  /* easy case if inner path is not parameterized */
2350  if (!inner_paramrels)
2351  return bms_copy(outer_paramrels);
2352  /* else, form the union ... */
2353  required_outer = bms_union(outer_paramrels, inner_paramrels);
2354  /* ... and remove any mention of now-satisfied outer rels */
2355  required_outer = bms_del_members(required_outer,
2356  outerrelids);
2357  /* maintain invariant that required_outer is exactly NULL if empty */
2358  if (bms_is_empty(required_outer))
2359  {
2360  bms_free(required_outer);
2361  required_outer = NULL;
2362  }
2363  return required_outer;
2364 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define Assert(condition)
Definition: c.h:804
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:928
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

Definition at line 2373 of file pathnode.c.

References Assert, bms_overlap(), bms_union(), Path::parent, PATH_REQ_OUTER, and RelOptInfo::relids.

Referenced by try_hashjoin_path(), and try_mergejoin_path().

2374 {
2375  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2376  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2377  Relids required_outer;
2378 
2379  /* neither path can require rels from the other */
2380  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2381  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2382  /* form the union ... */
2383  required_outer = bms_union(outer_paramrels, inner_paramrels);
2384  /* we do not need an explicit test for empty; bms_union gets it right */
2385  return required_outer;
2386 }
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
Relids relids
Definition: pathnodes.h:676
#define Assert(condition)
Definition: c.h:804
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494

◆ compare_fractional_path_costs()

int compare_fractional_path_costs ( Path path1,
Path path2,
double  fraction 
)

Definition at line 117 of file pathnode.c.

References compare_path_costs(), Path::startup_cost, TOTAL_COST, and Path::total_cost.

Referenced by choose_hashed_setop(), get_cheapest_fractional_path(), and get_cheapest_fractional_path_for_pathkeys().

119 {
120  Cost cost1,
121  cost2;
122 
123  if (fraction <= 0.0 || fraction >= 1.0)
124  return compare_path_costs(path1, path2, TOTAL_COST);
125  cost1 = path1->startup_cost +
126  fraction * (path1->total_cost - path1->startup_cost);
127  cost2 = path2->startup_cost +
128  fraction * (path2->total_cost - path2->startup_cost);
129  if (cost1 < cost2)
130  return -1;
131  if (cost1 > cost2)
132  return +1;
133  return 0;
134 }
Cost startup_cost
Definition: pathnodes.h:1185
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Cost total_cost
Definition: pathnodes.h:1186
double Cost
Definition: nodes.h:673

◆ compare_path_costs()

int compare_path_costs ( Path path1,
Path path2,
CostSelector  criterion 
)

Definition at line 71 of file pathnode.c.

References STARTUP_COST, Path::startup_cost, and Path::total_cost.

Referenced by append_startup_cost_compare(), append_total_cost_compare(), compare_fractional_path_costs(), generate_mergejoin_paths(), get_cheapest_parameterized_child_path(), get_cheapest_path_for_pathkeys(), and set_cheapest().

72 {
73  if (criterion == STARTUP_COST)
74  {
75  if (path1->startup_cost < path2->startup_cost)
76  return -1;
77  if (path1->startup_cost > path2->startup_cost)
78  return +1;
79 
80  /*
81  * If paths have the same startup cost (not at all unlikely), order
82  * them by total cost.
83  */
84  if (path1->total_cost < path2->total_cost)
85  return -1;
86  if (path1->total_cost > path2->total_cost)
87  return +1;
88  }
89  else
90  {
91  if (path1->total_cost < path2->total_cost)
92  return -1;
93  if (path1->total_cost > path2->total_cost)
94  return +1;
95 
96  /*
97  * If paths have the same total cost, order them by startup cost.
98  */
99  if (path1->startup_cost < path2->startup_cost)
100  return -1;
101  if (path1->startup_cost > path2->startup_cost)
102  return +1;
103  }
104  return 0;
105 }
Cost startup_cost
Definition: pathnodes.h:1185
Cost total_cost
Definition: pathnodes.h:1186

◆ compare_path_costs_fuzzily()

static PathCostComparison compare_path_costs_fuzzily ( Path path1,
Path path2,
double  fuzz_factor 
)
static

Definition at line 166 of file pathnode.c.

References CONSIDER_PATH_STARTUP_COST, COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT, COSTS_EQUAL, Path::startup_cost, and Path::total_cost.

Referenced by add_path().

167 {
168 #define CONSIDER_PATH_STARTUP_COST(p) \
169  ((p)->param_info == NULL ? (p)->parent->consider_startup : (p)->parent->consider_param_startup)
170 
171  /*
172  * Check total cost first since it's more likely to be different; many
173  * paths have zero startup cost.
174  */
175  if (path1->total_cost > path2->total_cost * fuzz_factor)
176  {
177  /* path1 fuzzily worse on total cost */
178  if (CONSIDER_PATH_STARTUP_COST(path1) &&
179  path2->startup_cost > path1->startup_cost * fuzz_factor)
180  {
181  /* ... but path2 fuzzily worse on startup, so DIFFERENT */
182  return COSTS_DIFFERENT;
183  }
184  /* else path2 dominates */
185  return COSTS_BETTER2;
186  }
187  if (path2->total_cost > path1->total_cost * fuzz_factor)
188  {
189  /* path2 fuzzily worse on total cost */
190  if (CONSIDER_PATH_STARTUP_COST(path2) &&
191  path1->startup_cost > path2->startup_cost * fuzz_factor)
192  {
193  /* ... but path1 fuzzily worse on startup, so DIFFERENT */
194  return COSTS_DIFFERENT;
195  }
196  /* else path1 dominates */
197  return COSTS_BETTER1;
198  }
199  /* fuzzily the same on total cost ... */
200  if (path1->startup_cost > path2->startup_cost * fuzz_factor)
201  {
202  /* ... but path1 fuzzily worse on startup, so path2 wins */
203  return COSTS_BETTER2;
204  }
205  if (path2->startup_cost > path1->startup_cost * fuzz_factor)
206  {
207  /* ... but path2 fuzzily worse on startup, so path1 wins */
208  return COSTS_BETTER1;
209  }
210  /* fuzzily the same on both costs */
211  return COSTS_EQUAL;
212 
213 #undef CONSIDER_PATH_STARTUP_COST
214 }
Cost startup_cost
Definition: pathnodes.h:1185
Cost total_cost
Definition: pathnodes.h:1186
#define CONSIDER_PATH_STARTUP_COST(p)

◆ create_agg_path()

AggPath* create_agg_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
AggStrategy  aggstrategy,
AggSplit  aggsplit,
List groupClause,
List qual,
const AggClauseCosts aggcosts,
double  numGroups 
)

Definition at line 3096 of file pathnode.c.

References AGG_SORTED, AggPath::aggsplit, AggPath::aggstrategy, RelOptInfo::consider_parallel, PathTarget::cost, cost_agg(), AggPath::groupClause, list_length(), makeNode, NIL, AggPath::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AggPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, AggPath::qual, Path::rows, QualCost::startup, Path::startup_cost, subpath(), AggPath::subpath, T_Agg, Path::total_cost, AggClauseCosts::transitionSpace, AggPath::transitionSpace, and PathTarget::width.

Referenced by add_paths_to_grouping_rel(), create_distinct_paths(), create_partial_grouping_paths(), and make_union_unique().

3106 {
3107  AggPath *pathnode = makeNode(AggPath);
3108 
3109  pathnode->path.pathtype = T_Agg;
3110  pathnode->path.parent = rel;
3111  pathnode->path.pathtarget = target;
3112  /* For now, assume we are above any joins, so no parameterization */
3113  pathnode->path.param_info = NULL;
3114  pathnode->path.parallel_aware = false;
3115  pathnode->path.parallel_safe = rel->consider_parallel &&
3116  subpath->parallel_safe;
3117  pathnode->path.parallel_workers = subpath->parallel_workers;
3118  if (aggstrategy == AGG_SORTED)
3119  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
3120  else
3121  pathnode->path.pathkeys = NIL; /* output is unordered */
3122  pathnode->subpath = subpath;
3123 
3124  pathnode->aggstrategy = aggstrategy;
3125  pathnode->aggsplit = aggsplit;
3126  pathnode->numGroups = numGroups;
3127  pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
3128  pathnode->groupClause = groupClause;
3129  pathnode->qual = qual;
3130 
3131  cost_agg(&pathnode->path, root,
3132  aggstrategy, aggcosts,
3133  list_length(groupClause), numGroups,
3134  qual,
3135  subpath->startup_cost, subpath->total_cost,
3136  subpath->rows, subpath->pathtarget->width);
3137 
3138  /* add tlist eval cost for each output row */
3139  pathnode->path.startup_cost += target->cost.startup;
3140  pathnode->path.total_cost += target->cost.startup +
3141  target->cost.per_tuple * pathnode->path.rows;
3142 
3143  return pathnode;
3144 }
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:81
PathTarget * pathtarget
Definition: pathnodes.h:1175
AggStrategy aggstrategy
Definition: pathnodes.h:1760
List * qual
Definition: pathnodes.h:1765
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2560
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
AggSplit aggsplit
Definition: pathnodes.h:1761
double numGroups
Definition: pathnodes.h:1762
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
List * groupClause
Definition: pathnodes.h:1764
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
uint64 transitionSpace
Definition: pathnodes.h:1763
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:684
Path * subpath
Definition: pathnodes.h:1759
Size transitionSpace
Definition: pathnodes.h:60
bool parallel_aware
Definition: pathnodes.h:1179
Path path
Definition: pathnodes.h:1758
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_append_path()

AppendPath* create_append_path ( PlannerInfo root,
RelOptInfo rel,
List subpaths,
List partial_subpaths,
List pathkeys,
Relids  required_outer,
int  parallel_workers,
bool  parallel_aware,
double  rows 
)

Definition at line 1244 of file pathnode.c.

References PlannerInfo::all_baserels, append_startup_cost_compare(), append_total_cost_compare(), Assert, bms_equal(), RelOptInfo::consider_parallel, cost_append(), AppendPath::first_partial_path, get_appendrel_parampathinfo(), get_baserel_parampathinfo(), IS_PARTITIONED_REL, lfirst, PlannerInfo::limit_tuples, AppendPath::limit_tuples, linitial, list_concat(), list_length(), list_sort(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::relids, RELOPT_BASEREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), AppendPath::subpaths, T_Append, and Path::total_cost.

Referenced by add_paths_to_append_rel(), create_degenerate_grouping_paths(), generate_nonunion_paths(), generate_orderedappend_paths(), generate_union_paths(), mark_dummy_rel(), reparameterize_path(), and set_dummy_rel_pathlist().

1250 {
1251  AppendPath *pathnode = makeNode(AppendPath);
1252  ListCell *l;
1253 
1254  Assert(!parallel_aware || parallel_workers > 0);
1255 
1256  pathnode->path.pathtype = T_Append;
1257  pathnode->path.parent = rel;
1258  pathnode->path.pathtarget = rel->reltarget;
1259 
1260  /*
1261  * When generating an Append path for a partitioned table, there may be
1262  * parameterized quals that are useful for run-time pruning. Hence,
1263  * compute path.param_info the same way as for any other baserel, so that
1264  * such quals will be available for make_partition_pruneinfo(). (This
1265  * would not work right for a non-baserel, ie a scan on a non-leaf child
1266  * partition, and it's not necessary anyway in that case. Must skip it if
1267  * we don't have "root", too.)
1268  */
1269  if (root && rel->reloptkind == RELOPT_BASEREL && IS_PARTITIONED_REL(rel))
1270  pathnode->path.param_info = get_baserel_parampathinfo(root,
1271  rel,
1272  required_outer);
1273  else
1275  required_outer);
1276 
1277  pathnode->path.parallel_aware = parallel_aware;
1278  pathnode->path.parallel_safe = rel->consider_parallel;
1279  pathnode->path.parallel_workers = parallel_workers;
1280  pathnode->path.pathkeys = pathkeys;
1281 
1282  /*
1283  * For parallel append, non-partial paths are sorted by descending total
1284  * costs. That way, the total time to finish all non-partial paths is
1285  * minimized. Also, the partial paths are sorted by descending startup
1286  * costs. There may be some paths that require to do startup work by a
1287  * single worker. In such case, it's better for workers to choose the
1288  * expensive ones first, whereas the leader should choose the cheapest
1289  * startup plan.
1290  */
1291  if (pathnode->path.parallel_aware)
1292  {
1293  /*
1294  * We mustn't fiddle with the order of subpaths when the Append has
1295  * pathkeys. The order they're listed in is critical to keeping the
1296  * pathkeys valid.
1297  */
1298  Assert(pathkeys == NIL);
1299 
1301  list_sort(partial_subpaths, append_startup_cost_compare);
1302  }
1303  pathnode->first_partial_path = list_length(subpaths);
1304  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1305 
1306  /*
1307  * Apply query-wide LIMIT if known and path is for sole base relation.
1308  * (Handling this at this low level is a bit klugy.)
1309  */
1310  if (root != NULL && bms_equal(rel->relids, root->all_baserels))
1311  pathnode->limit_tuples = root->limit_tuples;
1312  else
1313  pathnode->limit_tuples = -1.0;
1314 
1315  foreach(l, pathnode->subpaths)
1316  {
1317  Path *subpath = (Path *) lfirst(l);
1318 
1319  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1320  subpath->parallel_safe;
1321 
1322  /* All child paths must have same parameterization */
1323  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1324  }
1325 
1326  Assert(!parallel_aware || pathnode->path.parallel_safe);
1327 
1328  /*
1329  * If there's exactly one child path, the Append is a no-op and will be
1330  * discarded later (in setrefs.c); therefore, we can inherit the child's
1331  * size and cost, as well as its pathkeys if any (overriding whatever the
1332  * caller might've said). Otherwise, we must do the normal costsize
1333  * calculation.
1334  */
1335  if (list_length(pathnode->subpaths) == 1)
1336  {
1337  Path *child = (Path *) linitial(pathnode->subpaths);
1338 
1339  pathnode->path.rows = child->rows;
1340  pathnode->path.startup_cost = child->startup_cost;
1341  pathnode->path.total_cost = child->total_cost;
1342  pathnode->path.pathkeys = child->pathkeys;
1343  }
1344  else
1345  cost_append(pathnode);
1346 
1347  /* If the caller provided a row estimate, override the computed value. */
1348  if (rows >= 0)
1349  pathnode->path.rows = rows;
1350 
1351  return pathnode;
1352 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
RelOptKind reloptkind
Definition: pathnodes.h:673
double limit_tuples
Definition: pathnodes.h:1447
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
Definition: nodes.h:49
static int append_total_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1364
int first_partial_path
Definition: pathnodes.h:1446
NodeTag pathtype
Definition: pathnodes.h:1172
List * subpaths
Definition: pathnodes.h:1444
static int append_startup_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1386
#define linitial(l)
Definition: pg_list.h:174
Relids all_baserels
Definition: pathnodes.h:209
double limit_tuples
Definition: pathnodes.h:340
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
Relids relids
Definition: pathnodes.h:676
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
void cost_append(AppendPath *apath)
Definition: costsize.c:2143
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:684
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1496
#define IS_PARTITIONED_REL(rel)
Definition: pathnodes.h:778
bool parallel_aware
Definition: pathnodes.h:1179
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1591
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ create_bitmap_and_path()

BitmapAndPath* create_bitmap_and_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

Definition at line 1079 of file pathnode.c.

References BitmapAndPath::bitmapquals, bms_add_members(), RelOptInfo::consider_parallel, cost_bitmap_and_node(), get_baserel_parampathinfo(), lfirst, makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, BitmapAndPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_BitmapAnd.

Referenced by bitmap_and_cost_est(), and choose_bitmap_and().

1082 {
1083  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1084  Relids required_outer = NULL;
1085  ListCell *lc;
1086 
1087  pathnode->path.pathtype = T_BitmapAnd;
1088  pathnode->path.parent = rel;
1089  pathnode->path.pathtarget = rel->reltarget;
1090 
1091  /*
1092  * Identify the required outer rels as the union of what the child paths
1093  * depend on. (Alternatively, we could insist that the caller pass this
1094  * in, but it's more convenient and reliable to compute it here.)
1095  */
1096  foreach(lc, bitmapquals)
1097  {
1098  Path *bitmapqual = (Path *) lfirst(lc);
1099 
1100  required_outer = bms_add_members(required_outer,
1101  PATH_REQ_OUTER(bitmapqual));
1102  }
1103  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1104  required_outer);
1105 
1106  /*
1107  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1108  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1109  * set the flag for this path based only on the relation-level flag,
1110  * without actually iterating over the list of children.
1111  */
1112  pathnode->path.parallel_aware = false;
1113  pathnode->path.parallel_safe = rel->consider_parallel;
1114  pathnode->path.parallel_workers = 0;
1115 
1116  pathnode->path.pathkeys = NIL; /* always unordered */
1117 
1118  pathnode->bitmapquals = bitmapquals;
1119 
1120  /* this sets bitmapselectivity as well as the regular cost fields: */
1121  cost_bitmap_and_node(pathnode, root);
1122 
1123  return pathnode;
1124 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1099
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * bitmapquals
Definition: pathnodes.h:1322
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define lfirst(lc)
Definition: pg_list.h:169
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:793

◆ create_bitmap_heap_path()

BitmapHeapPath* create_bitmap_heap_path ( PlannerInfo root,
RelOptInfo rel,
Path bitmapqual,
Relids  required_outer,
double  loop_count,
int  parallel_degree 
)

Definition at line 1046 of file pathnode.c.

References BitmapHeapPath::bitmapqual, RelOptInfo::consider_parallel, cost_bitmap_heap_scan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, BitmapHeapPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, T_BitmapHeapScan, and true.

Referenced by create_index_paths(), create_partial_bitmap_paths(), and reparameterize_path().

1052 {
1053  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1054 
1055  pathnode->path.pathtype = T_BitmapHeapScan;
1056  pathnode->path.parent = rel;
1057  pathnode->path.pathtarget = rel->reltarget;
1058  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1059  required_outer);
1060  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1061  pathnode->path.parallel_safe = rel->consider_parallel;
1062  pathnode->path.parallel_workers = parallel_degree;
1063  pathnode->path.pathkeys = NIL; /* always unordered */
1064 
1065  pathnode->bitmapqual = bitmapqual;
1066 
1067  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1068  pathnode->path.param_info,
1069  bitmapqual, loop_count);
1070 
1071  return pathnode;
1072 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
#define true
Definition: c.h:395
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * bitmapqual
Definition: pathnodes.h:1310
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_bitmap_or_path()

BitmapOrPath* create_bitmap_or_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

Definition at line 1131 of file pathnode.c.

References BitmapOrPath::bitmapquals, bms_add_members(), RelOptInfo::consider_parallel, cost_bitmap_or_node(), get_baserel_parampathinfo(), lfirst, makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, BitmapOrPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_BitmapOr.

Referenced by generate_bitmap_or_paths().

1134 {
1135  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1136  Relids required_outer = NULL;
1137  ListCell *lc;
1138 
1139  pathnode->path.pathtype = T_BitmapOr;
1140  pathnode->path.parent = rel;
1141  pathnode->path.pathtarget = rel->reltarget;
1142 
1143  /*
1144  * Identify the required outer rels as the union of what the child paths
1145  * depend on. (Alternatively, we could insist that the caller pass this
1146  * in, but it's more convenient and reliable to compute it here.)
1147  */
1148  foreach(lc, bitmapquals)
1149  {
1150  Path *bitmapqual = (Path *) lfirst(lc);
1151 
1152  required_outer = bms_add_members(required_outer,
1153  PATH_REQ_OUTER(bitmapqual));
1154  }
1155  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1156  required_outer);
1157 
1158  /*
1159  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1160  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1161  * set the flag for this path based only on the relation-level flag,
1162  * without actually iterating over the list of children.
1163  */
1164  pathnode->path.parallel_aware = false;
1165  pathnode->path.parallel_safe = rel->consider_parallel;
1166  pathnode->path.parallel_workers = 0;
1167 
1168  pathnode->path.pathkeys = NIL; /* always unordered */
1169 
1170  pathnode->bitmapquals = bitmapquals;
1171 
1172  /* this sets bitmapselectivity as well as the regular cost fields: */
1173  cost_bitmap_or_node(pathnode, root);
1174 
1175  return pathnode;
1176 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * bitmapquals
Definition: pathnodes.h:1335
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define lfirst(lc)
Definition: pg_list.h:169
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1143
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:793

◆ create_ctescan_path()

Path* create_ctescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 2096 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_ctescan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_CteScan.

Referenced by set_cte_pathlist().

2097 {
2098  Path *pathnode = makeNode(Path);
2099 
2100  pathnode->pathtype = T_CteScan;
2101  pathnode->parent = rel;
2102  pathnode->pathtarget = rel->reltarget;
2103  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2104  required_outer);
2105  pathnode->parallel_aware = false;
2106  pathnode->parallel_safe = rel->consider_parallel;
2107  pathnode->parallel_workers = 0;
2108  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
2109 
2110  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2111 
2112  return pathnode;
2113 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1608
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_foreign_join_path()

ForeignPath* create_foreign_join_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
double  rows,
Cost  startup_cost,
Cost  total_cost,
List pathkeys,
Relids  required_outer,
Path fdw_outerpath,
List fdw_private 
)

Definition at line 2250 of file pathnode.c.

References bms_is_empty(), RelOptInfo::consider_parallel, elog, ERROR, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, RelOptInfo::lateral_relids, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ForeignPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, T_ForeignScan, and Path::total_cost.

Referenced by add_paths_with_pathkeys_for_rel(), and postgresGetForeignJoinPaths().

2257 {
2258  ForeignPath *pathnode = makeNode(ForeignPath);
2259 
2260  /*
2261  * We should use get_joinrel_parampathinfo to handle parameterized paths,
2262  * but the API of this function doesn't support it, and existing
2263  * extensions aren't yet trying to build such paths anyway. For the
2264  * moment just throw an error if someone tries it; eventually we should
2265  * revisit this.
2266  */
2267  if (!bms_is_empty(required_outer) || !bms_is_empty(rel->lateral_relids))
2268  elog(ERROR, "parameterized foreign joins are not supported yet");
2269 
2270  pathnode->path.pathtype = T_ForeignScan;
2271  pathnode->path.parent = rel;
2272  pathnode->path.pathtarget = target ? target : rel->reltarget;
2273  pathnode->path.param_info = NULL; /* XXX see above */
2274  pathnode->path.parallel_aware = false;
2275  pathnode->path.parallel_safe = rel->consider_parallel;
2276  pathnode->path.parallel_workers = 0;
2277  pathnode->path.rows = rows;
2278  pathnode->path.startup_cost = startup_cost;
2279  pathnode->path.total_cost = total_cost;
2280  pathnode->path.pathkeys = pathkeys;
2281 
2282  pathnode->fdw_outerpath = fdw_outerpath;
2283  pathnode->fdw_private = fdw_private;
2284 
2285  return pathnode;
2286 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
Path * fdw_outerpath
Definition: pathnodes.h:1391
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Relids lateral_relids
Definition: pathnodes.h:701
#define ERROR
Definition: elog.h:46
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
List * fdw_private
Definition: pathnodes.h:1392
#define elog(elevel,...)
Definition: elog.h:232
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_foreign_upper_path()

ForeignPath* create_foreign_upper_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
double  rows,
Cost  startup_cost,
Cost  total_cost,
List pathkeys,
Path fdw_outerpath,
List fdw_private 
)

Definition at line 2300 of file pathnode.c.

References Assert, bms_is_empty(), RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, RelOptInfo::lateral_relids, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ForeignPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, T_ForeignScan, and Path::total_cost.

Referenced by add_foreign_final_paths(), add_foreign_grouping_paths(), and add_foreign_ordered_paths().

2306 {
2307  ForeignPath *pathnode = makeNode(ForeignPath);
2308 
2309  /*
2310  * Upper relations should never have any lateral references, since joining
2311  * is complete.
2312  */
2314 
2315  pathnode->path.pathtype = T_ForeignScan;
2316  pathnode->path.parent = rel;
2317  pathnode->path.pathtarget = target ? target : rel->reltarget;
2318  pathnode->path.param_info = NULL;
2319  pathnode->path.parallel_aware = false;
2320  pathnode->path.parallel_safe = rel->consider_parallel;
2321  pathnode->path.parallel_workers = 0;
2322  pathnode->path.rows = rows;
2323  pathnode->path.startup_cost = startup_cost;
2324  pathnode->path.total_cost = total_cost;
2325  pathnode->path.pathkeys = pathkeys;
2326 
2327  pathnode->fdw_outerpath = fdw_outerpath;
2328  pathnode->fdw_private = fdw_private;
2329 
2330  return pathnode;
2331 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
Path * fdw_outerpath
Definition: pathnodes.h:1391
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Relids lateral_relids
Definition: pathnodes.h:701
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
List * fdw_private
Definition: pathnodes.h:1392
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_foreignscan_path()

ForeignPath* create_foreignscan_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
double  rows,
Cost  startup_cost,
Cost  total_cost,
List pathkeys,
Relids  required_outer,
Path fdw_outerpath,
List fdw_private 
)

Definition at line 2206 of file pathnode.c.

References Assert, RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, get_baserel_parampathinfo(), IS_SIMPLE_REL, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ForeignPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, T_ForeignScan, and Path::total_cost.

Referenced by add_paths_with_pathkeys_for_rel(), fileGetForeignPaths(), and postgresGetForeignPaths().

2213 {
2214  ForeignPath *pathnode = makeNode(ForeignPath);
2215 
2216  /* Historically some FDWs were confused about when to use this */
2217  Assert(IS_SIMPLE_REL(rel));
2218 
2219  pathnode->path.pathtype = T_ForeignScan;
2220  pathnode->path.parent = rel;
2221  pathnode->path.pathtarget = target ? target : rel->reltarget;
2222  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2223  required_outer);
2224  pathnode->path.parallel_aware = false;
2225  pathnode->path.parallel_safe = rel->consider_parallel;
2226  pathnode->path.parallel_workers = 0;
2227  pathnode->path.rows = rows;
2228  pathnode->path.startup_cost = startup_cost;
2229  pathnode->path.total_cost = total_cost;
2230  pathnode->path.pathkeys = pathkeys;
2231 
2232  pathnode->fdw_outerpath = fdw_outerpath;
2233  pathnode->fdw_private = fdw_private;
2234 
2235  return pathnode;
2236 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
Path * fdw_outerpath
Definition: pathnodes.h:1391
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:649
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
List * fdw_private
Definition: pathnodes.h:1392
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_functionscan_path()

Path* create_functionscan_path ( PlannerInfo root,
RelOptInfo rel,
List pathkeys,
Relids  required_outer 
)

Definition at line 2018 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_functionscan(), get_baserel_parampathinfo(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_FunctionScan.

Referenced by set_function_pathlist().

2020 {
2021  Path *pathnode = makeNode(Path);
2022 
2023  pathnode->pathtype = T_FunctionScan;
2024  pathnode->parent = rel;
2025  pathnode->pathtarget = rel->reltarget;
2026  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2027  required_outer);
2028  pathnode->parallel_aware = false;
2029  pathnode->parallel_safe = rel->consider_parallel;
2030  pathnode->parallel_workers = 0;
2031  pathnode->pathkeys = pathkeys;
2032 
2033  cost_functionscan(pathnode, root, rel, pathnode->param_info);
2034 
2035  return pathnode;
2036 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1441
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_gather_merge_path()

GatherMergePath* create_gather_merge_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List pathkeys,
Relids  required_outer,
double *  rows 
)

Definition at line 1860 of file pathnode.c.

References Assert, cost_gather_merge(), cost_sort(), get_baserel_parampathinfo(), makeNode, GatherMergePath::num_workers, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GatherMergePath::path, Path::pathkeys, pathkeys_contained_in(), Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), GatherMergePath::subpath, T_GatherMerge, Path::total_cost, PathTarget::width, and work_mem.

Referenced by create_ordered_paths(), gather_grouping_paths(), generate_gather_paths(), and generate_useful_gather_paths().

1863 {
1865  Cost input_startup_cost = 0;
1866  Cost input_total_cost = 0;
1867 
1868  Assert(subpath->parallel_safe);
1869  Assert(pathkeys);
1870 
1871  pathnode->path.pathtype = T_GatherMerge;
1872  pathnode->path.parent = rel;
1873  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1874  required_outer);
1875  pathnode->path.parallel_aware = false;
1876 
1877  pathnode->subpath = subpath;
1878  pathnode->num_workers = subpath->parallel_workers;
1879  pathnode->path.pathkeys = pathkeys;
1880  pathnode->path.pathtarget = target ? target : rel->reltarget;
1881  pathnode->path.rows += subpath->rows;
1882 
1883  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1884  {
1885  /* Subpath is adequately ordered, we won't need to sort it */
1886  input_startup_cost += subpath->startup_cost;
1887  input_total_cost += subpath->total_cost;
1888  }
1889  else
1890  {
1891  /* We'll need to insert a Sort node, so include cost for that */
1892  Path sort_path; /* dummy for result of cost_sort */
1893 
1894  cost_sort(&sort_path,
1895  root,
1896  pathkeys,
1897  subpath->total_cost,
1898  subpath->rows,
1899  subpath->pathtarget->width,
1900  0.0,
1901  work_mem,
1902  -1);
1903  input_startup_cost += sort_path.startup_cost;
1904  input_total_cost += sort_path.total_cost;
1905  }
1906 
1907  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1908  input_startup_cost, input_total_cost, rows);
1909 
1910  return pathnode;
1911 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, Cost input_startup_cost, Cost input_total_cost, double *rows)
Definition: costsize.c:416
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:2036
int work_mem
Definition: globals.c:124
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
double Cost
Definition: nodes.h:673
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_gather_path()

GatherPath* create_gather_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
Relids  required_outer,
double *  rows 
)

Definition at line 1951 of file pathnode.c.

References Assert, cost_gather(), get_baserel_parampathinfo(), makeNode, NIL, GatherPath::num_workers, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GatherPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, GatherPath::single_copy, subpath(), GatherPath::subpath, and T_Gather.

Referenced by generate_gather_paths(), and generate_union_paths().

1953 {
1954  GatherPath *pathnode = makeNode(GatherPath);
1955 
1956  Assert(subpath->parallel_safe);
1957 
1958  pathnode->path.pathtype = T_Gather;
1959  pathnode->path.parent = rel;
1960  pathnode->path.pathtarget = target;
1961  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1962  required_outer);
1963  pathnode->path.parallel_aware = false;
1964  pathnode->path.parallel_safe = false;
1965  pathnode->path.parallel_workers = 0;
1966  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1967 
1968  pathnode->subpath = subpath;
1969  pathnode->num_workers = subpath->parallel_workers;
1970  pathnode->single_copy = false;
1971 
1972  if (pathnode->num_workers == 0)
1973  {
1974  pathnode->path.pathkeys = subpath->pathkeys;
1975  pathnode->num_workers = 1;
1976  pathnode->single_copy = true;
1977  }
1978 
1979  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1980 
1981  return pathnode;
1982 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
bool single_copy
Definition: pathnodes.h:1553
int num_workers
Definition: pathnodes.h:1554
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * subpath
Definition: pathnodes.h:1552
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
bool parallel_safe
Definition: pathnodes.h:1180
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:378
Definition: nodes.h:84
bool parallel_aware
Definition: pathnodes.h:1179
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_group_path()

GroupPath* create_group_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List groupClause,
List qual,
double  numGroups 
)

Definition at line 2985 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cost_group(), GroupPath::groupClause, list_length(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GroupPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, GroupPath::qual, RelOptInfo::reltarget, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupPath::subpath, T_Group, and Path::total_cost.

Referenced by add_paths_to_grouping_rel(), and create_partial_grouping_paths().

2991 {
2992  GroupPath *pathnode = makeNode(GroupPath);
2993  PathTarget *target = rel->reltarget;
2994 
2995  pathnode->path.pathtype = T_Group;
2996  pathnode->path.parent = rel;
2997  pathnode->path.pathtarget = target;
2998  /* For now, assume we are above any joins, so no parameterization */
2999  pathnode->path.param_info = NULL;
3000  pathnode->path.parallel_aware = false;
3001  pathnode->path.parallel_safe = rel->consider_parallel &&
3002  subpath->parallel_safe;
3003  pathnode->path.parallel_workers = subpath->parallel_workers;
3004  /* Group doesn't change sort ordering */
3005  pathnode->path.pathkeys = subpath->pathkeys;
3006 
3007  pathnode->subpath = subpath;
3008 
3009  pathnode->groupClause = groupClause;
3010  pathnode->qual = qual;
3011 
3012  cost_group(&pathnode->path, root,
3013  list_length(groupClause),
3014  numGroups,
3015  qual,
3016  subpath->startup_cost, subpath->total_cost,
3017  subpath->rows);
3018 
3019  /* add tlist eval cost for each output row */
3020  pathnode->path.startup_cost += target->cost.startup;
3021  pathnode->path.total_cost += target->cost.startup +
3022  target->cost.per_tuple * pathnode->path.rows;
3023 
3024  return pathnode;
3025 }
List * qual
Definition: pathnodes.h:1733
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1185
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2832
RelOptInfo * parent
Definition: pathnodes.h:1174
Definition: nodes.h:80
Path path
Definition: pathnodes.h:1730
List * groupClause
Definition: pathnodes.h:1732
Path * subpath
Definition: pathnodes.h:1731
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_group_result_path()

GroupResultPath* create_group_result_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List havingqual 
)

Definition at line 1504 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cost_qual_eval(), cpu_tuple_cost, makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GroupResultPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, GroupResultPath::quals, Path::rows, QualCost::startup, Path::startup_cost, T_Result, and Path::total_cost.

Referenced by create_degenerate_grouping_paths(), and query_planner().

1506 {
1508 
1509  pathnode->path.pathtype = T_Result;
1510  pathnode->path.parent = rel;
1511  pathnode->path.pathtarget = target;
1512  pathnode->path.param_info = NULL; /* there are no other rels... */
1513  pathnode->path.parallel_aware = false;
1514  pathnode->path.parallel_safe = rel->consider_parallel;
1515  pathnode->path.parallel_workers = 0;
1516  pathnode->path.pathkeys = NIL;
1517  pathnode->quals = havingqual;
1518 
1519  /*
1520  * We can't quite use cost_resultscan() because the quals we want to
1521  * account for are not baserestrict quals of the rel. Might as well just
1522  * hack it here.
1523  */
1524  pathnode->path.rows = 1;
1525  pathnode->path.startup_cost = target->cost.startup;
1526  pathnode->path.total_cost = target->cost.startup +
1527  cpu_tuple_cost + target->cost.per_tuple;
1528 
1529  /*
1530  * Add cost of qual, if any --- but we ignore its selectivity, since our
1531  * rowcount estimate should be 1 no matter what the qual is.
1532  */
1533  if (havingqual)
1534  {
1535  QualCost qual_cost;
1536 
1537  cost_qual_eval(&qual_cost, havingqual, root);
1538  /* havingqual is evaluated once at startup */
1539  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1540  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1541  }
1542 
1543  return pathnode;
1544 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4308
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
bool consider_parallel
Definition: pathnodes.h:684
double cpu_tuple_cost
Definition: costsize.c:121
bool parallel_aware
Definition: pathnodes.h:1179

◆ create_groupingsets_path()

GroupingSetsPath* create_groupingsets_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List having_qual,
AggStrategy  aggstrategy,
List rollups,
const AggClauseCosts agg_costs,
double  numGroups 
)

Definition at line 3163 of file pathnode.c.

References AGG_HASHED, AGG_MIXED, AGG_PLAIN, AGG_SORTED, GroupingSetsPath::aggstrategy, Assert, RelOptInfo::consider_parallel, PathTarget::cost, cost_agg(), cost_sort(), PlannerInfo::group_pathkeys, RollupData::gsets, RollupData::is_hashed, lfirst, linitial, list_length(), makeNode, NIL, RollupData::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GroupingSetsPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, GroupingSetsPath::qual, RelOptInfo::reltarget, GroupingSetsPath::rollups, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupingSetsPath::subpath, T_Agg, Path::total_cost, AggClauseCosts::transitionSpace, GroupingSetsPath::transitionSpace, PathTarget::width, and work_mem.

Referenced by consider_groupingsets_paths().

3171 {
3173  PathTarget *target = rel->reltarget;
3174  ListCell *lc;
3175  bool is_first = true;
3176  bool is_first_sort = true;
3177 
3178  /* The topmost generated Plan node will be an Agg */
3179  pathnode->path.pathtype = T_Agg;
3180  pathnode->path.parent = rel;
3181  pathnode->path.pathtarget = target;
3182  pathnode->path.param_info = subpath->param_info;
3183  pathnode->path.parallel_aware = false;
3184  pathnode->path.parallel_safe = rel->consider_parallel &&
3185  subpath->parallel_safe;
3186  pathnode->path.parallel_workers = subpath->parallel_workers;
3187  pathnode->subpath = subpath;
3188 
3189  /*
3190  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
3191  * to AGG_HASHED, here if possible.
3192  */
3193  if (aggstrategy == AGG_SORTED &&
3194  list_length(rollups) == 1 &&
3195  ((RollupData *) linitial(rollups))->groupClause == NIL)
3196  aggstrategy = AGG_PLAIN;
3197 
3198  if (aggstrategy == AGG_MIXED &&
3199  list_length(rollups) == 1)
3200  aggstrategy = AGG_HASHED;
3201 
3202  /*
3203  * Output will be in sorted order by group_pathkeys if, and only if, there
3204  * is a single rollup operation on a non-empty list of grouping
3205  * expressions.
3206  */
3207  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
3208  pathnode->path.pathkeys = root->group_pathkeys;
3209  else
3210  pathnode->path.pathkeys = NIL;
3211 
3212  pathnode->aggstrategy = aggstrategy;
3213  pathnode->rollups = rollups;
3214  pathnode->qual = having_qual;
3215  pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
3216 
3217  Assert(rollups != NIL);
3218  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
3219  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
3220 
3221  foreach(lc, rollups)
3222  {
3223  RollupData *rollup = lfirst(lc);
3224  List *gsets = rollup->gsets;
3225  int numGroupCols = list_length(linitial(gsets));
3226 
3227  /*
3228  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
3229  * (already-sorted) input, and following ones do their own sort.
3230  *
3231  * In AGG_HASHED mode, there is one rollup for each grouping set.
3232  *
3233  * In AGG_MIXED mode, the first rollups are hashed, the first
3234  * non-hashed one takes the (already-sorted) input, and following ones
3235  * do their own sort.
3236  */
3237  if (is_first)
3238  {
3239  cost_agg(&pathnode->path, root,
3240  aggstrategy,
3241  agg_costs,
3242  numGroupCols,
3243  rollup->numGroups,
3244  having_qual,
3245  subpath->startup_cost,
3246  subpath->total_cost,
3247  subpath->rows,
3248  subpath->pathtarget->width);
3249  is_first = false;
3250  if (!rollup->is_hashed)
3251  is_first_sort = false;
3252  }
3253  else
3254  {
3255  Path sort_path; /* dummy for result of cost_sort */
3256  Path agg_path; /* dummy for result of cost_agg */
3257 
3258  if (rollup->is_hashed || is_first_sort)
3259  {
3260  /*
3261  * Account for cost of aggregation, but don't charge input
3262  * cost again
3263  */
3264  cost_agg(&agg_path, root,
3265  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
3266  agg_costs,
3267  numGroupCols,
3268  rollup->numGroups,
3269  having_qual,
3270  0.0, 0.0,
3271  subpath->rows,
3272  subpath->pathtarget->width);
3273  if (!rollup->is_hashed)
3274  is_first_sort = false;
3275  }
3276  else
3277  {
3278  /* Account for cost of sort, but don't charge input cost again */
3279  cost_sort(&sort_path, root, NIL,
3280  0.0,
3281  subpath->rows,
3282  subpath->pathtarget->width,
3283  0.0,
3284  work_mem,
3285  -1.0);
3286 
3287  /* Account for cost of aggregation */
3288 
3289  cost_agg(&agg_path, root,
3290  AGG_SORTED,
3291  agg_costs,
3292  numGroupCols,
3293  rollup->numGroups,
3294  having_qual,
3295  sort_path.startup_cost,
3296  sort_path.total_cost,
3297  sort_path.rows,
3298  subpath->pathtarget->width);
3299  }
3300 
3301  pathnode->path.total_cost += agg_path.total_cost;
3302  pathnode->path.rows += agg_path.rows;
3303  }
3304  }
3305 
3306  /* add tlist eval cost for each output row */
3307  pathnode->path.startup_cost += target->cost.startup;
3308  pathnode->path.total_cost += target->cost.startup +
3309  target->cost.per_tuple * pathnode->path.rows;
3310 
3311  return pathnode;
3312 }
List * group_pathkeys
Definition: pathnodes.h:295
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:81
PathTarget * pathtarget
Definition: pathnodes.h:1175
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2560
int parallel_workers
Definition: pathnodes.h:1181
bool is_hashed
Definition: pathnodes.h:1787
ParamPathInfo * param_info
Definition: pathnodes.h:1177
double numGroups
Definition: pathnodes.h:1785
Cost startup
Definition: pathnodes.h:45
uint64 transitionSpace
Definition: pathnodes.h:1801
NodeTag pathtype
Definition: pathnodes.h:1172
Cost per_tuple
Definition: pathnodes.h:46
#define linitial(l)
Definition: pg_list.h:174
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
AggStrategy aggstrategy
Definition: pathnodes.h:1798
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:2036
int work_mem
Definition: globals.c:124
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:684
Size transitionSpace
Definition: pathnodes.h:60
bool parallel_aware
Definition: pathnodes.h:1179
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
List * gsets
Definition: pathnodes.h:1783

◆ create_hashjoin_path()

HashPath* create_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
bool  parallel_hash,
List restrict_clauses,
Relids  required_outer,
List hashclauses 
)

Definition at line 2560 of file pathnode.c.

References RelOptInfo::consider_parallel, final_cost_hashjoin(), get_joinrel_parampathinfo(), JoinPath::inner_unique, JoinPathExtraData::inner_unique, JoinPath::innerjoinpath, JoinPath::joinrestrictinfo, JoinPath::jointype, HashPath::jpath, makeNode, NIL, JoinPath::outerjoinpath, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, JoinPath::path, HashPath::path_hashclauses, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, JoinPathExtraData::sjinfo, and T_HashJoin.

Referenced by try_hashjoin_path(), and try_partial_hashjoin_path().

2571 {
2572  HashPath *pathnode = makeNode(HashPath);
2573 
2574  pathnode->jpath.path.pathtype = T_HashJoin;
2575  pathnode->jpath.path.parent = joinrel;
2576  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2577  pathnode->jpath.path.param_info =
2579  joinrel,
2580  outer_path,
2581  inner_path,
2582  extra->sjinfo,
2583  required_outer,
2584  &restrict_clauses);
2585  pathnode->jpath.path.parallel_aware =
2586  joinrel->consider_parallel && parallel_hash;
2587  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2588  outer_path->parallel_safe && inner_path->parallel_safe;
2589  /* This is a foolish way to estimate parallel_workers, but for now... */
2590  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2591 
2592  /*
2593  * A hashjoin never has pathkeys, since its output ordering is
2594  * unpredictable due to possible batching. XXX If the inner relation is
2595  * small enough, we could instruct the executor that it must not batch,
2596  * and then we could assume that the output inherits the outer relation's
2597  * ordering, which might save a sort step. However there is considerable
2598  * downside if our estimate of the inner relation size is badly off. For
2599  * the moment we don't risk it. (Note also that if we wanted to take this
2600  * seriously, joinpath.c would have to consider many more paths for the
2601  * outer rel than it does now.)
2602  */
2603  pathnode->jpath.path.pathkeys = NIL;
2604  pathnode->jpath.jointype = jointype;
2605  pathnode->jpath.inner_unique = extra->inner_unique;
2606  pathnode->jpath.outerjoinpath = outer_path;
2607  pathnode->jpath.innerjoinpath = inner_path;
2608  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2609  pathnode->path_hashclauses = hashclauses;
2610  /* final_cost_hashjoin will fill in pathnode->num_batches */
2611 
2612  final_cost_hashjoin(root, pathnode, workspace, extra);
2613 
2614  return pathnode;
2615 }
#define NIL
Definition: pg_list.h:65
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3849
JoinPath jpath
Definition: pathnodes.h:1656
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1384
Path * innerjoinpath
Definition: pathnodes.h:1583
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2521
List * joinrestrictinfo
Definition: pathnodes.h:1585
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * outerjoinpath
Definition: pathnodes.h:1582
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
Path path
Definition: pathnodes.h:1575
bool parallel_safe
Definition: pathnodes.h:1180
bool inner_unique
Definition: pathnodes.h:1579
bool consider_parallel
Definition: pathnodes.h:684
JoinType jointype
Definition: pathnodes.h:1577
bool parallel_aware
Definition: pathnodes.h:1179
List * path_hashclauses
Definition: pathnodes.h:1657
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_incremental_sort_path()

IncrementalSortPath* create_incremental_sort_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
int  presorted_keys,
double  limit_tuples 
)

Definition at line 2892 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_incremental_sort(), makeNode, IncrementalSortPath::nPresortedCols, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SortPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, sort(), IncrementalSortPath::spath, Path::startup_cost, subpath(), SortPath::subpath, T_IncrementalSort, Path::total_cost, PathTarget::width, and work_mem.

Referenced by add_paths_to_grouping_rel(), create_one_window_path(), create_ordered_paths(), create_partial_grouping_paths(), gather_grouping_paths(), and generate_useful_gather_paths().

2898 {
2900  SortPath *pathnode = &sort->spath;
2901 
2902  pathnode->path.pathtype = T_IncrementalSort;
2903  pathnode->path.parent = rel;
2904  /* Sort doesn't project, so use source path's pathtarget */
2905  pathnode->path.pathtarget = subpath->pathtarget;
2906  /* For now, assume we are above any joins, so no parameterization */
2907  pathnode->path.param_info = NULL;
2908  pathnode->path.parallel_aware = false;
2909  pathnode->path.parallel_safe = rel->consider_parallel &&
2910  subpath->parallel_safe;
2911  pathnode->path.parallel_workers = subpath->parallel_workers;
2912  pathnode->path.pathkeys = pathkeys;
2913 
2914  pathnode->subpath = subpath;
2915 
2916  cost_incremental_sort(&pathnode->path,
2917  root, pathkeys, presorted_keys,
2918  subpath->startup_cost,
2919  subpath->total_cost,
2920  subpath->rows,
2921  subpath->pathtarget->width,
2922  0.0, /* XXX comparison_cost shouldn't be 0? */
2923  work_mem, limit_tuples);
2924 
2925  sort->nPresortedCols = presorted_keys;
2926 
2927  return sort;
2928 }
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, Cost input_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1896
PathTarget * pathtarget
Definition: pathnodes.h:1175
Path * subpath
Definition: pathnodes.h:1705
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:195
int work_mem
Definition: globals.c:124
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
Path path
Definition: pathnodes.h:1704
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_index_path()

IndexPath* create_index_path ( PlannerInfo root,
IndexOptInfo index,
List indexclauses,
List indexorderbys,
List indexorderbycols,
List pathkeys,
ScanDirection  indexscandir,
bool  indexonly,
Relids  required_outer,
double  loop_count,
bool  partial_path 
)

Definition at line 997 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_index(), get_baserel_parampathinfo(), IndexPath::indexclauses, IndexPath::indexinfo, IndexPath::indexorderbycols, IndexPath::indexorderbys, IndexPath::indexscandir, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, IndexPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, IndexOptInfo::rel, RelOptInfo::reltarget, T_IndexOnlyScan, and T_IndexScan.

Referenced by build_index_paths(), and plan_cluster_use_sort().

1008 {
1009  IndexPath *pathnode = makeNode(IndexPath);
1010  RelOptInfo *rel = index->rel;
1011 
1012  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1013  pathnode->path.parent = rel;
1014  pathnode->path.pathtarget = rel->reltarget;
1015  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1016  required_outer);
1017  pathnode->path.parallel_aware = false;
1018  pathnode->path.parallel_safe = rel->consider_parallel;
1019  pathnode->path.parallel_workers = 0;
1020  pathnode->path.pathkeys = pathkeys;
1021 
1022  pathnode->indexinfo = index;
1023  pathnode->indexclauses = indexclauses;
1024  pathnode->indexorderbys = indexorderbys;
1025  pathnode->indexorderbycols = indexorderbycols;
1026  pathnode->indexscandir = indexscandir;
1027 
1028  cost_index(pathnode, root, loop_count, partial_path);
1029 
1030  return pathnode;
1031 }
List * indexorderbycols
Definition: pathnodes.h:1240
PathTarget * pathtarget
Definition: pathnodes.h:1175
Path path
Definition: pathnodes.h:1236
IndexOptInfo * indexinfo
Definition: pathnodes.h:1237
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * indexclauses
Definition: pathnodes.h:1238
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * rel
Definition: pathnodes.h:832
RelOptInfo * parent
Definition: pathnodes.h:1174
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:491
List * indexorderbys
Definition: pathnodes.h:1239
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
ScanDirection indexscandir
Definition: pathnodes.h:1241
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_limit_path()

LimitPath* create_limit_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
Node limitOffset,
Node limitCount,
LimitOption  limitOption,
int64  offset_est,
int64  count_est 
)

Definition at line 3721 of file pathnode.c.

References adjust_limit_rows_costs(), RelOptInfo::consider_parallel, LimitPath::limitCount, LimitPath::limitOffset, LimitPath::limitOption, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, LimitPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, Path::startup_cost, subpath(), LimitPath::subpath, T_Limit, and Path::total_cost.

Referenced by grouping_planner().

3726 {
3727  LimitPath *pathnode = makeNode(LimitPath);
3728 
3729  pathnode->path.pathtype = T_Limit;
3730  pathnode->path.parent = rel;
3731  /* Limit doesn't project, so use source path's pathtarget */
3732  pathnode->path.pathtarget = subpath->pathtarget;
3733  /* For now, assume we are above any joins, so no parameterization */
3734  pathnode->path.param_info = NULL;
3735  pathnode->path.parallel_aware = false;
3736  pathnode->path.parallel_safe = rel->consider_parallel &&
3737  subpath->parallel_safe;
3738  pathnode->path.parallel_workers = subpath->parallel_workers;
3739  pathnode->path.rows = subpath->rows;
3740  pathnode->path.startup_cost = subpath->startup_cost;
3741  pathnode->path.total_cost = subpath->total_cost;
3742  pathnode->path.pathkeys = subpath->pathkeys;
3743  pathnode->subpath = subpath;
3744  pathnode->limitOffset = limitOffset;
3745  pathnode->limitCount = limitCount;
3746  pathnode->limitOption = limitOption;
3747 
3748  /*
3749  * Adjust the output rows count and costs according to the offset/limit.
3750  */
3751  adjust_limit_rows_costs(&pathnode->path.rows,
3752  &pathnode->path.startup_cost,
3753  &pathnode->path.total_cost,
3754  offset_est, count_est);
3755 
3756  return pathnode;
3757 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
LimitOption limitOption
Definition: pathnodes.h:1897
Node * limitOffset
Definition: pathnodes.h:1895
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
void adjust_limit_rows_costs(double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
Definition: pathnode.c:3776
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
Path * subpath
Definition: pathnodes.h:1894
RelOptInfo * parent
Definition: pathnodes.h:1174
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
Path path
Definition: pathnodes.h:1893
bool parallel_aware
Definition: pathnodes.h:1179
Node * limitCount
Definition: pathnodes.h:1896
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
Definition: nodes.h:89

◆ create_lockrows_path()

LockRowsPath* create_lockrows_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List rowMarks,
int  epqParam 
)

Definition at line 3564 of file pathnode.c.

References cpu_tuple_cost, LockRowsPath::epqParam, makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, LockRowsPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, LockRowsPath::rowMarks, Path::rows, Path::startup_cost, subpath(), LockRowsPath::subpath, T_LockRows, and Path::total_cost.

Referenced by grouping_planner().

3566 {
3567  LockRowsPath *pathnode = makeNode(LockRowsPath);
3568 
3569  pathnode->path.pathtype = T_LockRows;
3570  pathnode->path.parent = rel;
3571  /* LockRows doesn't project, so use source path's pathtarget */
3572  pathnode->path.pathtarget = subpath->pathtarget;
3573  /* For now, assume we are above any joins, so no parameterization */
3574  pathnode->path.param_info = NULL;
3575  pathnode->path.parallel_aware = false;
3576  pathnode->path.parallel_safe = false;
3577  pathnode->path.parallel_workers = 0;
3578  pathnode->path.rows = subpath->rows;
3579 
3580  /*
3581  * The result cannot be assumed sorted, since locking might cause the sort
3582  * key columns to be replaced with new values.
3583  */
3584  pathnode->path.pathkeys = NIL;
3585 
3586  pathnode->subpath = subpath;
3587  pathnode->rowMarks = rowMarks;
3588  pathnode->epqParam = epqParam;
3589 
3590  /*
3591  * We should charge something extra for the costs of row locking and
3592  * possible refetches, but it's hard to say how much. For now, use
3593  * cpu_tuple_cost per row.
3594  */
3595  pathnode->path.startup_cost = subpath->startup_cost;
3596  pathnode->path.total_cost = subpath->total_cost +
3597  cpu_tuple_cost * subpath->rows;
3598 
3599  return pathnode;
3600 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * rowMarks
Definition: pathnodes.h:1859
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * subpath
Definition: pathnodes.h:1858
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
double cpu_tuple_cost
Definition: costsize.c:121
bool parallel_aware
Definition: pathnodes.h:1179
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

Definition at line 1552 of file pathnode.c.

References Assert, RelOptInfo::consider_parallel, cost_material(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, MaterialPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), MaterialPath::subpath, T_Material, Path::total_cost, and PathTarget::width.

Referenced by match_unsorted_outer(), and set_tablesample_rel_pathlist().

1553 {
1554  MaterialPath *pathnode = makeNode(MaterialPath);
1555 
1556  Assert(subpath->parent == rel);
1557 
1558  pathnode->path.pathtype = T_Material;
1559  pathnode->path.parent = rel;
1560  pathnode->path.pathtarget = rel->reltarget;
1561  pathnode->path.param_info = subpath->param_info;
1562  pathnode->path.parallel_aware = false;
1563  pathnode->path.parallel_safe = rel->consider_parallel &&
1564  subpath->parallel_safe;
1565  pathnode->path.parallel_workers = subpath->parallel_workers;
1566  pathnode->path.pathkeys = subpath->pathkeys;
1567 
1568  pathnode->subpath = subpath;
1569 
1570  cost_material(&pathnode->path,
1571  subpath->startup_cost,
1572  subpath->total_cost,
1573  subpath->rows,
1574  subpath->pathtarget->width);
1575 
1576  return pathnode;
1577 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
Path * subpath
Definition: pathnodes.h:1494
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
Cost total_cost
Definition: pathnodes.h:1186
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2365
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_memoize_path()

MemoizePath* create_memoize_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List param_exprs,
List hash_operators,
bool  singlerow,
double  calls 
)

Definition at line 1584 of file pathnode.c.

References Assert, MemoizePath::calls, RelOptInfo::consider_parallel, cpu_tuple_cost, MemoizePath::est_entries, MemoizePath::hash_operators, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, MemoizePath::param_exprs, Path::param_info, Path::parent, MemoizePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, MemoizePath::singlerow, Path::startup_cost, subpath(), MemoizePath::subpath, T_Memoize, and Path::total_cost.

Referenced by get_memoize_path(), and reparameterize_path().

1587 {
1588  MemoizePath *pathnode = makeNode(MemoizePath);
1589 
1590  Assert(subpath->parent == rel);
1591 
1592  pathnode->path.pathtype = T_Memoize;
1593  pathnode->path.parent = rel;
1594  pathnode->path.pathtarget = rel->reltarget;
1595  pathnode->path.param_info = subpath->param_info;
1596  pathnode->path.parallel_aware = false;
1597  pathnode->path.parallel_safe = rel->consider_parallel &&
1598  subpath->parallel_safe;
1599  pathnode->path.parallel_workers = subpath->parallel_workers;
1600  pathnode->path.pathkeys = subpath->pathkeys;
1601 
1602  pathnode->subpath = subpath;
1603  pathnode->hash_operators = hash_operators;
1604  pathnode->param_exprs = param_exprs;
1605  pathnode->singlerow = singlerow;
1606  pathnode->calls = calls;
1607 
1608  /*
1609  * For now we set est_entries to 0. cost_memoize_rescan() does all the
1610  * hard work to determine how many cache entries there are likely to be,
1611  * so it seems best to leave it up to that function to fill this field in.
1612  * If left at 0, the executor will make a guess at a good value.
1613  */
1614  pathnode->est_entries = 0;
1615 
1616  /*
1617  * Add a small additional charge for caching the first entry. All the
1618  * harder calculations for rescans are performed in cost_memoize_rescan().
1619  */
1620  pathnode->path.startup_cost = subpath->startup_cost + cpu_tuple_cost;
1621  pathnode->path.total_cost = subpath->total_cost + cpu_tuple_cost;
1622  pathnode->path.rows = subpath->rows;
1623 
1624  return pathnode;
1625 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
uint32 est_entries
Definition: pathnodes.h:1511
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
bool singlerow
Definition: pathnodes.h:1508
double calls
Definition: pathnodes.h:1510
Path * subpath
Definition: pathnodes.h:1505
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
List * hash_operators
Definition: pathnodes.h:1506
List * param_exprs
Definition: pathnodes.h:1507
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
double cpu_tuple_cost
Definition: costsize.c:121
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_merge_append_path()

MergeAppendPath* create_merge_append_path ( PlannerInfo root,
RelOptInfo rel,
List subpaths,
List pathkeys,
Relids  required_outer 
)

Definition at line 1404 of file pathnode.c.

References PlannerInfo::all_baserels, Assert, bms_equal(), RelOptInfo::consider_parallel, cost_merge_append(), cost_sort(), get_appendrel_parampathinfo(), lfirst, PlannerInfo::limit_tuples, MergeAppendPath::limit_tuples, list_length(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, MergeAppendPath::path, PATH_REQ_OUTER, Path::pathkeys, pathkeys_contained_in(), Path::pathtarget, Path::pathtype, RelOptInfo::relids, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), MergeAppendPath::subpaths, T_MergeAppend, Path::total_cost, RelOptInfo::tuples, PathTarget::width, and work_mem.

Referenced by generate_orderedappend_paths().

1409 {
1411  Cost input_startup_cost;
1412  Cost input_total_cost;
1413  ListCell *l;
1414 
1415  pathnode->path.pathtype = T_MergeAppend;
1416  pathnode->path.parent = rel;
1417  pathnode->path.pathtarget = rel->reltarget;
1419  required_outer);
1420  pathnode->path.parallel_aware = false;
1421  pathnode->path.parallel_safe = rel->consider_parallel;
1422  pathnode->path.parallel_workers = 0;
1423  pathnode->path.pathkeys = pathkeys;
1424  pathnode->subpaths = subpaths;
1425 
1426  /*
1427  * Apply query-wide LIMIT if known and path is for sole base relation.
1428  * (Handling this at this low level is a bit klugy.)
1429  */
1430  if (bms_equal(rel->relids, root->all_baserels))
1431  pathnode->limit_tuples = root->limit_tuples;
1432  else
1433  pathnode->limit_tuples = -1.0;
1434 
1435  /*
1436  * Add up the sizes and costs of the input paths.
1437  */
1438  pathnode->path.rows = 0;
1439  input_startup_cost = 0;
1440  input_total_cost = 0;
1441  foreach(l, subpaths)
1442  {
1443  Path *subpath = (Path *) lfirst(l);
1444 
1445  pathnode->path.rows += subpath->rows;
1446  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1447  subpath->parallel_safe;
1448 
1449  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1450  {
1451  /* Subpath is adequately ordered, we won't need to sort it */
1452  input_startup_cost += subpath->startup_cost;
1453  input_total_cost += subpath->total_cost;
1454  }
1455  else
1456  {
1457  /* We'll need to insert a Sort node, so include cost for that */
1458  Path sort_path; /* dummy for result of cost_sort */
1459 
1460  cost_sort(&sort_path,
1461  root,
1462  pathkeys,
1463  subpath->total_cost,
1464  subpath->parent->tuples,
1465  subpath->pathtarget->width,
1466  0.0,
1467  work_mem,
1468  pathnode->limit_tuples);
1469  input_startup_cost += sort_path.startup_cost;
1470  input_total_cost += sort_path.total_cost;
1471  }
1472 
1473  /* All child paths must have same parameterization */
1474  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1475  }
1476 
1477  /*
1478  * Now we can compute total costs of the MergeAppend. If there's exactly
1479  * one child path, the MergeAppend is a no-op and will be discarded later
1480  * (in setrefs.c); otherwise we do the normal cost calculation.
1481  */
1482  if (list_length(subpaths) == 1)
1483  {
1484  pathnode->path.startup_cost = input_startup_cost;
1485  pathnode->path.total_cost = input_total_cost;
1486  }
1487  else
1488  cost_merge_append(&pathnode->path, root,
1489  pathkeys, list_length(subpaths),
1490  input_startup_cost, input_total_cost,
1491  pathnode->path.rows);
1492 
1493  return pathnode;
1494 }
PathTarget * pathtarget
Definition: pathnodes.h:1175
double tuples
Definition: pathnodes.h:716
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Relids all_baserels
Definition: pathnodes.h:209
double limit_tuples
Definition: pathnodes.h:340
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
Relids relids
Definition: pathnodes.h:676
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:2036
int work_mem
Definition: globals.c:124
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
void cost_merge_append(Path *path, PlannerInfo *root, List *pathkeys, int n_streams, Cost input_startup_cost, Cost input_total_cost, double tuples)
Definition: costsize.c:2316
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1591
struct PathTarget * reltarget
Definition: pathnodes.h:687
double limit_tuples
Definition: pathnodes.h:1469
double Cost
Definition: nodes.h:673
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ create_mergejoin_path()

MergePath* create_mergejoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer,
List mergeclauses,
List outersortkeys,
List innersortkeys 
)

Definition at line 2494 of file pathnode.c.

References RelOptInfo::consider_parallel, final_cost_mergejoin(), get_joinrel_parampathinfo(), JoinPath::inner_unique, JoinPathExtraData::inner_unique, JoinPath::innerjoinpath, MergePath::innersortkeys, JoinPath::joinrestrictinfo, JoinPath::jointype, MergePath::jpath, makeNode, JoinPath::outerjoinpath, MergePath::outersortkeys, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, JoinPath::path, MergePath::path_mergeclauses, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, JoinPathExtraData::sjinfo, and T_MergeJoin.

Referenced by try_mergejoin_path(), and try_partial_mergejoin_path().

2507 {
2508  MergePath *pathnode = makeNode(MergePath);
2509 
2510  pathnode->jpath.path.pathtype = T_MergeJoin;
2511  pathnode->jpath.path.parent = joinrel;
2512  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2513  pathnode->jpath.path.param_info =
2515  joinrel,
2516  outer_path,
2517  inner_path,
2518  extra->sjinfo,
2519  required_outer,
2520  &restrict_clauses);
2521  pathnode->jpath.path.parallel_aware = false;
2522  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2523  outer_path->parallel_safe && inner_path->parallel_safe;
2524  /* This is a foolish way to estimate parallel_workers, but for now... */
2525  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2526  pathnode->jpath.path.pathkeys = pathkeys;
2527  pathnode->jpath.jointype = jointype;
2528  pathnode->jpath.inner_unique = extra->inner_unique;
2529  pathnode->jpath.outerjoinpath = outer_path;
2530  pathnode->jpath.innerjoinpath = inner_path;
2531  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2532  pathnode->path_mergeclauses = mergeclauses;
2533  pathnode->outersortkeys = outersortkeys;
2534  pathnode->innersortkeys = innersortkeys;
2535  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2536  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2537 
2538  final_cost_mergejoin(root, pathnode, workspace, extra);
2539 
2540  return pathnode;
2541 }
List * path_mergeclauses
Definition: pathnodes.h:1638
List * outersortkeys
Definition: pathnodes.h:1639
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1384
Path * innerjoinpath
Definition: pathnodes.h:1583
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2521
List * joinrestrictinfo
Definition: pathnodes.h:1585
RelOptInfo * parent
Definition: pathnodes.h:1174
Path * outerjoinpath
Definition: pathnodes.h:1582
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
Path path
Definition: pathnodes.h:1575
bool parallel_safe
Definition: pathnodes.h:1180
bool inner_unique
Definition: pathnodes.h:1579
bool consider_parallel
Definition: pathnodes.h:684
List * innersortkeys
Definition: pathnodes.h:1640
JoinType jointype
Definition: pathnodes.h:1577
JoinPath jpath
Definition: pathnodes.h:1637
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3413

◆ create_minmaxagg_path()

MinMaxAggPath* create_minmaxagg_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List mmaggregates,
List quals 
)

Definition at line 3324 of file pathnode.c.

References PathTarget::cost, cost_qual_eval(), cpu_tuple_cost, lfirst, makeNode, MinMaxAggPath::mmaggregates, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, MinMaxAggPath::path, MinMaxAggInfo::pathcost, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, MinMaxAggPath::quals, Path::rows, QualCost::startup, Path::startup_cost, T_Result, and Path::total_cost.

Referenced by preprocess_minmax_aggregates().

3329 {
3330  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3331  Cost initplan_cost;
3332  ListCell *lc;
3333 
3334  /* The topmost generated Plan node will be a Result */
3335  pathnode->path.pathtype = T_Result;
3336  pathnode->path.parent = rel;
3337  pathnode->path.pathtarget = target;
3338  /* For now, assume we are above any joins, so no parameterization */
3339  pathnode->path.param_info = NULL;
3340  pathnode->path.parallel_aware = false;
3341  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3342  pathnode->path.parallel_safe = false;
3343  pathnode->path.parallel_workers = 0;
3344  /* Result is one unordered row */
3345  pathnode->path.rows = 1;
3346  pathnode->path.pathkeys = NIL;
3347 
3348  pathnode->mmaggregates = mmaggregates;
3349  pathnode->quals = quals;
3350 
3351  /* Calculate cost of all the initplans ... */
3352  initplan_cost = 0;
3353  foreach(lc, mmaggregates)
3354  {
3355  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3356 
3357  initplan_cost += mminfo->pathcost;
3358  }
3359 
3360  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3361  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3362  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3363  target->cost.per_tuple + cpu_tuple_cost;
3364 
3365  /*
3366  * Add cost of qual, if any --- but we ignore its selectivity, since our
3367  * rowcount estimate should be 1 no matter what the qual is.
3368  */
3369  if (quals)
3370  {
3371  QualCost qual_cost;
3372 
3373  cost_qual_eval(&qual_cost, quals, root);
3374  pathnode->path.startup_cost += qual_cost.startup;
3375  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3376  }
3377 
3378  return pathnode;
3379 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
List * quals
Definition: pathnodes.h:1811
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4308
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
List * mmaggregates
Definition: pathnodes.h:1810
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
double cpu_tuple_cost
Definition: costsize.c:121
bool parallel_aware
Definition: pathnodes.h:1179
double Cost
Definition: nodes.h:673

◆ create_modifytable_path()

ModifyTablePath* create_modifytable_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
CmdType  operation,
bool  canSetTag,
Index  nominalRelation,
Index  rootRelation,
bool  partColsUpdated,
List resultRelations,
List updateColnosLists,
List withCheckOptionLists,
List returningLists,
List rowMarks,
OnConflictExpr onconflict,
int  epqParam 
)

Definition at line 3624 of file pathnode.c.

References Assert, ModifyTablePath::canSetTag, CMD_UPDATE, ModifyTablePath::epqParam, list_length(), makeNode, NIL, ModifyTablePath::nominalRelation, ModifyTablePath::onconflict, ModifyTablePath::operation, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ModifyTablePath::partColsUpdated, ModifyTablePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, ModifyTablePath::resultRelations, ModifyTablePath::returningLists, ModifyTablePath::rootRelation, ModifyTablePath::rowMarks, Path::rows, Path::startup_cost, subpath(), ModifyTablePath::subpath, T_ModifyTable, Path::total_cost, ModifyTablePath::updateColnosLists, PathTarget::width, and ModifyTablePath::withCheckOptionLists.

Referenced by grouping_planner().

3634 {
3636 
3637  Assert(operation == CMD_UPDATE ?
3638  list_length(resultRelations) == list_length(updateColnosLists) :
3639  updateColnosLists == NIL);
3640  Assert(withCheckOptionLists == NIL ||
3641  list_length(resultRelations) == list_length(withCheckOptionLists));
3642  Assert(returningLists == NIL ||
3643  list_length(resultRelations) == list_length(returningLists));
3644 
3645  pathnode->path.pathtype = T_ModifyTable;
3646  pathnode->path.parent = rel;
3647  /* pathtarget is not interesting, just make it minimally valid */
3648  pathnode->path.pathtarget = rel->reltarget;
3649  /* For now, assume we are above any joins, so no parameterization */
3650  pathnode->path.param_info = NULL;
3651  pathnode->path.parallel_aware = false;
3652  pathnode->path.parallel_safe = false;
3653  pathnode->path.parallel_workers = 0;
3654  pathnode->path.pathkeys = NIL;
3655 
3656  /*
3657  * Compute cost & rowcount as subpath cost & rowcount (if RETURNING)
3658  *
3659  * Currently, we don't charge anything extra for the actual table
3660  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3661  * expressions if any. It would only be window dressing, since
3662  * ModifyTable is always a top-level node and there is no way for the
3663  * costs to change any higher-level planning choices. But we might want
3664  * to make it look better sometime.
3665  */
3666  pathnode->path.startup_cost = subpath->startup_cost;
3667  pathnode->path.total_cost = subpath->total_cost;
3668  if (returningLists != NIL)
3669  {
3670  pathnode->path.rows = subpath->rows;
3671 
3672  /*
3673  * Set width to match the subpath output. XXX this is totally wrong:
3674  * we should return an average of the RETURNING tlist widths. But
3675  * it's what happened historically, and improving it is a task for
3676  * another day. (Again, it's mostly window dressing.)
3677  */
3678  pathnode->path.pathtarget->width = subpath->pathtarget->width;
3679  }
3680  else
3681  {
3682  pathnode->path.rows = 0;
3683  pathnode->path.pathtarget->width = 0;
3684  }
3685 
3686  pathnode->subpath = subpath;
3687  pathnode->operation = operation;
3688  pathnode->canSetTag = canSetTag;
3689  pathnode->nominalRelation = nominalRelation;
3690  pathnode->rootRelation = rootRelation;
3691  pathnode->partColsUpdated = partColsUpdated;
3692  pathnode->resultRelations = resultRelations;
3693  pathnode->updateColnosLists = updateColnosLists;
3694  pathnode->withCheckOptionLists = withCheckOptionLists;
3695  pathnode->returningLists = returningLists;
3696  pathnode->rowMarks = rowMarks;
3697  pathnode->onconflict = onconflict;
3698  pathnode->epqParam = epqParam;
3699 
3700  return pathnode;
3701 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
List * returningLists
Definition: pathnodes.h:1882
OnConflictExpr * onconflict
Definition: pathnodes.h:1884
Index nominalRelation
Definition: pathnodes.h:1876
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Cost startup_cost
Definition: pathnodes.h:1185
bool partColsUpdated
Definition: pathnodes.h:1878
RelOptInfo * parent
Definition: pathnodes.h:1174
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
Index rootRelation
Definition: pathnodes.h:1877
static int list_length(const List *l)
Definition: pg_list.h:149
List * withCheckOptionLists
Definition: pathnodes.h:1881
CmdType operation
Definition: pathnodes.h:1874
List * resultRelations
Definition: pathnodes.h:1879
List * updateColnosLists
Definition: pathnodes.h:1880
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_namedtuplestorescan_path()

Path* create_namedtuplestorescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 2121 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_namedtuplestorescan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_NamedTuplestoreScan.

Referenced by set_namedtuplestore_pathlist().

2123 {
2124  Path *pathnode = makeNode(Path);
2125 
2126  pathnode->pathtype = T_NamedTuplestoreScan;
2127  pathnode->parent = rel;
2128  pathnode->pathtarget = rel->reltarget;
2129  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2130  required_outer);
2131  pathnode->parallel_aware = false;
2132  pathnode->parallel_safe = rel->consider_parallel;
2133  pathnode->parallel_workers = 0;
2134  pathnode->pathkeys = NIL; /* result is always unordered */
2135 
2136  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2137 
2138  return pathnode;
2139 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1649
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_nestloop_path()

NestPath* create_nestloop_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer 
)

Definition at line 2406 of file pathnode.c.

References bms_overlap(), bms_union(), RelOptInfo::consider_parallel, final_cost_nestloop(), get_joinrel_parampathinfo(), JoinPath::inner_unique, JoinPathExtraData::inner_unique, JoinPath::innerjoinpath, join_clause_is_movable_into(), JoinPath::joinrestrictinfo, JoinPath::jointype, lappend(), lfirst, makeNode, NIL, JoinPath::outerjoinpath, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, JoinPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::relids, RelOptInfo::reltarget, JoinPathExtraData::sjinfo, and T_NestLoop.

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

2416 {
2417  NestPath *pathnode = makeNode(NestPath);
2418  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2419 
2420  /*
2421  * If the inner path is parameterized by the outer, we must drop any
2422  * restrict_clauses that are due to be moved into the inner path. We have
2423  * to do this now, rather than postpone the work till createplan time,
2424  * because the restrict_clauses list can affect the size and cost
2425  * estimates for this path.
2426  */
2427  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2428  {
2429  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2430  inner_req_outer);
2431  List *jclauses = NIL;
2432  ListCell *lc;
2433 
2434  foreach(lc, restrict_clauses)
2435  {
2436  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2437 
2438  if (!join_clause_is_movable_into(rinfo,
2439  inner_path->parent->relids,
2440  inner_and_outer))
2441  jclauses = lappend(jclauses, rinfo);
2442  }
2443  restrict_clauses = jclauses;
2444  }
2445 
2446  pathnode->path.pathtype = T_NestLoop;
2447  pathnode->path.parent = joinrel;
2448  pathnode->path.pathtarget = joinrel->reltarget;
2449  pathnode->path.param_info =
2451  joinrel,
2452  outer_path,
2453  inner_path,
2454  extra->sjinfo,
2455  required_outer,
2456  &restrict_clauses);
2457  pathnode->path.parallel_aware = false;
2458  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2459  outer_path->parallel_safe && inner_path->parallel_safe;
2460  /* This is a foolish way to estimate parallel_workers, but for now... */
2461  pathnode->path.parallel_workers = outer_path->parallel_workers;
2462  pathnode->path.pathkeys = pathkeys;
2463  pathnode->jointype = jointype;
2464  pathnode->inner_unique = extra->inner_unique;
2465  pathnode->outerjoinpath = outer_path;
2466  pathnode->innerjoinpath = inner_path;
2467  pathnode->joinrestrictinfo = restrict_clauses;
2468 
2469  final_cost_nestloop(root, pathnode, workspace, extra);
2470 
2471  return pathnode;
2472 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1384
Path * innerjoinpath
Definition: pathnodes.h:1583
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2977
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2521
List * joinrestrictinfo
Definition: pathnodes.h:1585
RelOptInfo * parent
Definition: pathnodes.h:1174
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1193
Relids relids
Definition: pathnodes.h:676
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:598
List * lappend(List *list, void *datum)
Definition: list.c:336
Path * outerjoinpath
Definition: pathnodes.h:1582
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
Path path
Definition: pathnodes.h:1575
#define lfirst(lc)
Definition: pg_list.h:169
bool parallel_safe
Definition: pathnodes.h:1180
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool inner_unique
Definition: pathnodes.h:1579
bool consider_parallel
Definition: pathnodes.h:684
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
JoinType jointype
Definition: pathnodes.h:1577
bool parallel_aware
Definition: pathnodes.h:1179
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_projection_path()

ProjectionPath* create_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

Definition at line 2626 of file pathnode.c.

References Assert, RelOptInfo::consider_parallel, PathTarget::cost, cpu_tuple_cost, ProjectionPath::dummypp, equal(), PathTarget::exprs, is_parallel_safe(), is_projection_capable_path(), IsA, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ProjectionPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectionPath::subpath, T_Result, and Path::total_cost.

Referenced by adjust_paths_for_srfs(), apply_projection_to_path(), apply_scanjoin_target_to_paths(), and recurse_set_operations().

2630 {
2631  ProjectionPath *pathnode = makeNode(ProjectionPath);
2632  PathTarget *oldtarget;
2633 
2634  /*
2635  * We mustn't put a ProjectionPath directly above another; it's useless
2636  * and will confuse create_projection_plan. Rather than making sure all
2637  * callers handle that, let's implement it here, by stripping off any
2638  * ProjectionPath in what we're given. Given this rule, there won't be
2639  * more than one.
2640  */
2641  if (IsA(subpath, ProjectionPath))
2642  {
2643  ProjectionPath *subpp = (ProjectionPath *) subpath;
2644 
2645  Assert(subpp->path.parent == rel);
2646  subpath = subpp->subpath;
2647  Assert(!IsA(subpath, ProjectionPath));
2648  }
2649 
2650  pathnode->path.pathtype = T_Result;
2651  pathnode->path.parent = rel;
2652  pathnode->path.pathtarget = target;
2653  /* For now, assume we are above any joins, so no parameterization */
2654  pathnode->path.param_info = NULL;
2655  pathnode->path.parallel_aware = false;
2656  pathnode->path.parallel_safe = rel->consider_parallel &&
2657  subpath->parallel_safe &&
2658  is_parallel_safe(root, (Node *) target->exprs);
2659  pathnode->path.parallel_workers = subpath->parallel_workers;
2660  /* Projection does not change the sort order */
2661  pathnode->path.pathkeys = subpath->pathkeys;
2662 
2663  pathnode->subpath = subpath;
2664 
2665  /*
2666  * We might not need a separate Result node. If the input plan node type
2667  * can project, we can just tell it to project something else. Or, if it
2668  * can't project but the desired target has the same expression list as
2669  * what the input will produce anyway, we can still give it the desired
2670  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2671  * Note: in the latter case, create_projection_plan has to recheck our
2672  * conclusion; see comments therein.
2673  */
2674  oldtarget = subpath->pathtarget;
2675  if (is_projection_capable_path(subpath) ||
2676  equal(oldtarget->exprs, target->exprs))
2677  {
2678  /* No separate Result node needed */
2679  pathnode->dummypp = true;
2680 
2681  /*
2682  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2683  */
2684  pathnode->path.rows = subpath->rows;
2685  pathnode->path.startup_cost = subpath->startup_cost +
2686  (target->cost.startup - oldtarget->cost.startup);
2687  pathnode->path.total_cost = subpath->total_cost +
2688  (target->cost.startup - oldtarget->cost.startup) +
2689  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2690  }
2691  else
2692  {
2693  /* We really do need the Result node */
2694  pathnode->dummypp = false;
2695 
2696  /*
2697  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2698  * evaluating the tlist. There is no qual to worry about.
2699  */
2700  pathnode->path.rows = subpath->rows;
2701  pathnode->path.startup_cost = subpath->startup_cost +
2702  target->cost.startup;
2703  pathnode->path.total_cost = subpath->total_cost +
2704  target->cost.startup +
2705  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2706  }
2707 
2708  return pathnode;
2709 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:590
PathTarget * pathtarget
Definition: pathnodes.h:1175
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3122
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
Definition: nodes.h:539
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:638
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
List * exprs
Definition: pathnodes.h:1102
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
bool consider_parallel
Definition: pathnodes.h:684
double cpu_tuple_cost
Definition: costsize.c:121
bool is_projection_capable_path(Path *path)
Definition: createplan.c:7028
bool parallel_aware
Definition: pathnodes.h:1179
Path * subpath
Definition: pathnodes.h:1679
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_recursiveunion_path()

RecursiveUnionPath* create_recursiveunion_path ( PlannerInfo root,
RelOptInfo rel,
Path leftpath,
Path rightpath,
PathTarget target,
List distinctList,
int  wtParam,
double  numGroups 
)

Definition at line 3519 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_recursive_union(), RecursiveUnionPath::distinctList, RecursiveUnionPath::leftpath, makeNode, NIL, RecursiveUnionPath::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, RecursiveUnionPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RecursiveUnionPath::rightpath, T_RecursiveUnion, and RecursiveUnionPath::wtParam.

Referenced by generate_recursion_path().

3527 {
3529 
3530  pathnode->path.pathtype = T_RecursiveUnion;
3531  pathnode->path.parent = rel;
3532  pathnode->path.pathtarget = target;
3533  /* For now, assume we are above any joins, so no parameterization */
3534  pathnode->path.param_info = NULL;
3535  pathnode->path.parallel_aware = false;
3536  pathnode->path.parallel_safe = rel->consider_parallel &&
3537  leftpath->parallel_safe && rightpath->parallel_safe;
3538  /* Foolish, but we'll do it like joins for now: */
3539  pathnode->path.parallel_workers = leftpath->parallel_workers;
3540  /* RecursiveUnion result is always unsorted */
3541  pathnode->path.pathkeys = NIL;
3542 
3543  pathnode->leftpath = leftpath;
3544  pathnode->rightpath = rightpath;
3545  pathnode->distinctList = distinctList;
3546  pathnode->wtParam = wtParam;
3547  pathnode->numGroups = numGroups;
3548 
3549  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3550 
3551  return pathnode;
3552 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1723
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179

◆ create_resultscan_path()

Path* create_resultscan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 2147 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_resultscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_Result.

Referenced by reparameterize_path(), and set_result_pathlist().

2149 {
2150  Path *pathnode = makeNode(Path);
2151 
2152  pathnode->pathtype = T_Result;
2153  pathnode->parent = rel;
2154  pathnode->pathtarget = rel->reltarget;
2155  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2156  required_outer);
2157  pathnode->parallel_aware = false;
2158  pathnode->parallel_safe = rel->consider_parallel;
2159  pathnode->parallel_workers = 0;
2160  pathnode->pathkeys = NIL; /* result is always unordered */
2161 
2162  cost_resultscan(pathnode, root, rel, pathnode->param_info);
2163 
2164  return pathnode;
2165 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
Definition: nodes.h:46
RelOptInfo * parent
Definition: pathnodes.h:1174
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1686
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_samplescan_path()

Path* create_samplescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 954 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_samplescan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_SampleScan.

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

955 {
956  Path *pathnode = makeNode(Path);
957 
958  pathnode->pathtype = T_SampleScan;
959  pathnode->parent = rel;
960  pathnode->pathtarget = rel->reltarget;
961  pathnode->param_info = get_baserel_parampathinfo(root, rel,
962  required_outer);
963  pathnode->parallel_aware = false;
964  pathnode->parallel_safe = rel->consider_parallel;
965  pathnode->parallel_workers = 0;
966  pathnode->pathkeys = NIL; /* samplescan has unordered result */
967 
968  cost_samplescan(pathnode, root, rel, pathnode->param_info);
969 
970  return pathnode;
971 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
RelOptInfo * parent
Definition: pathnodes.h:1174
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:303
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_seqscan_path()

Path* create_seqscan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer,
int  parallel_workers 
)

Definition at line 929 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_seqscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, T_SeqScan, and true.

Referenced by create_plain_partial_paths(), plan_cluster_use_sort(), reparameterize_path(), and set_plain_rel_pathlist().

931 {
932  Path *pathnode = makeNode(Path);
933 
934  pathnode->pathtype = T_SeqScan;
935  pathnode->parent = rel;
936  pathnode->pathtarget = rel->reltarget;
937  pathnode->param_info = get_baserel_parampathinfo(root, rel,
938  required_outer);
939  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
940  pathnode->parallel_safe = rel->consider_parallel;
941  pathnode->parallel_workers = parallel_workers;
942  pathnode->pathkeys = NIL; /* seqscan has unordered result */
943 
944  cost_seqscan(pathnode, root, rel, pathnode->param_info);
945 
946  return pathnode;
947 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1175
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1294
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
NodeTag pathtype
Definition: pathnodes.h:1172
#define true
Definition: c.h:395
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:226
RelOptInfo * parent
Definition: pathnodes.h:1174
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
bool parallel_safe
Definition: pathnodes.h:1180
bool consider_parallel
Definition: pathnodes.h:684
bool parallel_aware
Definition: pathnodes.h:1179
struct PathTarget * reltarget
Definition: pathnodes.h:687

◆ create_set_projection_path()

ProjectSetPath* create_set_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

Definition at line 2823 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cpu_tuple_cost, expression_returns_set_rows(), PathTarget::exprs, is_parallel_safe(), lfirst, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ProjectSetPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectSetPath::subpath, T_ProjectSet, and Path::total_cost.

Referenced by adjust_paths_for_srfs().

2827 {
2828  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2829  double tlist_rows;
2830  ListCell *lc;
2831 
2832  pathnode->path.pathtype = T_ProjectSet;
2833  pathnode->path.parent = rel;
2834  pathnode->path.pathtarget = target;
2835  /* For now, assume we are above any joins, so no parameterization */
2836  pathnode->path.param_info = NULL;
2837  pathnode->path.parallel_aware = false;
2838  pathnode->path.parallel_safe = rel->consider_parallel &&
2839  subpath->parallel_safe &&
2840  is_parallel_safe(root, (Node *) target->exprs);
2841  pathnode->path.parallel_workers = subpath->parallel_workers;
2842  /* Projection does not change the sort order XXX? */
2843  pathnode->path.pathkeys = subpath->pathkeys;
2844 
2845  pathnode->subpath = subpath;
2846 
2847  /*
2848  * Estimate number of rows produced by SRFs for each row of input; if
2849  * there's more than one in this node, use the maximum.
2850  */
2851  tlist_rows = 1;
2852  foreach(lc, target->exprs)
2853  {
2854  Node *node = (Node *) lfirst(lc);
2855  double itemrows;
2856 
2857  itemrows = expression_returns_set_rows(root, node);
2858  if (tlist_rows < itemrows)
2859  tlist_rows = itemrows;
2860  }
2861 
2862  /*
2863  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2864  * per input row, and half of cpu_tuple_cost for each added output row.
2865  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2866  * this estimate later.
2867  */
2868  pathnode->path.rows = subpath->rows * tlist_rows;
2869  pathnode->path.startup_cost = subpath->startup_cost +
2870  target->cost.startup;
2871  pathnode->path.total_cost = subpath->total_cost +
2872  target->cost.startup +
2873  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2874  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2875 
2876  return pathnode;
2877 }
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
Definition: clauses.c:286
PathTarget * pathtarget
Definition: pathnodes.h:1175
int parallel_workers
Definition: pathnodes.h:1181
ParamPathInfo * param_info
Definition: pathnodes.h:1177
Definition: nodes.h:539
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1172
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:638
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1185
RelOptInfo * parent
Definition: pathnodes.h:1174
List * exprs
Definition: pathnodes.h:1102
Cost total_cost
Definition: pathnodes.h:1186
List * pathkeys
Definition: pathnodes.h:1188
#define makeNode(_type_)
Definition: nodes.h:587
#define lfirst(lc)
Definition: pg_list.h:169
Path * subpath
Definition: pathnodes.h:1691
double rows
Definition: pathnodes.h:1184
bool parallel_safe
Definition: pathnodes.h:1180
QualCost cost
Definition: pathnodes.h:1104
bool consider_parallel
Definition: pathnodes.h:684
double cpu_tuple_cost
Definition: costsize.c:121
bool parallel_aware
Definition: pathnodes.h:1179
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_setop_path()

SetOpPath* create_setop_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
SetOpCmd  cmd,
SetOpStrategy  strategy,
List distinctList,
AttrNumber  flagColIdx,
int  firstFlag,
double  numGroups,
double  outputRows 
)

Definition at line 3457 of file pathnode.c.

References SetOpPath::cmd, RelOptInfo::consider_parallel, cpu_operator_cost, SetOpPath::distinctList, SetOpPath::firstFlag, SetOpPath::flagColIdx, list_length(), makeNode, NIL, SetOpPath::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SetOpPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, SETOP_SORTED, Path::startup_cost, SetOpPath::strategy, SetOpPath::subpath, T_SetOp, and Path::total_cost.

Referenced by generate_nonunion_paths().

3467 {
3468  SetOpPath *pathnode = makeNode(SetOpPath);
3469 
3470  pathnode->path.pathtype = T_SetOp;
3471  pathnode->path.parent = rel;
3472  /* SetOp doesn't project, so use source path's pathtarget */
3473  pathnode->path.pathtarget = subpath->pathtarget;
3474  /* For now, assume we are above any joins, so no parameterization */
3475  pathnode->path.param_info = NULL;
3476  pathnode->path.parallel_aware = false;
3477  pathnode->path.parallel_safe = rel->consider_parallel &&
3478  subpath->parallel_safe;
3479  pathnode->path.parallel_workers = subpath->parallel_workers;
3480  /* SetOp preserves the input sort order if in sort mode */
3481  pathnode->path.pathkeys =
3482  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3483 
3484  pathnode->subpath = subpath;
3485  pathnode->cmd = cmd;
3486  pathnode->strategy = strategy;
3487  pathnode->distinctList = distinctList;
3488  pathnode->flagColIdx = flagColIdx;
3489  pathnode->firstFlag = firstFlag;
3490  pathnode->numGroups = numGroups;
3491 
3492  /*
3493  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3494  * all columns get compared at most of the tuples.
3495  */
3496  pathnode->path.startup_cost = subpath->startup_cost;
3497  pathnode->path.total_cost = subpath->total_cost +
3498  cpu_operator_cost * subpath->rows * list_length(distinctList);
3499  pathnode->path.rows = outputRows;
3500 
3501  return pathnode;
3502 }
#define NIL
Definition: pg_list.h:65
List * distinctList
Definition: pathnodes.h:1833
PathTarget * pathtarget
Definition: pathnodes.h:1175
SetOpStrategy strategy
Definition: pathnodes.h:1832
Path * subpath
Definition: pathnodes.h:1830
int parallel_workers
Definition: pathnodes.h:1181