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)
 
AppendPathcreate_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
 
GroupResultPathcreate_group_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *havingqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
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)
 
SortPathcreate_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, CmdType operation, bool canSetTag, Index nominalRelation, Index rootRelation, bool partColsUpdated, List *resultRelations, List *subpaths, List *subroots, 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:529
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: appendinfo.c:502
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:577

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:3876

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:4144

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:681
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:400
void pfree(void *pointer)
Definition: mcxt.c:1057
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1150
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
bool consider_parallel
Definition: pathnodes.h:673
PathKeysComparison
Definition: paths.h:181
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define foreach_current_index(cell)
Definition: pg_list.h:381

◆ 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:681
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define lfirst(lc)
Definition: pg_list.h:190
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181

◆ 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(), inheritance_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:580
ParamPathInfo * param_info
Definition: pathnodes.h:1147
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:400
void pfree(void *pointer)
Definition: mcxt.c:1057
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
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:1156
List * pathkeys
Definition: pathnodes.h:1158
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
List * pathlist
Definition: pathnodes.h:679
Definition: pg_list.h:50
BMS_Comparison
Definition: bitmapset.h:57
#define foreach_current_index(cell)
Definition: pg_list.h:381

◆ 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:672
ParamPathInfo * param_info
Definition: pathnodes.h:1147
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
bool consider_startup
Definition: pathnodes.h:671
Cost startup_cost
Definition: pathnodes.h:1155
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define lfirst(lc)
Definition: pg_list.h:190
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
List * pathlist
Definition: pathnodes.h:679
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 3690 of file pathnode.c.

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

3695 {
3696  double input_rows = *rows;
3697  Cost input_startup_cost = *startup_cost;
3698  Cost input_total_cost = *total_cost;
3699 
3700  if (offset_est != 0)
3701  {
3702  double offset_rows;
3703 
3704  if (offset_est > 0)
3705  offset_rows = (double) offset_est;
3706  else
3707  offset_rows = clamp_row_est(input_rows * 0.10);
3708  if (offset_rows > *rows)
3709  offset_rows = *rows;
3710  if (input_rows > 0)
3711  *startup_cost +=
3712  (input_total_cost - input_startup_cost)
3713  * offset_rows / input_rows;
3714  *rows -= offset_rows;
3715  if (*rows < 1)
3716  *rows = 1;
3717  }
3718 
3719  if (count_est != 0)
3720  {
3721  double count_rows;
3722 
3723  if (count_est > 0)
3724  count_rows = (double) count_est;
3725  else
3726  count_rows = clamp_row_est(input_rows * 0.10);
3727  if (count_rows > *rows)
3728  count_rows = *rows;
3729  if (input_rows > 0)
3730  *total_cost = *startup_cost +
3731  (input_total_cost - input_startup_cost)
3732  * count_rows / input_rows;
3733  *rows = count_rows;
3734  if (*rows < 1)
3735  *rows = 1;
3736  }
3737 }
double clamp_row_est(double nrows)
Definition: costsize.c:189
double Cost
Definition: nodes.h:663

◆ append_startup_cost_compare()

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

Definition at line 1359 of file pathnode.c.

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

Referenced by create_append_path().

1360 {
1361  Path *path1 = (Path *) lfirst(a);
1362  Path *path2 = (Path *) lfirst(b);
1363  int cmp;
1364 
1365  cmp = compare_path_costs(path1, path2, STARTUP_COST);
1366  if (cmp != 0)
1367  return -cmp;
1368  return bms_compare(path1->parent->relids, path2->parent->relids);
1369 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:147
RelOptInfo * parent
Definition: pathnodes.h:1144
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: pathnodes.h:665
#define lfirst(lc)
Definition: pg_list.h:190
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ append_total_cost_compare()

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

Definition at line 1337 of file pathnode.c.

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

Referenced by create_append_path().

1338 {
1339  Path *path1 = (Path *) lfirst(a);
1340  Path *path2 = (Path *) lfirst(b);
1341  int cmp;
1342 
1343  cmp = compare_path_costs(path1, path2, TOTAL_COST);
1344  if (cmp != 0)
1345  return -cmp;
1346  return bms_compare(path1->parent->relids, path2->parent->relids);
1347 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:147
RelOptInfo * parent
Definition: pathnodes.h:1144
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: pathnodes.h:665
#define lfirst(lc)
Definition: pg_list.h:190
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:742

◆ apply_projection_to_path()

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

Definition at line 2644 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().

2648 {
2649  QualCost oldcost;
2650 
2651  /*
2652  * If given path can't project, we might need a Result node, so make a
2653  * separate ProjectionPath.
2654  */
2655  if (!is_projection_capable_path(path))
2656  return (Path *) create_projection_path(root, rel, path, target);
2657 
2658  /*
2659  * We can just jam the desired tlist into the existing path, being sure to
2660  * update its cost estimates appropriately.
2661  */
2662  oldcost = path->pathtarget->cost;
2663  path->pathtarget = target;
2664 
2665  path->startup_cost += target->cost.startup - oldcost.startup;
2666  path->total_cost += target->cost.startup - oldcost.startup +
2667  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2668 
2669  /*
2670  * If the path happens to be a Gather or GatherMerge path, we'd like to
2671  * arrange for the subpath to return the required target list so that
2672  * workers can help project. But if there is something that is not
2673  * parallel-safe in the target expressions, then we can't.
2674  */
2675  if ((IsA(path, GatherPath) || IsA(path, GatherMergePath)) &&
2676  is_parallel_safe(root, (Node *) target->exprs))
2677  {
2678  /*
2679  * We always use create_projection_path here, even if the subpath is
2680  * projection-capable, so as to avoid modifying the subpath in place.
2681  * It seems unlikely at present that there could be any other
2682  * references to the subpath, but better safe than sorry.
2683  *
2684  * Note that we don't change the parallel path's cost estimates; it
2685  * might be appropriate to do so, to reflect the fact that the bulk of
2686  * the target evaluation will happen in workers.
2687  */
2688  if (IsA(path, GatherPath))
2689  {
2690  GatherPath *gpath = (GatherPath *) path;
2691 
2692  gpath->subpath = (Path *)
2694  gpath->subpath->parent,
2695  gpath->subpath,
2696  target);
2697  }
2698  else
2699  {
2700  GatherMergePath *gmpath = (GatherMergePath *) path;
2701 
2702  gmpath->subpath = (Path *)
2704  gmpath->subpath->parent,
2705  gmpath->subpath,
2706  target);
2707  }
2708  }
2709  else if (path->parallel_safe &&
2710  !is_parallel_safe(root, (Node *) target->exprs))
2711  {
2712  /*
2713  * We're inserting a parallel-restricted target list into a path
2714  * currently marked parallel-safe, so we have to mark it as no longer
2715  * safe.
2716  */
2717  path->parallel_safe = false;
2718  }
2719 
2720  return path;
2721 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:580
PathTarget * pathtarget
Definition: pathnodes.h:1145
Definition: nodes.h:529
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2553
Cost startup
Definition: pathnodes.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:854
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * subpath
Definition: pathnodes.h:1495
List * exprs
Definition: pathnodes.h:1074
Cost total_cost
Definition: pathnodes.h:1156
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6925

◆ calc_nestloop_required_outer()

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

Definition at line 2267 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().

2271 {
2272  Relids required_outer;
2273 
2274  /* inner_path can require rels from outer path, but not vice versa */
2275  Assert(!bms_overlap(outer_paramrels, innerrelids));
2276  /* easy case if inner path is not parameterized */
2277  if (!inner_paramrels)
2278  return bms_copy(outer_paramrels);
2279  /* else, form the union ... */
2280  required_outer = bms_union(outer_paramrels, inner_paramrels);
2281  /* ... and remove any mention of now-satisfied outer rels */
2282  required_outer = bms_del_members(required_outer,
2283  outerrelids);
2284  /* maintain invariant that required_outer is exactly NULL if empty */
2285  if (bms_is_empty(required_outer))
2286  {
2287  bms_free(required_outer);
2288  required_outer = NULL;
2289  }
2290  return required_outer;
2291 }
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:745
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 2300 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().

2301 {
2302  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2303  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2304  Relids required_outer;
2305 
2306  /* neither path can require rels from the other */
2307  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2308  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2309  /* form the union ... */
2310  required_outer = bms_union(outer_paramrels, inner_paramrels);
2311  /* we do not need an explicit test for empty; bms_union gets it right */
2312  return required_outer;
2313 }
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
Relids relids
Definition: pathnodes.h:665
#define Assert(condition)
Definition: c.h:745
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:1155
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Cost total_cost
Definition: pathnodes.h:1156
double Cost
Definition: nodes.h:663

◆ 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:1155
Cost total_cost
Definition: pathnodes.h:1156

◆ 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:1155
Cost total_cost
Definition: pathnodes.h:1156
#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 3006 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().

3016 {
3017  AggPath *pathnode = makeNode(AggPath);
3018 
3019  pathnode->path.pathtype = T_Agg;
3020  pathnode->path.parent = rel;
3021  pathnode->path.pathtarget = target;
3022  /* For now, assume we are above any joins, so no parameterization */
3023  pathnode->path.param_info = NULL;
3024  pathnode->path.parallel_aware = false;
3025  pathnode->path.parallel_safe = rel->consider_parallel &&
3026  subpath->parallel_safe;
3027  pathnode->path.parallel_workers = subpath->parallel_workers;
3028  if (aggstrategy == AGG_SORTED)
3029  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
3030  else
3031  pathnode->path.pathkeys = NIL; /* output is unordered */
3032  pathnode->subpath = subpath;
3033 
3034  pathnode->aggstrategy = aggstrategy;
3035  pathnode->aggsplit = aggsplit;
3036  pathnode->numGroups = numGroups;
3037  pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
3038  pathnode->groupClause = groupClause;
3039  pathnode->qual = qual;
3040 
3041  cost_agg(&pathnode->path, root,
3042  aggstrategy, aggcosts,
3043  list_length(groupClause), numGroups,
3044  qual,
3045  subpath->startup_cost, subpath->total_cost,
3046  subpath->rows, subpath->pathtarget->width);
3047 
3048  /* add tlist eval cost for each output row */
3049  pathnode->path.startup_cost += target->cost.startup;
3050  pathnode->path.total_cost += target->cost.startup +
3051  target->cost.per_tuple * pathnode->path.rows;
3052 
3053  return pathnode;
3054 }
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:79
PathTarget * pathtarget
Definition: pathnodes.h:1145
AggStrategy aggstrategy
Definition: pathnodes.h:1700
List * qual
Definition: pathnodes.h:1705
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:2310
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
AggSplit aggsplit
Definition: pathnodes.h:1701
double numGroups
Definition: pathnodes.h:1702
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
List * groupClause
Definition: pathnodes.h:1704
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
uint64 transitionSpace
Definition: pathnodes.h:1703
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
Path * subpath
Definition: pathnodes.h:1699
Size transitionSpace
Definition: pathnodes.h:64
bool parallel_aware
Definition: pathnodes.h:1149
Path path
Definition: pathnodes.h:1698
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,
List partitioned_rels,
double  rows 
)

Definition at line 1215 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(), lfirst, PlannerInfo::limit_tuples, AppendPath::limit_tuples, linitial, list_concat(), list_copy(), list_length(), list_sort(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AppendPath::partitioned_rels, 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(), inheritance_planner(), mark_dummy_rel(), reparameterize_path(), and set_dummy_rel_pathlist().

1221 {
1222  AppendPath *pathnode = makeNode(AppendPath);
1223  ListCell *l;
1224 
1225  Assert(!parallel_aware || parallel_workers > 0);
1226 
1227  pathnode->path.pathtype = T_Append;
1228  pathnode->path.parent = rel;
1229  pathnode->path.pathtarget = rel->reltarget;
1230 
1231  /*
1232  * When generating an Append path for a partitioned table, there may be
1233  * parameters that are useful so we can eliminate certain partitions
1234  * during execution. Here we'll go all the way and fully populate the
1235  * parameter info data as we do for normal base relations. However, we
1236  * need only bother doing this for RELOPT_BASEREL rels, as
1237  * RELOPT_OTHER_MEMBER_REL's Append paths are merged into the base rel's
1238  * Append subpaths. It would do no harm to do this, we just avoid it to
1239  * save wasting effort.
1240  */
1241  if (partitioned_rels != NIL && root && rel->reloptkind == RELOPT_BASEREL)
1242  pathnode->path.param_info = get_baserel_parampathinfo(root,
1243  rel,
1244  required_outer);
1245  else
1247  required_outer);
1248 
1249  pathnode->path.parallel_aware = parallel_aware;
1250  pathnode->path.parallel_safe = rel->consider_parallel;
1251  pathnode->path.parallel_workers = parallel_workers;
1252  pathnode->path.pathkeys = pathkeys;
1253  pathnode->partitioned_rels = list_copy(partitioned_rels);
1254 
1255  /*
1256  * For parallel append, non-partial paths are sorted by descending total
1257  * costs. That way, the total time to finish all non-partial paths is
1258  * minimized. Also, the partial paths are sorted by descending startup
1259  * costs. There may be some paths that require to do startup work by a
1260  * single worker. In such case, it's better for workers to choose the
1261  * expensive ones first, whereas the leader should choose the cheapest
1262  * startup plan.
1263  */
1264  if (pathnode->path.parallel_aware)
1265  {
1266  /*
1267  * We mustn't fiddle with the order of subpaths when the Append has
1268  * pathkeys. The order they're listed in is critical to keeping the
1269  * pathkeys valid.
1270  */
1271  Assert(pathkeys == NIL);
1272 
1274  list_sort(partial_subpaths, append_startup_cost_compare);
1275  }
1276  pathnode->first_partial_path = list_length(subpaths);
1277  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1278 
1279  /*
1280  * Apply query-wide LIMIT if known and path is for sole base relation.
1281  * (Handling this at this low level is a bit klugy.)
1282  */
1283  if (root != NULL && bms_equal(rel->relids, root->all_baserels))
1284  pathnode->limit_tuples = root->limit_tuples;
1285  else
1286  pathnode->limit_tuples = -1.0;
1287 
1288  foreach(l, pathnode->subpaths)
1289  {
1290  Path *subpath = (Path *) lfirst(l);
1291 
1292  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1293  subpath->parallel_safe;
1294 
1295  /* All child paths must have same parameterization */
1296  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1297  }
1298 
1299  Assert(!parallel_aware || pathnode->path.parallel_safe);
1300 
1301  /*
1302  * If there's exactly one child path, the Append is a no-op and will be
1303  * discarded later (in setrefs.c); therefore, we can inherit the child's
1304  * size and cost, as well as its pathkeys if any (overriding whatever the
1305  * caller might've said). Otherwise, we must do the normal costsize
1306  * calculation.
1307  */
1308  if (list_length(pathnode->subpaths) == 1)
1309  {
1310  Path *child = (Path *) linitial(pathnode->subpaths);
1311 
1312  pathnode->path.rows = child->rows;
1313  pathnode->path.startup_cost = child->startup_cost;
1314  pathnode->path.total_cost = child->total_cost;
1315  pathnode->path.pathkeys = child->pathkeys;
1316  }
1317  else
1318  cost_append(pathnode);
1319 
1320  /* If the caller provided a row estimate, override the computed value. */
1321  if (rows >= 0)
1322  pathnode->path.rows = rows;
1323 
1324  return pathnode;
1325 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
RelOptKind reloptkind
Definition: pathnodes.h:662
double limit_tuples
Definition: pathnodes.h:1407
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * list_copy(const List *oldlist)
Definition: list.c:1403
List * list_concat(List *list1, const List *list2)
Definition: list.c:515
Definition: nodes.h:49
static int append_total_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1337
int first_partial_path
Definition: pathnodes.h:1406
NodeTag pathtype
Definition: pathnodes.h:1142
List * subpaths
Definition: pathnodes.h:1404
static int append_startup_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1359
#define linitial(l)
Definition: pg_list.h:195
Relids all_baserels
Definition: pathnodes.h:227
double limit_tuples
Definition: pathnodes.h:337
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
Relids relids
Definition: pathnodes.h:665
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
void cost_append(AppendPath *apath)
Definition: costsize.c:2034
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
List * partitioned_rels
Definition: pathnodes.h:1403
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1481
bool parallel_aware
Definition: pathnodes.h:1149
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1576
struct PathTarget * reltarget
Definition: pathnodes.h:676
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:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1086
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * bitmapquals
Definition: pathnodes.h:1292
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
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:1145
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:942
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
#define true
Definition: c.h:328
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * bitmapqual
Definition: pathnodes.h:1280
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * bitmapquals
Definition: pathnodes.h:1305
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1130
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
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 2023 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().

2024 {
2025  Path *pathnode = makeNode(Path);
2026 
2027  pathnode->pathtype = T_CteScan;
2028  pathnode->parent = rel;
2029  pathnode->pathtarget = rel->reltarget;
2030  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2031  required_outer);
2032  pathnode->parallel_aware = false;
2033  pathnode->parallel_safe = rel->consider_parallel;
2034  pathnode->parallel_workers = 0;
2035  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
2036 
2037  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2038 
2039  return pathnode;
2040 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1500
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 2177 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().

2184 {
2185  ForeignPath *pathnode = makeNode(ForeignPath);
2186 
2187  /*
2188  * We should use get_joinrel_parampathinfo to handle parameterized paths,
2189  * but the API of this function doesn't support it, and existing
2190  * extensions aren't yet trying to build such paths anyway. For the
2191  * moment just throw an error if someone tries it; eventually we should
2192  * revisit this.
2193  */
2194  if (!bms_is_empty(required_outer) || !bms_is_empty(rel->lateral_relids))
2195  elog(ERROR, "parameterized foreign joins are not supported yet");
2196 
2197  pathnode->path.pathtype = T_ForeignScan;
2198  pathnode->path.parent = rel;
2199  pathnode->path.pathtarget = target ? target : rel->reltarget;
2200  pathnode->path.param_info = NULL; /* XXX see above */
2201  pathnode->path.parallel_aware = false;
2202  pathnode->path.parallel_safe = rel->consider_parallel;
2203  pathnode->path.parallel_workers = 0;
2204  pathnode->path.rows = rows;
2205  pathnode->path.startup_cost = startup_cost;
2206  pathnode->path.total_cost = total_cost;
2207  pathnode->path.pathkeys = pathkeys;
2208 
2209  pathnode->fdw_outerpath = fdw_outerpath;
2210  pathnode->fdw_private = fdw_private;
2211 
2212  return pathnode;
2213 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
Path * fdw_outerpath
Definition: pathnodes.h:1349
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Relids lateral_relids
Definition: pathnodes.h:690
#define ERROR
Definition: elog.h:43
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
List * fdw_private
Definition: pathnodes.h:1350
#define elog(elevel,...)
Definition: elog.h:214
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 2227 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().

2233 {
2234  ForeignPath *pathnode = makeNode(ForeignPath);
2235 
2236  /*
2237  * Upper relations should never have any lateral references, since joining
2238  * is complete.
2239  */
2241 
2242  pathnode->path.pathtype = T_ForeignScan;
2243  pathnode->path.parent = rel;
2244  pathnode->path.pathtarget = target ? target : rel->reltarget;
2245  pathnode->path.param_info = NULL;
2246  pathnode->path.parallel_aware = false;
2247  pathnode->path.parallel_safe = rel->consider_parallel;
2248  pathnode->path.parallel_workers = 0;
2249  pathnode->path.rows = rows;
2250  pathnode->path.startup_cost = startup_cost;
2251  pathnode->path.total_cost = total_cost;
2252  pathnode->path.pathkeys = pathkeys;
2253 
2254  pathnode->fdw_outerpath = fdw_outerpath;
2255  pathnode->fdw_private = fdw_private;
2256 
2257  return pathnode;
2258 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
Path * fdw_outerpath
Definition: pathnodes.h:1349
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Relids lateral_relids
Definition: pathnodes.h:690
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
List * fdw_private
Definition: pathnodes.h:1350
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 2133 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().

2140 {
2141  ForeignPath *pathnode = makeNode(ForeignPath);
2142 
2143  /* Historically some FDWs were confused about when to use this */
2144  Assert(IS_SIMPLE_REL(rel));
2145 
2146  pathnode->path.pathtype = T_ForeignScan;
2147  pathnode->path.parent = rel;
2148  pathnode->path.pathtarget = target ? target : rel->reltarget;
2149  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2150  required_outer);
2151  pathnode->path.parallel_aware = false;
2152  pathnode->path.parallel_safe = rel->consider_parallel;
2153  pathnode->path.parallel_workers = 0;
2154  pathnode->path.rows = rows;
2155  pathnode->path.startup_cost = startup_cost;
2156  pathnode->path.total_cost = total_cost;
2157  pathnode->path.pathkeys = pathkeys;
2158 
2159  pathnode->fdw_outerpath = fdw_outerpath;
2160  pathnode->fdw_private = fdw_private;
2161 
2162  return pathnode;
2163 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
Path * fdw_outerpath
Definition: pathnodes.h:1349
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:638
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
List * fdw_private
Definition: pathnodes.h:1350
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ create_functionscan_path()

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

Definition at line 1945 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().

1947 {
1948  Path *pathnode = makeNode(Path);
1949 
1950  pathnode->pathtype = T_FunctionScan;
1951  pathnode->parent = rel;
1952  pathnode->pathtarget = rel->reltarget;
1953  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1954  required_outer);
1955  pathnode->parallel_aware = false;
1956  pathnode->parallel_safe = rel->consider_parallel;
1957  pathnode->parallel_workers = 0;
1958  pathnode->pathkeys = pathkeys;
1959 
1960  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1961 
1962  return pathnode;
1963 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1333
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 1787 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().

1790 {
1792  Cost input_startup_cost = 0;
1793  Cost input_total_cost = 0;
1794 
1795  Assert(subpath->parallel_safe);
1796  Assert(pathkeys);
1797 
1798  pathnode->path.pathtype = T_GatherMerge;
1799  pathnode->path.parent = rel;
1800  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1801  required_outer);
1802  pathnode->path.parallel_aware = false;
1803 
1804  pathnode->subpath = subpath;
1805  pathnode->num_workers = subpath->parallel_workers;
1806  pathnode->path.pathkeys = pathkeys;
1807  pathnode->path.pathtarget = target ? target : rel->reltarget;
1808  pathnode->path.rows += subpath->rows;
1809 
1810  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1811  {
1812  /* Subpath is adequately ordered, we won't need to sort it */
1813  input_startup_cost += subpath->startup_cost;
1814  input_total_cost += subpath->total_cost;
1815  }
1816  else
1817  {
1818  /* We'll need to insert a Sort node, so include cost for that */
1819  Path sort_path; /* dummy for result of cost_sort */
1820 
1821  cost_sort(&sort_path,
1822  root,
1823  pathkeys,
1824  subpath->total_cost,
1825  subpath->rows,
1826  subpath->pathtarget->width,
1827  0.0,
1828  work_mem,
1829  -1);
1830  input_startup_cost += sort_path.startup_cost;
1831  input_total_cost += sort_path.total_cost;
1832  }
1833 
1834  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1835  input_startup_cost, input_total_cost, rows);
1836 
1837  return pathnode;
1838 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
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:403
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
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:1927
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
double Cost
Definition: nodes.h:663
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 1878 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().

1880 {
1881  GatherPath *pathnode = makeNode(GatherPath);
1882 
1883  Assert(subpath->parallel_safe);
1884 
1885  pathnode->path.pathtype = T_Gather;
1886  pathnode->path.parent = rel;
1887  pathnode->path.pathtarget = target;
1888  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1889  required_outer);
1890  pathnode->path.parallel_aware = false;
1891  pathnode->path.parallel_safe = false;
1892  pathnode->path.parallel_workers = 0;
1893  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1894 
1895  pathnode->subpath = subpath;
1896  pathnode->num_workers = subpath->parallel_workers;
1897  pathnode->single_copy = false;
1898 
1899  if (pathnode->num_workers == 0)
1900  {
1901  pathnode->path.pathkeys = subpath->pathkeys;
1902  pathnode->num_workers = 1;
1903  pathnode->single_copy = true;
1904  }
1905 
1906  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1907 
1908  return pathnode;
1909 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
bool single_copy
Definition: pathnodes.h:1496
int num_workers
Definition: pathnodes.h:1497
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * subpath
Definition: pathnodes.h:1495
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
bool parallel_safe
Definition: pathnodes.h:1150
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:365
Definition: nodes.h:82
bool parallel_aware
Definition: pathnodes.h:1149
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 2895 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().

2901 {
2902  GroupPath *pathnode = makeNode(GroupPath);
2903  PathTarget *target = rel->reltarget;
2904 
2905  pathnode->path.pathtype = T_Group;
2906  pathnode->path.parent = rel;
2907  pathnode->path.pathtarget = target;
2908  /* For now, assume we are above any joins, so no parameterization */
2909  pathnode->path.param_info = NULL;
2910  pathnode->path.parallel_aware = false;
2911  pathnode->path.parallel_safe = rel->consider_parallel &&
2912  subpath->parallel_safe;
2913  pathnode->path.parallel_workers = subpath->parallel_workers;
2914  /* Group doesn't change sort ordering */
2915  pathnode->path.pathkeys = subpath->pathkeys;
2916 
2917  pathnode->subpath = subpath;
2918 
2919  pathnode->groupClause = groupClause;
2920  pathnode->qual = qual;
2921 
2922  cost_group(&pathnode->path, root,
2923  list_length(groupClause),
2924  numGroups,
2925  qual,
2926  subpath->startup_cost, subpath->total_cost,
2927  subpath->rows);
2928 
2929  /* add tlist eval cost for each output row */
2930  pathnode->path.startup_cost += target->cost.startup;
2931  pathnode->path.total_cost += target->cost.startup +
2932  target->cost.per_tuple * pathnode->path.rows;
2933 
2934  return pathnode;
2935 }
List * qual
Definition: pathnodes.h:1673
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1155
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:2581
RelOptInfo * parent
Definition: pathnodes.h:1144
Definition: nodes.h:78
Path path
Definition: pathnodes.h:1670
List * groupClause
Definition: pathnodes.h:1672
Path * subpath
Definition: pathnodes.h:1671
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
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 1479 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().

1481 {
1483 
1484  pathnode->path.pathtype = T_Result;
1485  pathnode->path.parent = rel;
1486  pathnode->path.pathtarget = target;
1487  pathnode->path.param_info = NULL; /* there are no other rels... */
1488  pathnode->path.parallel_aware = false;
1489  pathnode->path.parallel_safe = rel->consider_parallel;
1490  pathnode->path.parallel_workers = 0;
1491  pathnode->path.pathkeys = NIL;
1492  pathnode->quals = havingqual;
1493 
1494  /*
1495  * We can't quite use cost_resultscan() because the quals we want to
1496  * account for are not baserestrict quals of the rel. Might as well just
1497  * hack it here.
1498  */
1499  pathnode->path.rows = 1;
1500  pathnode->path.startup_cost = target->cost.startup;
1501  pathnode->path.total_cost = target->cost.startup +
1502  cpu_tuple_cost + target->cost.per_tuple;
1503 
1504  /*
1505  * Add cost of qual, if any --- but we ignore its selectivity, since our
1506  * rowcount estimate should be 1 no matter what the qual is.
1507  */
1508  if (havingqual)
1509  {
1510  QualCost qual_cost;
1511 
1512  cost_qual_eval(&qual_cost, havingqual, root);
1513  /* havingqual is evaluated once at startup */
1514  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1515  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1516  }
1517 
1518  return pathnode;
1519 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4056
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
bool consider_parallel
Definition: pathnodes.h:673
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: pathnodes.h:1149

◆ 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 3073 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().

3081 {
3083  PathTarget *target = rel->reltarget;
3084  ListCell *lc;
3085  bool is_first = true;
3086  bool is_first_sort = true;
3087 
3088  /* The topmost generated Plan node will be an Agg */
3089  pathnode->path.pathtype = T_Agg;
3090  pathnode->path.parent = rel;
3091  pathnode->path.pathtarget = target;
3092  pathnode->path.param_info = subpath->param_info;
3093  pathnode->path.parallel_aware = false;
3094  pathnode->path.parallel_safe = rel->consider_parallel &&
3095  subpath->parallel_safe;
3096  pathnode->path.parallel_workers = subpath->parallel_workers;
3097  pathnode->subpath = subpath;
3098 
3099  /*
3100  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
3101  * to AGG_HASHED, here if possible.
3102  */
3103  if (aggstrategy == AGG_SORTED &&
3104  list_length(rollups) == 1 &&
3105  ((RollupData *) linitial(rollups))->groupClause == NIL)
3106  aggstrategy = AGG_PLAIN;
3107 
3108  if (aggstrategy == AGG_MIXED &&
3109  list_length(rollups) == 1)
3110  aggstrategy = AGG_HASHED;
3111 
3112  /*
3113  * Output will be in sorted order by group_pathkeys if, and only if, there
3114  * is a single rollup operation on a non-empty list of grouping
3115  * expressions.
3116  */
3117  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
3118  pathnode->path.pathkeys = root->group_pathkeys;
3119  else
3120  pathnode->path.pathkeys = NIL;
3121 
3122  pathnode->aggstrategy = aggstrategy;
3123  pathnode->rollups = rollups;
3124  pathnode->qual = having_qual;
3125  pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
3126 
3127  Assert(rollups != NIL);
3128  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
3129  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
3130 
3131  foreach(lc, rollups)
3132  {
3133  RollupData *rollup = lfirst(lc);
3134  List *gsets = rollup->gsets;
3135  int numGroupCols = list_length(linitial(gsets));
3136 
3137  /*
3138  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
3139  * (already-sorted) input, and following ones do their own sort.
3140  *
3141  * In AGG_HASHED mode, there is one rollup for each grouping set.
3142  *
3143  * In AGG_MIXED mode, the first rollups are hashed, the first
3144  * non-hashed one takes the (already-sorted) input, and following ones
3145  * do their own sort.
3146  */
3147  if (is_first)
3148  {
3149  cost_agg(&pathnode->path, root,
3150  aggstrategy,
3151  agg_costs,
3152  numGroupCols,
3153  rollup->numGroups,
3154  having_qual,
3155  subpath->startup_cost,
3156  subpath->total_cost,
3157  subpath->rows,
3158  subpath->pathtarget->width);
3159  is_first = false;
3160  if (!rollup->is_hashed)
3161  is_first_sort = false;
3162  }
3163  else
3164  {
3165  Path sort_path; /* dummy for result of cost_sort */
3166  Path agg_path; /* dummy for result of cost_agg */
3167 
3168  if (rollup->is_hashed || is_first_sort)
3169  {
3170  /*
3171  * Account for cost of aggregation, but don't charge input
3172  * cost again
3173  */
3174  cost_agg(&agg_path, root,
3175  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
3176  agg_costs,
3177  numGroupCols,
3178  rollup->numGroups,
3179  having_qual,
3180  0.0, 0.0,
3181  subpath->rows,
3182  subpath->pathtarget->width);
3183  if (!rollup->is_hashed)
3184  is_first_sort = false;
3185  }
3186  else
3187  {
3188  /* Account for cost of sort, but don't charge input cost again */
3189  cost_sort(&sort_path, root, NIL,
3190  0.0,
3191  subpath->rows,
3192  subpath->pathtarget->width,
3193  0.0,
3194  work_mem,
3195  -1.0);
3196 
3197  /* Account for cost of aggregation */
3198 
3199  cost_agg(&agg_path, root,
3200  AGG_SORTED,
3201  agg_costs,
3202  numGroupCols,
3203  rollup->numGroups,
3204  having_qual,
3205  sort_path.startup_cost,
3206  sort_path.total_cost,
3207  sort_path.rows,
3208  subpath->pathtarget->width);
3209  }
3210 
3211  pathnode->path.total_cost += agg_path.total_cost;
3212  pathnode->path.rows += agg_path.rows;
3213  }
3214  }
3215 
3216  /* add tlist eval cost for each output row */
3217  pathnode->path.startup_cost += target->cost.startup;
3218  pathnode->path.total_cost += target->cost.startup +
3219  target->cost.per_tuple * pathnode->path.rows;
3220 
3221  return pathnode;
3222 }
List * group_pathkeys
Definition: pathnodes.h:300
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:79
PathTarget * pathtarget
Definition: pathnodes.h:1145
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:2310
int parallel_workers
Definition: pathnodes.h:1151
bool is_hashed
Definition: pathnodes.h:1727
ParamPathInfo * param_info
Definition: pathnodes.h:1147
double numGroups
Definition: pathnodes.h:1725
Cost startup
Definition: pathnodes.h:45
uint64 transitionSpace
Definition: pathnodes.h:1741
NodeTag pathtype
Definition: pathnodes.h:1142
Cost per_tuple
Definition: pathnodes.h:46
#define linitial(l)
Definition: pg_list.h:195
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
AggStrategy aggstrategy
Definition: pathnodes.h:1738
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:1927
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
Size transitionSpace
Definition: pathnodes.h:64
bool parallel_aware
Definition: pathnodes.h:1149
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:676
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
List * gsets
Definition: pathnodes.h:1723

◆ 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 2487 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().

2498 {
2499  HashPath *pathnode = makeNode(HashPath);
2500 
2501  pathnode->jpath.path.pathtype = T_HashJoin;
2502  pathnode->jpath.path.parent = joinrel;
2503  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2504  pathnode->jpath.path.param_info =
2506  joinrel,
2507  outer_path,
2508  inner_path,
2509  extra->sjinfo,
2510  required_outer,
2511  &restrict_clauses);
2512  pathnode->jpath.path.parallel_aware =
2513  joinrel->consider_parallel && parallel_hash;
2514  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2515  outer_path->parallel_safe && inner_path->parallel_safe;
2516  /* This is a foolish way to estimate parallel_workers, but for now... */
2517  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2518 
2519  /*
2520  * A hashjoin never has pathkeys, since its output ordering is
2521  * unpredictable due to possible batching. XXX If the inner relation is
2522  * small enough, we could instruct the executor that it must not batch,
2523  * and then we could assume that the output inherits the outer relation's
2524  * ordering, which might save a sort step. However there is considerable
2525  * downside if our estimate of the inner relation size is badly off. For
2526  * the moment we don't risk it. (Note also that if we wanted to take this
2527  * seriously, joinpath.c would have to consider many more paths for the
2528  * outer rel than it does now.)
2529  */
2530  pathnode->jpath.path.pathkeys = NIL;
2531  pathnode->jpath.jointype = jointype;
2532  pathnode->jpath.inner_unique = extra->inner_unique;
2533  pathnode->jpath.outerjoinpath = outer_path;
2534  pathnode->jpath.innerjoinpath = inner_path;
2535  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2536  pathnode->path_hashclauses = hashclauses;
2537  /* final_cost_hashjoin will fill in pathnode->num_batches */
2538 
2539  final_cost_hashjoin(root, pathnode, workspace, extra);
2540 
2541  return pathnode;
2542 }
#define NIL
Definition: pg_list.h:65
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3599
JoinPath jpath
Definition: pathnodes.h:1599
PathTarget * pathtarget
Definition: pathnodes.h:1145
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:1369
Path * innerjoinpath
Definition: pathnodes.h:1526
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2427
List * joinrestrictinfo
Definition: pathnodes.h:1528
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * outerjoinpath
Definition: pathnodes.h:1525
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
Path path
Definition: pathnodes.h:1518
bool parallel_safe
Definition: pathnodes.h:1150
bool inner_unique
Definition: pathnodes.h:1522
bool consider_parallel
Definition: pathnodes.h:673
JoinType jointype
Definition: pathnodes.h:1520
bool parallel_aware
Definition: pathnodes.h:1149
List * path_hashclauses
Definition: pathnodes.h:1600
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ create_incremental_sort_path()

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

Definition at line 2802 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().

2808 {
2810  SortPath *pathnode = &sort->spath;
2811 
2812  pathnode->path.pathtype = T_IncrementalSort;
2813  pathnode->path.parent = rel;
2814  /* Sort doesn't project, so use source path's pathtarget */
2815  pathnode->path.pathtarget = subpath->pathtarget;
2816  /* For now, assume we are above any joins, so no parameterization */
2817  pathnode->path.param_info = NULL;
2818  pathnode->path.parallel_aware = false;
2819  pathnode->path.parallel_safe = rel->consider_parallel &&
2820  subpath->parallel_safe;
2821  pathnode->path.parallel_workers = subpath->parallel_workers;
2822  pathnode->path.pathkeys = pathkeys;
2823 
2824  pathnode->subpath = subpath;
2825 
2826  cost_incremental_sort(&pathnode->path,
2827  root, pathkeys, presorted_keys,
2828  subpath->startup_cost,
2829  subpath->total_cost,
2830  subpath->rows,
2831  subpath->pathtarget->width,
2832  0.0, /* XXX comparison_cost shouldn't be 0? */
2833  work_mem, limit_tuples);
2834 
2835  sort->nPresortedCols = presorted_keys;
2836 
2837  return pathnode;
2838 }
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:1788
PathTarget * pathtarget
Definition: pathnodes.h:1145
Path * subpath
Definition: pathnodes.h:1648
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:195
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
Path path
Definition: pathnodes.h:1647
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:1210
PathTarget * pathtarget
Definition: pathnodes.h:1145
Path path
Definition: pathnodes.h:1206
IndexOptInfo * indexinfo
Definition: pathnodes.h:1207
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * indexclauses
Definition: pathnodes.h:1208
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * rel
Definition: pathnodes.h:820
RelOptInfo * parent
Definition: pathnodes.h:1144
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:478
List * indexorderbys
Definition: pathnodes.h:1209
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
ScanDirection indexscandir
Definition: pathnodes.h:1211
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 3635 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().

3640 {
3641  LimitPath *pathnode = makeNode(LimitPath);
3642 
3643  pathnode->path.pathtype = T_Limit;
3644  pathnode->path.parent = rel;
3645  /* Limit doesn't project, so use source path's pathtarget */
3646  pathnode->path.pathtarget = subpath->pathtarget;
3647  /* For now, assume we are above any joins, so no parameterization */
3648  pathnode->path.param_info = NULL;
3649  pathnode->path.parallel_aware = false;
3650  pathnode->path.parallel_safe = rel->consider_parallel &&
3651  subpath->parallel_safe;
3652  pathnode->path.parallel_workers = subpath->parallel_workers;
3653  pathnode->path.rows = subpath->rows;
3654  pathnode->path.startup_cost = subpath->startup_cost;
3655  pathnode->path.total_cost = subpath->total_cost;
3656  pathnode->path.pathkeys = subpath->pathkeys;
3657  pathnode->subpath = subpath;
3658  pathnode->limitOffset = limitOffset;
3659  pathnode->limitCount = limitCount;
3660  pathnode->limitOption = limitOption;
3661 
3662  /*
3663  * Adjust the output rows count and costs according to the offset/limit.
3664  */
3665  adjust_limit_rows_costs(&pathnode->path.rows,
3666  &pathnode->path.startup_cost,
3667  &pathnode->path.total_cost,
3668  offset_est, count_est);
3669 
3670  return pathnode;
3671 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
LimitOption limitOption
Definition: pathnodes.h:1837
Node * limitOffset
Definition: pathnodes.h:1835
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
void adjust_limit_rows_costs(double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
Definition: pathnode.c:3690
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
Path * subpath
Definition: pathnodes.h:1834
RelOptInfo * parent
Definition: pathnodes.h:1144
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
Path path
Definition: pathnodes.h:1833
bool parallel_aware
Definition: pathnodes.h:1149
Node * limitCount
Definition: pathnodes.h:1836
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
Definition: nodes.h:87

◆ create_lockrows_path()

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

Definition at line 3474 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().

3476 {
3477  LockRowsPath *pathnode = makeNode(LockRowsPath);
3478 
3479  pathnode->path.pathtype = T_LockRows;
3480  pathnode->path.parent = rel;
3481  /* LockRows doesn't project, so use source path's pathtarget */
3482  pathnode->path.pathtarget = subpath->pathtarget;
3483  /* For now, assume we are above any joins, so no parameterization */
3484  pathnode->path.param_info = NULL;
3485  pathnode->path.parallel_aware = false;
3486  pathnode->path.parallel_safe = false;
3487  pathnode->path.parallel_workers = 0;
3488  pathnode->path.rows = subpath->rows;
3489 
3490  /*
3491  * The result cannot be assumed sorted, since locking might cause the sort
3492  * key columns to be replaced with new values.
3493  */
3494  pathnode->path.pathkeys = NIL;
3495 
3496  pathnode->subpath = subpath;
3497  pathnode->rowMarks = rowMarks;
3498  pathnode->epqParam = epqParam;
3499 
3500  /*
3501  * We should charge something extra for the costs of row locking and
3502  * possible refetches, but it's hard to say how much. For now, use
3503  * cpu_tuple_cost per row.
3504  */
3505  pathnode->path.startup_cost = subpath->startup_cost;
3506  pathnode->path.total_cost = subpath->total_cost +
3507  cpu_tuple_cost * subpath->rows;
3508 
3509  return pathnode;
3510 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * rowMarks
Definition: pathnodes.h:1799
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * subpath
Definition: pathnodes.h:1798
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: pathnodes.h:1149
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

Definition at line 1527 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().

1528 {
1529  MaterialPath *pathnode = makeNode(MaterialPath);
1530 
1531  Assert(subpath->parent == rel);
1532 
1533  pathnode->path.pathtype = T_Material;
1534  pathnode->path.parent = rel;
1535  pathnode->path.pathtarget = rel->reltarget;
1536  pathnode->path.param_info = subpath->param_info;
1537  pathnode->path.parallel_aware = false;
1538  pathnode->path.parallel_safe = rel->consider_parallel &&
1539  subpath->parallel_safe;
1540  pathnode->path.parallel_workers = subpath->parallel_workers;
1541  pathnode->path.pathkeys = subpath->pathkeys;
1542 
1543  pathnode->subpath = subpath;
1544 
1545  cost_material(&pathnode->path,
1546  subpath->startup_cost,
1547  subpath->total_cost,
1548  subpath->rows,
1549  subpath->pathtarget->width);
1550 
1551  return pathnode;
1552 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Path * subpath
Definition: pathnodes.h:1456
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
Cost total_cost
Definition: pathnodes.h:1156
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2256
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
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,
List partitioned_rels 
)

Definition at line 1377 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_copy(), list_length(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, MergeAppendPath::partitioned_rels, 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().

1383 {
1385  Cost input_startup_cost;
1386  Cost input_total_cost;
1387  ListCell *l;
1388 
1389  pathnode->path.pathtype = T_MergeAppend;
1390  pathnode->path.parent = rel;
1391  pathnode->path.pathtarget = rel->reltarget;
1393  required_outer);
1394  pathnode->path.parallel_aware = false;
1395  pathnode->path.parallel_safe = rel->consider_parallel;
1396  pathnode->path.parallel_workers = 0;
1397  pathnode->path.pathkeys = pathkeys;
1398  pathnode->partitioned_rels = list_copy(partitioned_rels);
1399  pathnode->subpaths = subpaths;
1400 
1401  /*
1402  * Apply query-wide LIMIT if known and path is for sole base relation.
1403  * (Handling this at this low level is a bit klugy.)
1404  */
1405  if (bms_equal(rel->relids, root->all_baserels))
1406  pathnode->limit_tuples = root->limit_tuples;
1407  else
1408  pathnode->limit_tuples = -1.0;
1409 
1410  /*
1411  * Add up the sizes and costs of the input paths.
1412  */
1413  pathnode->path.rows = 0;
1414  input_startup_cost = 0;
1415  input_total_cost = 0;
1416  foreach(l, subpaths)
1417  {
1418  Path *subpath = (Path *) lfirst(l);
1419 
1420  pathnode->path.rows += subpath->rows;
1421  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1422  subpath->parallel_safe;
1423 
1424  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1425  {
1426  /* Subpath is adequately ordered, we won't need to sort it */
1427  input_startup_cost += subpath->startup_cost;
1428  input_total_cost += subpath->total_cost;
1429  }
1430  else
1431  {
1432  /* We'll need to insert a Sort node, so include cost for that */
1433  Path sort_path; /* dummy for result of cost_sort */
1434 
1435  cost_sort(&sort_path,
1436  root,
1437  pathkeys,
1438  subpath->total_cost,
1439  subpath->parent->tuples,
1440  subpath->pathtarget->width,
1441  0.0,
1442  work_mem,
1443  pathnode->limit_tuples);
1444  input_startup_cost += sort_path.startup_cost;
1445  input_total_cost += sort_path.total_cost;
1446  }
1447 
1448  /* All child paths must have same parameterization */
1449  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1450  }
1451 
1452  /*
1453  * Now we can compute total costs of the MergeAppend. If there's exactly
1454  * one child path, the MergeAppend is a no-op and will be discarded later
1455  * (in setrefs.c); otherwise we do the normal cost calculation.
1456  */
1457  if (list_length(subpaths) == 1)
1458  {
1459  pathnode->path.startup_cost = input_startup_cost;
1460  pathnode->path.total_cost = input_total_cost;
1461  }
1462  else
1463  cost_merge_append(&pathnode->path, root,
1464  pathkeys, list_length(subpaths),
1465  input_startup_cost, input_total_cost,
1466  pathnode->path.rows);
1467 
1468  return pathnode;
1469 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
double tuples
Definition: pathnodes.h:705
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * list_copy(const List *oldlist)
Definition: list.c:1403
List * partitioned_rels
Definition: pathnodes.h:1429
NodeTag pathtype
Definition: pathnodes.h:1142
Relids all_baserels
Definition: pathnodes.h:227
double limit_tuples
Definition: pathnodes.h:337
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
Relids relids
Definition: pathnodes.h:665
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:1927
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
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:2207
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1576
struct PathTarget * reltarget
Definition: pathnodes.h:676
double limit_tuples
Definition: pathnodes.h:1431
double Cost
Definition: nodes.h:663
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 2421 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().

2434 {
2435  MergePath *pathnode = makeNode(MergePath);
2436 
2437  pathnode->jpath.path.pathtype = T_MergeJoin;
2438  pathnode->jpath.path.parent = joinrel;
2439  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2440  pathnode->jpath.path.param_info =
2442  joinrel,
2443  outer_path,
2444  inner_path,
2445  extra->sjinfo,
2446  required_outer,
2447  &restrict_clauses);
2448  pathnode->jpath.path.parallel_aware = false;
2449  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2450  outer_path->parallel_safe && inner_path->parallel_safe;
2451  /* This is a foolish way to estimate parallel_workers, but for now... */
2452  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2453  pathnode->jpath.path.pathkeys = pathkeys;
2454  pathnode->jpath.jointype = jointype;
2455  pathnode->jpath.inner_unique = extra->inner_unique;
2456  pathnode->jpath.outerjoinpath = outer_path;
2457  pathnode->jpath.innerjoinpath = inner_path;
2458  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2459  pathnode->path_mergeclauses = mergeclauses;
2460  pathnode->outersortkeys = outersortkeys;
2461  pathnode->innersortkeys = innersortkeys;
2462  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2463  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2464 
2465  final_cost_mergejoin(root, pathnode, workspace, extra);
2466 
2467  return pathnode;
2468 }
List * path_mergeclauses
Definition: pathnodes.h:1581
List * outersortkeys
Definition: pathnodes.h:1582
PathTarget * pathtarget
Definition: pathnodes.h:1145
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:1369
Path * innerjoinpath
Definition: pathnodes.h:1526
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2427
List * joinrestrictinfo
Definition: pathnodes.h:1528
RelOptInfo * parent
Definition: pathnodes.h:1144
Path * outerjoinpath
Definition: pathnodes.h:1525
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
Path path
Definition: pathnodes.h:1518
bool parallel_safe
Definition: pathnodes.h:1150
bool inner_unique
Definition: pathnodes.h:1522
bool consider_parallel
Definition: pathnodes.h:673
List * innersortkeys
Definition: pathnodes.h:1583
JoinType jointype
Definition: pathnodes.h:1520
JoinPath jpath
Definition: pathnodes.h:1580
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3163

◆ create_minmaxagg_path()

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

Definition at line 3234 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().

3239 {
3240  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3241  Cost initplan_cost;
3242  ListCell *lc;
3243 
3244  /* The topmost generated Plan node will be a Result */
3245  pathnode->path.pathtype = T_Result;
3246  pathnode->path.parent = rel;
3247  pathnode->path.pathtarget = target;
3248  /* For now, assume we are above any joins, so no parameterization */
3249  pathnode->path.param_info = NULL;
3250  pathnode->path.parallel_aware = false;
3251  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3252  pathnode->path.parallel_safe = false;
3253  pathnode->path.parallel_workers = 0;
3254  /* Result is one unordered row */
3255  pathnode->path.rows = 1;
3256  pathnode->path.pathkeys = NIL;
3257 
3258  pathnode->mmaggregates = mmaggregates;
3259  pathnode->quals = quals;
3260 
3261  /* Calculate cost of all the initplans ... */
3262  initplan_cost = 0;
3263  foreach(lc, mmaggregates)
3264  {
3265  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3266 
3267  initplan_cost += mminfo->pathcost;
3268  }
3269 
3270  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3271  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3272  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3273  target->cost.per_tuple + cpu_tuple_cost;
3274 
3275  /*
3276  * Add cost of qual, if any --- but we ignore its selectivity, since our
3277  * rowcount estimate should be 1 no matter what the qual is.
3278  */
3279  if (quals)
3280  {
3281  QualCost qual_cost;
3282 
3283  cost_qual_eval(&qual_cost, quals, root);
3284  pathnode->path.startup_cost += qual_cost.startup;
3285  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3286  }
3287 
3288  return pathnode;
3289 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
List * quals
Definition: pathnodes.h:1751
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4056
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
List * mmaggregates
Definition: pathnodes.h:1750
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: pathnodes.h:1149
double Cost
Definition: nodes.h:663

◆ create_modifytable_path()

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

Definition at line 3533 of file pathnode.c.

References Assert, ModifyTablePath::canSetTag, ModifyTablePath::epqParam, lfirst, list_head(), 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::subpaths, ModifyTablePath::subroots, T_ModifyTable, Path::total_cost, total_size, PathTarget::width, and ModifyTablePath::withCheckOptionLists.

Referenced by grouping_planner(), and inheritance_planner().

3542 {
3544  double total_size;
3545  ListCell *lc;
3546 
3547  Assert(list_length(resultRelations) == list_length(subpaths));
3548  Assert(list_length(resultRelations) == list_length(subroots));
3549  Assert(withCheckOptionLists == NIL ||
3550  list_length(resultRelations) == list_length(withCheckOptionLists));
3551  Assert(returningLists == NIL ||
3552  list_length(resultRelations) == list_length(returningLists));
3553 
3554  pathnode->path.pathtype = T_ModifyTable;
3555  pathnode->path.parent = rel;
3556  /* pathtarget is not interesting, just make it minimally valid */
3557  pathnode->path.pathtarget = rel->reltarget;
3558  /* For now, assume we are above any joins, so no parameterization */
3559  pathnode->path.param_info = NULL;
3560  pathnode->path.parallel_aware = false;
3561  pathnode->path.parallel_safe = false;
3562  pathnode->path.parallel_workers = 0;
3563  pathnode->path.pathkeys = NIL;
3564 
3565  /*
3566  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3567  *
3568  * Currently, we don't charge anything extra for the actual table
3569  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3570  * expressions if any. It would only be window dressing, since
3571  * ModifyTable is always a top-level node and there is no way for the
3572  * costs to change any higher-level planning choices. But we might want
3573  * to make it look better sometime.
3574  */
3575  pathnode->path.startup_cost = 0;
3576  pathnode->path.total_cost = 0;
3577  pathnode->path.rows = 0;
3578  total_size = 0;
3579  foreach(lc, subpaths)
3580  {
3581  Path *subpath = (Path *) lfirst(lc);
3582 
3583  if (lc == list_head(subpaths)) /* first node? */
3584  pathnode->path.startup_cost = subpath->startup_cost;
3585  pathnode->path.total_cost += subpath->total_cost;
3586  pathnode->path.rows += subpath->rows;
3587  total_size += subpath->pathtarget->width * subpath->rows;
3588  }
3589 
3590  /*
3591  * Set width to the average width of the subpath outputs. XXX this is
3592  * totally wrong: we should report zero if no RETURNING, else an average
3593  * of the RETURNING tlist widths. But it's what happened historically,
3594  * and improving it is a task for another day.
3595  */
3596  if (pathnode->path.rows > 0)
3597  total_size /= pathnode->path.rows;
3598  pathnode->path.pathtarget->width = rint(total_size);
3599 
3600  pathnode->operation = operation;
3601  pathnode->canSetTag = canSetTag;
3602  pathnode->nominalRelation = nominalRelation;
3603  pathnode->rootRelation = rootRelation;
3604  pathnode->partColsUpdated = partColsUpdated;
3605  pathnode->resultRelations = resultRelations;
3606  pathnode->subpaths = subpaths;
3607  pathnode->subroots = subroots;
3608  pathnode->withCheckOptionLists = withCheckOptionLists;
3609  pathnode->returningLists = returningLists;
3610  pathnode->rowMarks = rowMarks;
3611  pathnode->onconflict = onconflict;
3612  pathnode->epqParam = epqParam;
3613 
3614  return pathnode;
3615 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
List * returningLists
Definition: pathnodes.h:1822
OnConflictExpr * onconflict
Definition: pathnodes.h:1824
Index nominalRelation
Definition: pathnodes.h:1815
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Cost startup_cost
Definition: pathnodes.h:1155
bool partColsUpdated
Definition: pathnodes.h:1817
RelOptInfo * parent
Definition: pathnodes.h:1144
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
int64 total_size
Definition: pg_checksums.c:68
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define Assert(condition)
Definition: c.h:745
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
Index rootRelation
Definition: pathnodes.h:1816
static int list_length(const List *l)
Definition: pg_list.h:169
List * withCheckOptionLists
Definition: pathnodes.h:1821
CmdType operation
Definition: pathnodes.h:1813
List * resultRelations
Definition: pathnodes.h:1818
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676
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 2048 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().

2050 {
2051  Path *pathnode = makeNode(Path);
2052 
2053  pathnode->pathtype = T_NamedTuplestoreScan;
2054  pathnode->parent = rel;
2055  pathnode->pathtarget = rel->reltarget;
2056  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2057  required_outer);
2058  pathnode->parallel_aware = false;
2059  pathnode->parallel_safe = rel->consider_parallel;
2060  pathnode->parallel_workers = 0;
2061  pathnode->pathkeys = NIL; /* result is always unordered */
2062 
2063  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2064 
2065  return pathnode;
2066 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1541
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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 2333 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().

2343 {
2344  NestPath *pathnode = makeNode(NestPath);
2345  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2346 
2347  /*
2348  * If the inner path is parameterized by the outer, we must drop any
2349  * restrict_clauses that are due to be moved into the inner path. We have
2350  * to do this now, rather than postpone the work till createplan time,
2351  * because the restrict_clauses list can affect the size and cost
2352  * estimates for this path.
2353  */
2354  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2355  {
2356  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2357  inner_req_outer);
2358  List *jclauses = NIL;
2359  ListCell *lc;
2360 
2361  foreach(lc, restrict_clauses)
2362  {
2363  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2364 
2365  if (!join_clause_is_movable_into(rinfo,
2366  inner_path->parent->relids,
2367  inner_and_outer))
2368  jclauses = lappend(jclauses, rinfo);
2369  }
2370  restrict_clauses = jclauses;
2371  }
2372 
2373  pathnode->path.pathtype = T_NestLoop;
2374  pathnode->path.parent = joinrel;
2375  pathnode->path.pathtarget = joinrel->reltarget;
2376  pathnode->path.param_info =
2378  joinrel,
2379  outer_path,
2380  inner_path,
2381  extra->sjinfo,
2382  required_outer,
2383  &restrict_clauses);
2384  pathnode->path.parallel_aware = false;
2385  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2386  outer_path->parallel_safe && inner_path->parallel_safe;
2387  /* This is a foolish way to estimate parallel_workers, but for now... */
2388  pathnode->path.parallel_workers = outer_path->parallel_workers;
2389  pathnode->path.pathkeys = pathkeys;
2390  pathnode->jointype = jointype;
2391  pathnode->inner_unique = extra->inner_unique;
2392  pathnode->outerjoinpath = outer_path;
2393  pathnode->innerjoinpath = inner_path;
2394  pathnode->joinrestrictinfo = restrict_clauses;
2395 
2396  final_cost_nestloop(root, pathnode, workspace, extra);
2397 
2398  return pathnode;
2399 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
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:1369
Path * innerjoinpath
Definition: pathnodes.h:1526
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2726
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2427
List * joinrestrictinfo
Definition: pathnodes.h:1528
RelOptInfo * parent
Definition: pathnodes.h:1144
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1163
Relids relids
Definition: pathnodes.h:665
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:577
List * lappend(List *list, void *datum)
Definition: list.c:321
Path * outerjoinpath
Definition: pathnodes.h:1525
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
Path path
Definition: pathnodes.h:1518
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1150
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool inner_unique
Definition: pathnodes.h:1522
bool consider_parallel
Definition: pathnodes.h:673
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
JoinType jointype
Definition: pathnodes.h:1520
bool parallel_aware
Definition: pathnodes.h:1149
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ create_projection_path()

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

Definition at line 2553 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cpu_tuple_cost, ProjectionPath::dummypp, equal(), PathTarget::exprs, is_parallel_safe(), is_projection_capable_path(), 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().

2557 {
2558  ProjectionPath *pathnode = makeNode(ProjectionPath);
2559  PathTarget *oldtarget = subpath->pathtarget;
2560 
2561  pathnode->path.pathtype = T_Result;
2562  pathnode->path.parent = rel;
2563  pathnode->path.pathtarget = target;
2564  /* For now, assume we are above any joins, so no parameterization */
2565  pathnode->path.param_info = NULL;
2566  pathnode->path.parallel_aware = false;
2567  pathnode->path.parallel_safe = rel->consider_parallel &&
2568  subpath->parallel_safe &&
2569  is_parallel_safe(root, (Node *) target->exprs);
2570  pathnode->path.parallel_workers = subpath->parallel_workers;
2571  /* Projection does not change the sort order */
2572  pathnode->path.pathkeys = subpath->pathkeys;
2573 
2574  pathnode->subpath = subpath;
2575 
2576  /*
2577  * We might not need a separate Result node. If the input plan node type
2578  * can project, we can just tell it to project something else. Or, if it
2579  * can't project but the desired target has the same expression list as
2580  * what the input will produce anyway, we can still give it the desired
2581  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2582  * Note: in the latter case, create_projection_plan has to recheck our
2583  * conclusion; see comments therein.
2584  */
2585  if (is_projection_capable_path(subpath) ||
2586  equal(oldtarget->exprs, target->exprs))
2587  {
2588  /* No separate Result node needed */
2589  pathnode->dummypp = true;
2590 
2591  /*
2592  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2593  */
2594  pathnode->path.rows = subpath->rows;
2595  pathnode->path.startup_cost = subpath->startup_cost +
2596  (target->cost.startup - oldtarget->cost.startup);
2597  pathnode->path.total_cost = subpath->total_cost +
2598  (target->cost.startup - oldtarget->cost.startup) +
2599  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2600  }
2601  else
2602  {
2603  /* We really do need the Result node */
2604  pathnode->dummypp = false;
2605 
2606  /*
2607  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2608  * evaluating the tlist. There is no qual to worry about.
2609  */
2610  pathnode->path.rows = subpath->rows;
2611  pathnode->path.startup_cost = subpath->startup_cost +
2612  target->cost.startup;
2613  pathnode->path.total_cost = subpath->total_cost +
2614  target->cost.startup +
2615  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2616  }
2617 
2618  return pathnode;
2619 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:3032
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Definition: nodes.h:529
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:854
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
List * exprs
Definition: pathnodes.h:1074
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
bool consider_parallel
Definition: pathnodes.h:673
double cpu_tuple_cost
Definition: costsize.c:113
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6925
bool parallel_aware
Definition: pathnodes.h:1149
Path * subpath
Definition: pathnodes.h:1622
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 3429 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().

3437 {
3439 
3440  pathnode->path.pathtype = T_RecursiveUnion;
3441  pathnode->path.parent = rel;
3442  pathnode->path.pathtarget = target;
3443  /* For now, assume we are above any joins, so no parameterization */
3444  pathnode->path.param_info = NULL;
3445  pathnode->path.parallel_aware = false;
3446  pathnode->path.parallel_safe = rel->consider_parallel &&
3447  leftpath->parallel_safe && rightpath->parallel_safe;
3448  /* Foolish, but we'll do it like joins for now: */
3449  pathnode->path.parallel_workers = leftpath->parallel_workers;
3450  /* RecursiveUnion result is always unsorted */
3451  pathnode->path.pathkeys = NIL;
3452 
3453  pathnode->leftpath = leftpath;
3454  pathnode->rightpath = rightpath;
3455  pathnode->distinctList = distinctList;
3456  pathnode->wtParam = wtParam;
3457  pathnode->numGroups = numGroups;
3458 
3459  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3460 
3461  return pathnode;
3462 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1615
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149

◆ create_resultscan_path()

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

Definition at line 2074 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().

2076 {
2077  Path *pathnode = makeNode(Path);
2078 
2079  pathnode->pathtype = T_Result;
2080  pathnode->parent = rel;
2081  pathnode->pathtarget = rel->reltarget;
2082  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2083  required_outer);
2084  pathnode->parallel_aware = false;
2085  pathnode->parallel_safe = rel->consider_parallel;
2086  pathnode->parallel_workers = 0;
2087  pathnode->pathkeys = NIL; /* result is always unordered */
2088 
2089  cost_resultscan(pathnode, root, rel, pathnode->param_info);
2090 
2091  return pathnode;
2092 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
Definition: nodes.h:46
RelOptInfo * parent
Definition: pathnodes.h:1144
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1578
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:290
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ 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:1145
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1279
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
NodeTag pathtype
Definition: pathnodes.h:1142
#define true
Definition: c.h:328
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:213
RelOptInfo * parent
Definition: pathnodes.h:1144
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
bool parallel_safe
Definition: pathnodes.h:1150
bool consider_parallel
Definition: pathnodes.h:673
bool parallel_aware
Definition: pathnodes.h:1149
struct PathTarget * reltarget
Definition: pathnodes.h:676

◆ create_set_projection_path()

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

Definition at line 2733 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().

2737 {
2738  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2739  double tlist_rows;
2740  ListCell *lc;
2741 
2742  pathnode->path.pathtype = T_ProjectSet;
2743  pathnode->path.parent = rel;
2744  pathnode->path.pathtarget = target;
2745  /* For now, assume we are above any joins, so no parameterization */
2746  pathnode->path.param_info = NULL;
2747  pathnode->path.parallel_aware = false;
2748  pathnode->path.parallel_safe = rel->consider_parallel &&
2749  subpath->parallel_safe &&
2750  is_parallel_safe(root, (Node *) target->exprs);
2751  pathnode->path.parallel_workers = subpath->parallel_workers;
2752  /* Projection does not change the sort order XXX? */
2753  pathnode->path.pathkeys = subpath->pathkeys;
2754 
2755  pathnode->subpath = subpath;
2756 
2757  /*
2758  * Estimate number of rows produced by SRFs for each row of input; if
2759  * there's more than one in this node, use the maximum.
2760  */
2761  tlist_rows = 1;
2762  foreach(lc, target->exprs)
2763  {
2764  Node *node = (Node *) lfirst(lc);
2765  double itemrows;
2766 
2767  itemrows = expression_returns_set_rows(root, node);
2768  if (tlist_rows < itemrows)
2769  tlist_rows = itemrows;
2770  }
2771 
2772  /*
2773  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2774  * per input row, and half of cpu_tuple_cost for each added output row.
2775  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2776  * this estimate later.
2777  */
2778  pathnode->path.rows = subpath->rows * tlist_rows;
2779  pathnode->path.startup_cost = subpath->startup_cost +
2780  target->cost.startup;
2781  pathnode->path.total_cost = subpath->total_cost +
2782  target->cost.startup +
2783  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2784  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2785 
2786  return pathnode;
2787 }
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
Definition: clauses.c:569
PathTarget * pathtarget
Definition: pathnodes.h:1145
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Definition: nodes.h:529
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1142
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:854
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
List * exprs
Definition: pathnodes.h:1074
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
#define lfirst(lc)
Definition: pg_list.h:190
Path * subpath
Definition: pathnodes.h:1634
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
QualCost cost
Definition: pathnodes.h:1076
bool consider_parallel
Definition: pathnodes.h:673
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: pathnodes.h:1149
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 3367 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().

3377 {
3378  SetOpPath *pathnode = makeNode(SetOpPath);
3379 
3380  pathnode->path.pathtype = T_SetOp;
3381  pathnode->path.parent = rel;
3382  /* SetOp doesn't project, so use source path's pathtarget */
3383  pathnode->path.pathtarget = subpath->pathtarget;
3384  /* For now, assume we are above any joins, so no parameterization */
3385  pathnode->path.param_info = NULL;
3386  pathnode->path.parallel_aware = false;
3387  pathnode->path.parallel_safe = rel->consider_parallel &&
3388  subpath->parallel_safe;
3389  pathnode->path.parallel_workers = subpath->parallel_workers;
3390  /* SetOp preserves the input sort order if in sort mode */
3391  pathnode->path.pathkeys =
3392  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3393 
3394  pathnode->subpath = subpath;
3395  pathnode->cmd = cmd;
3396  pathnode->strategy = strategy;
3397  pathnode->distinctList = distinctList;
3398  pathnode->flagColIdx = flagColIdx;
3399  pathnode->firstFlag = firstFlag;
3400  pathnode->numGroups = numGroups;
3401 
3402  /*
3403  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3404  * all columns get compared at most of the tuples.
3405  */
3406  pathnode->path.startup_cost = subpath->startup_cost;
3407  pathnode->path.total_cost = subpath->total_cost +
3408  cpu_operator_cost * subpath->rows * list_length(distinctList);
3409  pathnode->path.rows = outputRows;
3410 
3411  return pathnode;
3412 }
#define NIL
Definition: pg_list.h:65
List * distinctList
Definition: pathnodes.h:1773
PathTarget * pathtarget
Definition: pathnodes.h:1145
SetOpStrategy strategy
Definition: pathnodes.h:1772
Path * subpath
Definition: pathnodes.h:1770
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
double numGroups
Definition: pathnodes.h:1776
NodeTag pathtype
Definition: pathnodes.h:1142
SetOpCmd cmd
Definition: pathnodes.h:1771
Cost startup_cost
Definition: pathnodes.h:1155
RelOptInfo * parent
Definition: pathnodes.h:1144
AttrNumber flagColIdx
Definition: pathnodes.h:1774
double cpu_operator_cost
Definition: costsize.c:115
Cost total_cost
Definition: pathnodes.h:1156
int firstFlag
Definition: pathnodes.h:1775
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:673
Definition: nodes.h:85
bool parallel_aware
Definition: pathnodes.h:1149
Path path
Definition: pathnodes.h:1769

◆ create_sort_path()

SortPath* create_sort_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
double  limit_tuples 
)

Definition at line 2851 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_sort(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SortPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, subpath(), SortPath::subpath, T_Sort, Path::total_cost, PathTarget::width, and work_mem.

Referenced by add_paths_to_grouping_rel(), add_paths_with_pathkeys_for_rel(), create_distinct_paths(), create_one_window_path(), create_ordered_paths(), create_partial_grouping_paths(), gather_grouping_paths(), generate_nonunion_paths(), generate_useful_gather_paths(), and make_union_unique().

2856 {
2857  SortPath *pathnode = makeNode(SortPath);
2858 
2859  pathnode->path.pathtype = T_Sort;
2860  pathnode->path.parent = rel;
2861  /* Sort doesn't project, so use source path's pathtarget */
2862  pathnode->path.pathtarget = subpath->pathtarget;
2863  /* For now, assume we are above any joins, so no parameterization */
2864  pathnode->path.param_info = NULL;
2865  pathnode->path.parallel_aware = false;
2866  pathnode->path.parallel_safe = rel->consider_parallel &&
2867  subpath->parallel_safe;
2868  pathnode->path.parallel_workers = subpath->parallel_workers;
2869  pathnode->path.pathkeys = pathkeys;
2870 
2871  pathnode->subpath = subpath;
2872 
2873  cost_sort(&pathnode->path, root, pathkeys,
2874  subpath->total_cost,
2875  subpath->rows,
2876  subpath->pathtarget->width,
2877  0.0, /* XXX comparison_cost shouldn't be 0? */
2878  work_mem, limit_tuples);
2879 
2880  return pathnode;
2881 }
PathTarget * pathtarget
Definition: pathnodes.h:1145
Path * subpath
Definition: pathnodes.h:1648
int parallel_workers
Definition: pathnodes.h:1151
ParamPathInfo * param_info
Definition: pathnodes.h:1147
Definition: nodes.h:76
NodeTag pathtype
Definition: pathnodes.h:1142
RelOptInfo * parent
Definition: pathnodes.h:1144
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:1927
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1156
List * pathkeys
Definition: pathnodes.h:1158
#define makeNode(_type_)
Definition: nodes.h:577
double rows
Definition: pathnodes.h:1154
bool parallel_safe
Definition: pathnodes.h:1150