PostgreSQL Source Code  git master
pathnode.c File Reference
#include "postgres.h"
#include <math.h>
#include "miscadmin.h"
#include "foreign/fdwapi.h"
#include "nodes/extensible.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.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 "optimizer/var.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 void *a, const void *b)
 
static int append_startup_cost_compare (const void *a, const void *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 *indexclausecols, 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, 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)
 
ResultPathcreate_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *resconstantqual)
 
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_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)
 
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_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, List *winpathkeys)
 
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, List *partitioned_rels, 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, 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:517
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: prepunion.c:2534
Definition: pg_list.h:45

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

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

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:69
static List * reparameterize_pathlist_by_child(PlannerInfo *root, List *pathlist, RelOptInfo *child_rel)
Definition: pathnode.c:3939

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 762 of file pathnode.c.

References Assert, CHECK_FOR_INTERRUPTS, compare_pathkeys(), RelOptInfo::consider_parallel, lappend_cell(), lcons(), lfirst, list_delete_cell(), list_head(), lnext, 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().

763 {
764  bool accept_new = true; /* unless we find a superior old path */
765  ListCell *insert_after = NULL; /* where to insert new item */
766  ListCell *p1;
767  ListCell *p1_prev;
768  ListCell *p1_next;
769 
770  /* Check for query cancel. */
772 
773  /* Path to be added must be parallel safe. */
774  Assert(new_path->parallel_safe);
775 
776  /* Relation should be OK for parallelism, too. */
777  Assert(parent_rel->consider_parallel);
778 
779  /*
780  * As in add_path, throw out any paths which are dominated by the new
781  * path, but throw out the new path if some existing path dominates it.
782  */
783  p1_prev = NULL;
784  for (p1 = list_head(parent_rel->partial_pathlist); p1 != NULL;
785  p1 = p1_next)
786  {
787  Path *old_path = (Path *) lfirst(p1);
788  bool remove_old = false; /* unless new proves superior */
789  PathKeysComparison keyscmp;
790 
791  p1_next = lnext(p1);
792 
793  /* Compare pathkeys. */
794  keyscmp = compare_pathkeys(new_path->pathkeys, old_path->pathkeys);
795 
796  /* Unless pathkeys are incompable, keep just one of the two paths. */
797  if (keyscmp != PATHKEYS_DIFFERENT)
798  {
799  if (new_path->total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
800  {
801  /* New path costs more; keep it only if pathkeys are better. */
802  if (keyscmp != PATHKEYS_BETTER1)
803  accept_new = false;
804  }
805  else if (old_path->total_cost > new_path->total_cost
806  * STD_FUZZ_FACTOR)
807  {
808  /* Old path costs more; keep it only if pathkeys are better. */
809  if (keyscmp != PATHKEYS_BETTER2)
810  remove_old = true;
811  }
812  else if (keyscmp == PATHKEYS_BETTER1)
813  {
814  /* Costs are about the same, new path has better pathkeys. */
815  remove_old = true;
816  }
817  else if (keyscmp == PATHKEYS_BETTER2)
818  {
819  /* Costs are about the same, old path has better pathkeys. */
820  accept_new = false;
821  }
822  else if (old_path->total_cost > new_path->total_cost * 1.0000000001)
823  {
824  /* Pathkeys are the same, and the old path costs more. */
825  remove_old = true;
826  }
827  else
828  {
829  /*
830  * Pathkeys are the same, and new path isn't materially
831  * cheaper.
832  */
833  accept_new = false;
834  }
835  }
836 
837  /*
838  * Remove current element from partial_pathlist if dominated by new.
839  */
840  if (remove_old)
841  {
842  parent_rel->partial_pathlist =
843  list_delete_cell(parent_rel->partial_pathlist, p1, p1_prev);
844  pfree(old_path);
845  /* p1_prev does not advance */
846  }
847  else
848  {
849  /* new belongs after this old path if it has cost >= old's */
850  if (new_path->total_cost >= old_path->total_cost)
851  insert_after = p1;
852  /* p1_prev advances */
853  p1_prev = p1;
854  }
855 
856  /*
857  * If we found an old path that dominates new_path, we can quit
858  * scanning the partial_pathlist; we will not add new_path, and we
859  * assume new_path cannot dominate any later path.
860  */
861  if (!accept_new)
862  break;
863  }
864 
865  if (accept_new)
866  {
867  /* Accept the new path: insert it at proper place */
868  if (insert_after)
869  lappend_cell(parent_rel->partial_pathlist, insert_after, new_path);
870  else
871  parent_rel->partial_pathlist =
872  lcons(new_path, parent_rel->partial_pathlist);
873  }
874  else
875  {
876  /* Reject and recycle the new path */
877  pfree(new_path);
878  }
879 }
List * partial_pathlist
Definition: relation.h:628
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
ListCell * lappend_cell(List *list, ListCell *prev, void *datum)
Definition: list.c:209
void pfree(void *pointer)
Definition: mcxt.c:1031
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
#define lnext(lc)
Definition: pg_list.h:105
List * list_delete_cell(List *list, ListCell *cell, ListCell *prev)
Definition: list.c:528
Cost total_cost
Definition: relation.h:1090
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:1092
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1084
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
bool consider_parallel
Definition: relation.h:620
PathKeysComparison
Definition: paths.h:183
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98

◆ add_partial_path_precheck()

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

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

894 {
895  ListCell *p1;
896 
897  /*
898  * Our goal here is twofold. First, we want to find out whether this path
899  * is clearly inferior to some existing partial path. If so, we want to
900  * reject it immediately. Second, we want to find out whether this path
901  * is clearly superior to some existing partial path -- at least, modulo
902  * final cost computations. If so, we definitely want to consider it.
903  *
904  * Unlike add_path(), we always compare pathkeys here. This is because we
905  * expect partial_pathlist to be very short, and getting a definitive
906  * answer at this stage avoids the need to call add_path_precheck.
907  */
908  foreach(p1, parent_rel->partial_pathlist)
909  {
910  Path *old_path = (Path *) lfirst(p1);
911  PathKeysComparison keyscmp;
912 
913  keyscmp = compare_pathkeys(pathkeys, old_path->pathkeys);
914  if (keyscmp != PATHKEYS_DIFFERENT)
915  {
916  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR &&
917  keyscmp != PATHKEYS_BETTER1)
918  return false;
919  if (old_path->total_cost > total_cost * STD_FUZZ_FACTOR &&
920  keyscmp != PATHKEYS_BETTER2)
921  return true;
922  }
923  }
924 
925  /*
926  * This path is neither clearly inferior to an existing partial path nor
927  * clearly good enough that it might replace one. Compare it to
928  * non-parallel plans. If it loses even before accounting for the cost of
929  * the Gather node, we should definitely reject it.
930  *
931  * Note that we pass the total_cost to add_path_precheck twice. This is
932  * because it's never advantageous to consider the startup cost of a
933  * partial path; the resulting plans, if run in parallel, will be run to
934  * completion.
935  */
936  if (!add_path_precheck(parent_rel, total_cost, total_cost, pathkeys,
937  NULL))
938  return false;
939 
940  return true;
941 }
bool add_path_precheck(RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
Definition: pathnode.c:657
List * partial_pathlist
Definition: relation.h:628
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define lfirst(lc)
Definition: pg_list.h:106
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:183

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

◆ add_path_precheck()

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

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

660 {
661  List *new_path_pathkeys;
662  bool consider_startup;
663  ListCell *p1;
664 
665  /* Pretend parameterized paths have no pathkeys, per add_path policy */
666  new_path_pathkeys = required_outer ? NIL : pathkeys;
667 
668  /* Decide whether new path's startup cost is interesting */
669  consider_startup = required_outer ? parent_rel->consider_param_startup : parent_rel->consider_startup;
670 
671  foreach(p1, parent_rel->pathlist)
672  {
673  Path *old_path = (Path *) lfirst(p1);
674  PathKeysComparison keyscmp;
675 
676  /*
677  * We are looking for an old_path with the same parameterization (and
678  * by assumption the same rowcount) that dominates the new path on
679  * pathkeys as well as both cost metrics. If we find one, we can
680  * reject the new path.
681  *
682  * Cost comparisons here should match compare_path_costs_fuzzily.
683  */
684  if (total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
685  {
686  /* new path can win on startup cost only if consider_startup */
687  if (startup_cost > old_path->startup_cost * STD_FUZZ_FACTOR ||
688  !consider_startup)
689  {
690  /* new path loses on cost, so check pathkeys... */
691  List *old_path_pathkeys;
692 
693  old_path_pathkeys = old_path->param_info ? NIL : old_path->pathkeys;
694  keyscmp = compare_pathkeys(new_path_pathkeys,
695  old_path_pathkeys);
696  if (keyscmp == PATHKEYS_EQUAL ||
697  keyscmp == PATHKEYS_BETTER2)
698  {
699  /* new path does not win on pathkeys... */
700  if (bms_equal(required_outer, PATH_REQ_OUTER(old_path)))
701  {
702  /* Found an old path that dominates the new one */
703  return false;
704  }
705  }
706  }
707  }
708  else
709  {
710  /*
711  * Since the pathlist is sorted by total_cost, we can stop looking
712  * once we reach a path with a total_cost larger than the new
713  * path's.
714  */
715  break;
716  }
717  }
718 
719  return true;
720 }
#define NIL
Definition: pg_list.h:69
bool consider_param_startup
Definition: relation.h:619
ParamPathInfo * param_info
Definition: relation.h:1081
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
bool consider_startup
Definition: relation.h:618
Cost startup_cost
Definition: relation.h:1089
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define lfirst(lc)
Definition: pg_list.h:106
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:183
List * pathlist
Definition: relation.h:626
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:153

◆ append_startup_cost_compare()

static int append_startup_cost_compare ( const void *  a,
const void *  b 
)
static

Definition at line 1329 of file pathnode.c.

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

Referenced by create_append_path().

1330 {
1331  Path *path1 = (Path *) lfirst(*(ListCell **) a);
1332  Path *path2 = (Path *) lfirst(*(ListCell **) b);
1333  int cmp;
1334 
1335  cmp = compare_path_costs(path1, path2, STARTUP_COST);
1336  if (cmp != 0)
1337  return -cmp;
1338  return bms_compare(path1->parent->relids, path2->parent->relids);
1339 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:206
RelOptInfo * parent
Definition: relation.h:1078
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: relation.h:612
#define lfirst(lc)
Definition: pg_list.h:106
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 void *  a,
const void *  b 
)
static

Definition at line 1308 of file pathnode.c.

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

Referenced by create_append_path().

1309 {
1310  Path *path1 = (Path *) lfirst(*(ListCell **) a);
1311  Path *path2 = (Path *) lfirst(*(ListCell **) b);
1312  int cmp;
1313 
1314  cmp = compare_path_costs(path1, path2, TOTAL_COST);
1315  if (cmp != 0)
1316  return -cmp;
1317  return bms_compare(path1->parent->relids, path2->parent->relids);
1318 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:206
RelOptInfo * parent
Definition: relation.h:1078
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Relids relids
Definition: relation.h:612
#define lfirst(lc)
Definition: pg_list.h:106
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 2475 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().

2479 {
2480  QualCost oldcost;
2481 
2482  /*
2483  * If given path can't project, we might need a Result node, so make a
2484  * separate ProjectionPath.
2485  */
2486  if (!is_projection_capable_path(path))
2487  return (Path *) create_projection_path(root, rel, path, target);
2488 
2489  /*
2490  * We can just jam the desired tlist into the existing path, being sure to
2491  * update its cost estimates appropriately.
2492  */
2493  oldcost = path->pathtarget->cost;
2494  path->pathtarget = target;
2495 
2496  path->startup_cost += target->cost.startup - oldcost.startup;
2497  path->total_cost += target->cost.startup - oldcost.startup +
2498  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2499 
2500  /*
2501  * If the path happens to be a Gather or GatherMerge path, we'd like to
2502  * arrange for the subpath to return the required target list so that
2503  * workers can help project. But if there is something that is not
2504  * parallel-safe in the target expressions, then we can't.
2505  */
2506  if ((IsA(path, GatherPath) ||IsA(path, GatherMergePath)) &&
2507  is_parallel_safe(root, (Node *) target->exprs))
2508  {
2509  /*
2510  * We always use create_projection_path here, even if the subpath is
2511  * projection-capable, so as to avoid modifying the subpath in place.
2512  * It seems unlikely at present that there could be any other
2513  * references to the subpath, but better safe than sorry.
2514  *
2515  * Note that we don't change the parallel path's cost estimates; it
2516  * might be appropriate to do so, to reflect the fact that the bulk of
2517  * the target evaluation will happen in workers.
2518  */
2519  if (IsA(path, GatherPath))
2520  {
2521  GatherPath *gpath = (GatherPath *) path;
2522 
2523  gpath->subpath = (Path *)
2525  gpath->subpath->parent,
2526  gpath->subpath,
2527  target);
2528  }
2529  else
2530  {
2531  GatherMergePath *gmpath = (GatherMergePath *) path;
2532 
2533  gmpath->subpath = (Path *)
2535  gmpath->subpath->parent,
2536  gmpath->subpath,
2537  target);
2538  }
2539  }
2540  else if (path->parallel_safe &&
2541  !is_parallel_safe(root, (Node *) target->exprs))
2542  {
2543  /*
2544  * We're inserting a parallel-restricted target list into a path
2545  * currently marked parallel-safe, so we have to mark it as no longer
2546  * safe.
2547  */
2548  path->parallel_safe = false;
2549  }
2550 
2551  return path;
2552 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
PathTarget * pathtarget
Definition: relation.h:1079
Definition: nodes.h:517
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2384
Cost startup
Definition: relation.h:46
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1088
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1395
List * exprs
Definition: relation.h:1008
Cost total_cost
Definition: relation.h:1090
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
Path * subpath
Definition: relation.h:1408
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6704

◆ calc_nestloop_required_outer()

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

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

2102 {
2103  Relids required_outer;
2104 
2105  /* inner_path can require rels from outer path, but not vice versa */
2106  Assert(!bms_overlap(outer_paramrels, innerrelids));
2107  /* easy case if inner path is not parameterized */
2108  if (!inner_paramrels)
2109  return bms_copy(outer_paramrels);
2110  /* else, form the union ... */
2111  required_outer = bms_union(outer_paramrels, inner_paramrels);
2112  /* ... and remove any mention of now-satisfied outer rels */
2113  required_outer = bms_del_members(required_outer,
2114  outerrelids);
2115  /* maintain invariant that required_outer is exactly NULL if empty */
2116  if (bms_is_empty(required_outer))
2117  {
2118  bms_free(required_outer);
2119  required_outer = NULL;
2120  }
2121  return required_outer;
2122 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:133
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:729
void bms_free(Bitmapset *a)
Definition: bitmapset.c:267
#define Assert(condition)
Definition: c.h:699
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:955
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2132 {
2133  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2134  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2135  Relids required_outer;
2136 
2137  /* neither path can require rels from the other */
2138  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2139  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2140  /* form the union ... */
2141  required_outer = bms_union(outer_paramrels, inner_paramrels);
2142  /* we do not need an explicit test for empty; bms_union gets it right */
2143  return required_outer;
2144 }
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
#define Assert(condition)
Definition: c.h:699
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509

◆ 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: relation.h:1089
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Cost total_cost
Definition: relation.h:1090
double Cost
Definition: nodes.h:648

◆ 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: relation.h:1089
Cost total_cost
Definition: relation.h:1090

◆ 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: relation.h:1089
Cost total_cost
Definition: relation.h:1090
#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 2786 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, and Path::total_cost.

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

2796 {
2797  AggPath *pathnode = makeNode(AggPath);
2798 
2799  pathnode->path.pathtype = T_Agg;
2800  pathnode->path.parent = rel;
2801  pathnode->path.pathtarget = target;
2802  /* For now, assume we are above any joins, so no parameterization */
2803  pathnode->path.param_info = NULL;
2804  pathnode->path.parallel_aware = false;
2805  pathnode->path.parallel_safe = rel->consider_parallel &&
2806  subpath->parallel_safe;
2807  pathnode->path.parallel_workers = subpath->parallel_workers;
2808  if (aggstrategy == AGG_SORTED)
2809  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2810  else
2811  pathnode->path.pathkeys = NIL; /* output is unordered */
2812  pathnode->subpath = subpath;
2813 
2814  pathnode->aggstrategy = aggstrategy;
2815  pathnode->aggsplit = aggsplit;
2816  pathnode->numGroups = numGroups;
2817  pathnode->groupClause = groupClause;
2818  pathnode->qual = qual;
2819 
2820  cost_agg(&pathnode->path, root,
2821  aggstrategy, aggcosts,
2822  list_length(groupClause), numGroups,
2823  qual,
2824  subpath->startup_cost, subpath->total_cost,
2825  subpath->rows);
2826 
2827  /* add tlist eval cost for each output row */
2828  pathnode->path.startup_cost += target->cost.startup;
2829  pathnode->path.total_cost += target->cost.startup +
2830  target->cost.per_tuple * pathnode->path.rows;
2831 
2832  return pathnode;
2833 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:78
PathTarget * pathtarget
Definition: relation.h:1079
AggStrategy aggstrategy
Definition: relation.h:1592
List * qual
Definition: relation.h:1596
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)
Definition: costsize.c:2060
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
AggSplit aggsplit
Definition: relation.h:1593
double numGroups
Definition: relation.h:1594
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * groupClause
Definition: relation.h:1595
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
Path * subpath
Definition: relation.h:1591
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1590
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_append_path()

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

Definition at line 1219 of file pathnode.c.

References 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, list_concat(), list_copy(), list_length(), list_qsort(), 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, RELOPT_BASEREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, Path::rows, subpath(), AppendPath::subpaths, and T_Append.

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

1225 {
1226  AppendPath *pathnode = makeNode(AppendPath);
1227  ListCell *l;
1228 
1229  Assert(!parallel_aware || parallel_workers > 0);
1230 
1231  pathnode->path.pathtype = T_Append;
1232  pathnode->path.parent = rel;
1233  pathnode->path.pathtarget = rel->reltarget;
1234 
1235  /*
1236  * When generating an Append path for a partitioned table, there may be
1237  * parameters that are useful so we can eliminate certain partitions
1238  * during execution. Here we'll go all the way and fully populate the
1239  * parameter info data as we do for normal base relations. However, we
1240  * need only bother doing this for RELOPT_BASEREL rels, as
1241  * RELOPT_OTHER_MEMBER_REL's Append paths are merged into the base rel's
1242  * Append subpaths. It would do no harm to do this, we just avoid it to
1243  * save wasting effort.
1244  */
1245  if (partitioned_rels != NIL && root && rel->reloptkind == RELOPT_BASEREL)
1246  pathnode->path.param_info = get_baserel_parampathinfo(root,
1247  rel,
1248  required_outer);
1249  else
1251  required_outer);
1252 
1253  pathnode->path.parallel_aware = parallel_aware;
1254  pathnode->path.parallel_safe = rel->consider_parallel;
1255  pathnode->path.parallel_workers = parallel_workers;
1256  pathnode->path.pathkeys = NIL; /* result is always considered unsorted */
1257  pathnode->partitioned_rels = list_copy(partitioned_rels);
1258 
1259  /*
1260  * For parallel append, non-partial paths are sorted by descending total
1261  * costs. That way, the total time to finish all non-partial paths is
1262  * minimized. Also, the partial paths are sorted by descending startup
1263  * costs. There may be some paths that require to do startup work by a
1264  * single worker. In such case, it's better for workers to choose the
1265  * expensive ones first, whereas the leader should choose the cheapest
1266  * startup plan.
1267  */
1268  if (pathnode->path.parallel_aware)
1269  {
1270  subpaths = list_qsort(subpaths, append_total_cost_compare);
1271  partial_subpaths = list_qsort(partial_subpaths,
1273  }
1274  pathnode->first_partial_path = list_length(subpaths);
1275  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1276 
1277  foreach(l, subpaths)
1278  {
1279  Path *subpath = (Path *) lfirst(l);
1280 
1281  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1282  subpath->parallel_safe;
1283 
1284  /* All child paths must have same parameterization */
1285  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1286  }
1287 
1288  Assert(!parallel_aware || pathnode->path.parallel_safe);
1289 
1290  cost_append(pathnode);
1291 
1292  /* If the caller provided a row estimate, override the computed value. */
1293  if (rows >= 0)
1294  pathnode->path.rows = rows;
1295 
1296  return pathnode;
1297 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
RelOptKind reloptkind
Definition: relation.h:609
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:49
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Path path
Definition: relation.h:1304
int first_partial_path
Definition: relation.h:1310
NodeTag pathtype
Definition: relation.h:1076
List * subpaths
Definition: relation.h:1307
RelOptInfo * parent
Definition: relation.h:1078
static int append_total_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1308
static int append_startup_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1329
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
void cost_append(AppendPath *apath)
Definition: costsize.c:1843
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
List * partitioned_rels
Definition: relation.h:1306
List * list_qsort(const List *list, list_qsort_comparator cmp)
Definition: list.c:1261
bool parallel_aware
Definition: relation.h:1083
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1552
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:153

◆ create_bitmap_and_path()

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

Definition at line 1116 of file pathnode.c.

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

Referenced by choose_bitmap_and().

1119 {
1120  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1121 
1122  pathnode->path.pathtype = T_BitmapAnd;
1123  pathnode->path.parent = rel;
1124  pathnode->path.pathtarget = rel->reltarget;
1125  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1126 
1127  /*
1128  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1129  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1130  * set the flag for this path based only on the relation-level flag,
1131  * without actually iterating over the list of children.
1132  */
1133  pathnode->path.parallel_aware = false;
1134  pathnode->path.parallel_safe = rel->consider_parallel;
1135  pathnode->path.parallel_workers = 0;
1136 
1137  pathnode->path.pathkeys = NIL; /* always unordered */
1138 
1139  pathnode->bitmapquals = bitmapquals;
1140 
1141  /* this sets bitmapselectivity as well as the regular cost fields: */
1142  cost_bitmap_and_node(pathnode, root);
1143 
1144  return pathnode;
1145 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1089
ParamPathInfo * param_info
Definition: relation.h:1081
List * bitmapquals
Definition: relation.h:1198
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

1089 {
1090  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1091 
1092  pathnode->path.pathtype = T_BitmapHeapScan;
1093  pathnode->path.parent = rel;
1094  pathnode->path.pathtarget = rel->reltarget;
1095  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1096  required_outer);
1097  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1098  pathnode->path.parallel_safe = rel->consider_parallel;
1099  pathnode->path.parallel_workers = parallel_degree;
1100  pathnode->path.pathkeys = NIL; /* always unordered */
1101 
1102  pathnode->bitmapqual = bitmapqual;
1103 
1104  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1105  pathnode->path.param_info,
1106  bitmapqual, loop_count);
1107 
1108  return pathnode;
1109 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:945
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
#define true
Definition: c.h:279
RelOptInfo * parent
Definition: relation.h:1078
Path * bitmapqual
Definition: relation.h:1186
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_bitmap_or_path()

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

Definition at line 1152 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

1155 {
1156  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1157 
1158  pathnode->path.pathtype = T_BitmapOr;
1159  pathnode->path.parent = rel;
1160  pathnode->path.pathtarget = rel->reltarget;
1161  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1162 
1163  /*
1164  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1165  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1166  * set the flag for this path based only on the relation-level flag,
1167  * without actually iterating over the list of children.
1168  */
1169  pathnode->path.parallel_aware = false;
1170  pathnode->path.parallel_safe = rel->consider_parallel;
1171  pathnode->path.parallel_workers = 0;
1172 
1173  pathnode->path.pathkeys = NIL; /* always unordered */
1174 
1175  pathnode->bitmapquals = bitmapquals;
1176 
1177  /* this sets bitmapselectivity as well as the regular cost fields: */
1178  cost_bitmap_or_node(pathnode, root);
1179 
1180  return pathnode;
1181 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * bitmapquals
Definition: relation.h:1211
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1133
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_ctescan_path()

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

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

1978 {
1979  Path *pathnode = makeNode(Path);
1980 
1981  pathnode->pathtype = T_CteScan;
1982  pathnode->parent = rel;
1983  pathnode->pathtarget = rel->reltarget;
1984  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1985  required_outer);
1986  pathnode->parallel_aware = false;
1987  pathnode->parallel_safe = rel->consider_parallel;
1988  pathnode->parallel_workers = 0;
1989  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1990 
1991  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1992 
1993  return pathnode;
1994 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1500
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ 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 2062 of file pathnode.c.

References RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, get_baserel_parampathinfo(), 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_grouping_paths(), add_paths_with_pathkeys_for_rel(), fileGetForeignPaths(), postgresGetForeignJoinPaths(), and postgresGetForeignPaths().

2069 {
2070  ForeignPath *pathnode = makeNode(ForeignPath);
2071 
2072  pathnode->path.pathtype = T_ForeignScan;
2073  pathnode->path.parent = rel;
2074  pathnode->path.pathtarget = target ? target : rel->reltarget;
2075  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2076  required_outer);
2077  pathnode->path.parallel_aware = false;
2078  pathnode->path.parallel_safe = rel->consider_parallel;
2079  pathnode->path.parallel_workers = 0;
2080  pathnode->path.rows = rows;
2081  pathnode->path.startup_cost = startup_cost;
2082  pathnode->path.total_cost = total_cost;
2083  pathnode->path.pathkeys = pathkeys;
2084 
2085  pathnode->fdw_outerpath = fdw_outerpath;
2086  pathnode->fdw_private = fdw_private;
2087 
2088  return pathnode;
2089 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
Path * fdw_outerpath
Definition: relation.h:1255
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
List * fdw_private
Definition: relation.h:1256
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_functionscan_path()

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

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

1901 {
1902  Path *pathnode = makeNode(Path);
1903 
1904  pathnode->pathtype = T_FunctionScan;
1905  pathnode->parent = rel;
1906  pathnode->pathtarget = rel->reltarget;
1907  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1908  required_outer);
1909  pathnode->parallel_aware = false;
1910  pathnode->parallel_safe = rel->consider_parallel;
1911  pathnode->parallel_workers = 0;
1912  pathnode->pathkeys = pathkeys;
1913 
1914  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1915 
1916  return pathnode;
1917 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1333
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ 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 1741 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(), and generate_gather_paths().

1744 {
1746  Cost input_startup_cost = 0;
1747  Cost input_total_cost = 0;
1748 
1749  Assert(subpath->parallel_safe);
1750  Assert(pathkeys);
1751 
1752  pathnode->path.pathtype = T_GatherMerge;
1753  pathnode->path.parent = rel;
1754  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1755  required_outer);
1756  pathnode->path.parallel_aware = false;
1757 
1758  pathnode->subpath = subpath;
1759  pathnode->num_workers = subpath->parallel_workers;
1760  pathnode->path.pathkeys = pathkeys;
1761  pathnode->path.pathtarget = target ? target : rel->reltarget;
1762  pathnode->path.rows += subpath->rows;
1763 
1764  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1765  {
1766  /* Subpath is adequately ordered, we won't need to sort it */
1767  input_startup_cost += subpath->startup_cost;
1768  input_total_cost += subpath->total_cost;
1769  }
1770  else
1771  {
1772  /* We'll need to insert a Sort node, so include cost for that */
1773  Path sort_path; /* dummy for result of cost_sort */
1774 
1775  cost_sort(&sort_path,
1776  root,
1777  pathkeys,
1778  subpath->total_cost,
1779  subpath->rows,
1780  subpath->pathtarget->width,
1781  0.0,
1782  work_mem,
1783  -1);
1784  input_startup_cost += sort_path.startup_cost;
1785  input_total_cost += sort_path.total_cost;
1786  }
1787 
1788  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1789  input_startup_cost, input_total_cost, rows);
1790 
1791  return pathnode;
1792 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
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:402
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
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:1661
int work_mem
Definition: globals.c:120
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
Path * subpath
Definition: relation.h:1408
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
double Cost
Definition: nodes.h:648
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_gather_path()

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

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

1834 {
1835  GatherPath *pathnode = makeNode(GatherPath);
1836 
1837  Assert(subpath->parallel_safe);
1838 
1839  pathnode->path.pathtype = T_Gather;
1840  pathnode->path.parent = rel;
1841  pathnode->path.pathtarget = target;
1842  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1843  required_outer);
1844  pathnode->path.parallel_aware = false;
1845  pathnode->path.parallel_safe = false;
1846  pathnode->path.parallel_workers = 0;
1847  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1848 
1849  pathnode->subpath = subpath;
1850  pathnode->num_workers = subpath->parallel_workers;
1851  pathnode->single_copy = false;
1852 
1853  if (pathnode->num_workers == 0)
1854  {
1855  pathnode->path.pathkeys = subpath->pathkeys;
1856  pathnode->num_workers = 1;
1857  pathnode->single_copy = true;
1858  }
1859 
1860  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1861 
1862  return pathnode;
1863 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
bool single_copy
Definition: relation.h:1396
int num_workers
Definition: relation.h:1397
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1395
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
bool parallel_safe
Definition: relation.h:1084
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:364
Definition: nodes.h:81
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1394
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_group_path()

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

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

2681 {
2682  GroupPath *pathnode = makeNode(GroupPath);
2683  PathTarget *target = rel->reltarget;
2684 
2685  pathnode->path.pathtype = T_Group;
2686  pathnode->path.parent = rel;
2687  pathnode->path.pathtarget = target;
2688  /* For now, assume we are above any joins, so no parameterization */
2689  pathnode->path.param_info = NULL;
2690  pathnode->path.parallel_aware = false;
2691  pathnode->path.parallel_safe = rel->consider_parallel &&
2692  subpath->parallel_safe;
2693  pathnode->path.parallel_workers = subpath->parallel_workers;
2694  /* Group doesn't change sort ordering */
2695  pathnode->path.pathkeys = subpath->pathkeys;
2696 
2697  pathnode->subpath = subpath;
2698 
2699  pathnode->groupClause = groupClause;
2700  pathnode->qual = qual;
2701 
2702  cost_group(&pathnode->path, root,
2703  list_length(groupClause),
2704  numGroups,
2705  qual,
2706  subpath->startup_cost, subpath->total_cost,
2707  subpath->rows);
2708 
2709  /* add tlist eval cost for each output row */
2710  pathnode->path.startup_cost += target->cost.startup;
2711  pathnode->path.total_cost += target->cost.startup +
2712  target->cost.per_tuple * pathnode->path.rows;
2713 
2714  return pathnode;
2715 }
List * qual
Definition: relation.h:1565
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
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:2248
RelOptInfo * parent
Definition: relation.h:1078
Definition: nodes.h:77
Path path
Definition: relation.h:1562
List * groupClause
Definition: relation.h:1564
Path * subpath
Definition: relation.h:1563
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ 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 2852 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, PathTarget::width, and work_mem.

Referenced by consider_groupingsets_paths().

2860 {
2862  PathTarget *target = rel->reltarget;
2863  ListCell *lc;
2864  bool is_first = true;
2865  bool is_first_sort = true;
2866 
2867  /* The topmost generated Plan node will be an Agg */
2868  pathnode->path.pathtype = T_Agg;
2869  pathnode->path.parent = rel;
2870  pathnode->path.pathtarget = target;
2871  pathnode->path.param_info = subpath->param_info;
2872  pathnode->path.parallel_aware = false;
2873  pathnode->path.parallel_safe = rel->consider_parallel &&
2874  subpath->parallel_safe;
2875  pathnode->path.parallel_workers = subpath->parallel_workers;
2876  pathnode->subpath = subpath;
2877 
2878  /*
2879  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
2880  * to AGG_HASHED, here if possible.
2881  */
2882  if (aggstrategy == AGG_SORTED &&
2883  list_length(rollups) == 1 &&
2884  ((RollupData *) linitial(rollups))->groupClause == NIL)
2885  aggstrategy = AGG_PLAIN;
2886 
2887  if (aggstrategy == AGG_MIXED &&
2888  list_length(rollups) == 1)
2889  aggstrategy = AGG_HASHED;
2890 
2891  /*
2892  * Output will be in sorted order by group_pathkeys if, and only if, there
2893  * is a single rollup operation on a non-empty list of grouping
2894  * expressions.
2895  */
2896  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
2897  pathnode->path.pathkeys = root->group_pathkeys;
2898  else
2899  pathnode->path.pathkeys = NIL;
2900 
2901  pathnode->aggstrategy = aggstrategy;
2902  pathnode->rollups = rollups;
2903  pathnode->qual = having_qual;
2904 
2905  Assert(rollups != NIL);
2906  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
2907  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
2908 
2909  foreach(lc, rollups)
2910  {
2911  RollupData *rollup = lfirst(lc);
2912  List *gsets = rollup->gsets;
2913  int numGroupCols = list_length(linitial(gsets));
2914 
2915  /*
2916  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
2917  * (already-sorted) input, and following ones do their own sort.
2918  *
2919  * In AGG_HASHED mode, there is one rollup for each grouping set.
2920  *
2921  * In AGG_MIXED mode, the first rollups are hashed, the first
2922  * non-hashed one takes the (already-sorted) input, and following ones
2923  * do their own sort.
2924  */
2925  if (is_first)
2926  {
2927  cost_agg(&pathnode->path, root,
2928  aggstrategy,
2929  agg_costs,
2930  numGroupCols,
2931  rollup->numGroups,
2932  having_qual,
2933  subpath->startup_cost,
2934  subpath->total_cost,
2935  subpath->rows);
2936  is_first = false;
2937  if (!rollup->is_hashed)
2938  is_first_sort = false;
2939  }
2940  else
2941  {
2942  Path sort_path; /* dummy for result of cost_sort */
2943  Path agg_path; /* dummy for result of cost_agg */
2944 
2945  if (rollup->is_hashed || is_first_sort)
2946  {
2947  /*
2948  * Account for cost of aggregation, but don't charge input
2949  * cost again
2950  */
2951  cost_agg(&agg_path, root,
2952  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
2953  agg_costs,
2954  numGroupCols,
2955  rollup->numGroups,
2956  having_qual,
2957  0.0, 0.0,
2958  subpath->rows);
2959  if (!rollup->is_hashed)
2960  is_first_sort = false;
2961  }
2962  else
2963  {
2964  /* Account for cost of sort, but don't charge input cost again */
2965  cost_sort(&sort_path, root, NIL,
2966  0.0,
2967  subpath->rows,
2968  subpath->pathtarget->width,
2969  0.0,
2970  work_mem,
2971  -1.0);
2972 
2973  /* Account for cost of aggregation */
2974 
2975  cost_agg(&agg_path, root,
2976  AGG_SORTED,
2977  agg_costs,
2978  numGroupCols,
2979  rollup->numGroups,
2980  having_qual,
2981  sort_path.startup_cost,
2982  sort_path.total_cost,
2983  sort_path.rows);
2984  }
2985 
2986  pathnode->path.total_cost += agg_path.total_cost;
2987  pathnode->path.rows += agg_path.rows;
2988  }
2989  }
2990 
2991  /* add tlist eval cost for each output row */
2992  pathnode->path.startup_cost += target->cost.startup;
2993  pathnode->path.total_cost += target->cost.startup +
2994  target->cost.per_tuple * pathnode->path.rows;
2995 
2996  return pathnode;
2997 }
List * group_pathkeys
Definition: relation.h:276
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:78
PathTarget * pathtarget
Definition: relation.h:1079
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)
Definition: costsize.c:2060
int parallel_workers
Definition: relation.h:1085
bool is_hashed
Definition: relation.h:1618
ParamPathInfo * param_info
Definition: relation.h:1081
double numGroups
Definition: relation.h:1616
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
#define linitial(l)
Definition: pg_list.h:111
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
AggStrategy aggstrategy
Definition: relation.h:1629
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:1661
int work_mem
Definition: globals.c:120
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
List * gsets
Definition: relation.h:1614

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

2329 {
2330  HashPath *pathnode = makeNode(HashPath);
2331 
2332  pathnode->jpath.path.pathtype = T_HashJoin;
2333  pathnode->jpath.path.parent = joinrel;
2334  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2335  pathnode->jpath.path.param_info =
2337  joinrel,
2338  outer_path,
2339  inner_path,
2340  extra->sjinfo,
2341  required_outer,
2342  &restrict_clauses);
2343  pathnode->jpath.path.parallel_aware =
2344  joinrel->consider_parallel && parallel_hash;
2345  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2346  outer_path->parallel_safe && inner_path->parallel_safe;
2347  /* This is a foolish way to estimate parallel_workers, but for now... */
2348  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2349 
2350  /*
2351  * A hashjoin never has pathkeys, since its output ordering is
2352  * unpredictable due to possible batching. XXX If the inner relation is
2353  * small enough, we could instruct the executor that it must not batch,
2354  * and then we could assume that the output inherits the outer relation's
2355  * ordering, which might save a sort step. However there is considerable
2356  * downside if our estimate of the inner relation size is badly off. For
2357  * the moment we don't risk it. (Note also that if we wanted to take this
2358  * seriously, joinpath.c would have to consider many more paths for the
2359  * outer rel than it does now.)
2360  */
2361  pathnode->jpath.path.pathkeys = NIL;
2362  pathnode->jpath.jointype = jointype;
2363  pathnode->jpath.inner_unique = extra->inner_unique;
2364  pathnode->jpath.outerjoinpath = outer_path;
2365  pathnode->jpath.innerjoinpath = inner_path;
2366  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2367  pathnode->path_hashclauses = hashclauses;
2368  /* final_cost_hashjoin will fill in pathnode->num_batches */
2369 
2370  final_cost_hashjoin(root, pathnode, workspace, extra);
2371 
2372  return pathnode;
2373 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3261
JoinPath jpath
Definition: relation.h:1500
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
bool parallel_safe
Definition: relation.h:1084
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
JoinType jointype
Definition: relation.h:1421
bool parallel_aware
Definition: relation.h:1083
List * path_hashclauses
Definition: relation.h:1501
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_index_path()

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

Definition at line 1024 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_index(), expand_indexqual_conditions(), get_baserel_parampathinfo(), IndexPath::indexclauses, IndexPath::indexinfo, IndexPath::indexorderbycols, IndexPath::indexorderbys, IndexPath::indexqualcols, IndexPath::indexquals, 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().

1036 {
1037  IndexPath *pathnode = makeNode(IndexPath);
1038  RelOptInfo *rel = index->rel;
1039  List *indexquals,
1040  *indexqualcols;
1041 
1042  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1043  pathnode->path.parent = rel;
1044  pathnode->path.pathtarget = rel->reltarget;
1045  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1046  required_outer);
1047  pathnode->path.parallel_aware = false;
1048  pathnode->path.parallel_safe = rel->consider_parallel;
1049  pathnode->path.parallel_workers = 0;
1050  pathnode->path.pathkeys = pathkeys;
1051 
1052  /* Convert clauses to indexquals the executor can handle */
1053  expand_indexqual_conditions(index, indexclauses, indexclausecols,
1054  &indexquals, &indexqualcols);
1055 
1056  /* Fill in the pathnode */
1057  pathnode->indexinfo = index;
1058  pathnode->indexclauses = indexclauses;
1059  pathnode->indexquals = indexquals;
1060  pathnode->indexqualcols = indexqualcols;
1061  pathnode->indexorderbys = indexorderbys;
1062  pathnode->indexorderbycols = indexorderbycols;
1063  pathnode->indexscandir = indexscandir;
1064 
1065  cost_index(pathnode, root, loop_count, partial_path);
1066 
1067  return pathnode;
1068 }
List * indexorderbycols
Definition: relation.h:1160
PathTarget * pathtarget
Definition: relation.h:1079
Path path
Definition: relation.h:1154
IndexOptInfo * indexinfo
Definition: relation.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * indexclauses
Definition: relation.h:1156
NodeTag pathtype
Definition: relation.h:1076
List * indexquals
Definition: relation.h:1157
RelOptInfo * rel
Definition: relation.h:755
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3552
RelOptInfo * parent
Definition: relation.h:1078
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:477
List * indexorderbys
Definition: relation.h:1159
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
List * indexqualcols
Definition: relation.h:1158
ScanDirection indexscandir
Definition: relation.h:1161
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_limit_path()

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

Definition at line 3415 of file pathnode.c.

References clamp_row_est(), RelOptInfo::consider_parallel, LimitPath::limitCount, LimitPath::limitOffset, 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().

3419 {
3420  LimitPath *pathnode = makeNode(LimitPath);
3421 
3422  pathnode->path.pathtype = T_Limit;
3423  pathnode->path.parent = rel;
3424  /* Limit doesn't project, so use source path's pathtarget */
3425  pathnode->path.pathtarget = subpath->pathtarget;
3426  /* For now, assume we are above any joins, so no parameterization */
3427  pathnode->path.param_info = NULL;
3428  pathnode->path.parallel_aware = false;
3429  pathnode->path.parallel_safe = rel->consider_parallel &&
3430  subpath->parallel_safe;
3431  pathnode->path.parallel_workers = subpath->parallel_workers;
3432  pathnode->path.rows = subpath->rows;
3433  pathnode->path.startup_cost = subpath->startup_cost;
3434  pathnode->path.total_cost = subpath->total_cost;
3435  pathnode->path.pathkeys = subpath->pathkeys;
3436  pathnode->subpath = subpath;
3437  pathnode->limitOffset = limitOffset;
3438  pathnode->limitCount = limitCount;
3439 
3440  /*
3441  * Adjust the output rows count and costs according to the offset/limit.
3442  * This is only a cosmetic issue if we are at top level, but if we are
3443  * building a subquery then it's important to report correct info to the
3444  * outer planner.
3445  *
3446  * When the offset or count couldn't be estimated, use 10% of the
3447  * estimated number of rows emitted from the subpath.
3448  *
3449  * XXX we don't bother to add eval costs of the offset/limit expressions
3450  * themselves to the path costs. In theory we should, but in most cases
3451  * those expressions are trivial and it's just not worth the trouble.
3452  */
3453  if (offset_est != 0)
3454  {
3455  double offset_rows;
3456 
3457  if (offset_est > 0)
3458  offset_rows = (double) offset_est;
3459  else
3460  offset_rows = clamp_row_est(subpath->rows * 0.10);
3461  if (offset_rows > pathnode->path.rows)
3462  offset_rows = pathnode->path.rows;
3463  if (subpath->rows > 0)
3464  pathnode->path.startup_cost +=
3465  (subpath->total_cost - subpath->startup_cost)
3466  * offset_rows / subpath->rows;
3467  pathnode->path.rows -= offset_rows;
3468  if (pathnode->path.rows < 1)
3469  pathnode->path.rows = 1;
3470  }
3471 
3472  if (count_est != 0)
3473  {
3474  double count_rows;
3475 
3476  if (count_est > 0)
3477  count_rows = (double) count_est;
3478  else
3479  count_rows = clamp_row_est(subpath->rows * 0.10);
3480  if (count_rows > pathnode->path.rows)
3481  count_rows = pathnode->path.rows;
3482  if (subpath->rows > 0)
3483  pathnode->path.total_cost = pathnode->path.startup_cost +
3484  (subpath->total_cost - subpath->startup_cost)
3485  * count_rows / subpath->rows;
3486  pathnode->path.rows = count_rows;
3487  if (pathnode->path.rows < 1)
3488  pathnode->path.rows = 1;
3489  }
3490 
3491  return pathnode;
3492 }
PathTarget * pathtarget
Definition: relation.h:1079
Node * limitOffset
Definition: relation.h:1731
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
Path * subpath
Definition: relation.h:1730
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
Path path
Definition: relation.h:1729
bool parallel_aware
Definition: relation.h:1083
double clamp_row_est(double nrows)
Definition: costsize.c:188
Node * limitCount
Definition: relation.h:1732
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:86

◆ create_lockrows_path()

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

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

3254 {
3255  LockRowsPath *pathnode = makeNode(LockRowsPath);
3256 
3257  pathnode->path.pathtype = T_LockRows;
3258  pathnode->path.parent = rel;
3259  /* LockRows doesn't project, so use source path's pathtarget */
3260  pathnode->path.pathtarget = subpath->pathtarget;
3261  /* For now, assume we are above any joins, so no parameterization */
3262  pathnode->path.param_info = NULL;
3263  pathnode->path.parallel_aware = false;
3264  pathnode->path.parallel_safe = false;
3265  pathnode->path.parallel_workers = 0;
3266  pathnode->path.rows = subpath->rows;
3267 
3268  /*
3269  * The result cannot be assumed sorted, since locking might cause the sort
3270  * key columns to be replaced with new values.
3271  */
3272  pathnode->path.pathkeys = NIL;
3273 
3274  pathnode->subpath = subpath;
3275  pathnode->rowMarks = rowMarks;
3276  pathnode->epqParam = epqParam;
3277 
3278  /*
3279  * We should charge something extra for the costs of row locking and
3280  * possible refetches, but it's hard to say how much. For now, use
3281  * cpu_tuple_cost per row.
3282  */
3283  pathnode->path.startup_cost = subpath->startup_cost;
3284  pathnode->path.total_cost = subpath->total_cost +
3285  cpu_tuple_cost * subpath->rows;
3286 
3287  return pathnode;
3288 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * rowMarks
Definition: relation.h:1694
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1693
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1484 {
1485  MaterialPath *pathnode = makeNode(MaterialPath);
1486 
1487  Assert(subpath->parent == rel);
1488 
1489  pathnode->path.pathtype = T_Material;
1490  pathnode->path.parent = rel;
1491  pathnode->path.pathtarget = rel->reltarget;
1492  pathnode->path.param_info = subpath->param_info;
1493  pathnode->path.parallel_aware = false;
1494  pathnode->path.parallel_safe = rel->consider_parallel &&
1495  subpath->parallel_safe;
1496  pathnode->path.parallel_workers = subpath->parallel_workers;
1497  pathnode->path.pathkeys = subpath->pathkeys;
1498 
1499  pathnode->subpath = subpath;
1500 
1501  cost_material(&pathnode->path,
1502  subpath->startup_cost,
1503  subpath->total_cost,
1504  subpath->rows,
1505  subpath->pathtarget->width);
1506 
1507  return pathnode;
1508 }
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Path * subpath
Definition: relation.h:1356
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2006
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

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

1353 {
1355  Cost input_startup_cost;
1356  Cost input_total_cost;
1357  ListCell *l;
1358 
1359  pathnode->path.pathtype = T_MergeAppend;
1360  pathnode->path.parent = rel;
1361  pathnode->path.pathtarget = rel->reltarget;
1363  required_outer);
1364  pathnode->path.parallel_aware = false;
1365  pathnode->path.parallel_safe = rel->consider_parallel;
1366  pathnode->path.parallel_workers = 0;
1367  pathnode->path.pathkeys = pathkeys;
1368  pathnode->partitioned_rels = list_copy(partitioned_rels);
1369  pathnode->subpaths = subpaths;
1370 
1371  /*
1372  * Apply query-wide LIMIT if known and path is for sole base relation.
1373  * (Handling this at this low level is a bit klugy.)
1374  */
1375  if (bms_equal(rel->relids, root->all_baserels))
1376  pathnode->limit_tuples = root->limit_tuples;
1377  else
1378  pathnode->limit_tuples = -1.0;
1379 
1380  /*
1381  * Add up the sizes and costs of the input paths.
1382  */
1383  pathnode->path.rows = 0;
1384  input_startup_cost = 0;
1385  input_total_cost = 0;
1386  foreach(l, subpaths)
1387  {
1388  Path *subpath = (Path *) lfirst(l);
1389 
1390  pathnode->path.rows += subpath->rows;
1391  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1392  subpath->parallel_safe;
1393 
1394  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1395  {
1396  /* Subpath is adequately ordered, we won't need to sort it */
1397  input_startup_cost += subpath->startup_cost;
1398  input_total_cost += subpath->total_cost;
1399  }
1400  else
1401  {
1402  /* We'll need to insert a Sort node, so include cost for that */
1403  Path sort_path; /* dummy for result of cost_sort */
1404 
1405  cost_sort(&sort_path,
1406  root,
1407  pathkeys,
1408  subpath->total_cost,
1409  subpath->parent->tuples,
1410  subpath->pathtarget->width,
1411  0.0,
1412  work_mem,
1413  pathnode->limit_tuples);
1414  input_startup_cost += sort_path.startup_cost;
1415  input_total_cost += sort_path.total_cost;
1416  }
1417 
1418  /* All child paths must have same parameterization */
1419  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1420  }
1421 
1422  /* Now we can compute total costs of the MergeAppend */
1423  cost_merge_append(&pathnode->path, root,
1424  pathkeys, list_length(subpaths),
1425  input_startup_cost, input_total_cost,
1426  pathnode->path.rows);
1427 
1428  return pathnode;
1429 }
PathTarget * pathtarget
Definition: relation.h:1079
double tuples
Definition: relation.h:652
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partitioned_rels
Definition: relation.h:1329
NodeTag pathtype
Definition: relation.h:1076
Relids all_baserels
Definition: relation.h:210
double limit_tuples
Definition: relation.h:307
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
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:1661
int work_mem
Definition: globals.c:120
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
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:1957
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
List * subpaths
Definition: relation.h:1330
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1552
struct PathTarget * reltarget
Definition: relation.h:623
double limit_tuples
Definition: relation.h:1331
double Cost
Definition: nodes.h:648
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:153

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

2265 {
2266  MergePath *pathnode = makeNode(MergePath);
2267 
2268  pathnode->jpath.path.pathtype = T_MergeJoin;
2269  pathnode->jpath.path.parent = joinrel;
2270  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2271  pathnode->jpath.path.param_info =
2273  joinrel,
2274  outer_path,
2275  inner_path,
2276  extra->sjinfo,
2277  required_outer,
2278  &restrict_clauses);
2279  pathnode->jpath.path.parallel_aware = false;
2280  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2281  outer_path->parallel_safe && inner_path->parallel_safe;
2282  /* This is a foolish way to estimate parallel_workers, but for now... */
2283  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2284  pathnode->jpath.path.pathkeys = pathkeys;
2285  pathnode->jpath.jointype = jointype;
2286  pathnode->jpath.inner_unique = extra->inner_unique;
2287  pathnode->jpath.outerjoinpath = outer_path;
2288  pathnode->jpath.innerjoinpath = inner_path;
2289  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2290  pathnode->path_mergeclauses = mergeclauses;
2291  pathnode->outersortkeys = outersortkeys;
2292  pathnode->innersortkeys = innersortkeys;
2293  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2294  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2295 
2296  final_cost_mergejoin(root, pathnode, workspace, extra);
2297 
2298  return pathnode;
2299 }
List * path_mergeclauses
Definition: relation.h:1482
List * outersortkeys
Definition: relation.h:1483
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
bool parallel_safe
Definition: relation.h:1084
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
List * innersortkeys
Definition: relation.h:1484
JoinType jointype
Definition: relation.h:1421
JoinPath jpath
Definition: relation.h:1481
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2830

◆ create_minmaxagg_path()

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

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

3014 {
3015  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3016  Cost initplan_cost;
3017  ListCell *lc;
3018 
3019  /* The topmost generated Plan node will be a Result */
3020  pathnode->path.pathtype = T_Result;
3021  pathnode->path.parent = rel;
3022  pathnode->path.pathtarget = target;
3023  /* For now, assume we are above any joins, so no parameterization */
3024  pathnode->path.param_info = NULL;
3025  pathnode->path.parallel_aware = false;
3026  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3027  pathnode->path.parallel_safe = false;
3028  pathnode->path.parallel_workers = 0;
3029  /* Result is one unordered row */
3030  pathnode->path.rows = 1;
3031  pathnode->path.pathkeys = NIL;
3032 
3033  pathnode->mmaggregates = mmaggregates;
3034  pathnode->quals = quals;
3035 
3036  /* Calculate cost of all the initplans ... */
3037  initplan_cost = 0;
3038  foreach(lc, mmaggregates)
3039  {
3040  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3041 
3042  initplan_cost += mminfo->pathcost;
3043  }
3044 
3045  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3046  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3047  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3048  target->cost.per_tuple + cpu_tuple_cost;
3049 
3050  /*
3051  * Add cost of qual, if any --- but we ignore its selectivity, since our
3052  * rowcount estimate should be 1 no matter what the qual is.
3053  */
3054  if (quals)
3055  {
3056  QualCost qual_cost;
3057 
3058  cost_qual_eval(&qual_cost, quals, root);
3059  pathnode->path.startup_cost += qual_cost.startup;
3060  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3061  }
3062 
3063  return pathnode;
3064 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * quals
Definition: relation.h:1641
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3716
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * mmaggregates
Definition: relation.h:1640
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083
double Cost
Definition: nodes.h:648

◆ create_modifytable_path()

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

Definition at line 3313 of file pathnode.c.

References Assert, ModifyTablePath::canSetTag, ModifyTablePath::epqParam, lfirst, list_copy(), 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::partitioned_rels, ModifyTablePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, ModifyTablePath::resultRelations, ModifyTablePath::returningLists, rint(), ModifyTablePath::rowMarks, Path::rows, Path::startup_cost, subpath(), ModifyTablePath::subpaths, ModifyTablePath::subroots, T_ModifyTable, Path::total_cost, PathTarget::width, and ModifyTablePath::withCheckOptionLists.

Referenced by grouping_planner(), and inheritance_planner().

3322 {
3324  double total_size;
3325  ListCell *lc;
3326 
3327  Assert(list_length(resultRelations) == list_length(subpaths));
3328  Assert(list_length(resultRelations) == list_length(subroots));
3329  Assert(withCheckOptionLists == NIL ||
3330  list_length(resultRelations) == list_length(withCheckOptionLists));
3331  Assert(returningLists == NIL ||
3332  list_length(resultRelations) == list_length(returningLists));
3333 
3334  pathnode->path.pathtype = T_ModifyTable;
3335  pathnode->path.parent = rel;
3336  /* pathtarget is not interesting, just make it minimally valid */
3337  pathnode->path.pathtarget = rel->reltarget;
3338  /* For now, assume we are above any joins, so no parameterization */
3339  pathnode->path.param_info = NULL;
3340  pathnode->path.parallel_aware = false;
3341  pathnode->path.parallel_safe = false;
3342  pathnode->path.parallel_workers = 0;
3343  pathnode->path.pathkeys = NIL;
3344 
3345  /*
3346  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3347  *
3348  * Currently, we don't charge anything extra for the actual table
3349  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3350  * expressions if any. It would only be window dressing, since
3351  * ModifyTable is always a top-level node and there is no way for the
3352  * costs to change any higher-level planning choices. But we might want
3353  * to make it look better sometime.
3354  */
3355  pathnode->path.startup_cost = 0;
3356  pathnode->path.total_cost = 0;
3357  pathnode->path.rows = 0;
3358  total_size = 0;
3359  foreach(lc, subpaths)
3360  {
3361  Path *subpath = (Path *) lfirst(lc);
3362 
3363  if (lc == list_head(subpaths)) /* first node? */
3364  pathnode->path.startup_cost = subpath->startup_cost;
3365  pathnode->path.total_cost += subpath->total_cost;
3366  pathnode->path.rows += subpath->rows;
3367  total_size += subpath->pathtarget->width * subpath->rows;
3368  }
3369 
3370  /*
3371  * Set width to the average width of the subpath outputs. XXX this is
3372  * totally wrong: we should report zero if no RETURNING, else an average
3373  * of the RETURNING tlist widths. But it's what happened historically,
3374  * and improving it is a task for another day.
3375  */
3376  if (pathnode->path.rows > 0)
3377  total_size /= pathnode->path.rows;
3378  pathnode->path.pathtarget->width = rint(total_size);
3379 
3380  pathnode->operation = operation;
3381  pathnode->canSetTag = canSetTag;
3382  pathnode->nominalRelation = nominalRelation;
3383  pathnode->partitioned_rels = list_copy(partitioned_rels);
3384  pathnode->partColsUpdated = partColsUpdated;
3385  pathnode->resultRelations = resultRelations;
3386  pathnode->subpaths = subpaths;
3387  pathnode->subroots = subroots;
3388  pathnode->withCheckOptionLists = withCheckOptionLists;
3389  pathnode->returningLists = returningLists;
3390  pathnode->rowMarks = rowMarks;
3391  pathnode->onconflict = onconflict;
3392  pathnode->epqParam = epqParam;
3393 
3394  return pathnode;
3395 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
List * returningLists
Definition: relation.h:1718
OnConflictExpr * onconflict
Definition: relation.h:1720
Index nominalRelation
Definition: relation.h:1710
List * rowMarks
Definition: relation.h:1719
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
bool partColsUpdated
Definition: relation.h:1713
List * subroots
Definition: relation.h:1716
RelOptInfo * parent
Definition: relation.h:1078
List * subpaths
Definition: relation.h:1715
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
double rint(double x)
Definition: rint.c:22
List * partitioned_rels
Definition: relation.h:1712
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1717
CmdType operation
Definition: relation.h:1708
List * resultRelations
Definition: relation.h:1714
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_namedtuplestorescan_path()

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

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

2004 {
2005  Path *pathnode = makeNode(Path);
2006 
2007  pathnode->pathtype = T_NamedTuplestoreScan;
2008  pathnode->parent = rel;
2009  pathnode->pathtarget = rel->reltarget;
2010  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2011  required_outer);
2012  pathnode->parallel_aware = false;
2013  pathnode->parallel_safe = rel->consider_parallel;
2014  pathnode->parallel_workers = 0;
2015  pathnode->pathkeys = NIL; /* result is always unordered */
2016 
2017  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2018 
2019  return pathnode;
2020 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1541
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

2174 {
2175  NestPath *pathnode = makeNode(NestPath);
2176  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2177 
2178  /*
2179  * If the inner path is parameterized by the outer, we must drop any
2180  * restrict_clauses that are due to be moved into the inner path. We have
2181  * to do this now, rather than postpone the work till createplan time,
2182  * because the restrict_clauses list can affect the size and cost
2183  * estimates for this path.
2184  */
2185  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2186  {
2187  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2188  inner_req_outer);
2189  List *jclauses = NIL;
2190  ListCell *lc;
2191 
2192  foreach(lc, restrict_clauses)
2193  {
2194  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2195 
2196  if (!join_clause_is_movable_into(rinfo,
2197  inner_path->parent->relids,
2198  inner_and_outer))
2199  jclauses = lappend(jclauses, rinfo);
2200  }
2201  restrict_clauses = jclauses;
2202  }
2203 
2204  pathnode->path.pathtype = T_NestLoop;
2205  pathnode->path.parent = joinrel;
2206  pathnode->path.pathtarget = joinrel->reltarget;
2207  pathnode->path.param_info =
2209  joinrel,
2210  outer_path,
2211  inner_path,
2212  extra->sjinfo,
2213  required_outer,
2214  &restrict_clauses);
2215  pathnode->path.parallel_aware = false;
2216  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2217  outer_path->parallel_safe && inner_path->parallel_safe;
2218  /* This is a foolish way to estimate parallel_workers, but for now... */
2219  pathnode->path.parallel_workers = outer_path->parallel_workers;
2220  pathnode->path.pathkeys = pathkeys;
2221  pathnode->jointype = jointype;
2222  pathnode->inner_unique = extra->inner_unique;
2223  pathnode->outerjoinpath = outer_path;
2224  pathnode->innerjoinpath = inner_path;
2225  pathnode->joinrestrictinfo = restrict_clauses;
2226 
2227  final_cost_nestloop(root, pathnode, workspace, extra);
2228 
2229  return pathnode;
2230 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2393
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:511
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509
JoinType jointype
Definition: relation.h:1421
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_projection_path()

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

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

2388 {
2389  ProjectionPath *pathnode = makeNode(ProjectionPath);
2390  PathTarget *oldtarget = subpath->pathtarget;
2391 
2392  pathnode->path.pathtype = T_Result;
2393  pathnode->path.parent = rel;
2394  pathnode->path.pathtarget = target;
2395  /* For now, assume we are above any joins, so no parameterization */
2396  pathnode->path.param_info = NULL;
2397  pathnode->path.parallel_aware = false;
2398  pathnode->path.parallel_safe = rel->consider_parallel &&
2399  subpath->parallel_safe &&
2400  is_parallel_safe(root, (Node *) target->exprs);
2401  pathnode->path.parallel_workers = subpath->parallel_workers;
2402  /* Projection does not change the sort order */
2403  pathnode->path.pathkeys = subpath->pathkeys;
2404 
2405  pathnode->subpath = subpath;
2406 
2407  /*
2408  * We might not need a separate Result node. If the input plan node type
2409  * can project, we can just tell it to project something else. Or, if it
2410  * can't project but the desired target has the same expression list as
2411  * what the input will produce anyway, we can still give it the desired
2412  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2413  * Note: in the latter case, create_projection_plan has to recheck our
2414  * conclusion; see comments therein.
2415  */
2416  if (is_projection_capable_path(subpath) ||
2417  equal(oldtarget->exprs, target->exprs))
2418  {
2419  /* No separate Result node needed */
2420  pathnode->dummypp = true;
2421 
2422  /*
2423  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2424  */
2425  pathnode->path.rows = subpath->rows;
2426  pathnode->path.startup_cost = subpath->startup_cost +
2427  (target->cost.startup - oldtarget->cost.startup);
2428  pathnode->path.total_cost = subpath->total_cost +
2429  (target->cost.startup - oldtarget->cost.startup) +
2430  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2431  }
2432  else
2433  {
2434  /* We really do need the Result node */
2435  pathnode->dummypp = false;
2436 
2437  /*
2438  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2439  * evaluating the tlist. There is no qual to worry about.
2440  */
2441  pathnode->path.rows = subpath->rows;
2442  pathnode->path.startup_cost = subpath->startup_cost +
2443  target->cost.startup;
2444  pathnode->path.total_cost = subpath->total_cost +
2445  target->cost.startup +
2446  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2447  }
2448 
2449  return pathnode;
2450 }
PathTarget * pathtarget
Definition: relation.h:1079
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2986
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Definition: nodes.h:517
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1088
Cost per_tuple
Definition: relation.h:47
Definition: nodes.h:46
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * exprs
Definition: relation.h:1008
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
bool consider_parallel
Definition: relation.h:620
double cpu_tuple_cost
Definition: costsize.c:113
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6704
bool parallel_aware
Definition: relation.h:1083
Path * subpath
Definition: relation.h:1523
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

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

3215 {
3217 
3218  pathnode->path.pathtype = T_RecursiveUnion;
3219  pathnode->path.parent = rel;
3220  pathnode->path.pathtarget = target;
3221  /* For now, assume we are above any joins, so no parameterization */
3222  pathnode->path.param_info = NULL;
3223  pathnode->path.parallel_aware = false;
3224  pathnode->path.parallel_safe = rel->consider_parallel &&
3225  leftpath->parallel_safe && rightpath->parallel_safe;
3226  /* Foolish, but we'll do it like joins for now: */
3227  pathnode->path.parallel_workers = leftpath->parallel_workers;
3228  /* RecursiveUnion result is always unsorted */
3229  pathnode->path.pathkeys = NIL;
3230 
3231  pathnode->leftpath = leftpath;
3232  pathnode->rightpath = rightpath;
3233  pathnode->distinctList = distinctList;
3234  pathnode->wtParam = wtParam;
3235  pathnode->numGroups = numGroups;
3236 
3237  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3238 
3239  return pathnode;
3240 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1581
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083

◆ create_result_path()

ResultPath* create_result_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List resconstantqual 
)

Definition at line 1439 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, ResultPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, ResultPath::quals, Path::rows, QualCost::startup, Path::startup_cost, T_Result, and Path::total_cost.

Referenced by create_degenerate_grouping_paths(), and query_planner().

1441 {
1442  ResultPath *pathnode = makeNode(ResultPath);
1443 
1444  pathnode->path.pathtype = T_Result;
1445  pathnode->path.parent = rel;
1446  pathnode->path.pathtarget = target;
1447  pathnode->path.param_info = NULL; /* there are no other rels... */
1448  pathnode->path.parallel_aware = false;
1449  pathnode->path.parallel_safe = rel->consider_parallel;
1450  pathnode->path.parallel_workers = 0;
1451  pathnode->path.pathkeys = NIL;
1452  pathnode->quals = resconstantqual;
1453 
1454  /* Hardly worth defining a cost_result() function ... just do it */
1455  pathnode->path.rows = 1;
1456  pathnode->path.startup_cost = target->cost.startup;
1457  pathnode->path.total_cost = target->cost.startup +
1458  cpu_tuple_cost + target->cost.per_tuple;
1459 
1460  /*
1461  * Add cost of qual, if any --- but we ignore its selectivity, since our
1462  * rowcount estimate should be 1 no matter what the qual is.
1463  */
1464  if (resconstantqual)
1465  {
1466  QualCost qual_cost;
1467 
1468  cost_qual_eval(&qual_cost, resconstantqual, root);
1469  /* resconstantqual is evaluated once at startup */
1470  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1471  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1472  }
1473 
1474  return pathnode;
1475 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Path path
Definition: relation.h:1343
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3716
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
List * quals
Definition: relation.h:1344
QualCost cost
Definition: relation.h:1010
bool consider_parallel
Definition: relation.h:620
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083

◆ create_samplescan_path()

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

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

980 {
981  Path *pathnode = makeNode(Path);
982 
983  pathnode->pathtype = T_SampleScan;
984  pathnode->parent = rel;
985  pathnode->pathtarget = rel->reltarget;
986  pathnode->param_info = get_baserel_parampathinfo(root, rel,
987  required_outer);
988  pathnode->parallel_aware = false;
989  pathnode->parallel_safe = rel->consider_parallel;
990  pathnode->parallel_workers = 0;
991  pathnode->pathkeys = NIL; /* samplescan has unordered result */
992 
993  cost_samplescan(pathnode, root, rel, pathnode->param_info);
994 
995  return pathnode;
996 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:289
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_seqscan_path()

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

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

956 {
957  Path *pathnode = makeNode(Path);
958 
959  pathnode->pathtype = T_SeqScan;
960  pathnode->parent = rel;
961  pathnode->pathtarget = rel->reltarget;
962  pathnode->param_info = get_baserel_parampathinfo(root, rel,
963  required_outer);
964  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
965  pathnode->parallel_safe = rel->consider_parallel;
966  pathnode->parallel_workers = parallel_workers;
967  pathnode->pathkeys = NIL; /* seqscan has unordered result */
968 
969  cost_seqscan(pathnode, root, rel, pathnode->param_info);
970 
971  return pathnode;
972 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
#define true
Definition: c.h:279
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:212
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_set_projection_path()

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

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

2568 {
2569  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2570  double tlist_rows;
2571  ListCell *lc;
2572 
2573  pathnode->path.pathtype = T_ProjectSet;
2574  pathnode->path.parent = rel;
2575  pathnode->path.pathtarget = target;
2576  /* For now, assume we are above any joins, so no parameterization */
2577  pathnode->path.param_info = NULL;
2578  pathnode->path.parallel_aware = false;
2579  pathnode->path.parallel_safe = rel->consider_parallel &&
2580  subpath->parallel_safe &&
2581  is_parallel_safe(root, (Node *) target->exprs);
2582  pathnode->path.parallel_workers = subpath->parallel_workers;
2583  /* Projection does not change the sort order XXX? */
2584  pathnode->path.pathkeys = subpath->pathkeys;
2585 
2586  pathnode->subpath = subpath;
2587 
2588  /*
2589  * Estimate number of rows produced by SRFs for each row of input; if
2590  * there's more than one in this node, use the maximum.
2591  */
2592  tlist_rows = 1;
2593  foreach(lc, target->exprs)
2594  {
2595  Node *node = (Node *) lfirst(lc);
2596  double itemrows;
2597 
2598  itemrows = expression_returns_set_rows(node);
2599  if (tlist_rows < itemrows)
2600  tlist_rows = itemrows;
2601  }
2602 
2603  /*
2604  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2605  * per input row, and half of cpu_tuple_cost for each added output row.
2606  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2607  * this estimate later.
2608  */
2609  pathnode->path.rows = subpath->rows * tlist_rows;
2610  pathnode->path.startup_cost = subpath->startup_cost +
2611  target->cost.startup;
2612  pathnode->path.total_cost = subpath->total_cost +
2613  target->cost.startup +
2614  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2615  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2616 
2617  return pathnode;
2618 }
PathTarget * pathtarget
Definition: relation.h:1079
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:803
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Definition: nodes.h:517
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1088
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * exprs
Definition: relation.h:1008
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1535
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
bool consider_parallel
Definition: relation.h:620
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

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

3155 {
3156  SetOpPath *pathnode = makeNode(SetOpPath);
3157 
3158  pathnode->path.pathtype = T_SetOp;
3159  pathnode->path.parent = rel;
3160  /* SetOp doesn't project, so use source path's pathtarget */
3161  pathnode->path.pathtarget = subpath->pathtarget;
3162  /* For now, assume we are above any joins, so no parameterization */
3163  pathnode->path.param_info = NULL;
3164  pathnode->path.parallel_aware = false;
3165  pathnode->path.parallel_safe = rel->consider_parallel &&
3166  subpath->parallel_safe;
3167  pathnode->path.parallel_workers = subpath->parallel_workers;
3168  /* SetOp preserves the input sort order if in sort mode */
3169  pathnode->path.pathkeys =
3170  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3171 
3172  pathnode->subpath = subpath;
3173  pathnode->cmd = cmd;
3174  pathnode->strategy = strategy;
3175  pathnode->distinctList = distinctList;
3176  pathnode->flagColIdx = flagColIdx;
3177  pathnode->firstFlag = firstFlag;
3178  pathnode->numGroups = numGroups;
3179 
3180  /*
3181  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3182  * all columns get compared at most of the tuples.
3183  */
3184  pathnode->path.startup_cost = subpath->startup_cost;
3185  pathnode->path.total_cost = subpath->total_cost +
3186  cpu_operator_cost * subpath->rows * list_length(distinctList);
3187  pathnode->path.rows = outputRows;
3188 
3189  return pathnode;
3190 }
#define NIL
Definition: pg_list.h:69
List * distinctList
Definition: relation.h:1668
PathTarget * pathtarget
Definition: relation.h:1079
SetOpStrategy strategy
Definition: relation.h:1667
Path * subpath
Definition: relation.h:1665
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
double numGroups
Definition: relation.h:1671
NodeTag pathtype
Definition: relation.h:1076
SetOpCmd cmd
Definition: relation.h:1666
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
AttrNumber flagColIdx
Definition: relation.h:1669
double cpu_operator_cost
Definition: costsize.c:115
Cost total_cost
Definition: relation.h:1090
int firstFlag
Definition: relation.h:1670
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
Definition: nodes.h:84
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1664

◆ create_sort_path()

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

Definition at line 2631 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(), and make_union_unique().

2636 {
2637  SortPath *pathnode = makeNode(SortPath);
2638 
2639  pathnode->path.pathtype = T_Sort;
2640  pathnode->path.parent = rel;
2641  /* Sort doesn't project, so use source path's pathtarget */
2642  pathnode->path.pathtarget = subpath->pathtarget;
2643  /* For now, assume we are above any joins, so no parameterization */
2644  pathnode->path.param_info = NULL;
2645  pathnode->path.parallel_aware = false;
2646  pathnode->path.parallel_safe = rel->consider_parallel &&
2647  subpath->parallel_safe;
2648  pathnode->path.parallel_workers = subpath->parallel_workers;
2649  pathnode->path.pathkeys = pathkeys;
2650 
2651  pathnode->subpath = subpath;
2652 
2653  cost_sort(&pathnode->path, root, pathkeys,
2654  subpath->total_cost,
2655  subpath->rows,
2656  subpath->pathtarget->width,
2657  0.0, /* XXX comparison_cost shouldn't be 0? */
2658  work_mem, limit_tuples);
2659 
2660  return pathnode;
2661 }
PathTarget * pathtarget
Definition: relation.h:1079
Path * subpath
Definition: relation.h:1549
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Definition: nodes.h:76
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
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:1661
int work_mem
Definition: globals.c:120
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1548
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_subqueryscan_path()

SubqueryScanPath* create_subqueryscan_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
Relids  required_outer 
)

Definition at line 1871 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_subqueryscan(), get_baserel_parampathinfo(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SubqueryScanPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, subpath(), SubqueryScanPath::subpath, and T_SubqueryScan.

Referenced by recurse_set_operations(), reparameterize_path(), and set_subquery_pathlist().

1873 {
1875 
1876  pathnode->path.pathtype = T_SubqueryScan;
1877  pathnode->path.parent = rel;
1878  pathnode->path.pathtarget = rel->reltarget;
1879  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1880  required_outer);
1881  pathnode->path.parallel_aware = false;
1882  pathnode->path.parallel_safe = rel->consider_parallel &&
1883  subpath->parallel_safe;
1884  pathnode->path.parallel_workers = subpath->parallel_workers;
1885  pathnode->path.pathkeys = pathkeys;
1886  pathnode->subpath = subpath;
1887 
1888  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info);
1889 
1890  return pathnode;
1891 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1284
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_tablefuncscan_path()

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

Definition at line 1925 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_tablefuncscan(), 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_TableFuncScan.

Referenced by set_tablefunc_pathlist().

1927 {
1928  Path *pathnode = makeNode(Path);
1929 
1930  pathnode->pathtype = T_TableFuncScan;
1931  pathnode->parent = rel;
1932  pathnode->pathtarget = rel->reltarget;
1933  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1934  required_outer);
1935  pathnode->parallel_aware = false;
1936  pathnode->parallel_safe = rel->consider_parallel;
1937  pathnode->parallel_workers = 0;
1938  pathnode->pathkeys = NIL; /* result is always unordered */
1939 
1940  cost_tablefuncscan(pathnode, root, rel, pathnode->param_info);
1941 
1942  return pathnode;
1943 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1394
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_tidscan_path()

TidPath* create_tidscan_path ( PlannerInfo root,
RelOptInfo rel,
List tidquals,
Relids  required_outer 
)

Definition at line 1188 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_tidscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, TidPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, T_TidScan, and TidPath::tidquals.

Referenced by create_tidscan_paths().

1190 {
1191  TidPath *pathnode = makeNode(TidPath);
1192 
1193  pathnode->path.pathtype = T_TidScan;
1194  pathnode->path.parent = rel;
1195  pathnode->path.pathtarget = rel->reltarget;
1196  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1197  required_outer);
1198  pathnode->path.parallel_aware = false;
1199  pathnode->path.parallel_safe = rel->consider_parallel;
1200  pathnode->path.parallel_workers = 0;
1201  pathnode->path.pathkeys = NIL; /* always unordered */
1202 
1203  pathnode->tidquals = tidquals;
1204 
1205  cost_tidscan(&pathnode->path, root, rel, tidquals,
1206  pathnode->path.param_info);
1207 
1208  return pathnode;
1209 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1181
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * tidquals
Definition: relation.h:1225
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
Path path
Definition: relation.h:1224
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_unique_path()

UniquePath* create_unique_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
SpecialJoinInfo sjinfo 
)

Definition at line 1522 of file pathnode.c.

References AGG_HASHED, Assert, bms_equal(), RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, cost_agg(), cost_sort(), cpu_operator_cost, estimate_num_groups(), GetMemoryChunkContext(), UniquePath::in_operators, JOIN_SEMI, SpecialJoinInfo::jointype, list_length(), makeNode, MemoryContextSwitchTo(), NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, UniquePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, planner_rt_fetch, query_is_distinct_for(), query_supports_distinctness(), relation_has_unique_index_for(), RelOptInfo::relid, RelOptInfo::relids, RelOptInfo::reltarget, RelOptInfo::rows, Path::rows, RTE_RELATION, RTE_SUBQUERY, RelOptInfo::rtekind, SpecialJoinInfo::semi_can_btree, SpecialJoinInfo::semi_can_hash, SpecialJoinInfo::semi_operators, SpecialJoinInfo::semi_rhs_exprs, Path::startup_cost, subpath(), UniquePath::subpath, RangeTblEntry::subquery, SpecialJoinInfo::syn_righthand, T_Unique, Path::total_cost, translate_sub_tlist(), UniquePath::umethod, UniquePath::uniq_exprs, UNIQUE_PATH_HASH, UNIQUE_PATH_NOOP, UNIQUE_PATH_SORT, PathTarget::width, and work_mem.

Referenced by consider_parallel_nestloop(), hash_inner_and_outer(), join_is_legal(), match_unsorted_outer(), populate_joinrel_with_paths(), and sort_inner_and_outer().

1524 {
1525  UniquePath *pathnode;
1526  Path sort_path; /* dummy for result of cost_sort */
1527  Path agg_path; /* dummy for result of cost_agg */
1528  MemoryContext oldcontext;
1529  int numCols;
1530 
1531  /* Caller made a mistake if subpath isn't cheapest_total ... */
1532  Assert(subpath == rel->cheapest_total_path);
1533  Assert(subpath->parent == rel);
1534  /* ... or if SpecialJoinInfo is the wrong one */
1535  Assert(sjinfo->jointype == JOIN_SEMI);
1536  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1537 
1538  /* If result already cached, return it */
1539  if (rel->cheapest_unique_path)
1540  return (UniquePath *) rel->cheapest_unique_path;
1541 
1542  /* If it's not possible to unique-ify, return NULL */
1543  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1544  return NULL;
1545 
1546  /*
1547  * When called during GEQO join planning, we are in a short-lived memory
1548  * context. We must make sure that the path and any subsidiary data
1549  * structures created for a baserel survive the GEQO cycle, else the
1550  * baserel is trashed for future GEQO cycles. On the other hand, when we
1551  * are creating those for a joinrel during GEQO, we don't want them to
1552  * clutter the main planning context. Upshot is that the best solution is
1553  * to explicitly allocate memory in the same context the given RelOptInfo
1554  * is in.
1555  */
1556  oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
1557 
1558  pathnode = makeNode(UniquePath);
1559 
1560  pathnode->path.pathtype = T_Unique;
1561  pathnode->path.parent = rel;
1562  pathnode->path.pathtarget = rel->reltarget;
1563  pathnode->path.param_info = subpath->param_info;
1564  pathnode->path.parallel_aware = false;
1565  pathnode->path.parallel_safe = rel->consider_parallel &&
1566  subpath->parallel_safe;
1567  pathnode->path.parallel_workers = subpath->parallel_workers;
1568 
1569  /*
1570  * Assume the output is unsorted, since we don't necessarily have pathkeys
1571  * to represent it. (This might get overridden below.)
1572  */
1573  pathnode->path.pathkeys = NIL;
1574 
1575  pathnode->subpath = subpath;
1576  pathnode->in_operators = sjinfo->semi_operators;
1577  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1578 
1579  /*
1580  * If the input is a relation and it has a unique index that proves the
1581  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1582  * that relation_has_unique_index_for automatically considers restriction
1583  * clauses for the rel, as well.
1584  */
1585  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1587  sjinfo->semi_rhs_exprs,
1588  sjinfo->semi_operators))
1589  {
1590  pathnode->umethod = UNIQUE_PATH_NOOP;
1591  pathnode->path.rows = rel->rows;
1592  pathnode->path.startup_cost = subpath->startup_cost;
1593  pathnode->path.total_cost = subpath->total_cost;
1594  pathnode->path.pathkeys = subpath->pathkeys;
1595 
1596  rel->cheapest_unique_path = (Path *) pathnode;
1597 
1598  MemoryContextSwitchTo(oldcontext);
1599 
1600  return pathnode;
1601  }
1602 
1603  /*
1604  * If the input is a subquery whose output must be unique already, then we
1605  * don't need to do anything. The test for uniqueness has to consider
1606  * exactly which columns we are extracting; for example "SELECT DISTINCT
1607  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1608  * this optimization unless semi_rhs_exprs consists only of simple Vars
1609  * referencing subquery outputs. (Possibly we could do something with
1610  * expressions in the subquery outputs, too, but for now keep it simple.)
1611  */
1612  if (rel->rtekind == RTE_SUBQUERY)
1613  {
1614  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1615 
1617  {
1618  List *sub_tlist_colnos;
1619 
1620  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1621  rel->relid);
1622 
1623  if (sub_tlist_colnos &&
1625  sub_tlist_colnos,
1626  sjinfo->semi_operators))
1627  {
1628  pathnode->umethod = UNIQUE_PATH_NOOP;
1629  pathnode->path.rows = rel->rows;
1630  pathnode->path.startup_cost = subpath->startup_cost;
1631  pathnode->path.total_cost = subpath->total_cost;
1632  pathnode->path.pathkeys = subpath->pathkeys;
1633 
1634  rel->cheapest_unique_path = (Path *) pathnode;
1635 
1636  MemoryContextSwitchTo(oldcontext);
1637 
1638  return pathnode;
1639  }
1640  }
1641  }
1642 
1643  /* Estimate number of output rows */
1644  pathnode->path.rows = estimate_num_groups(root,
1645  sjinfo->semi_rhs_exprs,
1646  rel->rows,
1647  NULL);
1648  numCols = list_length(sjinfo->semi_rhs_exprs);
1649 
1650  if (sjinfo->semi_can_btree)
1651  {
1652  /*
1653  * Estimate cost for sort+unique implementation
1654  */
1655  cost_sort(&sort_path, root, NIL,
1656  subpath->total_cost,
1657  rel->rows,
1658  subpath->pathtarget->width,
1659  0.0,
1660  work_mem,
1661  -1.0);
1662 
1663  /*
1664  * Charge one cpu_operator_cost per comparison per input tuple. We
1665  * assume all columns get compared at most of the tuples. (XXX
1666  * probably this is an overestimate.) This should agree with
1667  * create_upper_unique_path.
1668  */
1669  sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
1670  }
1671 
1672  if (sjinfo->semi_can_hash)
1673  {
1674  /*
1675  * Estimate the overhead per hashtable entry at 64 bytes (same as in
1676  * planner.c).
1677  */
1678  int hashentrysize = subpath->pathtarget->width + 64;
1679 
1680  if (hashentrysize * pathnode->path.rows > work_mem * 1024L)
1681  {
1682  /*
1683  * We should not try to hash. Hack the SpecialJoinInfo to
1684  * remember this, in case we come through here again.
1685  */
1686  sjinfo->semi_can_hash = false;
1687  }
1688  else
1689  cost_agg(&agg_path, root,
1690  AGG_HASHED, NULL,
1691  numCols, pathnode->path.rows,
1692  NIL,
1693  subpath->startup_cost,
1694  subpath->total_cost,
1695  rel->rows);
1696  }
1697 
1698  if (sjinfo->semi_can_btree && sjinfo->semi_can_hash)
1699  {
1700  if (agg_path.total_cost < sort_path.total_cost)
1701  pathnode->umethod = UNIQUE_PATH_HASH;
1702  else
1703  pathnode->umethod = UNIQUE_PATH_SORT;
1704  }
1705  else if (sjinfo->semi_can_btree)
1706  pathnode->umethod = UNIQUE_PATH_SORT;
1707  else if (sjinfo->semi_can_hash)
1708  pathnode->umethod = UNIQUE_PATH_HASH;
1709  else
1710  {
1711  /* we can get here only if we abandoned hashing above */
1712  MemoryContextSwitchTo(oldcontext);
1713  return NULL;
1714  }
1715 
1716  if (pathnode->umethod == UNIQUE_PATH_HASH)
1717  {
1718  pathnode->path.startup_cost = agg_path.startup_cost;
1719  pathnode->path.total_cost = agg_path.total_cost;
1720  }
1721  else
1722  {
1723  pathnode->path.startup_cost = sort_path.startup_cost;
1724  pathnode->path.total_cost = sort_path.total_cost;
1725  }
1726 
1727  rel->cheapest_unique_path = (Path *) pathnode;
1728 
1729  MemoryContextSwitchTo(oldcontext);
1730 
1731  return pathnode;
1732 }
struct Path * cheapest_unique_path
Definition: relation.h:631
#define NIL
Definition: pg_list.h:69
bool semi_can_btree
Definition: relation.h:2074
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset)
Definition: selfuncs.c:3419
PathTarget * pathtarget
Definition: relation.h:1079
bool query_is_distinct_for(Query *query, List *colnos, List *opids)
Definition: analyzejoins.c:782
Definition: nodes.h:80
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)
Definition: costsize.c:2060
int parallel_workers
Definition: relation.h:1085
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ParamPathInfo * param_info
Definition: relation.h:1081