PostgreSQL Source Code  git master
pathnode.c File Reference
#include "postgres.h"
#include <math.h>
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "nodes/extensible.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 "foreign/fdwapi.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 (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, 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, PathTarget *target, 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, PathTarget *target, 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, 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:512
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: prepunion.c:2433
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:560

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

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

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 CHECK_FOR_INTERRUPTS, compare_pathkeys(), lappend_cell(), lcons(), lfirst, list_delete_cell(), list_head(), lnext, 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_grouping_paths(), create_partial_bitmap_paths(), create_plain_partial_paths(), 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  /*
774  * As in add_path, throw out any paths which are dominated by the new
775  * path, but throw out the new path if some existing path dominates it.
776  */
777  p1_prev = NULL;
778  for (p1 = list_head(parent_rel->partial_pathlist); p1 != NULL;
779  p1 = p1_next)
780  {
781  Path *old_path = (Path *) lfirst(p1);
782  bool remove_old = false; /* unless new proves superior */
783  PathKeysComparison keyscmp;
784 
785  p1_next = lnext(p1);
786 
787  /* Compare pathkeys. */
788  keyscmp = compare_pathkeys(new_path->pathkeys, old_path->pathkeys);
789 
790  /* Unless pathkeys are incompable, keep just one of the two paths. */
791  if (keyscmp != PATHKEYS_DIFFERENT)
792  {
793  if (new_path->total_cost > old_path->total_cost * STD_FUZZ_FACTOR)
794  {
795  /* New path costs more; keep it only if pathkeys are better. */
796  if (keyscmp != PATHKEYS_BETTER1)
797  accept_new = false;
798  }
799  else if (old_path->total_cost > new_path->total_cost
800  * STD_FUZZ_FACTOR)
801  {
802  /* Old path costs more; keep it only if pathkeys are better. */
803  if (keyscmp != PATHKEYS_BETTER2)
804  remove_old = true;
805  }
806  else if (keyscmp == PATHKEYS_BETTER1)
807  {
808  /* Costs are about the same, new path has better pathkeys. */
809  remove_old = true;
810  }
811  else if (keyscmp == PATHKEYS_BETTER2)
812  {
813  /* Costs are about the same, old path has better pathkeys. */
814  accept_new = false;
815  }
816  else if (old_path->total_cost > new_path->total_cost * 1.0000000001)
817  {
818  /* Pathkeys are the same, and the old path costs more. */
819  remove_old = true;
820  }
821  else
822  {
823  /*
824  * Pathkeys are the same, and new path isn't materially
825  * cheaper.
826  */
827  accept_new = false;
828  }
829  }
830 
831  /*
832  * Remove current element from partial_pathlist if dominated by new.
833  */
834  if (remove_old)
835  {
836  parent_rel->partial_pathlist =
837  list_delete_cell(parent_rel->partial_pathlist, p1, p1_prev);
838  pfree(old_path);
839  /* p1_prev does not advance */
840  }
841  else
842  {
843  /* new belongs after this old path if it has cost >= old's */
844  if (new_path->total_cost >= old_path->total_cost)
845  insert_after = p1;
846  /* p1_prev advances */
847  p1_prev = p1;
848  }
849 
850  /*
851  * If we found an old path that dominates new_path, we can quit
852  * scanning the partial_pathlist; we will not add new_path, and we
853  * assume new_path cannot dominate any later path.
854  */
855  if (!accept_new)
856  break;
857  }
858 
859  if (accept_new)
860  {
861  /* Accept the new path: insert it at proper place */
862  if (insert_after)
863  lappend_cell(parent_rel->partial_pathlist, insert_after, new_path);
864  else
865  parent_rel->partial_pathlist =
866  lcons(new_path, parent_rel->partial_pathlist);
867  }
868  else
869  {
870  /* Reject and recycle the new path */
871  pfree(new_path);
872  }
873 }
List * partial_pathlist
Definition: relation.h:601
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:936
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:1054
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:1056
#define lfirst(lc)
Definition: pg_list.h:106
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
#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 886 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().

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

References BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, bms_subset_compare(), CHECK_FOR_INTERRUPTS, compare_path_costs_fuzzily(), compare_pathkeys(), COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT, COSTS_EQUAL, 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_with_pathkeys_for_rel(), consider_groupingsets_paths(), create_distinct_paths(), create_grouping_paths(), create_index_paths(), create_one_window_path(), create_ordered_paths(), create_tidscan_paths(), fileGetForeignPaths(), generate_gather_paths(), generate_mergeappend_paths(), get_index_paths(), grouping_planner(), inheritance_planner(), mark_dummy_rel(), plan_set_operations(), postgresGetForeignJoinPaths(), postgresGetForeignPaths(), preprocess_minmax_aggregates(), query_planner(), 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:563
ParamPathInfo * param_info
Definition: relation.h:1045
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:936
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:345
Cost total_cost
Definition: relation.h:1054
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:1056
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:98
List * pathlist
Definition: relation.h:599
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:592
ParamPathInfo * param_info
Definition: relation.h:1045
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
bool consider_startup
Definition: relation.h:591
Cost startup_cost
Definition: relation.h:1053
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define lfirst(lc)
Definition: pg_list.h:106
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
List * pathlist
Definition: relation.h:599
Definition: pg_list.h:45
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ append_startup_cost_compare()

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

Definition at line 1298 of file pathnode.c.

References lfirst, and Path::startup_cost.

Referenced by create_append_path().

1299 {
1300  Path *path1 = (Path *) lfirst(*(ListCell **) a);
1301  Path *path2 = (Path *) lfirst(*(ListCell **) b);
1302 
1303  if (path1->startup_cost > path2->startup_cost)
1304  return -1;
1305  if (path1->startup_cost < path2->startup_cost)
1306  return 1;
1307 
1308  return 0;
1309 }
Cost startup_cost
Definition: relation.h:1053
#define lfirst(lc)
Definition: pg_list.h:106

◆ append_total_cost_compare()

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

Definition at line 1280 of file pathnode.c.

References lfirst, and Path::total_cost.

Referenced by create_append_path().

1281 {
1282  Path *path1 = (Path *) lfirst(*(ListCell **) a);
1283  Path *path2 = (Path *) lfirst(*(ListCell **) b);
1284 
1285  if (path1->total_cost > path2->total_cost)
1286  return -1;
1287  if (path1->total_cost < path2->total_cost)
1288  return 1;
1289 
1290  return 0;
1291 }
Cost total_cost
Definition: relation.h:1054
#define lfirst(lc)
Definition: pg_list.h:106

◆ apply_projection_to_path()

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

Definition at line 2442 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(), grouping_planner(), and recurse_set_operations().

2446 {
2447  QualCost oldcost;
2448 
2449  /*
2450  * If given path can't project, we might need a Result node, so make a
2451  * separate ProjectionPath.
2452  */
2453  if (!is_projection_capable_path(path))
2454  return (Path *) create_projection_path(root, rel, path, target);
2455 
2456  /*
2457  * We can just jam the desired tlist into the existing path, being sure to
2458  * update its cost estimates appropriately.
2459  */
2460  oldcost = path->pathtarget->cost;
2461  path->pathtarget = target;
2462 
2463  path->startup_cost += target->cost.startup - oldcost.startup;
2464  path->total_cost += target->cost.startup - oldcost.startup +
2465  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2466 
2467  /*
2468  * If the path happens to be a Gather or GatherMerge path, we'd like to
2469  * arrange for the subpath to return the required target list so that
2470  * workers can help project. But if there is something that is not
2471  * parallel-safe in the target expressions, then we can't.
2472  */
2473  if ((IsA(path, GatherPath) ||IsA(path, GatherMergePath)) &&
2474  is_parallel_safe(root, (Node *) target->exprs))
2475  {
2476  /*
2477  * We always use create_projection_path here, even if the subpath is
2478  * projection-capable, so as to avoid modifying the subpath in place.
2479  * It seems unlikely at present that there could be any other
2480  * references to the subpath, but better safe than sorry.
2481  *
2482  * Note that we don't change the parallel path's cost estimates; it
2483  * might be appropriate to do so, to reflect the fact that the bulk of
2484  * the target evaluation will happen in workers.
2485  */
2486  if (IsA(path, GatherPath))
2487  {
2488  GatherPath *gpath = (GatherPath *) path;
2489 
2490  gpath->subpath = (Path *)
2492  gpath->subpath->parent,
2493  gpath->subpath,
2494  target);
2495  }
2496  else
2497  {
2498  GatherMergePath *gmpath = (GatherMergePath *) path;
2499 
2500  gmpath->subpath = (Path *)
2502  gmpath->subpath->parent,
2503  gmpath->subpath,
2504  target);
2505  }
2506  }
2507  else if (path->parallel_safe &&
2508  !is_parallel_safe(root, (Node *) target->exprs))
2509  {
2510  /*
2511  * We're inserting a parallel-restricted target list into a path
2512  * currently marked parallel-safe, so we have to mark it as no longer
2513  * safe.
2514  */
2515  path->parallel_safe = false;
2516  }
2517 
2518  return path;
2519 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:563
PathTarget * pathtarget
Definition: relation.h:1043
Definition: nodes.h:512
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2351
Cost startup
Definition: relation.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1359
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
Path * subpath
Definition: relation.h:1372
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6573

◆ calc_nestloop_required_outer()

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

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

2072 {
2073  Relids required_outer;
2074 
2075  /* inner_path can require rels from outer path, but not vice versa */
2076  Assert(!bms_overlap(outer_paramrels, innerrelids));
2077  /* easy case if inner path is not parameterized */
2078  if (!inner_paramrels)
2079  return bms_copy(outer_paramrels);
2080  /* else, form the union ... */
2081  required_outer = bms_union(outer_paramrels, inner_paramrels);
2082  /* ... and remove any mention of now-satisfied outer rels */
2083  required_outer = bms_del_members(required_outer,
2084  outerrelids);
2085  /* maintain invariant that required_outer is exactly NULL if empty */
2086  if (bms_is_empty(required_outer))
2087  {
2088  bms_free(required_outer);
2089  required_outer = NULL;
2090  }
2091  return required_outer;
2092 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
#define Assert(condition)
Definition: c.h:680
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:889
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2102 {
2103  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2104  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2105  Relids required_outer;
2106 
2107  /* neither path can require rels from the other */
2108  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2109  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2110  /* form the union ... */
2111  required_outer = bms_union(outer_paramrels, inner_paramrels);
2112  /* we do not need an explicit test for empty; bms_union gets it right */
2113  return required_outer;
2114 }
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
#define Assert(condition)
Definition: c.h:680
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443

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

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

◆ 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:1053
Cost total_cost
Definition: relation.h:1054
#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 2753 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 create_distinct_paths(), create_grouping_paths(), and make_union_unique().

2763 {
2764  AggPath *pathnode = makeNode(AggPath);
2765 
2766  pathnode->path.pathtype = T_Agg;
2767  pathnode->path.parent = rel;
2768  pathnode->path.pathtarget = target;
2769  /* For now, assume we are above any joins, so no parameterization */
2770  pathnode->path.param_info = NULL;
2771  pathnode->path.parallel_aware = false;
2772  pathnode->path.parallel_safe = rel->consider_parallel &&
2773  subpath->parallel_safe;
2774  pathnode->path.parallel_workers = subpath->parallel_workers;
2775  if (aggstrategy == AGG_SORTED)
2776  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2777  else
2778  pathnode->path.pathkeys = NIL; /* output is unordered */
2779  pathnode->subpath = subpath;
2780 
2781  pathnode->aggstrategy = aggstrategy;
2782  pathnode->aggsplit = aggsplit;
2783  pathnode->numGroups = numGroups;
2784  pathnode->groupClause = groupClause;
2785  pathnode->qual = qual;
2786 
2787  cost_agg(&pathnode->path, root,
2788  aggstrategy, aggcosts,
2789  list_length(groupClause), numGroups,
2790  qual,
2791  subpath->startup_cost, subpath->total_cost,
2792  subpath->rows);
2793 
2794  /* add tlist eval cost for each output row */
2795  pathnode->path.startup_cost += target->cost.startup;
2796  pathnode->path.total_cost += target->cost.startup +
2797  target->cost.per_tuple * pathnode->path.rows;
2798 
2799  return pathnode;
2800 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1043
AggStrategy aggstrategy
Definition: relation.h:1555
List * qual
Definition: relation.h:1559
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:2038
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
AggSplit aggsplit
Definition: relation.h:1556
double numGroups
Definition: relation.h:1557
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * groupClause
Definition: relation.h:1558
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Path * subpath
Definition: relation.h:1554
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1553
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_append_path()

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

Definition at line 1213 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(), 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, RelOptInfo::reltarget, Path::rows, subpath(), AppendPath::subpaths, and T_Append.

Referenced by add_paths_to_append_rel(), create_grouping_paths(), generate_nonunion_path(), generate_union_path(), mark_dummy_rel(), and set_dummy_rel_pathlist().

1218 {
1219  AppendPath *pathnode = makeNode(AppendPath);
1220  ListCell *l;
1221 
1222  Assert(!parallel_aware || parallel_workers > 0);
1223 
1224  pathnode->path.pathtype = T_Append;
1225  pathnode->path.parent = rel;
1226  pathnode->path.pathtarget = rel->reltarget;
1228  required_outer);
1229  pathnode->path.parallel_aware = parallel_aware;
1230  pathnode->path.parallel_safe = rel->consider_parallel;
1231  pathnode->path.parallel_workers = parallel_workers;
1232  pathnode->path.pathkeys = NIL; /* result is always considered unsorted */
1233  pathnode->partitioned_rels = list_copy(partitioned_rels);
1234 
1235  /*
1236  * For parallel append, non-partial paths are sorted by descending total
1237  * costs. That way, the total time to finish all non-partial paths is
1238  * minimized. Also, the partial paths are sorted by descending startup
1239  * costs. There may be some paths that require to do startup work by a
1240  * single worker. In such case, it's better for workers to choose the
1241  * expensive ones first, whereas the leader should choose the cheapest
1242  * startup plan.
1243  */
1244  if (pathnode->path.parallel_aware)
1245  {
1246  subpaths = list_qsort(subpaths, append_total_cost_compare);
1247  partial_subpaths = list_qsort(partial_subpaths,
1249  }
1250  pathnode->first_partial_path = list_length(subpaths);
1251  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1252 
1253  foreach(l, subpaths)
1254  {
1255  Path *subpath = (Path *) lfirst(l);
1256 
1257  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1258  subpath->parallel_safe;
1259 
1260  /* All child paths must have same parameterization */
1261  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1262  }
1263 
1264  Assert(!parallel_aware || pathnode->path.parallel_safe);
1265 
1266  cost_append(pathnode);
1267 
1268  /* If the caller provided a row estimate, override the computed value. */
1269  if (rows >= 0)
1270  pathnode->path.rows = rows;
1271 
1272  return pathnode;
1273 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:48
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Path path
Definition: relation.h:1268
int first_partial_path
Definition: relation.h:1274
NodeTag pathtype
Definition: relation.h:1040
List * subpaths
Definition: relation.h:1271
RelOptInfo * parent
Definition: relation.h:1042
static int append_total_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1280
static int append_startup_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1298
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
void cost_append(AppendPath *apath)
Definition: costsize.c:1834
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
List * partitioned_rels
Definition: relation.h:1270
List * list_qsort(const List *list, list_qsort_comparator cmp)
Definition: list.c:1258
bool parallel_aware
Definition: relation.h:1047
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1544
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

◆ create_bitmap_and_path()

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

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

1113 {
1114  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1115 
1116  pathnode->path.pathtype = T_BitmapAnd;
1117  pathnode->path.parent = rel;
1118  pathnode->path.pathtarget = rel->reltarget;
1119  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1120 
1121  /*
1122  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1123  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1124  * set the flag for this path based only on the relation-level flag,
1125  * without actually iterating over the list of children.
1126  */
1127  pathnode->path.parallel_aware = false;
1128  pathnode->path.parallel_safe = rel->consider_parallel;
1129  pathnode->path.parallel_workers = 0;
1130 
1131  pathnode->path.pathkeys = NIL; /* always unordered */
1132 
1133  pathnode->bitmapquals = bitmapquals;
1134 
1135  /* this sets bitmapselectivity as well as the regular cost fields: */
1136  cost_bitmap_and_node(pathnode, root);
1137 
1138  return pathnode;
1139 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1076
ParamPathInfo * param_info
Definition: relation.h:1045
List * bitmapquals
Definition: relation.h:1162
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

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

1083 {
1084  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1085 
1086  pathnode->path.pathtype = T_BitmapHeapScan;
1087  pathnode->path.parent = rel;
1088  pathnode->path.pathtarget = rel->reltarget;
1089  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1090  required_outer);
1091  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1092  pathnode->path.parallel_safe = rel->consider_parallel;
1093  pathnode->path.parallel_workers = parallel_degree;
1094  pathnode->path.pathkeys = NIL; /* always unordered */
1095 
1096  pathnode->bitmapqual = bitmapqual;
1097 
1098  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1099  pathnode->path.param_info,
1100  bitmapqual, loop_count);
1101 
1102  return pathnode;
1103 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:932
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
#define true
Definition: c.h:261
RelOptInfo * parent
Definition: relation.h:1042
Path * bitmapqual
Definition: relation.h:1150
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_bitmap_or_path()

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

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

1149 {
1150  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1151 
1152  pathnode->path.pathtype = T_BitmapOr;
1153  pathnode->path.parent = rel;
1154  pathnode->path.pathtarget = rel->reltarget;
1155  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1156 
1157  /*
1158  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1159  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1160  * set the flag for this path based only on the relation-level flag,
1161  * without actually iterating over the list of children.
1162  */
1163  pathnode->path.parallel_aware = false;
1164  pathnode->path.parallel_safe = rel->consider_parallel;
1165  pathnode->path.parallel_workers = 0;
1166 
1167  pathnode->path.pathkeys = NIL; /* always unordered */
1168 
1169  pathnode->bitmapquals = bitmapquals;
1170 
1171  /* this sets bitmapselectivity as well as the regular cost fields: */
1172  cost_bitmap_or_node(pathnode, root);
1173 
1174  return pathnode;
1175 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * bitmapquals
Definition: relation.h:1175
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1120
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_ctescan_path()

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

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

1948 {
1949  Path *pathnode = makeNode(Path);
1950 
1951  pathnode->pathtype = T_CteScan;
1952  pathnode->parent = rel;
1953  pathnode->pathtarget = rel->reltarget;
1954  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1955  required_outer);
1956  pathnode->parallel_aware = false;
1957  pathnode->parallel_safe = rel->consider_parallel;
1958  pathnode->parallel_workers = 0;
1959  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1960 
1961  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1962 
1963  return pathnode;
1964 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1487
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

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

2039 {
2040  ForeignPath *pathnode = makeNode(ForeignPath);
2041 
2042  pathnode->path.pathtype = T_ForeignScan;
2043  pathnode->path.parent = rel;
2044  pathnode->path.pathtarget = target ? target : rel->reltarget;
2045  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2046  required_outer);
2047  pathnode->path.parallel_aware = false;
2048  pathnode->path.parallel_safe = rel->consider_parallel;
2049  pathnode->path.parallel_workers = 0;
2050  pathnode->path.rows = rows;
2051  pathnode->path.startup_cost = startup_cost;
2052  pathnode->path.total_cost = total_cost;
2053  pathnode->path.pathkeys = pathkeys;
2054 
2055  pathnode->fdw_outerpath = fdw_outerpath;
2056  pathnode->fdw_private = fdw_private;
2057 
2058  return pathnode;
2059 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
Path * fdw_outerpath
Definition: relation.h:1219
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
List * fdw_private
Definition: relation.h:1220
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_functionscan_path()

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

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

1871 {
1872  Path *pathnode = makeNode(Path);
1873 
1874  pathnode->pathtype = T_FunctionScan;
1875  pathnode->parent = rel;
1876  pathnode->pathtarget = rel->reltarget;
1877  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1878  required_outer);
1879  pathnode->parallel_aware = false;
1880  pathnode->parallel_safe = rel->consider_parallel;
1881  pathnode->parallel_workers = 0;
1882  pathnode->pathkeys = pathkeys;
1883 
1884  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1885 
1886  return pathnode;
1887 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1320
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ 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 1711 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_grouping_paths(), create_ordered_paths(), and generate_gather_paths().

1714 {
1716  Cost input_startup_cost = 0;
1717  Cost input_total_cost = 0;
1718 
1719  Assert(subpath->parallel_safe);
1720  Assert(pathkeys);
1721 
1722  pathnode->path.pathtype = T_GatherMerge;
1723  pathnode->path.parent = rel;
1724  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1725  required_outer);
1726  pathnode->path.parallel_aware = false;
1727 
1728  pathnode->subpath = subpath;
1729  pathnode->num_workers = subpath->parallel_workers;
1730  pathnode->path.pathkeys = pathkeys;
1731  pathnode->path.pathtarget = target ? target : rel->reltarget;
1732  pathnode->path.rows += subpath->rows;
1733 
1734  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1735  {
1736  /* Subpath is adequately ordered, we won't need to sort it */
1737  input_startup_cost += subpath->startup_cost;
1738  input_total_cost += subpath->total_cost;
1739  }
1740  else
1741  {
1742  /* We'll need to insert a Sort node, so include cost for that */
1743  Path sort_path; /* dummy for result of cost_sort */
1744 
1745  cost_sort(&sort_path,
1746  root,
1747  pathkeys,
1748  subpath->total_cost,
1749  subpath->rows,
1750  subpath->pathtarget->width,
1751  0.0,
1752  work_mem,
1753  -1);
1754  input_startup_cost += sort_path.startup_cost;
1755  input_total_cost += sort_path.total_cost;
1756  }
1757 
1758  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1759  input_startup_cost, input_total_cost, rows);
1760 
1761  return pathnode;
1762 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
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:391
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
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:1648
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
Path * subpath
Definition: relation.h:1372
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
double Cost
Definition: nodes.h:643
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 1802 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 create_grouping_paths(), and generate_gather_paths().

1804 {
1805  GatherPath *pathnode = makeNode(GatherPath);
1806 
1807  Assert(subpath->parallel_safe);
1808 
1809  pathnode->path.pathtype = T_Gather;
1810  pathnode->path.parent = rel;
1811  pathnode->path.pathtarget = target;
1812  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1813  required_outer);
1814  pathnode->path.parallel_aware = false;
1815  pathnode->path.parallel_safe = false;
1816  pathnode->path.parallel_workers = 0;
1817  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1818 
1819  pathnode->subpath = subpath;
1820  pathnode->num_workers = subpath->parallel_workers;
1821  pathnode->single_copy = false;
1822 
1823  if (pathnode->num_workers == 0)
1824  {
1825  pathnode->path.pathkeys = subpath->pathkeys;
1826  pathnode->num_workers = 1;
1827  pathnode->single_copy = true;
1828  }
1829 
1830  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1831 
1832  return pathnode;
1833 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
bool single_copy
Definition: relation.h:1360
int num_workers
Definition: relation.h:1361
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1359
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
bool parallel_safe
Definition: relation.h:1048
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:353
Definition: nodes.h:80
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1358
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_group_path()

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

Definition at line 2642 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, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupPath::subpath, T_Group, and Path::total_cost.

Referenced by create_grouping_paths().

2649 {
2650  GroupPath *pathnode = makeNode(GroupPath);
2651 
2652  pathnode->path.pathtype = T_Group;
2653  pathnode->path.parent = rel;
2654  pathnode->path.pathtarget = target;
2655  /* For now, assume we are above any joins, so no parameterization */
2656  pathnode->path.param_info = NULL;
2657  pathnode->path.parallel_aware = false;
2658  pathnode->path.parallel_safe = rel->consider_parallel &&
2659  subpath->parallel_safe;
2660  pathnode->path.parallel_workers = subpath->parallel_workers;
2661  /* Group doesn't change sort ordering */
2662  pathnode->path.pathkeys = subpath->pathkeys;
2663 
2664  pathnode->subpath = subpath;
2665 
2666  pathnode->groupClause = groupClause;
2667  pathnode->qual = qual;
2668 
2669  cost_group(&pathnode->path, root,
2670  list_length(groupClause),
2671  numGroups,
2672  qual,
2673  subpath->startup_cost, subpath->total_cost,
2674  subpath->rows);
2675 
2676  /* add tlist eval cost for each output row */
2677  pathnode->path.startup_cost += target->cost.startup;
2678  pathnode->path.total_cost += target->cost.startup +
2679  target->cost.per_tuple * pathnode->path.rows;
2680 
2681  return pathnode;
2682 }
List * qual
Definition: relation.h:1528
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
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:2226
RelOptInfo * parent
Definition: relation.h:1042
Definition: nodes.h:76
Path path
Definition: relation.h:1525
List * groupClause
Definition: relation.h:1527
Path * subpath
Definition: relation.h:1526
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_groupingsets_path()

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

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

2828 {
2830  ListCell *lc;
2831  bool is_first = true;
2832  bool is_first_sort = true;
2833 
2834  /* The topmost generated Plan node will be an Agg */
2835  pathnode->path.pathtype = T_Agg;
2836  pathnode->path.parent = rel;
2837  pathnode->path.pathtarget = target;
2838  pathnode->path.param_info = subpath->param_info;
2839  pathnode->path.parallel_aware = false;
2840  pathnode->path.parallel_safe = rel->consider_parallel &&
2841  subpath->parallel_safe;
2842  pathnode->path.parallel_workers = subpath->parallel_workers;
2843  pathnode->subpath = subpath;
2844 
2845  /*
2846  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
2847  * to AGG_HASHED, here if possible.
2848  */
2849  if (aggstrategy == AGG_SORTED &&
2850  list_length(rollups) == 1 &&
2851  ((RollupData *) linitial(rollups))->groupClause == NIL)
2852  aggstrategy = AGG_PLAIN;
2853 
2854  if (aggstrategy == AGG_MIXED &&
2855  list_length(rollups) == 1)
2856  aggstrategy = AGG_HASHED;
2857 
2858  /*
2859  * Output will be in sorted order by group_pathkeys if, and only if, there
2860  * is a single rollup operation on a non-empty list of grouping
2861  * expressions.
2862  */
2863  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
2864  pathnode->path.pathkeys = root->group_pathkeys;
2865  else
2866  pathnode->path.pathkeys = NIL;
2867 
2868  pathnode->aggstrategy = aggstrategy;
2869  pathnode->rollups = rollups;
2870  pathnode->qual = having_qual;
2871 
2872  Assert(rollups != NIL);
2873  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
2874  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
2875 
2876  foreach(lc, rollups)
2877  {
2878  RollupData *rollup = lfirst(lc);
2879  List *gsets = rollup->gsets;
2880  int numGroupCols = list_length(linitial(gsets));
2881 
2882  /*
2883  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
2884  * (already-sorted) input, and following ones do their own sort.
2885  *
2886  * In AGG_HASHED mode, there is one rollup for each grouping set.
2887  *
2888  * In AGG_MIXED mode, the first rollups are hashed, the first
2889  * non-hashed one takes the (already-sorted) input, and following ones
2890  * do their own sort.
2891  */
2892  if (is_first)
2893  {
2894  cost_agg(&pathnode->path, root,
2895  aggstrategy,
2896  agg_costs,
2897  numGroupCols,
2898  rollup->numGroups,
2899  having_qual,
2900  subpath->startup_cost,
2901  subpath->total_cost,
2902  subpath->rows);
2903  is_first = false;
2904  if (!rollup->is_hashed)
2905  is_first_sort = false;
2906  }
2907  else
2908  {
2909  Path sort_path; /* dummy for result of cost_sort */
2910  Path agg_path; /* dummy for result of cost_agg */
2911 
2912  if (rollup->is_hashed || is_first_sort)
2913  {
2914  /*
2915  * Account for cost of aggregation, but don't charge input
2916  * cost again
2917  */
2918  cost_agg(&agg_path, root,
2919  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
2920  agg_costs,
2921  numGroupCols,
2922  rollup->numGroups,
2923  having_qual,
2924  0.0, 0.0,
2925  subpath->rows);
2926  if (!rollup->is_hashed)
2927  is_first_sort = false;
2928  }
2929  else
2930  {
2931  /* Account for cost of sort, but don't charge input cost again */
2932  cost_sort(&sort_path, root, NIL,
2933  0.0,
2934  subpath->rows,
2935  subpath->pathtarget->width,
2936  0.0,
2937  work_mem,
2938  -1.0);
2939 
2940  /* Account for cost of aggregation */
2941 
2942  cost_agg(&agg_path, root,
2943  AGG_SORTED,
2944  agg_costs,
2945  numGroupCols,
2946  rollup->numGroups,
2947  having_qual,
2948  sort_path.startup_cost,
2949  sort_path.total_cost,
2950  sort_path.rows);
2951  }
2952 
2953  pathnode->path.total_cost += agg_path.total_cost;
2954  pathnode->path.rows += agg_path.rows;
2955  }
2956  }
2957 
2958  /* add tlist eval cost for each output row */
2959  pathnode->path.startup_cost += target->cost.startup;
2960  pathnode->path.total_cost += target->cost.startup +
2961  target->cost.per_tuple * pathnode->path.rows;
2962 
2963  return pathnode;
2964 }
List * group_pathkeys
Definition: relation.h:264
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1043
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:2038
int parallel_workers
Definition: relation.h:1049
bool is_hashed
Definition: relation.h:1581
ParamPathInfo * param_info
Definition: relation.h:1045
double numGroups
Definition: relation.h:1579
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
#define linitial(l)
Definition: pg_list.h:111
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
AggStrategy aggstrategy
Definition: relation.h:1592
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:1648
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
Definition: pg_list.h:45
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
List * gsets
Definition: relation.h:1577

◆ create_hashjoin_path()

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

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

2297 {
2298  HashPath *pathnode = makeNode(HashPath);
2299 
2300  pathnode->jpath.path.pathtype = T_HashJoin;
2301  pathnode->jpath.path.parent = joinrel;
2302  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2303  pathnode->jpath.path.param_info =
2305  joinrel,
2306  outer_path,
2307  inner_path,
2308  extra->sjinfo,
2309  required_outer,
2310  &restrict_clauses);
2311  pathnode->jpath.path.parallel_aware = false;
2312  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2313  outer_path->parallel_safe && inner_path->parallel_safe;
2314  /* This is a foolish way to estimate parallel_workers, but for now... */
2315  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2316 
2317  /*
2318  * A hashjoin never has pathkeys, since its output ordering is
2319  * unpredictable due to possible batching. XXX If the inner relation is
2320  * small enough, we could instruct the executor that it must not batch,
2321  * and then we could assume that the output inherits the outer relation's
2322  * ordering, which might save a sort step. However there is considerable
2323  * downside if our estimate of the inner relation size is badly off. For
2324  * the moment we don't risk it. (Note also that if we wanted to take this
2325  * seriously, joinpath.c would have to consider many more paths for the
2326  * outer rel than it does now.)
2327  */
2328  pathnode->jpath.path.pathkeys = NIL;
2329  pathnode->jpath.jointype = jointype;
2330  pathnode->jpath.inner_unique = extra->inner_unique;
2331  pathnode->jpath.outerjoinpath = outer_path;
2332  pathnode->jpath.innerjoinpath = inner_path;
2333  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2334  pathnode->path_hashclauses = hashclauses;
2335  /* final_cost_hashjoin will fill in pathnode->num_batches */
2336 
2337  final_cost_hashjoin(root, pathnode, workspace, extra);
2338 
2339  return pathnode;
2340 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3221
JoinPath jpath
Definition: relation.h:1464
PathTarget * pathtarget
Definition: relation.h:1043
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:1340
Path * innerjoinpath
Definition: relation.h:1391
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
SpecialJoinInfo * sjinfo
Definition: relation.h:2279
List * joinrestrictinfo
Definition: relation.h:1393
RelOptInfo * parent
Definition: relation.h:1042
Path * outerjoinpath
Definition: relation.h:1390
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
Path path
Definition: relation.h:1383
bool parallel_safe
Definition: relation.h:1048
bool inner_unique
Definition: relation.h:1387
bool consider_parallel
Definition: relation.h:593
JoinType jointype
Definition: relation.h:1385
bool parallel_aware
Definition: relation.h:1047
List * path_hashclauses
Definition: relation.h:1465
struct PathTarget * reltarget
Definition: relation.h:596

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

1030 {
1031  IndexPath *pathnode = makeNode(IndexPath);
1032  RelOptInfo *rel = index->rel;
1033  List *indexquals,
1034  *indexqualcols;
1035 
1036  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1037  pathnode->path.parent = rel;
1038  pathnode->path.pathtarget = rel->reltarget;
1039  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1040  required_outer);
1041  pathnode->path.parallel_aware = false;
1042  pathnode->path.parallel_safe = rel->consider_parallel;
1043  pathnode->path.parallel_workers = 0;
1044  pathnode->path.pathkeys = pathkeys;
1045 
1046  /* Convert clauses to indexquals the executor can handle */
1047  expand_indexqual_conditions(index, indexclauses, indexclausecols,
1048  &indexquals, &indexqualcols);
1049 
1050  /* Fill in the pathnode */
1051  pathnode->indexinfo = index;
1052  pathnode->indexclauses = indexclauses;
1053  pathnode->indexquals = indexquals;
1054  pathnode->indexqualcols = indexqualcols;
1055  pathnode->indexorderbys = indexorderbys;
1056  pathnode->indexorderbycols = indexorderbycols;
1057  pathnode->indexscandir = indexscandir;
1058 
1059  cost_index(pathnode, root, loop_count, partial_path);
1060 
1061  return pathnode;
1062 }
List * indexorderbycols
Definition: relation.h:1124
PathTarget * pathtarget
Definition: relation.h:1043
Path path
Definition: relation.h:1118
IndexOptInfo * indexinfo
Definition: relation.h:1119
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * indexclauses
Definition: relation.h:1120
NodeTag pathtype
Definition: relation.h:1040
List * indexquals
Definition: relation.h:1121
RelOptInfo * rel
Definition: relation.h:721
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3526
RelOptInfo * parent
Definition: relation.h:1042
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:466
List * indexorderbys
Definition: relation.h:1123
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
List * indexqualcols
Definition: relation.h:1122
ScanDirection indexscandir
Definition: relation.h:1125
bool parallel_aware
Definition: relation.h:1047
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596

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

3382 {
3383  LimitPath *pathnode = makeNode(LimitPath);
3384 
3385  pathnode->path.pathtype = T_Limit;
3386  pathnode->path.parent = rel;
3387  /* Limit doesn't project, so use source path's pathtarget */
3388  pathnode->path.pathtarget = subpath->pathtarget;
3389  /* For now, assume we are above any joins, so no parameterization */
3390  pathnode->path.param_info = NULL;
3391  pathnode->path.parallel_aware = false;
3392  pathnode->path.parallel_safe = rel->consider_parallel &&
3393  subpath->parallel_safe;
3394  pathnode->path.parallel_workers = subpath->parallel_workers;
3395  pathnode->path.rows = subpath->rows;
3396  pathnode->path.startup_cost = subpath->startup_cost;
3397  pathnode->path.total_cost = subpath->total_cost;
3398  pathnode->path.pathkeys = subpath->pathkeys;
3399  pathnode->subpath = subpath;
3400  pathnode->limitOffset = limitOffset;
3401  pathnode->limitCount = limitCount;
3402 
3403  /*
3404  * Adjust the output rows count and costs according to the offset/limit.
3405  * This is only a cosmetic issue if we are at top level, but if we are
3406  * building a subquery then it's important to report correct info to the
3407  * outer planner.
3408  *
3409  * When the offset or count couldn't be estimated, use 10% of the
3410  * estimated number of rows emitted from the subpath.
3411  *
3412  * XXX we don't bother to add eval costs of the offset/limit expressions
3413  * themselves to the path costs. In theory we should, but in most cases
3414  * those expressions are trivial and it's just not worth the trouble.
3415  */
3416  if (offset_est != 0)
3417  {
3418  double offset_rows;
3419 
3420  if (offset_est > 0)
3421  offset_rows = (double) offset_est;
3422  else
3423  offset_rows = clamp_row_est(subpath->rows * 0.10);
3424  if (offset_rows > pathnode->path.rows)
3425  offset_rows = pathnode->path.rows;
3426  if (subpath->rows > 0)
3427  pathnode->path.startup_cost +=
3428  (subpath->total_cost - subpath->startup_cost)
3429  * offset_rows / subpath->rows;
3430  pathnode->path.rows -= offset_rows;
3431  if (pathnode->path.rows < 1)
3432  pathnode->path.rows = 1;
3433  }
3434 
3435  if (count_est != 0)
3436  {
3437  double count_rows;
3438 
3439  if (count_est > 0)
3440  count_rows = (double) count_est;
3441  else
3442  count_rows = clamp_row_est(subpath->rows * 0.10);
3443  if (count_rows > pathnode->path.rows)
3444  count_rows = pathnode->path.rows;
3445  if (subpath->rows > 0)
3446  pathnode->path.total_cost = pathnode->path.startup_cost +
3447  (subpath->total_cost - subpath->startup_cost)
3448  * count_rows / subpath->rows;
3449  pathnode->path.rows = count_rows;
3450  if (pathnode->path.rows < 1)
3451  pathnode->path.rows = 1;
3452  }
3453 
3454  return pathnode;
3455 }
PathTarget * pathtarget
Definition: relation.h:1043
Node * limitOffset
Definition: relation.h:1693
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
Path * subpath
Definition: relation.h:1692
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
Path path
Definition: relation.h:1691
bool parallel_aware
Definition: relation.h:1047
double clamp_row_est(double nrows)
Definition: costsize.c:177
Node * limitCount
Definition: relation.h:1694
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:85

◆ create_lockrows_path()

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

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

3221 {
3222  LockRowsPath *pathnode = makeNode(LockRowsPath);
3223 
3224  pathnode->path.pathtype = T_LockRows;
3225  pathnode->path.parent = rel;
3226  /* LockRows doesn't project, so use source path's pathtarget */
3227  pathnode->path.pathtarget = subpath->pathtarget;
3228  /* For now, assume we are above any joins, so no parameterization */
3229  pathnode->path.param_info = NULL;
3230  pathnode->path.parallel_aware = false;
3231  pathnode->path.parallel_safe = false;
3232  pathnode->path.parallel_workers = 0;
3233  pathnode->path.rows = subpath->rows;
3234 
3235  /*
3236  * The result cannot be assumed sorted, since locking might cause the sort
3237  * key columns to be replaced with new values.
3238  */
3239  pathnode->path.pathkeys = NIL;
3240 
3241  pathnode->subpath = subpath;
3242  pathnode->rowMarks = rowMarks;
3243  pathnode->epqParam = epqParam;
3244 
3245  /*
3246  * We should charge something extra for the costs of row locking and
3247  * possible refetches, but it's hard to say how much. For now, use
3248  * cpu_tuple_cost per row.
3249  */
3250  pathnode->path.startup_cost = subpath->startup_cost;
3251  pathnode->path.total_cost = subpath->total_cost +
3252  cpu_tuple_cost * subpath->rows;
3253 
3254  return pathnode;
3255 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * rowMarks
Definition: relation.h:1657
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1656
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1454 {
1455  MaterialPath *pathnode = makeNode(MaterialPath);
1456 
1457  Assert(subpath->parent == rel);
1458 
1459  pathnode->path.pathtype = T_Material;
1460  pathnode->path.parent = rel;
1461  pathnode->path.pathtarget = rel->reltarget;
1462  pathnode->path.param_info = subpath->param_info;
1463  pathnode->path.parallel_aware = false;
1464  pathnode->path.parallel_safe = rel->consider_parallel &&
1465  subpath->parallel_safe;
1466  pathnode->path.parallel_workers = subpath->parallel_workers;
1467  pathnode->path.pathkeys = subpath->pathkeys;
1468 
1469  pathnode->subpath = subpath;
1470 
1471  cost_material(&pathnode->path,
1472  subpath->startup_cost,
1473  subpath->total_cost,
1474  subpath->rows,
1475  subpath->pathtarget->width);
1476 
1477  return pathnode;
1478 }
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Path * subpath
Definition: relation.h:1320
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1984
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
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 1317 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().

1323 {
1325  Cost input_startup_cost;
1326  Cost input_total_cost;
1327  ListCell *l;
1328 
1329  pathnode->path.pathtype = T_MergeAppend;
1330  pathnode->path.parent = rel;
1331  pathnode->path.pathtarget = rel->reltarget;
1333  required_outer);
1334  pathnode->path.parallel_aware = false;
1335  pathnode->path.parallel_safe = rel->consider_parallel;
1336  pathnode->path.parallel_workers = 0;
1337  pathnode->path.pathkeys = pathkeys;
1338  pathnode->partitioned_rels = list_copy(partitioned_rels);
1339  pathnode->subpaths = subpaths;
1340 
1341  /*
1342  * Apply query-wide LIMIT if known and path is for sole base relation.
1343  * (Handling this at this low level is a bit klugy.)
1344  */
1345  if (bms_equal(rel->relids, root->all_baserels))
1346  pathnode->limit_tuples = root->limit_tuples;
1347  else
1348  pathnode->limit_tuples = -1.0;
1349 
1350  /*
1351  * Add up the sizes and costs of the input paths.
1352  */
1353  pathnode->path.rows = 0;
1354  input_startup_cost = 0;
1355  input_total_cost = 0;
1356  foreach(l, subpaths)
1357  {
1358  Path *subpath = (Path *) lfirst(l);
1359 
1360  pathnode->path.rows += subpath->rows;
1361  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1362  subpath->parallel_safe;
1363 
1364  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1365  {
1366  /* Subpath is adequately ordered, we won't need to sort it */
1367  input_startup_cost += subpath->startup_cost;
1368  input_total_cost += subpath->total_cost;
1369  }
1370  else
1371  {
1372  /* We'll need to insert a Sort node, so include cost for that */
1373  Path sort_path; /* dummy for result of cost_sort */
1374 
1375  cost_sort(&sort_path,
1376  root,
1377  pathkeys,
1378  subpath->total_cost,
1379  subpath->parent->tuples,
1380  subpath->pathtarget->width,
1381  0.0,
1382  work_mem,
1383  pathnode->limit_tuples);
1384  input_startup_cost += sort_path.startup_cost;
1385  input_total_cost += sort_path.total_cost;
1386  }
1387 
1388  /* All child paths must have same parameterization */
1389  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1390  }
1391 
1392  /* Now we can compute total costs of the MergeAppend */
1393  cost_merge_append(&pathnode->path, root,
1394  pathkeys, list_length(subpaths),
1395  input_startup_cost, input_total_cost,
1396  pathnode->path.rows);
1397 
1398  return pathnode;
1399 }
PathTarget * pathtarget
Definition: relation.h:1043
double tuples
Definition: relation.h:625
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partitioned_rels
Definition: relation.h:1293
NodeTag pathtype
Definition: relation.h:1040
Relids all_baserels
Definition: relation.h:196
double limit_tuples
Definition: relation.h:295
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
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:1648
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
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:1933
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
List * subpaths
Definition: relation.h:1294
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1544
struct PathTarget * reltarget
Definition: relation.h:596
double limit_tuples
Definition: relation.h:1295
double Cost
Definition: nodes.h:643
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131

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

2235 {
2236  MergePath *pathnode = makeNode(MergePath);
2237 
2238  pathnode->jpath.path.pathtype = T_MergeJoin;
2239  pathnode->jpath.path.parent = joinrel;
2240  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2241  pathnode->jpath.path.param_info =
2243  joinrel,
2244  outer_path,
2245  inner_path,
2246  extra->sjinfo,
2247  required_outer,
2248  &restrict_clauses);
2249  pathnode->jpath.path.parallel_aware = false;
2250  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2251  outer_path->parallel_safe && inner_path->parallel_safe;
2252  /* This is a foolish way to estimate parallel_workers, but for now... */
2253  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2254  pathnode->jpath.path.pathkeys = pathkeys;
2255  pathnode->jpath.jointype = jointype;
2256  pathnode->jpath.inner_unique = extra->inner_unique;
2257  pathnode->jpath.outerjoinpath = outer_path;
2258  pathnode->jpath.innerjoinpath = inner_path;
2259  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2260  pathnode->path_mergeclauses = mergeclauses;
2261  pathnode->outersortkeys = outersortkeys;
2262  pathnode->innersortkeys = innersortkeys;
2263  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2264  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2265 
2266  final_cost_mergejoin(root, pathnode, workspace, extra);
2267 
2268  return pathnode;
2269 }
List * path_mergeclauses
Definition: relation.h:1446
List * outersortkeys
Definition: relation.h:1447
PathTarget * pathtarget
Definition: relation.h:1043
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:1340
Path * innerjoinpath
Definition: relation.h:1391
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
SpecialJoinInfo * sjinfo
Definition: relation.h:2279
List * joinrestrictinfo
Definition: relation.h:1393
RelOptInfo * parent
Definition: relation.h:1042
Path * outerjoinpath
Definition: relation.h:1390
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
Path path
Definition: relation.h:1383
bool parallel_safe
Definition: relation.h:1048
bool inner_unique
Definition: relation.h:1387
bool consider_parallel
Definition: relation.h:593
List * innersortkeys
Definition: relation.h:1448
JoinType jointype
Definition: relation.h:1385
JoinPath jpath
Definition: relation.h:1445
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2808

◆ create_minmaxagg_path()

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

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

2981 {
2982  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2983  Cost initplan_cost;
2984  ListCell *lc;
2985 
2986  /* The topmost generated Plan node will be a Result */
2987  pathnode->path.pathtype = T_Result;
2988  pathnode->path.parent = rel;
2989  pathnode->path.pathtarget = target;
2990  /* For now, assume we are above any joins, so no parameterization */
2991  pathnode->path.param_info = NULL;
2992  pathnode->path.parallel_aware = false;
2993  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2994  pathnode->path.parallel_safe = false;
2995  pathnode->path.parallel_workers = 0;
2996  /* Result is one unordered row */
2997  pathnode->path.rows = 1;
2998  pathnode->path.pathkeys = NIL;
2999 
3000  pathnode->mmaggregates = mmaggregates;
3001  pathnode->quals = quals;
3002 
3003  /* Calculate cost of all the initplans ... */
3004  initplan_cost = 0;
3005  foreach(lc, mmaggregates)
3006  {
3007  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3008 
3009  initplan_cost += mminfo->pathcost;
3010  }
3011 
3012  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3013  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3014  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3015  target->cost.per_tuple + cpu_tuple_cost;
3016 
3017  /*
3018  * Add cost of qual, if any --- but we ignore its selectivity, since our
3019  * rowcount estimate should be 1 no matter what the qual is.
3020  */
3021  if (quals)
3022  {
3023  QualCost qual_cost;
3024 
3025  cost_qual_eval(&qual_cost, quals, root);
3026  pathnode->path.startup_cost += qual_cost.startup;
3027  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3028  }
3029 
3030  return pathnode;
3031 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * quals
Definition: relation.h:1604
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3672
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * mmaggregates
Definition: relation.h:1603
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
double Cost
Definition: nodes.h:643

◆ create_modifytable_path()

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

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

3286 {
3288  double total_size;
3289  ListCell *lc;
3290 
3291  Assert(list_length(resultRelations) == list_length(subpaths));
3292  Assert(list_length(resultRelations) == list_length(subroots));
3293  Assert(withCheckOptionLists == NIL ||
3294  list_length(resultRelations) == list_length(withCheckOptionLists));
3295  Assert(returningLists == NIL ||
3296  list_length(resultRelations) == list_length(returningLists));
3297 
3298  pathnode->path.pathtype = T_ModifyTable;
3299  pathnode->path.parent = rel;
3300  /* pathtarget is not interesting, just make it minimally valid */
3301  pathnode->path.pathtarget = rel->reltarget;
3302  /* For now, assume we are above any joins, so no parameterization */
3303  pathnode->path.param_info = NULL;
3304  pathnode->path.parallel_aware = false;
3305  pathnode->path.parallel_safe = false;
3306  pathnode->path.parallel_workers = 0;
3307  pathnode->path.pathkeys = NIL;
3308 
3309  /*
3310  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3311  *
3312  * Currently, we don't charge anything extra for the actual table
3313  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3314  * expressions if any. It would only be window dressing, since
3315  * ModifyTable is always a top-level node and there is no way for the
3316  * costs to change any higher-level planning choices. But we might want
3317  * to make it look better sometime.
3318  */
3319  pathnode->path.startup_cost = 0;
3320  pathnode->path.total_cost = 0;
3321  pathnode->path.rows = 0;
3322  total_size = 0;
3323  foreach(lc, subpaths)
3324  {
3325  Path *subpath = (Path *) lfirst(lc);
3326 
3327  if (lc == list_head(subpaths)) /* first node? */
3328  pathnode->path.startup_cost = subpath->startup_cost;
3329  pathnode->path.total_cost += subpath->total_cost;
3330  pathnode->path.rows += subpath->rows;
3331  total_size += subpath->pathtarget->width * subpath->rows;
3332  }
3333 
3334  /*
3335  * Set width to the average width of the subpath outputs. XXX this is
3336  * totally wrong: we should report zero if no RETURNING, else an average
3337  * of the RETURNING tlist widths. But it's what happened historically,
3338  * and improving it is a task for another day.
3339  */
3340  if (pathnode->path.rows > 0)
3341  total_size /= pathnode->path.rows;
3342  pathnode->path.pathtarget->width = rint(total_size);
3343 
3344  pathnode->operation = operation;
3345  pathnode->canSetTag = canSetTag;
3346  pathnode->nominalRelation = nominalRelation;
3347  pathnode->partitioned_rels = list_copy(partitioned_rels);
3348  pathnode->resultRelations = resultRelations;
3349  pathnode->subpaths = subpaths;
3350  pathnode->subroots = subroots;
3351  pathnode->withCheckOptionLists = withCheckOptionLists;
3352  pathnode->returningLists = returningLists;
3353  pathnode->rowMarks = rowMarks;
3354  pathnode->onconflict = onconflict;
3355  pathnode->epqParam = epqParam;
3356 
3357  return pathnode;
3358 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
List * returningLists
Definition: relation.h:1680
OnConflictExpr * onconflict
Definition: relation.h:1682
Index nominalRelation
Definition: relation.h:1673
List * rowMarks
Definition: relation.h:1681
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
List * subroots
Definition: relation.h:1678
RelOptInfo * parent
Definition: relation.h:1042
List * subpaths
Definition: relation.h:1677
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:1675
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1679
int width
Definition: relation.h:975
CmdType operation
Definition: relation.h:1671
List * resultRelations
Definition: relation.h:1676
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
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 1972 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().

1974 {
1975  Path *pathnode = makeNode(Path);
1976 
1977  pathnode->pathtype = T_NamedTuplestoreScan;
1978  pathnode->parent = rel;
1979  pathnode->pathtarget = rel->reltarget;
1980  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1981  required_outer);
1982  pathnode->parallel_aware = false;
1983  pathnode->parallel_safe = rel->consider_parallel;
1984  pathnode->parallel_workers = 0;
1985  pathnode->pathkeys = NIL; /* result is always unordered */
1986 
1987  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
1988 
1989  return pathnode;
1990 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1528
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

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

2144 {
2145  NestPath *pathnode = makeNode(NestPath);
2146  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2147 
2148  /*
2149  * If the inner path is parameterized by the outer, we must drop any
2150  * restrict_clauses that are due to be moved into the inner path. We have
2151  * to do this now, rather than postpone the work till createplan time,
2152  * because the restrict_clauses list can affect the size and cost
2153  * estimates for this path.
2154  */
2155  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2156  {
2157  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2158  inner_req_outer);
2159  List *jclauses = NIL;
2160  ListCell *lc;
2161 
2162  foreach(lc, restrict_clauses)
2163  {
2164  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2165 
2166  if (!join_clause_is_movable_into(rinfo,
2167  inner_path->parent->relids,
2168  inner_and_outer))
2169  jclauses = lappend(jclauses, rinfo);
2170  }
2171  restrict_clauses = jclauses;
2172  }
2173 
2174  pathnode->path.pathtype = T_NestLoop;
2175  pathnode->path.parent = joinrel;
2176  pathnode->path.pathtarget = joinrel->reltarget;
2177  pathnode->path.param_info =
2179  joinrel,
2180  outer_path,
2181  inner_path,
2182  extra->sjinfo,
2183  required_outer,
2184  &restrict_clauses);
2185  pathnode->path.parallel_aware = false;
2186  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2187  outer_path->parallel_safe && inner_path->parallel_safe;
2188  /* This is a foolish way to estimate parallel_workers, but for now... */
2189  pathnode->path.parallel_workers = outer_path->parallel_workers;
2190  pathnode->path.pathkeys = pathkeys;
2191  pathnode->jointype = jointype;
2192  pathnode->inner_unique = extra->inner_unique;
2193  pathnode->outerjoinpath = outer_path;
2194  pathnode->innerjoinpath = inner_path;
2195  pathnode->joinrestrictinfo = restrict_clauses;
2196 
2197  final_cost_nestloop(root, pathnode, workspace, extra);
2198 
2199  return pathnode;
2200 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
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:1340
Path * innerjoinpath
Definition: relation.h:1391
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2371
SpecialJoinInfo * sjinfo
Definition: relation.h:2279
List * joinrestrictinfo
Definition: relation.h:1393
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:510
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * outerjoinpath
Definition: relation.h:1390
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
Path path
Definition: relation.h:1383
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool inner_unique
Definition: relation.h:1387
bool consider_parallel
Definition: relation.h:593
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
JoinType jointype
Definition: relation.h:1385
bool parallel_aware
Definition: relation.h:1047
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_projection_path()

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

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

2355 {
2356  ProjectionPath *pathnode = makeNode(ProjectionPath);
2357  PathTarget *oldtarget = subpath->pathtarget;
2358 
2359  pathnode->path.pathtype = T_Result;
2360  pathnode->path.parent = rel;
2361  pathnode->path.pathtarget = target;
2362  /* For now, assume we are above any joins, so no parameterization */
2363  pathnode->path.param_info = NULL;
2364  pathnode->path.parallel_aware = false;
2365  pathnode->path.parallel_safe = rel->consider_parallel &&
2366  subpath->parallel_safe &&
2367  is_parallel_safe(root, (Node *) target->exprs);
2368  pathnode->path.parallel_workers = subpath->parallel_workers;
2369  /* Projection does not change the sort order */
2370  pathnode->path.pathkeys = subpath->pathkeys;
2371 
2372  pathnode->subpath = subpath;
2373 
2374  /*
2375  * We might not need a separate Result node. If the input plan node type
2376  * can project, we can just tell it to project something else. Or, if it
2377  * can't project but the desired target has the same expression list as
2378  * what the input will produce anyway, we can still give it the desired
2379  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2380  * Note: in the latter case, create_projection_plan has to recheck our
2381  * conclusion; see comments therein.
2382  */
2383  if (is_projection_capable_path(subpath) ||
2384  equal(oldtarget->exprs, target->exprs))
2385  {
2386  /* No separate Result node needed */
2387  pathnode->dummypp = true;
2388 
2389  /*
2390  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2391  */
2392  pathnode->path.rows = subpath->rows;
2393  pathnode->path.startup_cost = subpath->startup_cost +
2394  (target->cost.startup - oldtarget->cost.startup);
2395  pathnode->path.total_cost = subpath->total_cost +
2396  (target->cost.startup - oldtarget->cost.startup) +
2397  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2398  }
2399  else
2400  {
2401  /* We really do need the Result node */
2402  pathnode->dummypp = false;
2403 
2404  /*
2405  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2406  * evaluating the tlist. There is no qual to worry about.
2407  */
2408  pathnode->path.rows = subpath->rows;
2409  pathnode->path.startup_cost = subpath->startup_cost +
2410  target->cost.startup;
2411  pathnode->path.total_cost = subpath->total_cost +
2412  target->cost.startup +
2413  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2414  }
2415 
2416  return pathnode;
2417 }
PathTarget * pathtarget
Definition: relation.h:1043
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2984
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:512
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6573
bool parallel_aware
Definition: relation.h:1047
Path * subpath
Definition: relation.h:1486
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 3174 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().

3182 {
3184 
3185  pathnode->path.pathtype = T_RecursiveUnion;
3186  pathnode->path.parent = rel;
3187  pathnode->path.pathtarget = target;
3188  /* For now, assume we are above any joins, so no parameterization */
3189  pathnode->path.param_info = NULL;
3190  pathnode->path.parallel_aware = false;
3191  pathnode->path.parallel_safe = rel->consider_parallel &&
3192  leftpath->parallel_safe && rightpath->parallel_safe;
3193  /* Foolish, but we'll do it like joins for now: */
3194  pathnode->path.parallel_workers = leftpath->parallel_workers;
3195  /* RecursiveUnion result is always unsorted */
3196  pathnode->path.pathkeys = NIL;
3197 
3198  pathnode->leftpath = leftpath;
3199  pathnode->rightpath = rightpath;
3200  pathnode->distinctList = distinctList;
3201  pathnode->wtParam = wtParam;
3202  pathnode->numGroups = numGroups;
3203 
3204  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3205 
3206  return pathnode;
3207 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1568
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047

◆ create_result_path()

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

Definition at line 1409 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_grouping_paths(), and query_planner().

1411 {
1412  ResultPath *pathnode = makeNode(ResultPath);
1413 
1414  pathnode->path.pathtype = T_Result;
1415  pathnode->path.parent = rel;
1416  pathnode->path.pathtarget = target;
1417  pathnode->path.param_info = NULL; /* there are no other rels... */
1418  pathnode->path.parallel_aware = false;
1419  pathnode->path.parallel_safe = rel->consider_parallel;
1420  pathnode->path.parallel_workers = 0;
1421  pathnode->path.pathkeys = NIL;
1422  pathnode->quals = resconstantqual;
1423 
1424  /* Hardly worth defining a cost_result() function ... just do it */
1425  pathnode->path.rows = 1;
1426  pathnode->path.startup_cost = target->cost.startup;
1427  pathnode->path.total_cost = target->cost.startup +
1428  cpu_tuple_cost + target->cost.per_tuple;
1429 
1430  /*
1431  * Add cost of qual, if any --- but we ignore its selectivity, since our
1432  * rowcount estimate should be 1 no matter what the qual is.
1433  */
1434  if (resconstantqual)
1435  {
1436  QualCost qual_cost;
1437 
1438  cost_qual_eval(&qual_cost, resconstantqual, root);
1439  /* resconstantqual is evaluated once at startup */
1440  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1441  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1442  }
1443 
1444  return pathnode;
1445 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Path path
Definition: relation.h:1307
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3672
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
List * quals
Definition: relation.h:1308
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047

◆ create_samplescan_path()

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

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

974 {
975  Path *pathnode = makeNode(Path);
976 
977  pathnode->pathtype = T_SampleScan;
978  pathnode->parent = rel;
979  pathnode->pathtarget = rel->reltarget;
980  pathnode->param_info = get_baserel_parampathinfo(root, rel,
981  required_outer);
982  pathnode->parallel_aware = false;
983  pathnode->parallel_safe = rel->consider_parallel;
984  pathnode->parallel_workers = 0;
985  pathnode->pathkeys = NIL; /* samplescan has unordered result */
986 
987  cost_samplescan(pathnode, root, rel, pathnode->param_info);
988 
989  return pathnode;
990 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:278
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_seqscan_path()

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

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

950 {
951  Path *pathnode = makeNode(Path);
952 
953  pathnode->pathtype = T_SeqScan;
954  pathnode->parent = rel;
955  pathnode->pathtarget = rel->reltarget;
956  pathnode->param_info = get_baserel_parampathinfo(root, rel,
957  required_outer);
958  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
959  pathnode->parallel_safe = rel->consider_parallel;
960  pathnode->parallel_workers = parallel_workers;
961  pathnode->pathkeys = NIL; /* seqscan has unordered result */
962 
963  cost_seqscan(pathnode, root, rel, pathnode->param_info);
964 
965  return pathnode;
966 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
#define true
Definition: c.h:261
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:201
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_set_projection_path()

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

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

2535 {
2536  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2537  double tlist_rows;
2538  ListCell *lc;
2539 
2540  pathnode->path.pathtype = T_ProjectSet;
2541  pathnode->path.parent = rel;
2542  pathnode->path.pathtarget = target;
2543  /* For now, assume we are above any joins, so no parameterization */
2544  pathnode->path.param_info = NULL;
2545  pathnode->path.parallel_aware = false;
2546  pathnode->path.parallel_safe = rel->consider_parallel &&
2547  subpath->parallel_safe &&
2548  is_parallel_safe(root, (Node *) target->exprs);
2549  pathnode->path.parallel_workers = subpath->parallel_workers;
2550  /* Projection does not change the sort order XXX? */
2551  pathnode->path.pathkeys = subpath->pathkeys;
2552 
2553  pathnode->subpath = subpath;
2554 
2555  /*
2556  * Estimate number of rows produced by SRFs for each row of input; if
2557  * there's more than one in this node, use the maximum.
2558  */
2559  tlist_rows = 1;
2560  foreach(lc, target->exprs)
2561  {
2562  Node *node = (Node *) lfirst(lc);
2563  double itemrows;
2564 
2565  itemrows = expression_returns_set_rows(node);
2566  if (tlist_rows < itemrows)
2567  tlist_rows = itemrows;
2568  }
2569 
2570  /*
2571  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2572  * per input row, and half of cpu_tuple_cost for each added output row.
2573  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2574  * this estimate later.
2575  */
2576  pathnode->path.rows = subpath->rows * tlist_rows;
2577  pathnode->path.startup_cost = subpath->startup_cost +
2578  target->cost.startup;
2579  pathnode->path.total_cost = subpath->total_cost +
2580  target->cost.startup +
2581  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2582  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2583 
2584  return pathnode;
2585 }
PathTarget * pathtarget
Definition: relation.h:1043
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:802
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:512
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1498
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
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 3112 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_path().

3122 {
3123  SetOpPath *pathnode = makeNode(SetOpPath);
3124 
3125  pathnode->path.pathtype = T_SetOp;
3126  pathnode->path.parent = rel;
3127  /* SetOp doesn't project, so use source path's pathtarget */
3128  pathnode->path.pathtarget = subpath->pathtarget;
3129  /* For now, assume we are above any joins, so no parameterization */
3130  pathnode->path.param_info = NULL;
3131  pathnode->path.parallel_aware = false;
3132  pathnode->path.parallel_safe = rel->consider_parallel &&
3133  subpath->parallel_safe;
3134  pathnode->path.parallel_workers = subpath->parallel_workers;
3135  /* SetOp preserves the input sort order if in sort mode */
3136  pathnode->path.pathkeys =
3137  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3138 
3139  pathnode->subpath = subpath;
3140  pathnode->cmd = cmd;
3141  pathnode->strategy = strategy;
3142  pathnode->distinctList = distinctList;
3143  pathnode->flagColIdx = flagColIdx;
3144  pathnode->firstFlag = firstFlag;
3145  pathnode->numGroups = numGroups;
3146 
3147  /*
3148  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3149  * all columns get compared at most of the tuples.
3150  */
3151  pathnode->path.startup_cost = subpath->startup_cost;
3152  pathnode->path.total_cost = subpath->total_cost +
3153  cpu_operator_cost * subpath->rows * list_length(distinctList);
3154  pathnode->path.rows = outputRows;
3155 
3156  return pathnode;
3157 }
#define NIL
Definition: pg_list.h:69
List * distinctList
Definition: relation.h:1631
PathTarget * pathtarget
Definition: relation.h:1043
SetOpStrategy strategy
Definition: relation.h:1630
Path * subpath
Definition: relation.h:1628
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
double numGroups
Definition: relation.h:1634
NodeTag pathtype
Definition: relation.h:1040
SetOpCmd cmd
Definition: relation.h:1629
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
AttrNumber flagColIdx
Definition: relation.h:1632
double cpu_operator_cost
Definition: costsize.c:108
Cost total_cost
Definition: relation.h:1054
int firstFlag
Definition: relation.h:1633
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Definition: nodes.h:83
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1627

◆ create_sort_path()

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

Definition at line 2598 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 create_distinct_paths(), create_grouping_paths(), create_one_window_path(), create_ordered_paths(), generate_nonunion_path(), and make_union_unique().

2603 {
2604  SortPath *pathnode = makeNode(SortPath);
2605 
2606  pathnode->path.pathtype = T_Sort;
2607  pathnode->path.parent = rel;
2608  /* Sort doesn't project, so use source path's pathtarget */
2609  pathnode->path.pathtarget = subpath->pathtarget;
2610  /* For now, assume we are above any joins, so no parameterization */
2611  pathnode->path.param_info = NULL;
2612  pathnode->path.parallel_aware = false;
2613  pathnode->path.parallel_safe = rel->consider_parallel &&
2614  subpath->parallel_safe;
2615  pathnode->path.parallel_workers = subpath->parallel_workers;
2616  pathnode->path.pathkeys = pathkeys;
2617 
2618  pathnode->subpath = subpath;
2619 
2620  cost_sort(&pathnode->path, root, pathkeys,
2621  subpath->total_cost,
2622  subpath->rows,
2623  subpath->pathtarget->width,
2624  0.0, /* XXX comparison_cost shouldn't be 0? */
2625  work_mem, limit_tuples);
2626 
2627  return pathnode;
2628 }
PathTarget * pathtarget
Definition: relation.h:1043
Path * subpath
Definition: relation.h:1512
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:75
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
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:1648
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1511
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 1841 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().

1843 {
1845 
1846  pathnode->path.pathtype = T_SubqueryScan;
1847  pathnode->path.parent = rel;
1848  pathnode->path.pathtarget = rel->reltarget;
1849  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1850  required_outer);
1851  pathnode->path.parallel_aware = false;
1852  pathnode->path.parallel_safe = rel->consider_parallel &&
1853  subpath->parallel_safe;
1854  pathnode->path.parallel_workers = subpath->parallel_workers;
1855  pathnode->path.pathkeys = pathkeys;
1856  pathnode->subpath = subpath;
1857 
1858  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info);
1859 
1860  return pathnode;
1861 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1271
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
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 1895 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().

1897 {
1898  Path *pathnode = makeNode(Path);
1899 
1900  pathnode->pathtype = T_TableFuncScan;
1901  pathnode->parent = rel;
1902  pathnode->pathtarget = rel->reltarget;
1903  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1904  required_outer);
1905  pathnode->parallel_aware = false;
1906  pathnode->parallel_safe = rel->consider_parallel;
1907  pathnode->parallel_workers = 0;
1908  pathnode->pathkeys = NIL; /* result is always unordered */
1909 
1910  cost_tablefuncscan(pathnode, root, rel, pathnode->param_info);
1911 
1912  return pathnode;
1913 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1381
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_tidscan_path()

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

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

1184 {
1185  TidPath *pathnode = makeNode(TidPath);
1186 
1187  pathnode->path.pathtype = T_TidScan;
1188  pathnode->path.parent = rel;
1189  pathnode->path.pathtarget = rel->reltarget;
1190  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1191  required_outer);
1192  pathnode->path.parallel_aware = false;
1193  pathnode->path.parallel_safe = rel->consider_parallel;
1194  pathnode->path.parallel_workers = 0;
1195  pathnode->path.pathkeys = NIL; /* always unordered */
1196 
1197  pathnode->tidquals = tidquals;
1198 
1199  cost_tidscan(&pathnode->path, root, rel, tidquals,
1200  pathnode->path.param_info);
1201 
1202  return pathnode;
1203 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1168
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * tidquals
Definition: relation.h:1189
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
Path path
Definition: relation.h:1188
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_unique_path()

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

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

1494 {
1495  UniquePath *pathnode;
1496  Path sort_path; /* dummy for result of cost_sort */
1497  Path agg_path; /* dummy for result of cost_agg */
1498  MemoryContext oldcontext;
1499  int numCols;
1500 
1501  /* Caller made a mistake if subpath isn't cheapest_total ... */
1502  Assert(subpath == rel->cheapest_total_path);
1503  Assert(subpath->parent == rel);
1504  /* ... or if SpecialJoinInfo is the wrong one */
1505  Assert(sjinfo->jointype == JOIN_SEMI);
1506  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1507 
1508  /* If result already cached, return it */
1509  if (rel->cheapest_unique_path)
1510  return (UniquePath *) rel->cheapest_unique_path;
1511 
1512  /* If it's not possible to unique-ify, return NULL */
1513  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1514  return NULL;
1515 
1516  /*
1517  * When called during GEQO join planning, we are in a short-lived memory
1518  * context. We must make sure that the path and any subsidiary data
1519  * structures created for a baserel survive the GEQO cycle, else the
1520  * baserel is trashed for future GEQO cycles. On the other hand, when we
1521  * are creating those for a joinrel during GEQO, we don't want them to
1522  * clutter the main planning context. Upshot is that the best solution is
1523  * to explicitly allocate memory in the same context the given RelOptInfo
1524  * is in.
1525  */
1526  oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
1527 
1528  pathnode = makeNode(UniquePath);
1529 
1530  pathnode->path.pathtype = T_Unique;
1531  pathnode->path.parent = rel;
1532  pathnode->path.pathtarget = rel->reltarget;
1533  pathnode->path.param_info = subpath->param_info;
1534  pathnode->path.parallel_aware = false;
1535  pathnode->path.parallel_safe = rel->consider_parallel &&
1536  subpath->parallel_safe;
1537  pathnode->path.parallel_workers = subpath->parallel_workers;
1538 
1539  /*
1540  * Assume the output is unsorted, since we don't necessarily have pathkeys
1541  * to represent it. (This might get overridden below.)
1542  */
1543  pathnode->path.pathkeys = NIL;
1544 
1545  pathnode->subpath = subpath;
1546  pathnode->in_operators = sjinfo->semi_operators;
1547  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1548 
1549  /*
1550  * If the input is a relation and it has a unique index that proves the
1551  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1552  * that relation_has_unique_index_for automatically considers restriction
1553  * clauses for the rel, as well.
1554  */
1555  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1557  sjinfo->semi_rhs_exprs,
1558  sjinfo->semi_operators))
1559  {
1560  pathnode->umethod = UNIQUE_PATH_NOOP;
1561  pathnode->path.rows = rel->rows;
1562  pathnode->path.startup_cost = subpath->startup_cost;
1563  pathnode->path.total_cost = subpath->total_cost;
1564  pathnode->path.pathkeys = subpath->pathkeys;
1565 
1566  rel->cheapest_unique_path = (Path *) pathnode;
1567 
1568  MemoryContextSwitchTo(oldcontext);
1569 
1570  return pathnode;
1571  }
1572 
1573  /*
1574  * If the input is a subquery whose output must be unique already, then we
1575  * don't need to do anything. The test for uniqueness has to consider
1576  * exactly which columns we are extracting; for example "SELECT DISTINCT
1577  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1578  * this optimization unless semi_rhs_exprs consists only of simple Vars
1579  * referencing subquery outputs. (Possibly we could do something with
1580  * expressions in the subquery outputs, too, but for now keep it simple.)
1581  */
1582  if (rel->rtekind == RTE_SUBQUERY)
1583  {
1584  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1585 
1587  {
1588  List *sub_tlist_colnos;
1589 
1590  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1591  rel->relid);
1592 
1593  if (sub_tlist_colnos &&
1595  sub_tlist_colnos,
1596  sjinfo->semi_operators))
1597  {
1598  pathnode->umethod = UNIQUE_PATH_NOOP;
1599  pathnode->path.rows = rel->rows;
1600  pathnode->path.startup_cost = subpath->startup_cost;
1601  pathnode->path.total_cost = subpath->total_cost;
1602  pathnode->path.pathkeys = subpath->pathkeys;
1603 
1604  rel->cheapest_unique_path = (Path *) pathnode;
1605 
1606  MemoryContextSwitchTo(oldcontext);
1607 
1608  return pathnode;
1609  }
1610  }
1611  }
1612 
1613  /* Estimate number of output rows */
1614  pathnode->path.rows = estimate_num_groups(root,
1615  sjinfo->semi_rhs_exprs,
1616  rel->rows,
1617  NULL);
1618  numCols = list_length(sjinfo->semi_rhs_exprs);
1619 
1620  if (sjinfo->semi_can_btree)
1621  {
1622  /*
1623  * Estimate cost for sort+unique implementation
1624  */
1625  cost_sort(&sort_path, root, NIL,
1626  subpath->total_cost,
1627  rel->rows,
1628  subpath->pathtarget->width,
1629  0.0,
1630  work_mem,
1631  -1.0);
1632 
1633  /*
1634  * Charge one cpu_operator_cost per comparison per input tuple. We
1635  * assume all columns get compared at most of the tuples. (XXX
1636  * probably this is an overestimate.) This should agree with
1637  * create_upper_unique_path.
1638  */
1639  sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
1640  }
1641 
1642  if (sjinfo->semi_can_hash)
1643  {
1644  /*
1645  * Estimate the overhead per hashtable entry at 64 bytes (same as in
1646  * planner.c).
1647  */
1648  int hashentrysize = subpath->pathtarget->width + 64;
1649 
1650  if (hashentrysize * pathnode->path.rows > work_mem * 1024L)
1651  {
1652  /*
1653  * We should not try to hash. Hack the SpecialJoinInfo to
1654  * remember this, in case we come through here again.
1655  */
1656  sjinfo->semi_can_hash = false;
1657  }
1658  else
1659  cost_agg(&agg_path, root,
1660  AGG_HASHED, NULL,
1661  numCols, pathnode->path.rows,
1662  NIL,
1663  subpath->startup_cost,
1664  subpath->total_cost,
1665  rel->rows);
1666  }
1667 
1668  if (sjinfo->semi_can_btree && sjinfo->semi_can_hash)
1669  {
1670  if (agg_path.total_cost < sort_path.total_cost)
1671  pathnode->umethod = UNIQUE_PATH_HASH;
1672  else
1673  pathnode->umethod = UNIQUE_PATH_SORT;
1674  }
1675  else if (sjinfo->semi_can_btree)
1676  pathnode->umethod = UNIQUE_PATH_SORT;
1677  else if (sjinfo->semi_can_hash)
1678  pathnode->umethod = UNIQUE_PATH_HASH;
1679  else
1680  {
1681  /* we can get here only if we abandoned hashing above */
1682  MemoryContextSwitchTo(oldcontext);
1683  return NULL;
1684  }
1685 
1686  if (pathnode->umethod == UNIQUE_PATH_HASH)
1687  {
1688  pathnode->path.startup_cost = agg_path.startup_cost;
1689  pathnode->path.total_cost = agg_path.total_cost;
1690  }
1691  else
1692  {
1693  pathnode->path.startup_cost = sort_path.startup_cost;
1694  pathnode->path.total_cost = sort_path.total_cost;
1695  }
1696 
1697  rel->cheapest_unique_path = (Path *) pathnode;
1698 
1699  MemoryContextSwitchTo(oldcontext);
1700 
1701  return pathnode;
1702 }
struct Path * cheapest_unique_path
Definition: relation.h:604
#define NIL
Definition: pg_list.h:69
bool semi_can_btree
Definition: relation.h:2021
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset)
Definition: selfuncs.c:3398
PathTarget * pathtarget
Definition: relation.h:1043
bool query_is_distinct_for(Query *query, List *colnos, List *opids)
Definition: analyzejoins.c:782
Definition: nodes.h:79
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:2038
int parallel_workers
Definition: relation.h:1049
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ParamPathInfo * param_info
Definition: relation.h:1045
UniquePathMethod umethod
Definition: relation.h:1346
NodeTag pathtype
Definition: relation.h:1040
Relids syn_righthand
Definition: relation.h:2016
#define planner_rt_fetch(rti, root)
Definition: relation.h:328
static List * translate_sub_tlist(List *tlist, int relid)
Definition: pathnode.c:1776
Cost startup_cost
Definition: relation.h:1053
List * semi_rhs_exprs
Definition: relation.h:2024
bool semi_can_hash
Definition: relation.h:2022
RelOptInfo * parent
Definition: relation.h:1042
List * uniq_exprs
Definition: relation.h:1348
struct Path * cheapest_total_path
Definition: relation.h:603
Relids relids
Definition: relation.h:585
double cpu_operator_cost
Definition: costsize.c:108
Index relid
Definition: relation.h:613
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:1648
int work_mem
Definition: globals.c:113
RTEKind rtekind
Definition: relation.h:615
List * in_operators
Definition: relation.h:1347
double rows
Definition: relation.h:588
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:560
#define Assert(condition)
Definition: c.h:680
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
JoinType jointype
Definition: relation.h:2017
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
bool query_supports_distinctness(Query *query)
Definition: analyzejoins.c:745
int width
Definition: relation.h:975
Query * subquery
Definition: parsenodes.h:974
List * semi_operators
Definition: relation.h:2023
bool parallel_aware
Definition: relation.h:1047
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:2960
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
Path path
Definition: relation.h:1344
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
static MemoryContext GetMemoryChunkContext(void *pointer)
Definition: memutils.h:107
Path * subpath
Definition: relation.h:1345

◆ create_upper_unique_path()

UpperUniquePath* create_upper_unique_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
int  numCols,