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

Go to the source code of this file.

Macros

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

Enumerations

enum  PathCostComparison { COSTS_EQUAL , COSTS_BETTER1 , COSTS_BETTER2 , COSTS_DIFFERENT }
 

Functions

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

Macro Definition Documentation

◆ ADJUST_CHILD_ATTRS

#define ADJUST_CHILD_ATTRS (   node)
Value:
((node) = \
child_rel, \
child_rel->top_parent))
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: appendinfo.c:489
Definition: pg_list.h:52
Definition: nodes.h:118

◆ 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:165

◆ 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:4038

◆ 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)
static List * reparameterize_pathlist_by_child(PlannerInfo *root, List *pathlist, RelOptInfo *child_rel)
Definition: pathnode.c:4329
#define NIL
Definition: pg_list.h:66

◆ STD_FUZZ_FACTOR

#define STD_FUZZ_FACTOR   1.01

Definition at line 51 of file pathnode.c.

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:39
@ COSTS_EQUAL
Definition: pathnode.c:40
@ COSTS_BETTER1
Definition: pathnode.c:41
@ COSTS_BETTER2
Definition: pathnode.c:42
@ COSTS_DIFFERENT
Definition: pathnode.c:43

Function Documentation

◆ add_partial_path()

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 749 of file pathnode.c.

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

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

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

◆ add_partial_path_precheck()

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

Definition at line 867 of file pathnode.c.

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

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

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

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

◆ add_path_precheck()

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

Definition at line 644 of file pathnode.c.

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

References bms_equal(), compare_pathkeys(), RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, lfirst, NIL, 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().

◆ adjust_limit_rows_costs()

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

Definition at line 3809 of file pathnode.c.

3814 {
3815  double input_rows = *rows;
3816  Cost input_startup_cost = *startup_cost;
3817  Cost input_total_cost = *total_cost;
3818 
3819  if (offset_est != 0)
3820  {
3821  double offset_rows;
3822 
3823  if (offset_est > 0)
3824  offset_rows = (double) offset_est;
3825  else
3826  offset_rows = clamp_row_est(input_rows * 0.10);
3827  if (offset_rows > *rows)
3828  offset_rows = *rows;
3829  if (input_rows > 0)
3830  *startup_cost +=
3831  (input_total_cost - input_startup_cost)
3832  * offset_rows / input_rows;
3833  *rows -= offset_rows;
3834  if (*rows < 1)
3835  *rows = 1;
3836  }
3837 
3838  if (count_est != 0)
3839  {
3840  double count_rows;
3841 
3842  if (count_est > 0)
3843  count_rows = (double) count_est;
3844  else
3845  count_rows = clamp_row_est(input_rows * 0.10);
3846  if (count_rows > *rows)
3847  count_rows = *rows;
3848  if (input_rows > 0)
3849  *total_cost = *startup_cost +
3850  (input_total_cost - input_startup_cost)
3851  * count_rows / input_rows;
3852  *rows = count_rows;
3853  if (*rows < 1)
3854  *rows = 1;
3855  }
3856 }
double clamp_row_est(double nrows)
Definition: costsize.c:201
double Cost
Definition: nodes.h:251

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

◆ append_startup_cost_compare()

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

Definition at line 1395 of file pathnode.c.

1396 {
1397  Path *path1 = (Path *) lfirst(a);
1398  Path *path2 = (Path *) lfirst(b);
1399  int cmp;
1400 
1401  cmp = compare_path_costs(path1, path2, STARTUP_COST);
1402  if (cmp != 0)
1403  return -cmp;
1404  return bms_compare(path1->parent->relids, path2->parent->relids);
1405 }
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:147
int b
Definition: isn.c:70
int a
Definition: isn.c:69
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
@ STARTUP_COST
Definition: pathnodes.h:38
static int cmp(const chr *x, const chr *y, size_t len)
Definition: regc_locale.c:747

References a, b, bms_compare(), cmp(), compare_path_costs(), lfirst, and STARTUP_COST.

Referenced by create_append_path().

◆ append_total_cost_compare()

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

Definition at line 1373 of file pathnode.c.

1374 {
1375  Path *path1 = (Path *) lfirst(a);
1376  Path *path2 = (Path *) lfirst(b);
1377  int cmp;
1378 
1379  cmp = compare_path_costs(path1, path2, TOTAL_COST);
1380  if (cmp != 0)
1381  return -cmp;
1382  return bms_compare(path1->parent->relids, path2->parent->relids);
1383 }
@ TOTAL_COST
Definition: pathnodes.h:38

References a, b, bms_compare(), cmp(), compare_path_costs(), lfirst, and TOTAL_COST.

Referenced by create_append_path().

◆ apply_projection_to_path()

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

Definition at line 2754 of file pathnode.c.

2758 {
2759  QualCost oldcost;
2760 
2761  /*
2762  * If given path can't project, we might need a Result node, so make a
2763  * separate ProjectionPath.
2764  */
2765  if (!is_projection_capable_path(path))
2766  return (Path *) create_projection_path(root, rel, path, target);
2767 
2768  /*
2769  * We can just jam the desired tlist into the existing path, being sure to
2770  * update its cost estimates appropriately.
2771  */
2772  oldcost = path->pathtarget->cost;
2773  path->pathtarget = target;
2774 
2775  path->startup_cost += target->cost.startup - oldcost.startup;
2776  path->total_cost += target->cost.startup - oldcost.startup +
2777  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2778 
2779  /*
2780  * If the path happens to be a Gather or GatherMerge path, we'd like to
2781  * arrange for the subpath to return the required target list so that
2782  * workers can help project. But if there is something that is not
2783  * parallel-safe in the target expressions, then we can't.
2784  */
2785  if ((IsA(path, GatherPath) || IsA(path, GatherMergePath)) &&
2786  is_parallel_safe(root, (Node *) target->exprs))
2787  {
2788  /*
2789  * We always use create_projection_path here, even if the subpath is
2790  * projection-capable, so as to avoid modifying the subpath in place.
2791  * It seems unlikely at present that there could be any other
2792  * references to the subpath, but better safe than sorry.
2793  *
2794  * Note that we don't change the parallel path's cost estimates; it
2795  * might be appropriate to do so, to reflect the fact that the bulk of
2796  * the target evaluation will happen in workers.
2797  */
2798  if (IsA(path, GatherPath))
2799  {
2800  GatherPath *gpath = (GatherPath *) path;
2801 
2802  gpath->subpath = (Path *)
2804  gpath->subpath->parent,
2805  gpath->subpath,
2806  target);
2807  }
2808  else
2809  {
2810  GatherMergePath *gmpath = (GatherMergePath *) path;
2811 
2812  gmpath->subpath = (Path *)
2814  gmpath->subpath->parent,
2815  gmpath->subpath,
2816  target);
2817  }
2818  }
2819  else if (path->parallel_safe &&
2820  !is_parallel_safe(root, (Node *) target->exprs))
2821  {
2822  /*
2823  * We're inserting a parallel-restricted target list into a path
2824  * currently marked parallel-safe, so we have to mark it as no longer
2825  * safe.
2826  */
2827  path->parallel_safe = false;
2828  }
2829 
2830  return path;
2831 }
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:634
bool is_projection_capable_path(Path *path)
Definition: createplan.c:7159
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:77
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2646
Path * subpath
Definition: pathnodes.h:1919
List * exprs
Definition: pathnodes.h:1427
QualCost cost
Definition: pathnodes.h:1433
Cost per_tuple
Definition: pathnodes.h:48
Cost startup
Definition: pathnodes.h:47

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

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

◆ calc_nestloop_required_outer()

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

Definition at line 2360 of file pathnode.c.

2364 {
2365  Relids required_outer;
2366 
2367  /* inner_path can require rels from outer path, but not vice versa */
2368  Assert(!bms_overlap(outer_paramrels, innerrelids));
2369  /* easy case if inner path is not parameterized */
2370  if (!inner_paramrels)
2371  return bms_copy(outer_paramrels);
2372  /* else, form the union ... */
2373  required_outer = bms_union(outer_paramrels, inner_paramrels);
2374  /* ... and remove any mention of now-satisfied outer rels */
2375  required_outer = bms_del_members(required_outer,
2376  outerrelids);
2377  /* maintain invariant that required_outer is exactly NULL if empty */
2378  if (bms_is_empty(required_outer))
2379  {
2380  bms_free(required_outer);
2381  required_outer = NULL;
2382  }
2383  return required_outer;
2384 }
void bms_free(Bitmapset *a)
Definition: bitmapset.c:209
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:226
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:932
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:704
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:495
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74

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

Referenced by try_nestloop_path().

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

Definition at line 2393 of file pathnode.c.

2394 {
2395  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2396  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2397  Relids required_outer;
2398 
2399  /* neither path can require rels from the other */
2400  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2401  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2402  /* form the union ... */
2403  required_outer = bms_union(outer_paramrels, inner_paramrels);
2404  /* we do not need an explicit test for empty; bms_union gets it right */
2405  return required_outer;
2406 }

References Assert(), bms_overlap(), bms_union(), and PATH_REQ_OUTER.

Referenced by try_hashjoin_path(), and try_mergejoin_path().

◆ compare_fractional_path_costs()

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

Definition at line 117 of file pathnode.c.

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 }

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

◆ compare_path_costs()

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

Definition at line 71 of file pathnode.c.

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 }

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

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

◆ 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.

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 }
#define CONSIDER_PATH_STARTUP_COST(p)

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

Referenced by add_path().

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

3126 {
3127  AggPath *pathnode = makeNode(AggPath);
3128 
3129  pathnode->path.pathtype = T_Agg;
3130  pathnode->path.parent = rel;
3131  pathnode->path.pathtarget = target;
3132  /* For now, assume we are above any joins, so no parameterization */
3133  pathnode->path.param_info = NULL;
3134  pathnode->path.parallel_aware = false;
3135  pathnode->path.parallel_safe = rel->consider_parallel &&
3136  subpath->parallel_safe;
3137  pathnode->path.parallel_workers = subpath->parallel_workers;
3138  if (aggstrategy == AGG_SORTED)
3139  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
3140  else
3141  pathnode->path.pathkeys = NIL; /* output is unordered */
3142  pathnode->subpath = subpath;
3143 
3144  pathnode->aggstrategy = aggstrategy;
3145  pathnode->aggsplit = aggsplit;
3146  pathnode->numGroups = numGroups;
3147  pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
3148  pathnode->groupClause = groupClause;
3149  pathnode->qual = qual;
3150 
3151  cost_agg(&pathnode->path, root,
3152  aggstrategy, aggcosts,
3153  list_length(groupClause), numGroups,
3154  qual,
3155  subpath->startup_cost, subpath->total_cost,
3156  subpath->rows, subpath->pathtarget->width);
3157 
3158  /* add tlist eval cost for each output row */
3159  pathnode->path.startup_cost += target->cost.startup;
3160  pathnode->path.total_cost += target->cost.startup +
3161  target->cost.per_tuple * pathnode->path.rows;
3162 
3163  return pathnode;
3164 }
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2620
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
@ AGG_SORTED
Definition: nodes.h:352
static int list_length(const List *l)
Definition: pg_list.h:150
Size transitionSpace
Definition: pathnodes.h:62
Path * subpath
Definition: pathnodes.h:2131
Cardinality numGroups
Definition: pathnodes.h:2134
AggSplit aggsplit
Definition: pathnodes.h:2133
List * groupClause
Definition: pathnodes.h:2136
uint64 transitionSpace
Definition: pathnodes.h:2135
AggStrategy aggstrategy
Definition: pathnodes.h:2132
Path path
Definition: pathnodes.h:2130
List * qual
Definition: pathnodes.h:2137
NodeTag pathtype
Definition: pathnodes.h:1513
int parallel_workers
Definition: pathnodes.h:1544
bool parallel_aware
Definition: pathnodes.h:1540

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, AggPath::path, Path::pathkeys, Path::pathtype, QualCost::per_tuple, AggPath::qual, Path::rows, QualCost::startup, Path::startup_cost, subpath(), AggPath::subpath, Path::total_cost, AggClauseCosts::transitionSpace, and AggPath::transitionSpace.

Referenced by add_paths_to_grouping_rel(), create_final_distinct_paths(), create_partial_distinct_paths(), create_partial_grouping_paths(), and make_union_unique().

◆ create_append_path()

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

Definition at line 1244 of file pathnode.c.

1250 {
1251  AppendPath *pathnode = makeNode(AppendPath);
1252  ListCell *l;
1253 
1254  Assert(!parallel_aware || parallel_workers > 0);
1255 
1256  pathnode->path.pathtype = T_Append;
1257  pathnode->path.parent = rel;
1258  pathnode->path.pathtarget = rel->reltarget;
1259 
1260  /*
1261  * When generating an Append path for a partitioned table, there may be
1262  * parameterized quals that are useful for run-time pruning. Hence,
1263  * compute path.param_info the same way as for any other baserel, so that
1264  * such quals will be available for make_partition_pruneinfo(). (This
1265  * would not work right for a non-baserel, ie a scan on a non-leaf child
1266  * partition, and it's not necessary anyway in that case. Must skip it if
1267  * we don't have "root", too.)
1268  */
1269  if (root && rel->reloptkind == RELOPT_BASEREL && IS_PARTITIONED_REL(rel))
1270  pathnode->path.param_info = get_baserel_parampathinfo(root,
1271  rel,
1272  required_outer);
1273  else
1274  pathnode->path.param_info = get_appendrel_parampathinfo(rel,
1275  required_outer);
1276 
1277  pathnode->path.parallel_aware = parallel_aware;
1278  pathnode->path.parallel_safe = rel->consider_parallel;
1279  pathnode->path.parallel_workers = parallel_workers;
1280  pathnode->path.pathkeys = pathkeys;
1281 
1282  /*
1283  * For parallel append, non-partial paths are sorted by descending total
1284  * costs. That way, the total time to finish all non-partial paths is
1285  * minimized. Also, the partial paths are sorted by descending startup
1286  * costs. There may be some paths that require to do startup work by a
1287  * single worker. In such case, it's better for workers to choose the
1288  * expensive ones first, whereas the leader should choose the cheapest
1289  * startup plan.
1290  */
1291  if (pathnode->path.parallel_aware)
1292  {
1293  /*
1294  * We mustn't fiddle with the order of subpaths when the Append has
1295  * pathkeys. The order they're listed in is critical to keeping the
1296  * pathkeys valid.
1297  */
1298  Assert(pathkeys == NIL);
1299 
1301  list_sort(partial_subpaths, append_startup_cost_compare);
1302  }
1303  pathnode->first_partial_path = list_length(subpaths);
1304  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1305 
1306  /*
1307  * Apply query-wide LIMIT if known and path is for sole base relation.
1308  * (Handling this at this low level is a bit klugy.)
1309  */
1310  if (root != NULL && bms_equal(rel->relids, root->all_baserels))
1311  pathnode->limit_tuples = root->limit_tuples;
1312  else
1313  pathnode->limit_tuples = -1.0;
1314 
1315  foreach(l, pathnode->subpaths)
1316  {
1317  Path *subpath = (Path *) lfirst(l);
1318 
1319  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1320  subpath->parallel_safe;
1321 
1322  /* All child paths must have same parameterization */
1323  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1324  }
1325 
1326  Assert(!parallel_aware || pathnode->path.parallel_safe);
1327 
1328  /*
1329  * If there's exactly one child path then the output of the Append is
1330  * necessarily ordered the same as the child's, so we can inherit the
1331  * child's pathkeys if any, overriding whatever the caller might've said.
1332  * Furthermore, if the child's parallel awareness matches the Append's,
1333  * then the Append is a no-op and will be discarded later (in setrefs.c).
1334  * Then we can inherit the child's size and cost too, effectively charging
1335  * zero for the Append. Otherwise, we must do the normal costsize
1336  * calculation.
1337  */
1338  if (list_length(pathnode->subpaths) == 1)
1339  {
1340  Path *child = (Path *) linitial(pathnode->subpaths);
1341 
1342  if (child->parallel_aware == parallel_aware)
1343  {
1344  pathnode->path.rows = child->rows;
1345  pathnode->path.startup_cost = child->startup_cost;
1346  pathnode->path.total_cost = child->total_cost;
1347  }
1348  else
1349  cost_append(pathnode);
1350  /* Must do this last, else cost_append complains */
1351  pathnode->path.pathkeys = child->pathkeys;
1352  }
1353  else
1354  cost_append(pathnode);
1355 
1356  /* If the caller provided a row estimate, override the computed value. */
1357  if (rows >= 0)
1358  pathnode->path.rows = rows;
1359 
1360  return pathnode;
1361 }
void cost_append(AppendPath *apath)
Definition: costsize.c:2203
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1673
List * list_concat(List *list1, const List *list2)
Definition: list.c:560
static int append_startup_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1395
static int append_total_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1373
#define IS_PARTITIONED_REL(rel)
Definition: pathnodes.h:1010
@ RELOPT_BASEREL
Definition: pathnodes.h:779
#define linitial(l)
Definition: pg_list.h:176
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1317
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1614
int first_partial_path
Definition: pathnodes.h:1811
Cardinality limit_tuples
Definition: pathnodes.h:1812
List * subpaths
Definition: pathnodes.h:1809
Cardinality limit_tuples
Definition: pathnodes.h:445
Relids all_baserels
Definition: pathnodes.h:257
Relids relids
Definition: pathnodes.h:824
struct PathTarget * reltarget
Definition: pathnodes.h:846
RelOptKind reloptkind
Definition: pathnodes.h:818

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

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

◆ create_bitmap_and_path()

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

Definition at line 1079 of file pathnode.c.

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

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

Referenced by bitmap_and_cost_est(), and choose_bitmap_and().

◆ create_bitmap_heap_path()

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

Definition at line 1046 of file pathnode.c.

1052 {
1053  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1054 
1055  pathnode->path.pathtype = T_BitmapHeapScan;
1056  pathnode->path.parent = rel;
1057  pathnode->path.pathtarget = rel->reltarget;
1058  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1059  required_outer);
1060  pathnode->path.parallel_aware = (parallel_degree > 0);
1061  pathnode->path.parallel_safe = rel->consider_parallel;
1062  pathnode->path.parallel_workers = parallel_degree;
1063  pathnode->path.pathkeys = NIL; /* always unordered */
1064 
1065  pathnode->bitmapqual = bitmapqual;
1066 
1067  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1068  pathnode->path.param_info,
1069  bitmapqual, loop_count);
1070 
1071  return pathnode;
1072 }
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:983
Path * bitmapqual
Definition: pathnodes.h:1675

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

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

◆ create_bitmap_or_path()

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

Definition at line 1131 of file pathnode.c.

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

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

Referenced by generate_bitmap_or_paths().

◆ create_ctescan_path()

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

Definition at line 2116 of file pathnode.c.

2117 {
2118  Path *pathnode = makeNode(Path);
2119 
2120  pathnode->pathtype = T_CteScan;
2121  pathnode->parent = rel;
2122  pathnode->pathtarget = rel->reltarget;
2123  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2124  required_outer);
2125  pathnode->parallel_aware = false;
2126  pathnode->parallel_safe = rel->consider_parallel;
2127  pathnode->parallel_workers = 0;
2128  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
2129 
2130  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2131 
2132  return pathnode;
2133 }
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1668

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

Referenced by set_cte_pathlist().

◆ create_foreign_join_path()

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

Definition at line 2270 of file pathnode.c.

2277 {
2278  ForeignPath *pathnode = makeNode(ForeignPath);
2279 
2280  /*
2281  * We should use get_joinrel_parampathinfo to handle parameterized paths,
2282  * but the API of this function doesn't support it, and existing
2283  * extensions aren't yet trying to build such paths anyway. For the
2284  * moment just throw an error if someone tries it; eventually we should
2285  * revisit this.
2286  */
2287  if (!bms_is_empty(required_outer) || !bms_is_empty(rel->lateral_relids))
2288  elog(ERROR, "parameterized foreign joins are not supported yet");
2289 
2290  pathnode->path.pathtype = T_ForeignScan;
2291  pathnode->path.parent = rel;
2292  pathnode->path.pathtarget = target ? target : rel->reltarget;
2293  pathnode->path.param_info = NULL; /* XXX see above */
2294  pathnode->path.parallel_aware = false;
2295  pathnode->path.parallel_safe = rel->consider_parallel;
2296  pathnode->path.parallel_workers = 0;
2297  pathnode->path.rows = rows;
2298  pathnode->path.startup_cost = startup_cost;
2299  pathnode->path.total_cost = total_cost;
2300  pathnode->path.pathkeys = pathkeys;
2301 
2302  pathnode->fdw_outerpath = fdw_outerpath;
2303  pathnode->fdw_private = fdw_private;
2304 
2305  return pathnode;
2306 }
#define ERROR
Definition: elog.h:35
Path * fdw_outerpath
Definition: pathnodes.h:1756
List * fdw_private
Definition: pathnodes.h:1757
Relids lateral_relids
Definition: pathnodes.h:866

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

Referenced by add_paths_with_pathkeys_for_rel(), and postgresGetForeignJoinPaths().

◆ create_foreign_upper_path()

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

Definition at line 2320 of file pathnode.c.

2326 {
2327  ForeignPath *pathnode = makeNode(ForeignPath);
2328 
2329  /*
2330  * Upper relations should never have any lateral references, since joining
2331  * is complete.
2332  */
2334 
2335  pathnode->path.pathtype = T_ForeignScan;
2336  pathnode->path.parent = rel;
2337  pathnode->path.pathtarget = target ? target : rel->reltarget;
2338  pathnode->path.param_info = NULL;
2339  pathnode->path.parallel_aware = false;
2340  pathnode->path.parallel_safe = rel->consider_parallel;
2341  pathnode->path.parallel_workers = 0;
2342  pathnode->path.rows = rows;
2343  pathnode->path.startup_cost = startup_cost;
2344  pathnode->path.total_cost = total_cost;
2345  pathnode->path.pathkeys = pathkeys;
2346 
2347  pathnode->fdw_outerpath = fdw_outerpath;
2348  pathnode->fdw_private = fdw_private;
2349 
2350  return pathnode;
2351 }

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

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

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

2233 {
2234  ForeignPath *pathnode = makeNode(ForeignPath);
2235 
2236  /* Historically some FDWs were confused about when to use this */
2237  Assert(IS_SIMPLE_REL(rel));
2238 
2239  pathnode->path.pathtype = T_ForeignScan;
2240  pathnode->path.parent = rel;
2241  pathnode->path.pathtarget = target ? target : rel->reltarget;
2242  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2243  required_outer);
2244  pathnode->path.parallel_aware = false;
2245  pathnode->path.parallel_safe = rel->consider_parallel;
2246  pathnode->path.parallel_workers = 0;
2247  pathnode->path.rows = rows;
2248  pathnode->path.startup_cost = startup_cost;
2249  pathnode->path.total_cost = total_cost;
2250  pathnode->path.pathkeys = pathkeys;
2251 
2252  pathnode->fdw_outerpath = fdw_outerpath;
2253  pathnode->fdw_private = fdw_private;
2254 
2255  return pathnode;
2256 }
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:792

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

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

◆ create_functionscan_path()

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

Definition at line 2038 of file pathnode.c.

2040 {
2041  Path *pathnode = makeNode(Path);
2042 
2043  pathnode->pathtype = T_FunctionScan;
2044  pathnode->parent = rel;
2045  pathnode->pathtarget = rel->reltarget;
2046  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2047  required_outer);
2048  pathnode->parallel_aware = false;
2049  pathnode->parallel_safe = rel->consider_parallel;
2050  pathnode->parallel_workers = 0;
2051  pathnode->pathkeys = pathkeys;
2052 
2053  cost_functionscan(pathnode, root, rel, pathnode->param_info);
2054 
2055  return pathnode;
2056 }
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1501

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

Referenced by set_function_pathlist().

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

1876 {
1878  Cost input_startup_cost = 0;
1879  Cost input_total_cost = 0;
1880 
1881  Assert(subpath->parallel_safe);
1882  Assert(pathkeys);
1883 
1884  pathnode->path.pathtype = T_GatherMerge;
1885  pathnode->path.parent = rel;
1886  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1887  required_outer);
1888  pathnode->path.parallel_aware = false;
1889 
1890  pathnode->subpath = subpath;
1891  pathnode->num_workers = subpath->parallel_workers;
1892  pathnode->path.pathkeys = pathkeys;
1893  pathnode->path.pathtarget = target ? target : rel->reltarget;
1894  pathnode->path.rows += subpath->rows;
1895 
1896  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1897  {
1898  /* Subpath is adequately ordered, we won't need to sort it */
1899  input_startup_cost += subpath->startup_cost;
1900  input_total_cost += subpath->total_cost;
1901  }
1902  else
1903  {
1904  /* We'll need to insert a Sort node, so include cost for that */
1905  Path sort_path; /* dummy for result of cost_sort */
1906 
1907  cost_sort(&sort_path,
1908  root,
1909  pathkeys,
1910  subpath->total_cost,
1911  subpath->rows,
1912  subpath->pathtarget->width,
1913  0.0,
1914  work_mem,
1915  -1);
1916  input_startup_cost += sort_path.startup_cost;
1917  input_total_cost += sort_path.total_cost;
1918  }
1919 
1920  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1921  input_startup_cost, input_total_cost, rows);
1922 
1923  return pathnode;
1924 }
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:444
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:2096
int work_mem
Definition: globals.c:125
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:346

References Assert(), cost_gather_merge(), cost_sort(), get_baserel_parampathinfo(), makeNode, GatherMergePath::num_workers, Path::parallel_aware, GatherMergePath::path, Path::pathkeys, pathkeys_contained_in(), Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), GatherMergePath::subpath, Path::total_cost, and work_mem.

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

◆ create_gather_path()

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

Definition at line 1964 of file pathnode.c.

1966 {
1967  GatherPath *pathnode = makeNode(GatherPath);
1968 
1969  Assert(subpath->parallel_safe);
1970 
1971  pathnode->path.pathtype = T_Gather;
1972  pathnode->path.parent = rel;
1973  pathnode->path.pathtarget = target;
1974  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1975  required_outer);
1976  pathnode->path.parallel_aware = false;
1977  pathnode->path.parallel_safe = false;
1978  pathnode->path.parallel_workers = 0;
1979  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1980 
1981  pathnode->subpath = subpath;
1982  pathnode->num_workers = subpath->parallel_workers;
1983  pathnode->single_copy = false;
1984 
1985  if (pathnode->num_workers == 0)
1986  {
1987  pathnode->path.pathkeys = subpath->pathkeys;
1988  pathnode->num_workers = 1;
1989  pathnode->single_copy = true;
1990  }
1991 
1992  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1993 
1994  return pathnode;
1995 }
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:406
bool single_copy
Definition: pathnodes.h:1920
int num_workers
Definition: pathnodes.h:1921

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

Referenced by generate_gather_paths(), and generate_union_paths().

◆ create_group_path()

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

Definition at line 3005 of file pathnode.c.

3011 {
3012  GroupPath *pathnode = makeNode(GroupPath);
3013  PathTarget *target = rel->reltarget;
3014 
3015  pathnode->path.pathtype = T_Group;
3016  pathnode->path.parent = rel;
3017  pathnode->path.pathtarget = target;
3018  /* For now, assume we are above any joins, so no parameterization */
3019  pathnode->path.param_info = NULL;
3020  pathnode->path.parallel_aware = false;
3021  pathnode->path.parallel_safe = rel->consider_parallel &&
3022  subpath->parallel_safe;
3023  pathnode->path.parallel_workers = subpath->parallel_workers;
3024  /* Group doesn't change sort ordering */
3025  pathnode->path.pathkeys = subpath->pathkeys;
3026 
3027  pathnode->subpath = subpath;
3028 
3029  pathnode->groupClause = groupClause;
3030  pathnode->qual = qual;
3031 
3032  cost_group(&pathnode->path, root,
3033  list_length(groupClause),
3034  numGroups,
3035  qual,
3036  subpath->startup_cost, subpath->total_cost,
3037  subpath->rows);
3038 
3039  /* add tlist eval cost for each output row */
3040  pathnode->path.startup_cost += target->cost.startup;
3041  pathnode->path.total_cost += target->cost.startup +
3042  target->cost.per_tuple * pathnode->path.rows;
3043 
3044  return pathnode;
3045 }
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:2892
List * qual
Definition: pathnodes.h:2105
List * groupClause
Definition: pathnodes.h:2104
Path * subpath
Definition: pathnodes.h:2103
Path path
Definition: pathnodes.h:2102

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

Referenced by add_paths_to_grouping_rel(), and create_partial_grouping_paths().

◆ create_group_result_path()

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

Definition at line 1516 of file pathnode.c.

1518 {
1520 
1521  pathnode->path.pathtype = T_Result;
1522  pathnode->path.parent = rel;
1523  pathnode->path.pathtarget = target;
1524  pathnode->path.param_info = NULL; /* there are no other rels... */
1525  pathnode->path.parallel_aware = false;
1526  pathnode->path.parallel_safe = rel->consider_parallel;
1527  pathnode->path.parallel_workers = 0;
1528  pathnode->path.pathkeys = NIL;
1529  pathnode->quals = havingqual;
1530 
1531  /*
1532  * We can't quite use cost_resultscan() because the quals we want to
1533  * account for are not baserestrict quals of the rel. Might as well just
1534  * hack it here.
1535  */
1536  pathnode->path.rows = 1;
1537  pathnode->path.startup_cost = target->cost.startup;
1538  pathnode->path.total_cost = target->cost.startup +
1539  cpu_tuple_cost + target->cost.per_tuple;
1540 
1541  /*
1542  * Add cost of qual, if any --- but we ignore its selectivity, since our
1543  * rowcount estimate should be 1 no matter what the qual is.
1544  */
1545  if (havingqual)
1546  {
1547  QualCost qual_cost;
1548 
1549  cost_qual_eval(&qual_cost, havingqual, root);
1550  /* havingqual is evaluated once at startup */
1551  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1552  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1553  }
1554 
1555  return pathnode;
1556 }
double cpu_tuple_cost
Definition: costsize.c:122
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4368

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

Referenced by create_degenerate_grouping_paths(), and query_planner().

◆ create_groupingsets_path()

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

Definition at line 3182 of file pathnode.c.

3189 {
3191  PathTarget *target = rel->reltarget;
3192  ListCell *lc;
3193  bool is_first = true;
3194  bool is_first_sort = true;
3195 
3196  /* The topmost generated Plan node will be an Agg */
3197  pathnode->path.pathtype = T_Agg;
3198  pathnode->path.parent = rel;
3199  pathnode->path.pathtarget = target;
3200  pathnode->path.param_info = subpath->param_info;
3201  pathnode->path.parallel_aware = false;
3202  pathnode->path.parallel_safe = rel->consider_parallel &&
3203  subpath->parallel_safe;
3204  pathnode->path.parallel_workers = subpath->parallel_workers;
3205  pathnode->subpath = subpath;
3206 
3207  /*
3208  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
3209  * to AGG_HASHED, here if possible.
3210  */
3211  if (aggstrategy == AGG_SORTED &&
3212  list_length(rollups) == 1 &&
3213  ((RollupData *) linitial(rollups))->groupClause == NIL)
3214  aggstrategy = AGG_PLAIN;
3215 
3216  if (aggstrategy == AGG_MIXED &&
3217  list_length(rollups) == 1)
3218  aggstrategy = AGG_HASHED;
3219 
3220  /*
3221  * Output will be in sorted order by group_pathkeys if, and only if, there
3222  * is a single rollup operation on a non-empty list of grouping
3223  * expressions.
3224  */
3225  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
3226  pathnode->path.pathkeys = root->group_pathkeys;
3227  else
3228  pathnode->path.pathkeys = NIL;
3229 
3230  pathnode->aggstrategy = aggstrategy;
3231  pathnode->rollups = rollups;
3232  pathnode->qual = having_qual;
3233  pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
3234 
3235  Assert(rollups != NIL);
3236  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
3237  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
3238 
3239  foreach(lc, rollups)
3240  {
3241  RollupData *rollup = lfirst(lc);
3242  List *gsets = rollup->gsets;
3243  int numGroupCols = list_length(linitial(gsets));
3244 
3245  /*
3246  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
3247  * (already-sorted) input, and following ones do their own sort.
3248  *
3249  * In AGG_HASHED mode, there is one rollup for each grouping set.
3250  *
3251  * In AGG_MIXED mode, the first rollups are hashed, the first
3252  * non-hashed one takes the (already-sorted) input, and following ones
3253  * do their own sort.
3254  */
3255  if (is_first)
3256  {
3257  cost_agg(&pathnode->path, root,
3258  aggstrategy,
3259  agg_costs,
3260  numGroupCols,
3261  rollup->numGroups,
3262  having_qual,
3263  subpath->startup_cost,
3264  subpath->total_cost,
3265  subpath->rows,
3266  subpath->pathtarget->width);
3267  is_first = false;
3268  if (!rollup->is_hashed)
3269  is_first_sort = false;
3270  }
3271  else
3272  {
3273  Path sort_path; /* dummy for result of cost_sort */
3274  Path agg_path; /* dummy for result of cost_agg */
3275 
3276  if (rollup->is_hashed || is_first_sort)
3277  {
3278  /*
3279  * Account for cost of aggregation, but don't charge input
3280  * cost again
3281  */
3282  cost_agg(&agg_path, root,
3283  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
3284  agg_costs,
3285  numGroupCols,
3286  rollup->numGroups,
3287  having_qual,
3288  0.0, 0.0,
3289  subpath->rows,
3290  subpath->pathtarget->width);
3291  if (!rollup->is_hashed)
3292  is_first_sort = false;
3293  }
3294  else
3295  {
3296  /* Account for cost of sort, but don't charge input cost again */
3297  cost_sort(&sort_path, root, NIL,
3298  0.0,
3299  subpath->rows,
3300  subpath->pathtarget->width,
3301  0.0,
3302  work_mem,
3303  -1.0);
3304 
3305  /* Account for cost of aggregation */
3306 
3307  cost_agg(&agg_path, root,
3308  AGG_SORTED,
3309  agg_costs,
3310  numGroupCols,
3311  rollup->numGroups,
3312  having_qual,
3313  sort_path.startup_cost,
3314  sort_path.total_cost,
3315  sort_path.rows,
3316  subpath->pathtarget->width);
3317  }
3318 
3319  pathnode->path.total_cost += agg_path.total_cost;
3320  pathnode->path.rows += agg_path.rows;
3321  }
3322  }
3323 
3324  /* add tlist eval cost for each output row */
3325  pathnode->path.startup_cost += target->cost.startup;
3326  pathnode->path.total_cost += target->cost.startup +
3327  target->cost.per_tuple * pathnode->path.rows;
3328 
3329  return pathnode;
3330 }
@ AGG_HASHED
Definition: nodes.h:353
@ AGG_MIXED
Definition: nodes.h:354
@ AGG_PLAIN
Definition: nodes.h:351
uint64 transitionSpace
Definition: pathnodes.h:2177
AggStrategy aggstrategy
Definition: pathnodes.h:2174
List * group_pathkeys
Definition: pathnodes.h:378
Cardinality numGroups
Definition: pathnodes.h:2161
List * gsets
Definition: pathnodes.h:2159
bool is_hashed
Definition: pathnodes.h:2163

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, GroupingSetsPath::path, Path::pathkeys, Path::pathtype, QualCost::per_tuple, GroupingSetsPath::qual, RelOptInfo::reltarget, GroupingSetsPath::rollups, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupingSetsPath::subpath, Path::total_cost, AggClauseCosts::transitionSpace, GroupingSetsPath::transitionSpace, and work_mem.

Referenced by consider_groupingsets_paths().

◆ create_hashjoin_path()

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

Definition at line 2580 of file pathnode.c.

2591 {
2592  HashPath *pathnode = makeNode(HashPath);
2593 
2594  pathnode->jpath.path.pathtype = T_HashJoin;
2595  pathnode->jpath.path.parent = joinrel;
2596  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2597  pathnode->jpath.path.param_info =
2599  joinrel,
2600  outer_path,
2601  inner_path,
2602  extra->sjinfo,
2603  required_outer,
2604  &restrict_clauses);
2605  pathnode->jpath.path.parallel_aware =
2606  joinrel->consider_parallel && parallel_hash;
2607  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2608  outer_path->parallel_safe && inner_path->parallel_safe;
2609  /* This is a foolish way to estimate parallel_workers, but for now... */
2610  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2611 
2612  /*
2613  * A hashjoin never has pathkeys, since its output ordering is
2614  * unpredictable due to possible batching. XXX If the inner relation is
2615  * small enough, we could instruct the executor that it must not batch,
2616  * and then we could assume that the output inherits the outer relation's
2617  * ordering, which might save a sort step. However there is considerable
2618  * downside if our estimate of the inner relation size is badly off. For
2619  * the moment we don't risk it. (Note also that if we wanted to take this
2620  * seriously, joinpath.c would have to consider many more paths for the
2621  * outer rel than it does now.)
2622  */
2623  pathnode->jpath.path.pathkeys = NIL;
2624  pathnode->jpath.jointype = jointype;
2625  pathnode->jpath.inner_unique = extra->inner_unique;
2626  pathnode->jpath.outerjoinpath = outer_path;
2627  pathnode->jpath.innerjoinpath = inner_path;
2628  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2629  pathnode->path_hashclauses = hashclauses;
2630  /* final_cost_hashjoin will fill in pathnode->num_batches */
2631 
2632  final_cost_hashjoin(root, pathnode, workspace, extra);
2633 
2634  return pathnode;
2635 }
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3909
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:1407
List * path_hashclauses
Definition: pathnodes.h:2029
JoinPath jpath
Definition: pathnodes.h:2028
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:3021
Path * outerjoinpath
Definition: pathnodes.h:1951
Path * innerjoinpath
Definition: pathnodes.h:1952
JoinType jointype
Definition: pathnodes.h:1946
bool inner_unique
Definition: pathnodes.h:1948
List * joinrestrictinfo
Definition: pathnodes.h:1954

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_safe, Path::parallel_workers, HashPath::path_hashclauses, RelOptInfo::reltarget, and JoinPathExtraData::sjinfo.

Referenced by try_hashjoin_path(), and try_partial_hashjoin_path().

◆ create_incremental_sort_path()

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

Definition at line 2912 of file pathnode.c.

2918 {
2920  SortPath *pathnode = &sort->spath;
2921 
2922  pathnode->path.pathtype = T_IncrementalSort;
2923  pathnode->path.parent = rel;
2924  /* Sort doesn't project, so use source path's pathtarget */
2925  pathnode->path.pathtarget = subpath->pathtarget;
2926  /* For now, assume we are above any joins, so no parameterization */
2927  pathnode->path.param_info = NULL;
2928  pathnode->path.parallel_aware = false;
2929  pathnode->path.parallel_safe = rel->consider_parallel &&
2930  subpath->parallel_safe;
2931  pathnode->path.parallel_workers = subpath->parallel_workers;
2932  pathnode->path.pathkeys = pathkeys;
2933 
2934  pathnode->subpath = subpath;
2935 
2936  cost_incremental_sort(&pathnode->path,
2937  root, pathkeys, presorted_keys,
2938  subpath->startup_cost,
2939  subpath->total_cost,
2940  subpath->rows,
2941  subpath->pathtarget->width,
2942  0.0, /* XXX comparison_cost shouldn't be 0? */
2943  work_mem, limit_tuples);
2944 
2945  sort->nPresortedCols = presorted_keys;
2946 
2947  return sort;
2948 }
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:195
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, Cost input_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1956
Path path
Definition: pathnodes.h:2076
Path * subpath
Definition: pathnodes.h:2077

References RelOptInfo::consider_parallel, cost_incremental_sort(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, SortPath::path, Path::pathkeys, Path::pathtype, sort(), subpath(), SortPath::subpath, and work_mem.

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

◆ create_index_path()

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

Definition at line 997 of file pathnode.c.

1008 {
1009  IndexPath *pathnode = makeNode(IndexPath);
1010  RelOptInfo *rel = index->rel;
1011 
1012  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1013  pathnode->path.parent = rel;
1014  pathnode->path.pathtarget = rel->reltarget;
1015  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1016  required_outer);
1017  pathnode->path.parallel_aware = false;
1018  pathnode->path.parallel_safe = rel->consider_parallel;
1019  pathnode->path.parallel_workers = 0;
1020  pathnode->path.pathkeys = pathkeys;
1021 
1022  pathnode->indexinfo = index;
1023  pathnode->indexclauses = indexclauses;
1024  pathnode->indexorderbys = indexorderbys;
1025  pathnode->indexorderbycols = indexorderbycols;
1026  pathnode->indexscandir = indexscandir;
1027 
1028  cost_index(pathnode, root, loop_count, partial_path);
1029 
1030  return pathnode;
1031 }
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:519
List * indexclauses
Definition: pathnodes.h:1601
ScanDirection indexscandir
Definition: pathnodes.h:1604
Path path
Definition: pathnodes.h:1599
List * indexorderbycols
Definition: pathnodes.h:1603
List * indexorderbys
Definition: pathnodes.h:1602
IndexOptInfo * indexinfo
Definition: pathnodes.h:1600
Definition: type.h:95

References RelOptInfo::consider_parallel, cost_index(), get_baserel_parampathinfo(), IndexPath::indexclauses, IndexPath::indexinfo, IndexPath::indexorderbycols, IndexPath::indexorderbys, IndexPath::indexscandir, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, IndexPath::path, Path::pathkeys, Path::pathtype, and RelOptInfo::reltarget.

Referenced by build_index_paths(), and plan_cluster_use_sort().

◆ create_limit_path()

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

Definition at line 3754 of file pathnode.c.

3759 {
3760  LimitPath *pathnode = makeNode(LimitPath);
3761 
3762  pathnode->path.pathtype = T_Limit;
3763  pathnode->path.parent = rel;
3764  /* Limit doesn't project, so use source path's pathtarget */
3765  pathnode->path.pathtarget = subpath->pathtarget;
3766  /* For now, assume we are above any joins, so no parameterization */
3767  pathnode->path.param_info = NULL;
3768  pathnode->path.parallel_aware = false;
3769  pathnode->path.parallel_safe = rel->consider_parallel &&
3770  subpath->parallel_safe;
3771  pathnode->path.parallel_workers = subpath->parallel_workers;
3772  pathnode->path.rows = subpath->rows;
3773  pathnode->path.startup_cost = subpath->startup_cost;
3774  pathnode->path.total_cost = subpath->total_cost;
3775  pathnode->path.pathkeys = subpath->pathkeys;
3776  pathnode->subpath = subpath;
3777  pathnode->limitOffset = limitOffset;
3778  pathnode->limitCount = limitCount;
3779  pathnode->limitOption = limitOption;
3780 
3781  /*
3782  * Adjust the output rows count and costs according to the offset/limit.
3783  */
3784  adjust_limit_rows_costs(&pathnode->path.rows,
3785  &pathnode->path.startup_cost,
3786  &pathnode->path.total_cost,
3787  offset_est, count_est);
3788 
3789  return pathnode;
3790 }
void adjust_limit_rows_costs(double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
Definition: pathnode.c:3809
Path path
Definition: pathnodes.h:2274
Path * subpath
Definition: pathnodes.h:2275
LimitOption limitOption
Definition: pathnodes.h:2278
Node * limitOffset
Definition: pathnodes.h:2276
Node * limitCount
Definition: pathnodes.h:2277

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

Referenced by create_final_distinct_paths(), and grouping_planner().

◆ create_lockrows_path()

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

Definition at line 3593 of file pathnode.c.

3595 {
3596  LockRowsPath *pathnode = makeNode(LockRowsPath);
3597 
3598  pathnode->path.pathtype = T_LockRows;
3599  pathnode->path.parent = rel;
3600  /* LockRows doesn't project, so use source path's pathtarget */
3601  pathnode->path.pathtarget = subpath->pathtarget;
3602  /* For now, assume we are above any joins, so no parameterization */
3603  pathnode->path.param_info = NULL;
3604  pathnode->path.parallel_aware = false;
3605  pathnode->path.parallel_safe = false;
3606  pathnode->path.parallel_workers = 0;
3607  pathnode->path.rows = subpath->rows;
3608 
3609  /*
3610  * The result cannot be assumed sorted, since locking might cause the sort
3611  * key columns to be replaced with new values.
3612  */
3613  pathnode->path.pathkeys = NIL;
3614 
3615  pathnode->subpath = subpath;
3616  pathnode->rowMarks = rowMarks;
3617  pathnode->epqParam = epqParam;
3618 
3619  /*
3620  * We should charge something extra for the costs of row locking and
3621  * possible refetches, but it's hard to say how much. For now, use
3622  * cpu_tuple_cost per row.
3623  */
3624  pathnode->path.startup_cost = subpath->startup_cost;
3625  pathnode->path.total_cost = subpath->total_cost +
3626  cpu_tuple_cost * subpath->rows;
3627 
3628  return pathnode;
3629 }
Path * subpath
Definition: pathnodes.h:2237
List * rowMarks
Definition: pathnodes.h:2238

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

Referenced by grouping_planner().

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

Definition at line 1564 of file pathnode.c.

1565 {
1566  MaterialPath *pathnode = makeNode(MaterialPath);
1567 
1568  Assert(subpath->parent == rel);
1569 
1570  pathnode->path.pathtype = T_Material;
1571  pathnode->path.parent = rel;
1572  pathnode->path.pathtarget = rel->reltarget;
1573  pathnode->path.param_info = subpath->param_info;
1574  pathnode->path.parallel_aware = false;
1575  pathnode->path.parallel_safe = rel->consider_parallel &&
1576  subpath->parallel_safe;
1577  pathnode->path.parallel_workers = subpath->parallel_workers;
1578  pathnode->path.pathkeys = subpath->pathkeys;
1579 
1580  pathnode->subpath = subpath;
1581 
1582  cost_material(&pathnode->path,
1583  subpath->startup_cost,
1584  subpath->total_cost,
1585  subpath->rows,
1586  subpath->pathtarget->width);
1587 
1588  return pathnode;
1589 }
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2425
Path * subpath
Definition: pathnodes.h:1859

References Assert(), RelOptInfo::consider_parallel, cost_material(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, MaterialPath::path, Path::pathkeys, Path::pathtype, RelOptInfo::reltarget, subpath(), and MaterialPath::subpath.

Referenced by match_unsorted_outer(), reparameterize_path(), and set_tablesample_rel_pathlist().

◆ create_memoize_path()

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

Definition at line 1596 of file pathnode.c.

1599 {
1600  MemoizePath *pathnode = makeNode(MemoizePath);
1601 
1602  Assert(subpath->parent == rel);
1603 
1604  pathnode->path.pathtype = T_Memoize;
1605  pathnode->path.parent = rel;
1606  pathnode->path.pathtarget = rel->reltarget;
1607  pathnode->path.param_info = subpath->param_info;
1608  pathnode->path.parallel_aware = false;
1609  pathnode->path.parallel_safe = rel->consider_parallel &&
1610  subpath->parallel_safe;
1611  pathnode->path.parallel_workers = subpath->parallel_workers;
1612  pathnode->path.pathkeys = subpath->pathkeys;
1613 
1614  pathnode->subpath = subpath;
1615  pathnode->hash_operators = hash_operators;
1616  pathnode->param_exprs = param_exprs;
1617  pathnode->singlerow = singlerow;
1618  pathnode->binary_mode = binary_mode;
1619  pathnode->calls = calls;
1620 
1621  /*
1622  * For now we set est_entries to 0. cost_memoize_rescan() does all the
1623  * hard work to determine how many cache entries there are likely to be,
1624  * so it seems best to leave it up to that function to fill this field in.
1625  * If left at 0, the executor will make a guess at a good value.
1626  */
1627  pathnode->est_entries = 0;
1628 
1629  /*
1630  * Add a small additional charge for caching the first entry. All the
1631  * harder calculations for rescans are performed in cost_memoize_rescan().
1632  */
1633  pathnode->path.startup_cost = subpath->startup_cost + cpu_tuple_cost;
1634  pathnode->path.total_cost = subpath->total_cost + cpu_tuple_cost;
1635  pathnode->path.rows = subpath->rows;
1636 
1637  return pathnode;
1638 }
bool singlerow
Definition: pathnodes.h:1873
List * hash_operators
Definition: pathnodes.h:1871
uint32 est_entries
Definition: pathnodes.h:1878
bool binary_mode
Definition: pathnodes.h:1875
Cardinality calls
Definition: pathnodes.h:1877
Path * subpath
Definition: pathnodes.h:1870
List * param_exprs
Definition: pathnodes.h:1872

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

Referenced by get_memoize_path(), and reparameterize_path().

◆ create_merge_append_path()

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

Definition at line 1413 of file pathnode.c.

1418 {
1420  Cost input_startup_cost;
1421  Cost input_total_cost;
1422  ListCell *l;
1423 
1424  pathnode->path.pathtype = T_MergeAppend;
1425  pathnode->path.parent = rel;
1426  pathnode->path.pathtarget = rel->reltarget;
1427  pathnode->path.param_info = get_appendrel_parampathinfo(rel,
1428  required_outer);
1429  pathnode->path.parallel_aware = false;
1430  pathnode->path.parallel_safe = rel->consider_parallel;
1431  pathnode->path.parallel_workers = 0;
1432  pathnode->path.pathkeys = pathkeys;
1433  pathnode->subpaths = subpaths;
1434 
1435  /*
1436  * Apply query-wide LIMIT if known and path is for sole base relation.
1437  * (Handling this at this low level is a bit klugy.)
1438  */
1439  if (bms_equal(rel->relids, root->all_baserels))
1440  pathnode->limit_tuples = root->limit_tuples;
1441  else
1442  pathnode->limit_tuples = -1.0;
1443 
1444  /*
1445  * Add up the sizes and costs of the input paths.
1446  */
1447  pathnode->path.rows = 0;
1448  input_startup_cost = 0;
1449  input_total_cost = 0;
1450  foreach(l, subpaths)
1451  {
1452  Path *subpath = (Path *) lfirst(l);
1453 
1454  pathnode->path.rows += subpath->rows;
1455  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1456  subpath->parallel_safe;
1457 
1458  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1459  {
1460  /* Subpath is adequately ordered, we won't need to sort it */
1461  input_startup_cost += subpath->startup_cost;
1462  input_total_cost += subpath->total_cost;
1463  }
1464  else
1465  {
1466  /* We'll need to insert a Sort node, so include cost for that */
1467  Path sort_path; /* dummy for result of cost_sort */
1468 
1469  cost_sort(&sort_path,
1470  root,
1471  pathkeys,
1472  subpath->total_cost,
1473  subpath->parent->tuples,
1474  subpath->pathtarget->width,
1475  0.0,
1476  work_mem,
1477  pathnode->limit_tuples);
1478  input_startup_cost += sort_path.startup_cost;
1479  input_total_cost += sort_path.total_cost;
1480  }
1481 
1482  /* All child paths must have same parameterization */
1483  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1484  }
1485 
1486  /*
1487  * Now we can compute total costs of the MergeAppend. If there's exactly
1488  * one child path and its parallel awareness matches that of the
1489  * MergeAppend, then the MergeAppend is a no-op and will be discarded
1490  * later (in setrefs.c); otherwise we do the normal cost calculation.
1491  */
1492  if (list_length(subpaths) == 1 &&
1493  ((Path *) linitial(subpaths))->parallel_aware ==
1494  pathnode->path.parallel_aware)
1495  {
1496  pathnode->path.startup_cost = input_startup_cost;
1497  pathnode->path.total_cost = input_total_cost;
1498  }
1499  else
1500  cost_merge_append(&pathnode->path, root,
1501  pathkeys, list_length(subpaths),
1502  input_startup_cost, input_total_cost,
1503  pathnode->path.rows);
1504 
1505  return pathnode;
1506 }
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:2376
Cardinality limit_tuples
Definition: pathnodes.h:1834

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, linitial, list_length(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, MergeAppendPath::path, PATH_REQ_OUTER, Path::pathkeys, pathkeys_contained_in(), Path::pathtype, RelOptInfo::relids, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), MergeAppendPath::subpaths, Path::total_cost, and work_mem.

Referenced by generate_orderedappend_paths().

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

2527 {
2528  MergePath *pathnode = makeNode(MergePath);
2529 
2530  pathnode->jpath.path.pathtype = T_MergeJoin;
2531  pathnode->jpath.path.parent = joinrel;
2532  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2533  pathnode->jpath.path.param_info =
2535  joinrel,
2536  outer_path,
2537  inner_path,
2538  extra->sjinfo,
2539  required_outer,
2540  &restrict_clauses);
2541  pathnode->jpath.path.parallel_aware = false;
2542  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2543  outer_path->parallel_safe && inner_path->parallel_safe;
2544  /* This is a foolish way to estimate parallel_workers, but for now... */
2545  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2546  pathnode->jpath.path.pathkeys = pathkeys;
2547  pathnode->jpath.jointype = jointype;
2548  pathnode->jpath.inner_unique = extra->inner_unique;
2549  pathnode->jpath.outerjoinpath = outer_path;
2550  pathnode->jpath.innerjoinpath = inner_path;
2551  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2552  pathnode->path_mergeclauses = mergeclauses;
2553  pathnode->outersortkeys = outersortkeys;
2554  pathnode->innersortkeys = innersortkeys;
2555  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2556  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2557 
2558  final_cost_mergejoin(root, pathnode, workspace, extra);
2559 
2560  return pathnode;
2561 }
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3473
List * outersortkeys
Definition: pathnodes.h:2011
List * innersortkeys
Definition: pathnodes.h:2012
JoinPath jpath
Definition: pathnodes.h:2009
List * path_mergeclauses
Definition: pathnodes.h:2010

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_safe, Path::parallel_workers, MergePath::path_mergeclauses, RelOptInfo::reltarget, and JoinPathExtraData::sjinfo.

Referenced by try_mergejoin_path(), and try_partial_mergejoin_path().

◆ create_minmaxagg_path()

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

Definition at line 3342 of file pathnode.c.

3347 {
3348  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3349  Cost initplan_cost;
3350  ListCell *lc;
3351 
3352  /* The topmost generated Plan node will be a Result */
3353  pathnode->path.pathtype = T_Result;
3354  pathnode->path.parent = rel;
3355  pathnode->path.pathtarget = target;
3356  /* For now, assume we are above any joins, so no parameterization */
3357  pathnode->path.param_info = NULL;
3358  pathnode->path.parallel_aware = false;
3359  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3360  pathnode->path.parallel_safe = false;
3361  pathnode->path.parallel_workers = 0;
3362  /* Result is one unordered row */
3363  pathnode->path.rows = 1;
3364  pathnode->path.pathkeys = NIL;
3365 
3366  pathnode->mmaggregates = mmaggregates;
3367  pathnode->quals = quals;
3368 
3369  /* Calculate cost of all the initplans ... */
3370  initplan_cost = 0;
3371  foreach(lc, mmaggregates)
3372  {
3373  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3374 
3375  initplan_cost += mminfo->pathcost;
3376  }
3377 
3378  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3379  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3380  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3381  target->cost.per_tuple + cpu_tuple_cost;
3382 
3383  /*
3384  * Add cost of qual, if any --- but we ignore its selectivity, since our
3385  * rowcount estimate should be 1 no matter what the qual is.
3386  */
3387  if (quals)
3388  {
3389  QualCost qual_cost;
3390 
3391  cost_qual_eval(&qual_cost, quals, root);
3392  pathnode->path.startup_cost += qual_cost.startup;
3393  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3394  }
3395 
3396  return pathnode;
3397 }
List * quals
Definition: pathnodes.h:2187
List * mmaggregates
Definition: pathnodes.h:2186

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

Referenced by preprocess_minmax_aggregates().

◆ create_modifytable_path()

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

Definition at line 3655 of file pathnode.c.

3665 {
3667 
3668  Assert(operation == CMD_MERGE ||
3669  (operation == CMD_UPDATE ?
3670  list_length(resultRelations) == list_length(updateColnosLists) :
3671  updateColnosLists == NIL));
3672  Assert(withCheckOptionLists == NIL ||
3673  list_length(resultRelations) == list_length(withCheckOptionLists));
3674  Assert(returningLists == NIL ||
3675  list_length(resultRelations) == list_length(returningLists));
3676 
3677  pathnode->path.pathtype = T_ModifyTable;
3678  pathnode->path.parent = rel;
3679  /* pathtarget is not interesting, just make it minimally valid */
3680  pathnode->path.pathtarget = rel->reltarget;
3681  /* For now, assume we are above any joins, so no parameterization */
3682  pathnode->path.param_info = NULL;
3683  pathnode->path.parallel_aware = false;
3684  pathnode->path.parallel_safe = false;
3685  pathnode->path.parallel_workers = 0;
3686  pathnode->path.pathkeys = NIL;
3687 
3688  /*
3689  * Compute cost & rowcount as subpath cost & rowcount (if RETURNING)
3690  *
3691  * Currently, we don't charge anything extra for the actual table
3692  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3693  * expressions if any. It would only be window dressing, since
3694  * ModifyTable is always a top-level node and there is no way for the
3695  * costs to change any higher-level planning choices. But we might want
3696  * to make it look better sometime.
3697  */
3698  pathnode->path.startup_cost = subpath->startup_cost;
3699  pathnode->path.total_cost = subpath->total_cost;
3700  if (returningLists != NIL)
3701  {
3702  pathnode->path.rows = subpath->rows;
3703 
3704  /*
3705  * Set width to match the subpath output. XXX this is totally wrong:
3706  * we should return an average of the RETURNING tlist widths. But
3707  * it's what happened historically, and improving it is a task for
3708  * another day. (Again, it's mostly window dressing.)
3709  */
3710  pathnode->path.pathtarget->width = subpath->pathtarget->width;
3711  }
3712  else
3713  {
3714  pathnode->path.rows = 0;
3715  pathnode->path.pathtarget->width = 0;
3716  }
3717 
3718  pathnode->subpath = subpath;
3719  pathnode->operation = operation;
3720  pathnode->canSetTag = canSetTag;
3721  pathnode->nominalRelation = nominalRelation;
3722  pathnode->rootRelation = rootRelation;
3723  pathnode->partColsUpdated = partColsUpdated;
3724  pathnode->resultRelations = resultRelations;
3725  pathnode->updateColnosLists = updateColnosLists;
3726  pathnode->withCheckOptionLists = withCheckOptionLists;
3727  pathnode->returningLists = returningLists;
3728  pathnode->rowMarks = rowMarks;
3729  pathnode->onconflict = onconflict;
3730  pathnode->epqParam = epqParam;
3731  pathnode->mergeActionLists = mergeActionLists;
3732 
3733  return pathnode;
3734 }
@ CMD_MERGE
Definition: nodes.h:269
@ CMD_UPDATE
Definition: nodes.h:266
bool partColsUpdated
Definition: pathnodes.h:2257
List * returningLists
Definition: pathnodes.h:2261
List * resultRelations
Definition: pathnodes.h:2258
List * withCheckOptionLists
Definition: pathnodes.h:2260
List * updateColnosLists
Definition: pathnodes.h:2259
OnConflictExpr * onconflict
Definition: pathnodes.h:2263
CmdType operation
Definition: pathnodes.h:2253
Index rootRelation
Definition: pathnodes.h:2256
Index nominalRelation
Definition: pathnodes.h:2255
List * mergeActionLists
Definition: pathnodes.h:2265

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

Referenced by grouping_planner().

◆ create_namedtuplestorescan_path()

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

Definition at line 2141 of file pathnode.c.

2143 {
2144  Path *pathnode = makeNode(Path);
2145 
2146  pathnode->pathtype = T_NamedTuplestoreScan;
2147  pathnode->parent = rel;
2148  pathnode->pathtarget = rel->reltarget;
2149  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2150  required_outer);
2151  pathnode->parallel_aware = false;
2152  pathnode->parallel_safe = rel->consider_parallel;
2153  pathnode->parallel_workers = 0;
2154  pathnode->pathkeys = NIL; /* result is always unordered */
2155 
2156  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2157 
2158  return pathnode;
2159 }
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1709

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

Referenced by set_namedtuplestore_pathlist().

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

2436 {
2437  NestPath *pathnode = makeNode(NestPath);
2438  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2439 
2440  /*
2441  * If the inner path is parameterized by the outer, we must drop any
2442  * restrict_clauses that are due to be moved into the inner path. We have
2443  * to do this now, rather than postpone the work till createplan time,
2444  * because the restrict_clauses list can affect the size and cost
2445  * estimates for this path.
2446  */
2447  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2448  {
2449  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2450  inner_req_outer);
2451  List *jclauses = NIL;
2452  ListCell *lc;
2453 
2454  foreach(lc, restrict_clauses)
2455  {
2456  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2457 
2458  if (!join_clause_is_movable_into(rinfo,
2459  inner_path->parent->relids,
2460  inner_and_outer))
2461  jclauses = lappend(jclauses, rinfo);
2462  }
2463  restrict_clauses = jclauses;
2464  }
2465 
2466  pathnode->jpath.path.pathtype = T_NestLoop;
2467  pathnode->jpath.path.parent = joinrel;
2468  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2469  pathnode->jpath.path.param_info =
2471  joinrel,
2472  outer_path,
2473  inner_path,
2474  extra->sjinfo,
2475  required_outer,
2476  &restrict_clauses);
2477  pathnode->jpath.path.parallel_aware = false;
2478  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2479  outer_path->parallel_safe && inner_path->parallel_safe;
2480  /* This is a foolish way to estimate parallel_workers, but for now... */
2481  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2482  pathnode->jpath.path.pathkeys = pathkeys;
2483  pathnode->jpath.jointype = jointype;
2484  pathnode->jpath.inner_unique = extra->inner_unique;
2485  pathnode->jpath.outerjoinpath = outer_path;
2486  pathnode->jpath.innerjoinpath = inner_path;
2487  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2488 
2489  final_cost_nestloop(root, pathnode, workspace, extra);
2490 
2491  return pathnode;
2492 }
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3037
List * lappend(List *list, void *datum)
Definition: list.c:338
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:600
JoinPath jpath
Definition: pathnodes.h:1969

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, NestPath::jpath, lappend(), lfirst, makeNode, NIL, JoinPath::outerjoinpath, Path::parallel_safe, Path::parallel_workers, PATH_REQ_OUTER, RelOptInfo::reltarget, and JoinPathExtraData::sjinfo.

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

◆ create_projection_path()

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

Definition at line 2646 of file pathnode.c.

2650 {
2651  ProjectionPath *pathnode = makeNode(ProjectionPath);
2652  PathTarget *oldtarget;
2653 
2654  /*
2655  * We mustn't put a ProjectionPath directly above another; it's useless
2656  * and will confuse create_projection_plan. Rather than making sure all
2657  * callers handle that, let's implement it here, by stripping off any
2658  * ProjectionPath in what we're given. Given this rule, there won't be
2659  * more than one.
2660  */
2661  if (IsA(subpath, ProjectionPath))
2662  {
2663  ProjectionPath *subpp = (ProjectionPath *) subpath;
2664 
2665  Assert(subpp->path.parent == rel);
2666  subpath = subpp->subpath;
2668  }
2669 
2670  pathnode->path.pathtype = T_Result;
2671  pathnode->path.parent = rel;
2672  pathnode->path.pathtarget = target;
2673  /* For now, assume we are above any joins, so no parameterization */
2674  pathnode->path.param_info = NULL;
2675  pathnode->path.parallel_aware = false;
2676  pathnode->path.parallel_safe = rel->consider_parallel &&
2677  subpath->parallel_safe &&
2678  is_parallel_safe(root, (Node *) target->exprs);
2679  pathnode->path.parallel_workers = subpath->parallel_workers;
2680  /* Projection does not change the sort order */
2681  pathnode->path.pathkeys = subpath->pathkeys;
2682 
2683  pathnode->subpath = subpath;
2684 
2685  /*
2686  * We might not need a separate Result node. If the input plan node type
2687  * can project, we can just tell it to project something else. Or, if it
2688  * can't project but the desired target has the same expression list as
2689  * what the input will produce anyway, we can still give it the desired
2690  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2691  * Note: in the latter case, create_projection_plan has to recheck our
2692  * conclusion; see comments therein.
2693  */
2694  oldtarget = subpath->pathtarget;
2696  equal(oldtarget->exprs, target->exprs))
2697  {
2698  /* No separate Result node needed */
2699  pathnode->dummypp = true;
2700 
2701  /*
2702  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2703  */
2704  pathnode->path.rows = subpath->rows;
2705  pathnode->path.startup_cost = subpath->startup_cost +
2706  (target->cost.startup - oldtarget->cost.startup);
2707  pathnode->path.total_cost = subpath->total_cost +
2708  (target->cost.startup - oldtarget->cost.startup) +
2709  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2710  }
2711  else
2712  {
2713  /* We really do need the Result node */
2714  pathnode->dummypp = false;
2715 
2716  /*
2717  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2718  * evaluating the tlist. There is no qual to worry about.
2719  */
2720  pathnode->path.rows = subpath->rows;
2721  pathnode->path.startup_cost = subpath->startup_cost +
2722  target->cost.startup;
2723  pathnode->path.total_cost = subpath->total_cost +
2724  target->cost.startup +
2725  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2726  }
2727 
2728  return pathnode;
2729 }
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:225
Path * subpath
Definition: pathnodes.h:2051

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

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

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

3556 {
3558 
3559  pathnode->path.pathtype = T_RecursiveUnion;
3560  pathnode->path.parent = rel;
3561  pathnode->path.pathtarget = target;
3562  /* For now, assume we are above any joins, so no parameterization */
3563  pathnode->path.param_info = NULL;
3564  pathnode->path.parallel_aware = false;
3565  pathnode->path.parallel_safe = rel->consider_parallel &&
3566  leftpath->parallel_safe && rightpath->parallel_safe;
3567  /* Foolish, but we'll do it like joins for now: */
3568  pathnode->path.parallel_workers = leftpath->parallel_workers;
3569  /* RecursiveUnion result is always unsorted */
3570  pathnode->path.pathkeys = NIL;
3571 
3572  pathnode->leftpath = leftpath;
3573  pathnode->rightpath = rightpath;
3574  pathnode->distinctList = distinctList;
3575  pathnode->wtParam = wtParam;
3576  pathnode->numGroups = numGroups;
3577 
3578  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3579 
3580  return pathnode;
3581 }
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1783
Cardinality numGroups
Definition: pathnodes.h:2228

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

Referenced by generate_recursion_path().

◆ create_resultscan_path()

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

Definition at line 2167 of file pathnode.c.

2169 {
2170  Path *pathnode = makeNode(Path);
2171 
2172  pathnode->pathtype = T_Result;
2173  pathnode->parent = rel;
2174  pathnode->pathtarget = rel->reltarget;
2175  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2176  required_outer);
2177  pathnode->parallel_aware = false;
2178  pathnode->parallel_safe = rel->consider_parallel;
2179  pathnode->parallel_workers = 0;
2180  pathnode->pathkeys = NIL; /* result is always unordered */
2181 
2182  cost_resultscan(pathnode, root, rel, pathnode->param_info);
2183 
2184  return pathnode;
2185 }
void cost_resultscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1746

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

Referenced by reparameterize_path(), and set_result_pathlist().

◆ create_samplescan_path()

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

Definition at line 954 of file pathnode.c.

955 {
956  Path *pathnode = makeNode(Path);
957 
958  pathnode->pathtype = T_SampleScan;
959  pathnode->parent = rel;
960  pathnode->pathtarget = rel->reltarget;
961  pathnode->param_info = get_baserel_parampathinfo(root, rel,
962  required_outer);
963  pathnode->parallel_aware = false;
964  pathnode->parallel_safe = rel->consider_parallel;
965  pathnode->parallel_workers = 0;
966  pathnode->pathkeys = NIL; /* samplescan has unordered result */
967 
968  cost_samplescan(pathnode, root, rel, pathnode->param_info);
969 
970  return pathnode;
971 }
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:331

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

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

◆ create_seqscan_path()

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

Definition at line 929 of file pathnode.c.

931 {
932  Path *pathnode = makeNode(Path);
933 
934  pathnode->pathtype = T_SeqScan;
935  pathnode->parent = rel;
936  pathnode->pathtarget = rel->reltarget;
937  pathnode->param_info = get_baserel_parampathinfo(root, rel,
938  required_outer);
939  pathnode->parallel_aware = (parallel_workers > 0);
940  pathnode->parallel_safe = rel->consider_parallel;
941  pathnode->parallel_workers = parallel_workers;
942  pathnode->pathkeys = NIL; /* seqscan has unordered result */
943 
944  cost_seqscan(pathnode, root, rel, pathnode->param_info);
945 
946  return pathnode;
947 }
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:254

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

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

◆ create_set_projection_path()

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

Definition at line 2843 of file pathnode.c.

2847 {
2848  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2849  double tlist_rows;
2850  ListCell *lc;
2851 
2852  pathnode->path.pathtype = T_ProjectSet;
2853  pathnode->path.parent = rel;
2854  pathnode->path.pathtarget = target;
2855  /* For now, assume we are above any joins, so no parameterization */
2856  pathnode->path.param_info = NULL;
2857  pathnode->path.parallel_aware = false;
2858  pathnode->path.parallel_safe = rel->consider_parallel &&
2859  subpath->parallel_safe &&
2860  is_parallel_safe(root, (Node *) target->exprs);
2861  pathnode->path.parallel_workers = subpath->parallel_workers;
2862  /* Projection does not change the sort order XXX? */
2863  pathnode->path.pathkeys = subpath->pathkeys;
2864 
2865  pathnode->subpath = subpath;
2866 
2867  /*
2868  * Estimate number of rows produced by SRFs for each row of input; if
2869  * there's more than one in this node, use the maximum.
2870  */
2871  tlist_rows = 1;
2872  foreach(lc, target->exprs)
2873  {
2874  Node *node = (Node *) lfirst(lc);
2875  double itemrows;
2876 
2877  itemrows = expression_returns_set_rows(root, node);
2878  if (tlist_rows < itemrows)
2879  tlist_rows = itemrows;
2880  }
2881 
2882  /*
2883  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2884  * per input row, and half of cpu_tuple_cost for each added output row.
2885  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2886  * this estimate later.
2887  */
2888  pathnode->path.rows = subpath->rows * tlist_rows;
2889  pathnode->path.startup_cost = subpath->startup_cost +
2890  target->cost.startup;
2891  pathnode->path.total_cost = subpath->total_cost +
2892  target->cost.startup +
2893  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2894  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2895 
2896  return pathnode;
2897 }
double expression_returns_set_rows(PlannerInfo *root, Node *clause)
Definition: clauses.c:289
Path * subpath
Definition: pathnodes.h:2063

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, ProjectSetPath::path, Path::pathkeys, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectSetPath::subpath, and Path::total_cost.

Referenced by adjust_paths_for_srfs().

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

3496 {
3497  SetOpPath *pathnode = makeNode(SetOpPath);
3498 
3499  pathnode->path.pathtype = T_SetOp;
3500  pathnode->path.parent = rel;
3501  /* SetOp doesn't project, so use source path's pathtarget */
3502  pathnode->path.pathtarget = subpath->pathtarget;
3503  /* For now, assume we are above any joins, so no parameterization */
3504  pathnode->path.param_info = NULL;
3505  pathnode->path.parallel_aware = false;
3506  pathnode->path.parallel_safe = rel->consider_parallel &&
3507  subpath->parallel_safe;
3508  pathnode->path.parallel_workers = subpath->parallel_workers;
3509  /* SetOp preserves the input sort order if in sort mode */
3510  pathnode->path.pathkeys =
3511  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3512 
3513  pathnode->subpath = subpath;
3514  pathnode->cmd = cmd;
3515  pathnode->strategy = strategy;
3516  pathnode->distinctList = distinctList;
3517  pathnode->flagColIdx = flagColIdx;
3518  pathnode->firstFlag = firstFlag;
3519  pathnode->numGroups = numGroups;
3520 
3521  /*
3522  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3523  * all columns get compared at most of the tuples.
3524  */
3525  pathnode->path.startup_cost = subpath->startup_cost;
3526  pathnode->path.total_cost = subpath->total_cost +
3527  cpu_operator_cost * subpath->rows * list_length(distinctList);
3528  pathnode->path.rows = outputRows;
3529 
3530  return pathnode;
3531 }
double cpu_operator_cost
Definition: costsize.c:124
@ SETOP_SORTED
Definition: nodes.h:403
List * distinctList
Definition: pathnodes.h:2212
Cardinality numGroups
Definition: pathnodes.h:2215
int firstFlag
Definition: pathnodes.h:2214
Path * subpath
Definition: pathnodes.h:2209
SetOpCmd cmd
Definition: pathnodes.h:2210
Path path
Definition: pathnodes.h:2208
SetOpStrategy strategy
Definition: pathnodes.h:2211
AttrNumber flagColIdx
Definition: pathnodes.h:2213

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, SetOpPath::path, Path::pathkeys, Path::pathtype, Path::rows, SETOP_SORTED, Path::startup_cost, SetOpPath::strategy, subpath(), SetOpPath::subpath, and Path::total_cost.

Referenced by generate_nonunion_paths().

◆ create_sort_path()

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

Definition at line 2961 of file pathnode.c.

2966 {
2967  SortPath *pathnode = makeNode(SortPath);
2968 
2969  pathnode->path.pathtype = T_Sort;
2970  pathnode->path.parent = rel;
2971  /* Sort doesn't project, so use source path's pathtarget */
2972  pathnode->path.pathtarget = subpath->pathtarget;
2973  /* For now, assume we are above any joins, so no parameterization */
2974  pathnode->path.param_info = NULL;
2975  pathnode->path.parallel_aware = false;
2976  pathnode->path.parallel_safe = rel->consider_parallel &&
2977  subpath->parallel_safe;
2978  pathnode->path.parallel_workers = subpath->parallel_workers;
2979  pathnode->path.pathkeys = pathkeys;
2980 
2981  pathnode->subpath = subpath;
2982 
2983  cost_sort(&pathnode->path, root, pathkeys,
2984  subpath->total_cost,
2985  subpath->rows,
2986  subpath->pathtarget->width,
2987  0.0, /* XXX comparison_cost shouldn't be 0? */
2988  work_mem, limit_tuples);
2989 
2990  return pathnode;
2991 }

References RelOptInfo::consider_parallel, cost_sort(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, SortPath::path, Path::pathkeys, Path::pathtype, subpath(), SortPath::subpath, and work_mem.

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

◆ create_subqueryscan_path()

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

Definition at line 2008 of file pathnode.c.

2011 {
2013 
2014  pathnode->path.pathtype = T_SubqueryScan;
2015  pathnode->path.parent = rel;
2016  pathnode->path.pathtarget = rel->reltarget;
2017  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2018  required_outer);
2019  pathnode->path.parallel_aware = false;
2020  pathnode->path.parallel_safe = rel->consider_parallel &&
2021  subpath->parallel_safe;
2022  pathnode->path.parallel_workers = subpath->parallel_workers;
2023  pathnode->path.pathkeys = pathkeys;
2024  pathnode->subpath = subpath;
2025 
2026  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info,
2027  trivial_pathtarget);
2028 
2029  return pathnode;
2030 }
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, bool trivial_pathtarget)
Definition: costsize.c:1421

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

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

◆ create_tablefuncscan_path()

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

Definition at line 2064 of file pathnode.c.

2066 {
2067  Path *pathnode = makeNode(Path);
2068 
2069  pathnode->pathtype = T_TableFuncScan;
2070  pathnode->parent = rel;
2071  pathnode->pathtarget = rel->reltarget;
2072  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2073  required_outer);
2074  pathnode->parallel_aware = false;
2075  pathnode->parallel_safe = rel->consider_parallel;
2076  pathnode->parallel_workers = 0;
2077  pathnode->pathkeys = NIL; /* result is always unordered */
2078 
2079  cost_tablefuncscan(pathnode, root, rel, pathnode->param_info);
2080 
2081  return pathnode;
2082 }
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1562

References RelOptInfo::consider_parallel, cost_tablefuncscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::pathkeys, Path::pathtype, and RelOptInfo::reltarget.

Referenced by set_tablefunc_pathlist().

◆ create_tidrangescan_path()

TidRangePath* create_tidrangescan_path ( PlannerInfo root,
RelOptInfo rel,
List tidrangequals,
Relids  required_outer 
)

Definition at line 1212 of file pathnode.c.

1214 {
1215  TidRangePath *pathnode = makeNode(TidRangePath);
1216 
1217  pathnode->path.pathtype = T_TidRangeScan;
1218  pathnode->path.parent = rel;
1219  pathnode->path.pathtarget = rel->reltarget;
1220  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1221  required_outer);
1222  pathnode->path.parallel_aware = false;
1223  pathnode->path.parallel_safe = rel->consider_parallel;
1224  pathnode->path.parallel_workers = 0;
1225  pathnode->path.pathkeys = NIL; /* always unordered */
1226 
1227  pathnode->tidrangequals = tidrangequals;
1228 
1229  cost_tidrangescan(&pathnode->path, root, rel, tidrangequals,
1230  pathnode->path.param_info);
1231 
1232  return pathnode;
1233 }
void cost_tidrangescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidrangequals, ParamPathInfo *param_info)
Definition: costsize.c:1327
List * tidrangequals
Definition: pathnodes.h:1726

References RelOptInfo::consider_parallel, cost_tidrangescan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, TidRangePath::path, Path::pathkeys, Path::pathtype, RelOptInfo::reltarget, and TidRangePath::tidrangequals.

Referenced by create_tidscan_paths().

◆ create_tidscan_path()

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

Definition at line 1183 of file pathnode.c.

1185 {
1186  TidPath *pathnode = makeNode(TidPath);
1187 
1188  pathnode->path.pathtype = T_TidScan;
1189  pathnode->path.parent = rel;
1190  pathnode->path.pathtarget = rel->reltarget;
1191  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1192  required_outer);
1193  pathnode->path.parallel_aware = false;
1194  pathnode->path.parallel_safe = rel->consider_parallel;
1195  pathnode->path.parallel_workers = 0;
1196  pathnode->path.pathkeys = NIL; /* always unordered */
1197 
1198  pathnode->tidquals = tidquals;
1199 
1200  cost_tidscan(&pathnode->path, root, rel, tidquals,
1201  pathnode->path.param_info);
1202 
1203  return pathnode;
1204 }
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1219
List * tidquals
Definition: pathnodes.h:1714
Path path
Definition: pathnodes.h:1713

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

Referenced by BuildParameterizedTidPaths(), and create_tidscan_paths().

◆ create_unique_path()

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

Definition at line 1652 of file pathnode.c.

1654 {
1655  UniquePath *pathnode;
1656  Path sort_path; /* dummy for result of cost_sort */
1657  Path agg_path; /* dummy for result of cost_agg */
1658  MemoryContext oldcontext;
1659  int numCols;
1660 
1661  /* Caller made a mistake if subpath isn't cheapest_total ... */
1663  Assert(subpath->parent == rel);
1664  /* ... or if SpecialJoinInfo is the wrong one */
1665  Assert(sjinfo->jointype == JOIN_SEMI);
1666  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1667 
1668  /* If result already cached, return it */
1669  if (rel->cheapest_unique_path)
1670  return (UniquePath *) rel->cheapest_unique_path;
1671 
1672  /* If it's not possible to unique-ify, return NULL */
1673  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1674  return NULL;
1675 
1676  /*
1677  * When called during GEQO join planning, we are in a short-lived memory
1678  * context. We must make sure that the path and any subsidiary data
1679  * structures created for a baserel survive the GEQO cycle, else the
1680  * baserel is trashed for future GEQO cycles. On the other hand, when we
1681  * are creating those for a joinrel during GEQO, we don't want them to
1682  * clutter the main planning context. Upshot is that the best solution is
1683  * to explicitly allocate memory in the same context the given RelOptInfo
1684  * is in.
1685  */
1686  oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
1687 
1688  pathnode = makeNode(UniquePath);
1689 
1690  pathnode->path.pathtype = T_Unique;
1691  pathnode->path.parent = rel;
1692  pathnode->path.pathtarget = rel->reltarget;
1693  pathnode->path.param_info = subpath->param_info;
1694  pathnode->path.parallel_aware = false;
1695  pathnode->path.parallel_safe = rel->consider_parallel &&
1696  subpath->parallel_safe;
1697  pathnode->path.parallel_workers = subpath->parallel_workers;
1698 
1699  /*
1700  * Assume the output is unsorted, since we don't necessarily have pathkeys
1701  * to represent it. (This might get overridden below.)
1702  */
1703  pathnode->path.pathkeys = NIL;
1704 
1705  pathnode->subpath = subpath;
1706  pathnode->in_operators = sjinfo->semi_operators;
1707  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1708 
1709  /*
1710  * If the input is a relation and it has a unique index that proves the
1711  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1712  * that relation_has_unique_index_for automatically considers restriction
1713  * clauses for the rel, as well.
1714  */
1715  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1717  sjinfo->semi_rhs_exprs,
1718  sjinfo->semi_operators))
1719  {
1720  pathnode->umethod = UNIQUE_PATH_NOOP;
1721  pathnode->path.rows = rel->rows;
1722  pathnode->path.startup_cost = subpath->startup_cost;
1723  pathnode->path.total_cost = subpath->total_cost;
1724  pathnode->path.pathkeys = subpath->pathkeys;
1725 
1726  rel->cheapest_unique_path = (Path *) pathnode;
1727 
1728  MemoryContextSwitchTo(oldcontext);
1729 
1730  return pathnode;
1731  }
1732 
1733  /*
1734  * If the input is a subquery whose output must be unique already, then we
1735  * don't need to do anything. The test for uniqueness has to consider
1736  * exactly which columns we are extracting; for example "SELECT DISTINCT
1737  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1738  * this optimization unless semi_rhs_exprs consists only of simple Vars
1739  * referencing subquery outputs. (Possibly we could do something with
1740  * expressions in the subquery outputs, too, but for now keep it simple.)
1741  */
1742  if (rel->rtekind == RTE_SUBQUERY)
1743  {
1744  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1745 
1747  {
1748  List *sub_tlist_colnos;
1749 
1750  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1751  rel->relid);
1752 
1753  if (sub_tlist_colnos &&
1755  sub_tlist_colnos,
1756  sjinfo->semi_operators))
1757  {
1758  pathnode->umethod = UNIQUE_PATH_NOOP;
1759  pathnode->path.rows = rel->rows;
1760  pathnode->path.startup_cost = subpath->startup_cost;
1761  pathnode->path.total_cost = subpath->total_cost;
1762  pathnode->path.pathkeys = subpath->pathkeys;
1763 
1764  rel->cheapest_unique_path = (Path *) pathnode;
1765 
1766  MemoryContextSwitchTo(oldcontext);
1767 
1768  return pathnode;
1769  }
1770  }
1771  }
1772 
1773  /* Estimate number of output rows */
1774  pathnode->path.rows = estimate_num_groups(root,
1775  sjinfo->semi_rhs_exprs,
1776  rel->rows,
1777  NULL,
1778  NULL);
1779  numCols = list_length(sjinfo->semi_rhs_exprs);
1780 
1781  if (sjinfo->semi_can_btree)
1782  {
1783  /*
1784  * Estimate cost for sort+unique implementation
1785  */
1786  cost_sort(&sort_path, root, NIL,
1787  subpath->total_cost,
1788  rel->rows,
1789  subpath->pathtarget->width,
1790  0.0,
1791  work_mem,
1792  -1.0);
1793 
1794  /*
1795  * Charge one cpu_operator_cost per comparison per input tuple. We
1796  * assume all columns get compared at most of the tuples. (XXX
1797  * probably this is an overestimate.) This should agree with
1798  * create_upper_unique_path.
1799  */
1800  sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
1801  }
1802 
1803  if (sjinfo->semi_can_hash)
1804  {
1805  /*
1806  * Estimate the overhead per hashtable entry at 64 bytes (same as in
1807  * planner.c).
1808  */
1809  int hashentrysize = subpath->pathtarget->width + 64;
1810 
1811  if (hashentrysize * pathnode->path.rows > get_hash_memory_limit())
1812  {
1813  /*
1814  * We should not try to hash. Hack the SpecialJoinInfo to
1815  * remember this, in case we come through here again.
1816  */
1817  sjinfo->semi_can_hash = false;
1818  }
1819  else
1820  cost_agg(&agg_path, root,
1821  AGG_HASHED, NULL,
1822  numCols, pathnode->path.rows,
1823  NIL,
1824  subpath->startup_cost,
1825  subpath->total_cost,
1826  rel->rows,
1827  subpath->pathtarget->width);
1828  }
1829 
1830  if (sjinfo->semi_can_btree && sjinfo->semi_can_hash)
1831  {
1832  if (agg_path.total_cost < sort_path.total_cost)
1833  pathnode->umethod = UNIQUE_PATH_HASH;
1834  else
1835  pathnode->umethod = UNIQUE_PATH_SORT;
1836  }
1837  else if (sjinfo->semi_can_btree)
1838  pathnode->umethod = UNIQUE_PATH_SORT;
1839  else if (sjinfo->semi_can_hash)
1840  pathnode->umethod = UNIQUE_PATH_HASH;
1841  else
1842  {
1843  /* we can get here only if we abandoned hashing above */
1844  MemoryContextSwitchTo(oldcontext);
1845  return NULL;
1846  }
1847 
1848  if (pathnode->umethod == UNIQUE_PATH_HASH)
1849  {
1850  pathnode->path.startup_cost = agg_path.startup_cost;
1851  pathnode->path.total_cost = agg_path.total_cost;
1852  }
1853  else
1854  {
1855  pathnode->path.startup_cost = sort_path.startup_cost;
1856  pathnode->path.total_cost = sort_path.total_cost;
1857  }
1858 
1859  rel->cheapest_unique_path = (Path *) pathnode;
1860 
1861  MemoryContextSwitchTo(oldcontext);
1862 
1863  return pathnode;
1864 }
bool query_is_distinct_for(Query *query, List *colnos, List *opids)
Definition: analyzejoins.c:778
bool query_supports_distinctness(Query *query)
Definition: analyzejoins.c:741
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:3494
MemoryContext GetMemoryChunkContext(void *pointer)
Definition: mcxt.c:589
size_t get_hash_memory_limit(void)
Definition: nodeHash.c:3390
@ JOIN_SEMI
Definition: nodes.h:307
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:135
@ RTE_SUBQUERY
Definition: parsenodes.h:983
@ RTE_RELATION
Definition: parsenodes.h:982
static List * translate_sub_tlist(List *tlist, int relid)
Definition: pathnode.c:1938
@ UNIQUE_PATH_SORT
Definition: pathnodes.h:1899
@ UNIQUE_PATH_NOOP
Definition: pathnodes.h:1897
@ UNIQUE_PATH_HASH
Definition: pathnodes.h:1898
#define planner_rt_fetch(rti, root)
Definition: pathnodes.h:523
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset, EstimationInfo *estinfo)
Definition: selfuncs.c:3385
Query * subquery
Definition: parsenodes.h:1041
Index relid
Definition: pathnodes.h:871
struct Path * cheapest_unique_path
Definition: pathnodes.h:856
struct Path * cheapest_total_path
Definition: pathnodes.h:855
Cardinality rows
Definition: pathnodes.h:830
RTEKind rtekind
Definition: pathnodes.h:875
List * semi_rhs_exprs
Definition: pathnodes.h:2714
JoinType jointype
Definition: pathnodes.h:2707
Relids syn_righthand
Definition: pathnodes.h:2706
List * semi_operators
Definition: pathnodes.h:2713
Path * subpath
Definition: pathnodes.h:1905
List * uniq_exprs
Definition: pathnodes.h:1908
UniquePathMethod umethod
Definition: pathnodes.h:1906
List * in_operators
Definition: pathnodes.h:1907

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(), get_hash_memory_limit(), GetMemoryChunkContext(), UniquePath::in_operators, JOIN_SEMI, SpecialJoinInfo::jointype, list_length(), makeNode, MemoryContextSwitchTo(), NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, UniquePath::path, Path::pathkeys, 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, Path::total_cost, translate_sub_tlist(), UniquePath::umethod, UniquePath::uniq_exprs, UNIQUE_PATH_HASH, UNIQUE_PATH_NOOP, UNIQUE_PATH_SORT, 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().

◆ create_upper_unique_path()

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

Definition at line 3064 of file pathnode.c.

3069 {
3071 
3072  pathnode->path.pathtype = T_Unique;
3073  pathnode->path.parent = rel;
3074  /* Unique doesn't project, so use source path's pathtarget */
3075  pathnode->path.pathtarget = subpath->pathtarget;
3076  /* For now, assume we are above any joins, so no parameterization */
3077  pathnode->path.param_info = NULL;
3078  pathnode->path.parallel_aware = false;
3079  pathnode->path.parallel_safe = rel->consider_parallel &&
3080  subpath->parallel_safe;
3081  pathnode->path.parallel_workers = subpath->parallel_workers;
3082  /* Unique doesn't change the input ordering */
3083  pathnode->path.pathkeys = subpath->pathkeys;
3084 
3085  pathnode->subpath = subpath;
3086  pathnode->numkeys = numCols;
3087 
3088  /*
3089  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3090  * all columns get compared at most of the tuples. (XXX probably this is
3091  * an overestimate.)
3092  */
3093  pathnode->path.startup_cost = subpath->startup_cost;
3094  pathnode->path.total_cost = subpath->total_cost +
3095  cpu_operator_cost * subpath->rows * numCols;
3096  pathnode->path.rows = numGroups;
3097 
3098  return pathnode;
3099 }

References RelOptInfo::consider_parallel, cpu_operator_cost, makeNode, UpperUniquePath::numkeys, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, UpperUniquePath::path, Path::pathkeys, Path::pathtype, Path::rows, Path::startup_cost, subpath(), UpperUniquePath::subpath, and Path::total_cost.

Referenced by create_final_distinct_paths(), create_partial_distinct_paths(), and make_union_unique().

◆ create_valuesscan_path()

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

Definition at line 2090 of file pathnode.c.

2092 {
2093  Path *pathnode = makeNode(Path);
2094 
2095  pathnode->pathtype = T_ValuesScan;
2096  pathnode->parent = rel;
2097  pathnode->pathtarget = rel->reltarget;
2098  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2099  required_outer);
2100  pathnode->parallel_aware = false;
2101  pathnode->parallel_safe = rel->consider_parallel;
2102  pathnode->parallel_workers = 0;
2103  pathnode->pathkeys = NIL; /* result is always unordered */
2104 
2105  cost_valuesscan(pathnode, root, rel, pathnode->param_info);
2106 
2107  return pathnode;
2108 }
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1618

References RelOptInfo::consider_parallel, cost_valuesscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::pathkeys, Path::pathtype, and RelOptInfo::reltarget.

Referenced by set_values_pathlist().

◆ create_windowagg_path()

WindowAggPath* create_windowagg_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List windowFuncs,
WindowClause winclause,
List qual,
bool  topwindow 
)

Definition at line 3417 of file pathnode.c.

3425 {
3426  WindowAggPath *pathnode = makeNode(WindowAggPath);
3427 
3428  /* qual can only be set for the topwindow */
3429  Assert(qual == NIL || topwindow);
3430 
3431  pathnode->path.pathtype = T_WindowAgg;
3432  pathnode->path.parent = rel;
3433  pathnode->path.pathtarget = target;
3434  /* For now, assume we are above any joins, so no parameterization */
3435  pathnode->path.param_info = NULL;
3436  pathnode->path.parallel_aware = false;
3437  pathnode->path.parallel_safe = rel->consider_parallel &&
3438  subpath->parallel_safe;
3439  pathnode->path.parallel_workers = subpath->parallel_workers;
3440  /* WindowAgg preserves the input sort order */
3441  pathnode->path.pathkeys = subpath->pathkeys;
3442 
3443  pathnode->subpath = subpath;
3444  pathnode->winclause = winclause;
3445  pathnode->qual = qual;
3446  pathnode->topwindow = topwindow;
3447 
3448  /*
3449  * For costing purposes, assume that there are no redundant partitioning
3450  * or ordering columns; it's not worth the trouble to deal with that
3451  * corner case here. So we just pass the unmodified list lengths to
3452  * cost_windowagg.
3453  */
3454  cost_windowagg(&pathnode->path, root,
3455  windowFuncs,
3456  list_length(winclause->partitionClause),
3457  list_length(winclause->orderClause),
3458  subpath->startup_cost,
3459  subpath->total_cost,
3460  subpath->rows);
3461 
3462  /* add tlist eval cost for each output row */
3463  pathnode->path.startup_cost += target->cost.startup;
3464  pathnode->path.total_cost += target->cost.startup +
3465  target->cost.per_tuple * pathnode->path.rows;
3466 
3467  return pathnode;
3468 }
void cost_windowagg(Path *path, PlannerInfo *root, List *windowFuncs, int numPartCols, int numOrderCols, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2818
Path * subpath
Definition: pathnodes.h:2196
WindowClause * winclause
Definition: pathnodes.h:2197
List * partitionClause
Definition: parsenodes.h:1442
List * orderClause
Definition: parsenodes.h:1443

References Assert(), RelOptInfo::consider_parallel, PathTarget::cost, cost_windowagg(), list_length(), makeNode, NIL, WindowClause::orderClause, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, WindowClause::partitionClause, WindowAggPath::path, Path::pathkeys, Path::pathtype, QualCost::per_tuple, WindowAggPath::qual, Path::rows, QualCost::startup, Path::startup_cost, subpath(), WindowAggPath::subpath, WindowAggPath::topwindow, Path::total_cost, and WindowAggPath::winclause.

Referenced by create_one_window_path().

◆ create_worktablescan_path()

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

Definition at line 2193 of file pathnode.c.

2195 {
2196  Path *pathnode = makeNode(Path);
2197 
2198  pathnode->pathtype = T_WorkTableScan;
2199  pathnode->parent = rel;
2200  pathnode->pathtarget = rel->reltarget;
2201  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2202  required_outer);
2203  pathnode->parallel_aware = false;
2204  pathnode->parallel_safe = rel->consider_parallel;
2205  pathnode->parallel_workers = 0;
2206  pathnode->pathkeys = NIL; /* result is always unordered */
2207 
2208  /* Cost is the same as for a regular CTE scan */
2209  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2210 
2211  return pathnode;
2212 }

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

Referenced by set_worktable_pathlist().

◆ reparameterize_path()

Path* reparameterize_path ( PlannerInfo root,
Path path,
Relids  required_outer,
double  loop_count 
)

Definition at line 3877 of file pathnode.c.

3880 {
3881  RelOptInfo *rel = path->parent;
3882 
3883  /* Can only increase, not decrease, path's parameterization */
3884  if (!bms_is_subset(PATH_REQ_OUTER(path), required_outer))
3885  return NULL;
3886  switch (path->pathtype)
3887  {
3888  case T_SeqScan:
3889  return create_seqscan_path(root, rel, required_outer, 0);
3890  case T_SampleScan:
3891  return (Path *) create_samplescan_path(root, rel, required_outer);
3892  case T_IndexScan:
3893  case T_IndexOnlyScan:
3894  {
3895  IndexPath *ipath = (IndexPath *) path;
3896  IndexPath *newpath = makeNode(IndexPath);
3897 
3898  /*
3899  * We can't use create_index_path directly, and would not want
3900  * to because it would re-compute the indexqual conditions
3901  * which is wasted effort. Instead we hack things a bit:
3902  * flat-copy the path node, revise its param_info, and redo
3903  * the cost estimate.
3904  */
3905  memcpy(newpath, ipath, sizeof(IndexPath));
3906  newpath->path.param_info =
3907  get_baserel_parampathinfo(root, rel, required_outer);
3908  cost_index(newpath, root, loop_count, false);
3909  return (Path *) newpath;
3910  }
3911  case T_BitmapHeapScan:
3912  {
3913  BitmapHeapPath *bpath = (BitmapHeapPath *) path;
3914 
3915  return (Path *) create_bitmap_heap_path(root,
3916  rel,
3917  bpath->bitmapqual,
3918  required_outer,
3919  loop_count, 0);
3920  }
3921  case T_SubqueryScan:
3922  {
3923  SubqueryScanPath *spath = (SubqueryScanPath *) path;
3924  Path *subpath = spath->subpath;
3925  bool trivial_pathtarget;
3926 
3927  /*
3928  * If existing node has zero extra cost, we must have decided
3929  * its target is trivial. (The converse is not true, because
3930  * it might have a trivial target but quals to enforce; but in
3931  * that case the new node will too, so it doesn't matter
3932  * whether we get the right answer here.)
3933  */
3934  trivial_pathtarget =
3935  (subpath->total_cost == spath->path.total_cost);
3936 
3937  return (Path *) create_subqueryscan_path(root,
3938  rel,
3939  subpath,
3940  trivial_pathtarget,
3941  spath->path.pathkeys,
3942  required_outer);
3943  }
3944  case T_Result:
3945  /* Supported only for RTE_RESULT scan paths */
3946  if (IsA(path, Path))
3947  return create_resultscan_path(root, rel, required_outer);
3948  break;
3949  case T_Append:
3950  {
3951  AppendPath *apath = (AppendPath *) path;
3952  List *childpaths = NIL;
3953  List *partialpaths = NIL;
3954  int i;
3955  ListCell *lc;
3956 
3957  /* Reparameterize the children */
3958  i = 0;
3959  foreach(lc, apath->subpaths)
3960  {
3961  Path *spath = (Path *) lfirst(lc);
3962 
3963  spath = reparameterize_path(root, spath,
3964  required_outer,
3965  loop_count);
3966  if (spath == NULL)
3967  return NULL;
3968  /* We have to re-split the regular and partial paths */
3969  if (i < apath->first_partial_path)
3970  childpaths = lappend(childpaths, spath);
3971  else
3972  partialpaths = lappend(partialpaths, spath);
3973  i++;
3974  }
3975  return (Path *)
3976  create_append_path(root, rel, childpaths, partialpaths,
3977  apath->path.pathkeys, required_outer,
3978  apath->path.parallel_workers,
3979  apath->path.parallel_aware,
3980  -1);
3981  }
3982  case T_Material:
3983  {
3984  MaterialPath *mpath = (MaterialPath *) path;
3985  Path *spath = mpath->subpath;
3986 
3987  spath = reparameterize_path(root, spath,
3988  required_outer,
3989  loop_count);
3990  if (spath == NULL)
3991  return NULL;
3992  return (Path *) create_material_path(rel, spath);
3993  }
3994  case T_Memoize:
3995  {
3996  MemoizePath *mpath = (MemoizePath *) path;
3997  Path *spath = mpath->subpath;
3998 
3999  spath = reparameterize_path(root, spath,
4000  required_outer,
4001  loop_count);
4002  if (spath == NULL)
4003  return NULL;
4004  return (Path *) create_memoize_path(root, rel,
4005  spath,
4006  mpath->param_exprs,
4007  mpath->hash_operators,
4008  mpath->singlerow,
4009  mpath->binary_mode,
4010  mpath->calls);
4011  }
4012  default:
4013  break;
4014  }
4015  return NULL;
4016 }
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:316
int i
Definition: isn.c:73
AppendPath * create_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, double rows)
Definition: pathnode.c:1244
Path * create_resultscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:2167
Path * create_samplescan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
Definition: pathnode.c:954
MemoizePath * create_memoize_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *param_exprs, List *hash_operators, bool singlerow, bool binary_mode, double calls)
Definition: pathnode.c:1596
Path * reparameterize_path(PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
Definition: pathnode.c:3877
SubqueryScanPath * create_subqueryscan_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, bool trivial_pathtarget, List *pathkeys, Relids required_outer)
Definition: pathnode.c:2008
MaterialPath * create_material_path(RelOptInfo *rel, Path *subpath)
Definition: pathnode.c:1564
Path * create_seqscan_path(PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
Definition: pathnode.c:929
BitmapHeapPath * create_bitmap_heap_path(PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
Definition: pathnode.c:1046

References MemoizePath::binary_mode, BitmapHeapPath::bitmapqual, bms_is_subset(), MemoizePath::calls, cost_index(), create_append_path(), create_bitmap_heap_path(), create_material_path(), create_memoize_path(), create_resultscan_path(), create_samplescan_path(), create_seqscan_path(), create_subqueryscan_path(), get_baserel_parampathinfo(), MemoizePath::hash_operators, i, IsA, lappend(), lfirst, makeNode, NIL, Path::parallel_aware, Path::parallel_workers, MemoizePath::param_exprs, IndexPath::path, SubqueryScanPath::path, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtype, MemoizePath::singlerow, subpath(), SubqueryScanPath::subpath, MaterialPath::subpath, MemoizePath::subpath, AppendPath::subpaths, and Path::total_cost.

Referenced by get_cheapest_parameterized_child_path().

◆ reparameterize_path_by_child()

Path* reparameterize_path_by_child ( PlannerInfo root,
Path path,
RelOptInfo child_rel 
)

Definition at line 4038 of file pathnode.c.

4040 {
4041 
4042 #define FLAT_COPY_PATH(newnode, node, nodetype) \
4043  ( (newnode) = makeNode(nodetype), \
4044  memcpy((newnode), (node), sizeof(nodetype)) )
4045 
4046 #define ADJUST_CHILD_ATTRS(node) \
4047  ((node) = \
4048  (List *) adjust_appendrel_attrs_multilevel(root, (Node *) (node), \
4049  child_rel, \
4050  child_rel->top_parent))
4051 
4052 #define REPARAMETERIZE_CHILD_PATH(path) \
4053 do { \
4054  (path) = reparameterize_path_by_child(root, (path), child_rel); \
4055  if ((path) == NULL) \
4056  return NULL; \
4057 } while(0)
4058 
4059 #define REPARAMETERIZE_CHILD_PATH_LIST(pathlist) \
4060 do { \
4061  if ((pathlist) != NIL) \
4062  { \
4063  (pathlist) = reparameterize_pathlist_by_child(root, (pathlist), \
4064  child_rel); \
4065  if ((pathlist) == NIL) \
4066  return NULL; \
4067  } \
4068 } while(0)
4069 
4070  Path *new_path;
4071  ParamPathInfo *new_ppi;
4072  ParamPathInfo *old_ppi;
4073  Relids required_outer;
4074 
4075  /*
4076  * If the path is not parameterized by parent of the given relation, it
4077  * doesn't need reparameterization.
4078  */
4079  if (!path->param_info ||
4080  !bms_overlap(PATH_REQ_OUTER(path), child_rel->top_parent_relids))
4081  return path;
4082 
4083  /*
4084  * If possible, reparameterize the given path, making a copy.
4085  *
4086  * This function is currently only applied to the inner side of a nestloop
4087  * join that is being partitioned by the partitionwise-join code. Hence,
4088  * we need only support path types that plausibly arise in that context.
4089  * (In particular, supporting sorted path types would be a waste of code
4090  * and cycles: even if we translated them here, they'd just lose in
4091  * subsequent cost comparisons.) If we do see an unsupported path type,
4092  * that just means we won't be able to generate a partitionwise-join plan
4093  * using that path type.
4094  */
4095  switch (nodeTag(path))
4096  {
4097  case T_Path:
4098  FLAT_COPY_PATH(new_path, path, Path);
4099  break;
4100 
4101  case T_IndexPath:
4102  {
4103  IndexPath *ipath;
4104 
4105  FLAT_COPY_PATH(ipath, path, IndexPath);
4107  new_path = (Path *) ipath;
4108  }
4109  break;
4110 
4111  case T_BitmapHeapPath:
4112  {
4113  BitmapHeapPath *bhpath;
4114 
4115  FLAT_COPY_PATH(bhpath, path, BitmapHeapPath);
4117  new_path = (Path *) bhpath;
4118  }
4119  break;
4120 
4121  case T_BitmapAndPath:
4122  {
4123  BitmapAndPath *bapath;
4124 
4125  FLAT_COPY_PATH(bapath, path, BitmapAndPath);
4127  new_path = (Path *) bapath;
4128  }
4129  break;
4130 
4131  case T_BitmapOrPath:
4132  {
4133  BitmapOrPath *bopath;
4134 
4135  FLAT_COPY_PATH(bopath, path, BitmapOrPath);
4137  new_path = (Path *) bopath;
4138  }
4139  break;
4140 
4141  case T_ForeignPath:
4142  {
4143  ForeignPath *fpath;
4145 
4146  FLAT_COPY_PATH(fpath, path, ForeignPath);
4147  if (fpath->fdw_outerpath)
4149 
4150  /* Hand over to FDW if needed. */
4151  rfpc_func =
4152  path->parent->fdwroutine->ReparameterizeForeignPathByChild;
4153  if (rfpc_func)
4154  fpath->fdw_private = rfpc_func(root, fpath->fdw_private,
4155  child_rel);
4156  new_path = (Path *) fpath;
4157  }
4158  break;
4159 
4160  case T_CustomPath:
4161  {
4162  CustomPath *cpath;
4163 
4164  FLAT_COPY_PATH(cpath, path, CustomPath);
4166  if (cpath->methods &&
4168  cpath->custom_private =
4170  cpath->custom_private,
4171  child_rel);
4172  new_path = (Path *) cpath;
4173  }
4174  break;
4175 
4176  case T_NestPath:
4177  {
4178  JoinPath *jpath;
4179  NestPath *npath;
4180 
4181  FLAT_COPY_PATH(npath, path, NestPath);
4182 
4183  jpath = (JoinPath *) npath;
4187  new_path = (Path *) npath;
4188  }
4189  break;
4190 
4191  case T_MergePath:
4192  {
4193  JoinPath *jpath;
4194  MergePath *mpath;
4195 
4196  FLAT_COPY_PATH(mpath, path, MergePath);
4197 
4198  jpath = (JoinPath *) mpath;
4203  new_path = (Path *) mpath;
4204  }
4205  break;
4206 
4207  case T_HashPath:
4208  {
4209  JoinPath *jpath;
4210  HashPath *hpath;
4211 
4212  FLAT_COPY_PATH(hpath, path, HashPath);
4213 
4214  jpath = (JoinPath *) hpath;
4219  new_path = (Path *) hpath;
4220  }
4221  break;
4222 
4223  case T_AppendPath:
4224  {
4225  AppendPath *apath;
4226 
4227  FLAT_COPY_PATH(apath, path, AppendPath);
4229  new_path = (Path *) apath;
4230  }
4231  break;
4232 
4233  case T_MaterialPath:
4234  {
4235  MaterialPath *mpath;
4236 
4237  FLAT_COPY_PATH(mpath, path, MaterialPath);
4239  new_path = (Path *) mpath;
4240  }
4241  break;
4242 
4243  case T_MemoizePath:
4244  {
4245  MemoizePath *mpath;
4246 
4247  FLAT_COPY_PATH(mpath, path, MemoizePath);
4250  new_path = (Path *) mpath;
4251  }
4252  break;
4253 
4254  case T_GatherPath:
4255  {
4256  GatherPath *gpath;
4257 
4258  FLAT_COPY_PATH(gpath, path, GatherPath);
4260  new_path = (Path *) gpath;
4261  }
4262  break;
4263 
4264  default:
4265 
4266  /* We don't know how to reparameterize this path. */
4267  return NULL;
4268  }
4269 
4270  /*
4271  * Adjust the parameterization information, which refers to the topmost
4272  * parent. The topmost parent can be multiple levels away from the given
4273  * child, hence use multi-level expression adjustment routines.
4274  */
4275  old_ppi = new_path->param_info;
4276  required_outer =
4278  child_rel,
4279  child_rel->top_parent);
4280 
4281  /* If we already have a PPI for this parameterization, just return it */
4282  new_ppi = find_param_path_info(new_path->parent, required_outer);
4283 
4284  /*
4285  * If not, build a new one and link it to the list of PPIs. For the same
4286  * reason as explained in mark_dummy_rel(), allocate new PPI in the same
4287  * context the given RelOptInfo is in.
4288  */
4289  if (new_ppi == NULL)
4290  {
4291  MemoryContext oldcontext;
4292  RelOptInfo *rel = path->parent;
4293 
4294  oldcontext = MemoryContextSwitchTo(GetMemoryChunkContext(rel));
4295 
4296  new_ppi = makeNode(ParamPathInfo);
4297  new_ppi->ppi_req_outer = bms_copy(required_outer);
4298  new_ppi->ppi_rows = old_ppi->ppi_rows;
4299  new_ppi->ppi_clauses = old_ppi->ppi_clauses;
4300  ADJUST_CHILD_ATTRS(new_ppi->ppi_clauses);
4301  rel->ppilist = lappend(rel->ppilist, new_ppi);
4302 
4303  MemoryContextSwitchTo(oldcontext);
4304  }
4305  bms_free(required_outer);
4306 
4307  new_path->param_info = new_ppi;
4308 
4309  /*
4310  * Adjust the path target if the parent of the outer relation is
4311  * referenced in the targetlist. This can happen when only the parent of
4312  * outer relation is laterally referenced in this relation.
4313  */
4314  if (bms_overlap(path->parent->lateral_relids,
4315  child_rel->top_parent_relids))
4316  {
4317  new_path->pathtarget = copy_pathtarget(new_path->pathtarget);
4318  ADJUST_CHILD_ATTRS(new_path->pathtarget->exprs);
4319  }
4320 
4321  return new_path;
4322 }
Relids adjust_child_relids_multilevel(PlannerInfo *root, Relids relids, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: appendinfo.c:556
List *(* ReparameterizeForeignPathByChild_function)(PlannerInfo *root, List *fdw_private, RelOptInfo *child_rel)
Definition: fdwapi.h:182
#define nodeTag(nodeptr)
Definition: nodes.h:122
#define REPARAMETERIZE_CHILD_PATH_LIST(pathlist)
#define REPARAMETERIZE_CHILD_PATH(path)
#define FLAT_COPY_PATH(newnode, node, nodetype)
#define ADJUST_CHILD_ATTRS(node)
ParamPathInfo * find_param_path_info(RelOptInfo *rel, Relids required_outer)
Definition: relnode.c:1646
struct List *(* ReparameterizeCustomPathByChild)(PlannerInfo *root, List *custom_private, RelOptInfo *child_rel)
Definition: extensible.h:103
const struct CustomPathMethods * methods
Definition: pathnodes.h:1788
List * custom_paths
Definition: pathnodes.h:1786
List * custom_private
Definition: pathnodes.h:1787
Cardinality ppi_rows
Definition: pathnodes.h:1468
List * ppi_clauses
Definition: pathnodes.h:1469
Relids ppi_req_outer
Definition: pathnodes.h:1467
List * ppilist
Definition: pathnodes.h:852
Relids top_parent_relids
Definition: pathnodes.h:957
PathTarget * copy_pathtarget(PathTarget *src)
Definition: tlist.c:657

References ADJUST_CHILD_ATTRS, adjust_child_relids_multilevel(), BitmapHeapPath::bitmapqual, BitmapAndPath::bitmapquals, BitmapOrPath::bitmapquals, bms_copy(), bms_free(), bms_overlap(), copy_pathtarget(), CustomPath::custom_paths, CustomPath::custom_private, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, find_param_path_info(), FLAT_COPY_PATH, GetMemoryChunkContext(), IndexPath::indexclauses, JoinPath::innerjoinpath, JoinPath::joinrestrictinfo, lappend(), makeNode, MemoryContextSwitchTo(), CustomPath::methods, nodeTag, JoinPath::outerjoinpath, MemoizePath::param_exprs, HashPath::path_hashclauses, MergePath::path_mergeclauses, PATH_REQ_OUTER, ParamPathInfo::ppi_clauses, ParamPathInfo::ppi_req_outer, ParamPathInfo::ppi_rows, RelOptInfo::ppilist, REPARAMETERIZE_CHILD_PATH, REPARAMETERIZE_CHILD_PATH_LIST, CustomPathMethods::ReparameterizeCustomPathByChild, MaterialPath::subpath, MemoizePath::subpath, GatherPath::subpath, AppendPath::subpaths, and RelOptInfo::top_parent_relids.

Referenced by reparameterize_pathlist_by_child(), try_nestloop_path(), and try_partial_nestloop_path().

◆ reparameterize_pathlist_by_child()

static List * reparameterize_pathlist_by_child ( PlannerInfo root,
List pathlist,
RelOptInfo child_rel 
)
static

Definition at line 4329 of file pathnode.c.

4332 {
4333  ListCell *lc;
4334  List *result = NIL;
4335 
4336  foreach(lc, pathlist)
4337  {
4338  Path *path = reparameterize_path_by_child(root, lfirst(lc),
4339  child_rel);
4340 
4341  if (path == NULL)
4342  {
4343  list_free(result);
4344  return NIL;
4345  }
4346 
4347  result = lappend(result, path);
4348  }
4349 
4350  return result;
4351 }
void list_free(List *list)
Definition: list.c:1545

References lappend(), lfirst, list_free(), NIL, and reparameterize_path_by_child().

◆ set_cheapest()

void set_cheapest ( RelOptInfo parent_rel)

Definition at line 244 of file pathnode.c.

245 {
246  Path *cheapest_startup_path;
247  Path *cheapest_total_path;
248  Path *best_param_path;
249  List *parameterized_paths;
250  ListCell *p;
251 
252  Assert(IsA(parent_rel, RelOptInfo));
253 
254  if (parent_rel->pathlist == NIL)
255  elog(ERROR, "could not devise a query plan for the given query");
256 
257  cheapest_startup_path = cheapest_total_path = best_param_path = NULL;
258  parameterized_paths = NIL;
259 
260  foreach(p, parent_rel->pathlist)
261  {
262  Path *path = (Path *) lfirst(p);
263  int cmp;
264 
265  if (path->param_info)
266  {
267  /* Parameterized path, so add it to parameterized_paths */
268  parameterized_paths = lappend(parameterized_paths, path);
269 
270  /*
271  * If we have an unparameterized cheapest-total, we no longer care
272  * about finding the best parameterized path, so move on.
273  */
274  if (cheapest_total_path)
275  continue;
276 
277  /*
278  * Otherwise, track the best parameterized path, which is the one
279  * with least total cost among those of the minimum
280  * parameterization.
281  */
282  if (best_param_path == NULL)
283  best_param_path = path;
284  else
285  {
286  switch (bms_subset_compare(PATH_REQ_OUTER(path),
287  PATH_REQ_OUTER(best_param_path)))
288  {
289  case BMS_EQUAL:
290  /* keep the cheaper one */
291  if (compare_path_costs(path, best_param_path,
292  TOTAL_COST) < 0)
293  best_param_path = path;
294  break;
295  case BMS_SUBSET1:
296  /* new path is less-parameterized */
297  best_param_path = path;
298  break;
299  case BMS_SUBSET2:
300  /* old path is less-parameterized, keep it */
301  break;
302  case BMS_DIFFERENT:
303 
304  /*
305  * This means that neither path has the least possible
306  * parameterization for the rel. We'll sit on the old
307  * path until something better comes along.
308  */
309  break;
310  }
311  }
312  }
313  else
314  {
315  /* Unparameterized path, so consider it for cheapest slots */
316  if (cheapest_total_path == NULL)
317  {
318  cheapest_startup_path = cheapest_total_path = path;
319  continue;
320  }
321 
322  /*
323  * If we find two paths of identical costs, try to keep the
324  * better-sorted one. The paths might have unrelated sort
325  * orderings, in which case we can only guess which might be
326  * better to keep, but if one is superior then we definitely
327  * should keep that one.
328  */
329  cmp = compare_path_costs(cheapest_startup_path, path, STARTUP_COST);
330  if (cmp > 0 ||
331  (cmp == 0 &&
332  compare_pathkeys(cheapest_startup_path->pathkeys,
333  path->pathkeys) == PATHKEYS_BETTER2))
334  cheapest_startup_path = path;
335 
336  cmp = compare_path_costs(cheapest_total_path, path, TOTAL_COST);
337  if (cmp > 0 ||
338  (cmp == 0 &&
339  compare_pathkeys(cheapest_total_path->pathkeys,
340  path->pathkeys) == PATHKEYS_BETTER2))
341  cheapest_total_path = path;
342  }
343  }
344 
345  /* Add cheapest unparameterized path, if any, to parameterized_paths */
346  if (cheapest_total_path)
347  parameterized_paths = lcons(cheapest_total_path, parameterized_paths);
348 
349  /*
350  * If there is no unparameterized path, use the best parameterized path as
351  * cheapest_total_path (but not as cheapest_startup_path).
352  */
353  if (cheapest_total_path == NULL)
354  cheapest_total_path = best_param_path;
355  Assert(cheapest_total_path != NULL);
356 
357  parent_rel->cheapest_startup_path = cheapest_startup_path;
358  parent_rel->cheapest_total_path = cheapest_total_path;
359  parent_rel->cheapest_unique_path = NULL; /* computed only if needed */
360  parent_rel->cheapest_parameterized_paths = parameterized_paths;
361 }
@ BMS_DIFFERENT
Definition: bitmapset.h:67
List * lcons(void *datum, List *list)
Definition: list.c:494
List * cheapest_parameterized_paths
Definition: pathnodes.h:857
struct Path * cheapest_startup_path
Definition: pathnodes.h:854

References Assert(), BMS_DIFFERENT, BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, bms_subset_compare(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, cmp(), compare_path_costs(), compare_pathkeys(), elog(), ERROR, IsA, lappend(), lcons(), lfirst, NIL, PATH_REQ_OUTER, Path::pathkeys, PATHKEYS_BETTER2, RelOptInfo::pathlist, STARTUP_COST, and TOTAL_COST.

Referenced by apply_scanjoin_target_to_paths(), create_distinct_paths(), create_grouping_paths(), create_ordinary_grouping_paths(), create_partial_distinct_paths(), create_partitionwise_grouping_paths(), create_window_paths(), generate_partitionwise_join_paths(), mark_dummy_rel(), merge_clump(), postprocess_setop_rel(), query_planner(), set_dummy_rel_pathlist(), set_namedtuplestore_path