PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pathnode.c File Reference
#include "postgres.h"
#include <math.h>
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "nodes/extensible.h"
#include "optimizer/clauses.h"
#include "optimizer/cost.h"
#include "optimizer/pathnode.h"
#include "optimizer/paths.h"
#include "optimizer/planmain.h"
#include "optimizer/prep.h"
#include "optimizer/restrictinfo.h"
#include "optimizer/tlist.h"
#include "optimizer/var.h"
#include "parser/parsetree.h"
#include "foreign/fdwapi.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/selfuncs.h"
Include dependency graph for pathnode.c:

Go to the source code of this file.

Macros

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

Enumerations

enum  PathCostComparison { COSTS_EQUAL, COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT }
 

Functions

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

Macro Definition Documentation

#define ADJUST_CHILD_ATTRS (   node)
Value:
((node) = \
child_rel->relids, \
child_rel->top_parent_relids))
Definition: nodes.h:510
Node * adjust_appendrel_attrs_multilevel(PlannerInfo *root, Node *node, Relids child_relids, Relids top_parent_relids)
Definition: prepunion.c:2430
Definition: pg_list.h:45

Referenced by reparameterize_path_by_child().

#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 
)
Value:
( (newnode) = makeNode(nodetype), \
memcpy((newnode), (node), sizeof(nodetype)) )
#define makeNode(_type_)
Definition: nodes.h:558

Referenced by reparameterize_path_by_child().

#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:3460

Referenced by reparameterize_path_by_child().

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

Referenced by reparameterize_path_by_child().

#define STD_FUZZ_FACTOR   1.01

Enumeration Type Documentation

Enumerator
COSTS_EQUAL 
COSTS_BETTER1 
COSTS_BETTER2 
COSTS_DIFFERENT 

Definition at line 38 of file pathnode.c.

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

Function Documentation

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 760 of file pathnode.c.

References CHECK_FOR_INTERRUPTS, compare_pathkeys(), lappend_cell(), lcons(), lfirst, list_delete_cell(), list_head(), lnext, RelOptInfo::partial_pathlist, Path::pathkeys, PATHKEYS_BETTER1, PATHKEYS_BETTER2, PATHKEYS_DIFFERENT, pfree(), STD_FUZZ_FACTOR, and Path::total_cost.

Referenced by add_paths_to_append_rel(), build_index_paths(), create_grouping_paths(), create_partial_bitmap_paths(), create_plain_partial_paths(), try_partial_hashjoin_path(), try_partial_mergejoin_path(), and try_partial_nestloop_path().

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

Definition at line 884 of file pathnode.c.

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

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

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

Definition at line 420 of file pathnode.c.

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

Referenced by add_foreign_grouping_paths(), add_paths_to_append_rel(), add_paths_with_pathkeys_for_rel(), consider_groupingsets_paths(), create_distinct_paths(), create_grouping_paths(), create_index_paths(), create_one_window_path(), create_ordered_paths(), create_tidscan_paths(), fileGetForeignPaths(), generate_gather_paths(), generate_mergeappend_paths(), get_index_paths(), grouping_planner(), inheritance_planner(), mark_dummy_rel(), plan_set_operations(), postgresGetForeignJoinPaths(), postgresGetForeignPaths(), preprocess_minmax_aggregates(), query_planner(), set_cte_pathlist(), set_dummy_rel_pathlist(), set_function_pathlist(), set_namedtuplestore_pathlist(), set_plain_rel_pathlist(), set_subquery_pathlist(), set_tablefunc_pathlist(), set_tablesample_rel_pathlist(), set_values_pathlist(), set_worktable_pathlist(), try_hashjoin_path(), try_mergejoin_path(), and try_nestloop_path().

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

Definition at line 655 of file pathnode.c.

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

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

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

Definition at line 2378 of file pathnode.c.

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

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

2382 {
2383  QualCost oldcost;
2384 
2385  /*
2386  * If given path can't project, we might need a Result node, so make a
2387  * separate ProjectionPath.
2388  */
2389  if (!is_projection_capable_path(path))
2390  return (Path *) create_projection_path(root, rel, path, target);
2391 
2392  /*
2393  * We can just jam the desired tlist into the existing path, being sure to
2394  * update its cost estimates appropriately.
2395  */
2396  oldcost = path->pathtarget->cost;
2397  path->pathtarget = target;
2398 
2399  path->startup_cost += target->cost.startup - oldcost.startup;
2400  path->total_cost += target->cost.startup - oldcost.startup +
2401  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2402 
2403  /*
2404  * If the path happens to be a Gather path, we'd like to arrange for the
2405  * subpath to return the required target list so that workers can help
2406  * project. But if there is something that is not parallel-safe in the
2407  * target expressions, then we can't.
2408  */
2409  if (IsA(path, GatherPath) &&
2410  is_parallel_safe(root, (Node *) target->exprs))
2411  {
2412  GatherPath *gpath = (GatherPath *) path;
2413 
2414  /*
2415  * We always use create_projection_path here, even if the subpath is
2416  * projection-capable, so as to avoid modifying the subpath in place.
2417  * It seems unlikely at present that there could be any other
2418  * references to the subpath, but better safe than sorry.
2419  *
2420  * Note that we don't change the GatherPath's cost estimates; it might
2421  * be appropriate to do so, to reflect the fact that the bulk of the
2422  * target evaluation will happen in workers.
2423  */
2424  gpath->subpath = (Path *)
2426  gpath->subpath->parent,
2427  gpath->subpath,
2428  target);
2429  }
2430  else if (path->parallel_safe &&
2431  !is_parallel_safe(root, (Node *) target->exprs))
2432  {
2433  /*
2434  * We're inserting a parallel-restricted target list into a path
2435  * currently marked parallel-safe, so we have to mark it as no longer
2436  * safe.
2437  */
2438  path->parallel_safe = false;
2439  }
2440 
2441  return path;
2442 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:561
PathTarget * pathtarget
Definition: relation.h:1043
Definition: nodes.h:510
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2287
Cost startup
Definition: relation.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1353
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6559
Relids calc_nestloop_required_outer ( Relids  outerrelids,
Relids  outer_paramrels,
Relids  innerrelids,
Relids  inner_paramrels 
)

Definition at line 2004 of file pathnode.c.

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

Referenced by try_nestloop_path().

2008 {
2009  Relids required_outer;
2010 
2011  /* inner_path can require rels from outer path, but not vice versa */
2012  Assert(!bms_overlap(outer_paramrels, innerrelids));
2013  /* easy case if inner path is not parameterized */
2014  if (!inner_paramrels)
2015  return bms_copy(outer_paramrels);
2016  /* else, form the union ... */
2017  required_outer = bms_union(outer_paramrels, inner_paramrels);
2018  /* ... and remove any mention of now-satisfied outer rels */
2019  required_outer = bms_del_members(required_outer,
2020  outerrelids);
2021  /* maintain invariant that required_outer is exactly NULL if empty */
2022  if (bms_is_empty(required_outer))
2023  {
2024  bms_free(required_outer);
2025  required_outer = NULL;
2026  }
2027  return required_outer;
2028 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
#define Assert(condition)
Definition: c.h:681
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

Definition at line 2037 of file pathnode.c.

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

Referenced by try_hashjoin_path(), and try_mergejoin_path().

2038 {
2039  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2040  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2041  Relids required_outer;
2042 
2043  /* neither path can require rels from the other */
2044  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2045  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2046  /* form the union ... */
2047  required_outer = bms_union(outer_paramrels, inner_paramrels);
2048  /* we do not need an explicit test for empty; bms_union gets it right */
2049  return required_outer;
2050 }
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
#define Assert(condition)
Definition: c.h:681
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
int compare_fractional_path_costs ( Path path1,
Path path2,
double  fraction 
)

Definition at line 115 of file pathnode.c.

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

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

117 {
118  Cost cost1,
119  cost2;
120 
121  if (fraction <= 0.0 || fraction >= 1.0)
122  return compare_path_costs(path1, path2, TOTAL_COST);
123  cost1 = path1->startup_cost +
124  fraction * (path1->total_cost - path1->startup_cost);
125  cost2 = path2->startup_cost +
126  fraction * (path2->total_cost - path2->startup_cost);
127  if (cost1 < cost2)
128  return -1;
129  if (cost1 > cost2)
130  return +1;
131  return 0;
132 }
Cost startup_cost
Definition: relation.h:1053
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:69
Cost total_cost
Definition: relation.h:1054
double Cost
Definition: nodes.h:641
int compare_path_costs ( Path path1,
Path path2,
CostSelector  criterion 
)

Definition at line 69 of file pathnode.c.

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

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

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

Definition at line 164 of file pathnode.c.

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

Referenced by add_path().

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

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

Referenced by create_distinct_paths(), create_grouping_paths(), and make_union_unique().

2685 {
2686  AggPath *pathnode = makeNode(AggPath);
2687 
2688  pathnode->path.pathtype = T_Agg;
2689  pathnode->path.parent = rel;
2690  pathnode->path.pathtarget = target;
2691  /* For now, assume we are above any joins, so no parameterization */
2692  pathnode->path.param_info = NULL;
2693  pathnode->path.parallel_aware = false;
2694  pathnode->path.parallel_safe = rel->consider_parallel &&
2695  subpath->parallel_safe;
2696  pathnode->path.parallel_workers = subpath->parallel_workers;
2697  if (aggstrategy == AGG_SORTED)
2698  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2699  else
2700  pathnode->path.pathkeys = NIL; /* output is unordered */
2701  pathnode->subpath = subpath;
2702 
2703  pathnode->aggstrategy = aggstrategy;
2704  pathnode->aggsplit = aggsplit;
2705  pathnode->numGroups = numGroups;
2706  pathnode->groupClause = groupClause;
2707  pathnode->qual = qual;
2708 
2709  cost_agg(&pathnode->path, root,
2710  aggstrategy, aggcosts,
2711  list_length(groupClause), numGroups,
2712  subpath->startup_cost, subpath->total_cost,
2713  subpath->rows);
2714 
2715  /* add tlist eval cost for each output row */
2716  pathnode->path.startup_cost += target->cost.startup;
2717  pathnode->path.total_cost += target->cost.startup +
2718  target->cost.per_tuple * pathnode->path.rows;
2719 
2720  return pathnode;
2721 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1043
AggStrategy aggstrategy
Definition: relation.h:1549
List * qual
Definition: relation.h:1553
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
AggSplit aggsplit
Definition: relation.h:1550
double numGroups
Definition: relation.h:1551
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1874
List * groupClause
Definition: relation.h:1552
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Path * subpath
Definition: relation.h:1548
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1547
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
AppendPath* create_append_path ( RelOptInfo rel,
List subpaths,
Relids  required_outer,
int  parallel_workers,
List partitioned_rels 
)

Definition at line 1211 of file pathnode.c.

References Assert, bms_equal(), RelOptInfo::consider_parallel, get_appendrel_parampathinfo(), lfirst, list_copy(), list_head(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AppendPath::partitioned_rels, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, subpath(), AppendPath::subpaths, T_Append, and Path::total_cost.

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

1213 {
1214  AppendPath *pathnode = makeNode(AppendPath);
1215  ListCell *l;
1216 
1217  pathnode->path.pathtype = T_Append;
1218  pathnode->path.parent = rel;
1219  pathnode->path.pathtarget = rel->reltarget;
1221  required_outer);
1222  pathnode->path.parallel_aware = false;
1223  pathnode->path.parallel_safe = rel->consider_parallel;
1224  pathnode->path.parallel_workers = parallel_workers;
1225  pathnode->path.pathkeys = NIL; /* result is always considered unsorted */
1226  pathnode->partitioned_rels = list_copy(partitioned_rels);
1227  pathnode->subpaths = subpaths;
1228 
1229  /*
1230  * We don't bother with inventing a cost_append(), but just do it here.
1231  *
1232  * Compute rows and costs as sums of subplan rows and costs. We charge
1233  * nothing extra for the Append itself, which perhaps is too optimistic,
1234  * but since it doesn't do any selection or projection, it is a pretty
1235  * cheap node.
1236  */
1237  pathnode->path.rows = 0;
1238  pathnode->path.startup_cost = 0;
1239  pathnode->path.total_cost = 0;
1240  foreach(l, subpaths)
1241  {
1242  Path *subpath = (Path *) lfirst(l);
1243 
1244  pathnode->path.rows += subpath->rows;
1245 
1246  if (l == list_head(subpaths)) /* first node? */
1247  pathnode->path.startup_cost = subpath->startup_cost;
1248  pathnode->path.total_cost += subpath->total_cost;
1249  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1250  subpath->parallel_safe;
1251 
1252  /* All child paths must have same parameterization */
1253  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1254  }
1255 
1256  return pathnode;
1257 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:48
Path path
Definition: relation.h:1265
NodeTag pathtype
Definition: relation.h:1040
List * subpaths
Definition: relation.h:1268
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
bool consider_parallel
Definition: relation.h:593
List * partitioned_rels
Definition: relation.h:1267
bool parallel_aware
Definition: relation.h:1047
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1545
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
BitmapAndPath* create_bitmap_and_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

Definition at line 1108 of file pathnode.c.

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

Referenced by choose_bitmap_and().

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

Definition at line 1075 of file pathnode.c.

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

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

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

Definition at line 1144 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

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

Definition at line 1883 of file pathnode.c.

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

Referenced by set_cte_pathlist().

1884 {
1885  Path *pathnode = makeNode(Path);
1886 
1887  pathnode->pathtype = T_CteScan;
1888  pathnode->parent = rel;
1889  pathnode->pathtarget = rel->reltarget;
1890  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1891  required_outer);
1892  pathnode->parallel_aware = false;
1893  pathnode->parallel_safe = rel->consider_parallel;
1894  pathnode->parallel_workers = 0;
1895  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1896 
1897  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1898 
1899  return pathnode;
1900 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1484
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
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 1968 of file pathnode.c.

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

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

1975 {
1976  ForeignPath *pathnode = makeNode(ForeignPath);
1977 
1978  pathnode->path.pathtype = T_ForeignScan;
1979  pathnode->path.parent = rel;
1980  pathnode->path.pathtarget = target ? target : rel->reltarget;
1981  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1982  required_outer);
1983  pathnode->path.parallel_aware = false;
1984  pathnode->path.parallel_safe = rel->consider_parallel;
1985  pathnode->path.parallel_workers = 0;
1986  pathnode->path.rows = rows;
1987  pathnode->path.startup_cost = startup_cost;
1988  pathnode->path.total_cost = total_cost;
1989  pathnode->path.pathkeys = pathkeys;
1990 
1991  pathnode->fdw_outerpath = fdw_outerpath;
1992  pathnode->fdw_private = fdw_private;
1993 
1994  return pathnode;
1995 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
Path * fdw_outerpath
Definition: relation.h:1219
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
List * fdw_private
Definition: relation.h:1220
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
Path* create_functionscan_path ( PlannerInfo root,
RelOptInfo rel,
List pathkeys,
Relids  required_outer 
)

Definition at line 1805 of file pathnode.c.

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

Referenced by set_function_pathlist().

1807 {
1808  Path *pathnode = makeNode(Path);
1809 
1810  pathnode->pathtype = T_FunctionScan;
1811  pathnode->parent = rel;
1812  pathnode->pathtarget = rel->reltarget;
1813  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1814  required_outer);
1815  pathnode->parallel_aware = false;
1816  pathnode->parallel_safe = rel->consider_parallel;
1817  pathnode->parallel_workers = 0;
1818  pathnode->pathkeys = pathkeys;
1819 
1820  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1821 
1822  return pathnode;
1823 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1317
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
GatherMergePath* create_gather_merge_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List pathkeys,
Relids  required_outer,
double *  rows 
)

Definition at line 1647 of file pathnode.c.

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

Referenced by create_grouping_paths(), create_ordered_paths(), and generate_gather_paths().

1650 {
1652  Cost input_startup_cost = 0;
1653  Cost input_total_cost = 0;
1654 
1655  Assert(subpath->parallel_safe);
1656  Assert(pathkeys);
1657 
1658  pathnode->path.pathtype = T_GatherMerge;
1659  pathnode->path.parent = rel;
1660  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1661  required_outer);
1662  pathnode->path.parallel_aware = false;
1663 
1664  pathnode->subpath = subpath;
1665  pathnode->num_workers = subpath->parallel_workers;
1666  pathnode->path.pathkeys = pathkeys;
1667  pathnode->path.pathtarget = target ? target : rel->reltarget;
1668  pathnode->path.rows += subpath->rows;
1669 
1670  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1671  {
1672  /* Subpath is adequately ordered, we won't need to sort it */
1673  input_startup_cost += subpath->startup_cost;
1674  input_total_cost += subpath->total_cost;
1675  }
1676  else
1677  {
1678  /* We'll need to insert a Sort node, so include cost for that */
1679  Path sort_path; /* dummy for result of cost_sort */
1680 
1681  cost_sort(&sort_path,
1682  root,
1683  pathkeys,
1684  subpath->total_cost,
1685  subpath->rows,
1686  subpath->pathtarget->width,
1687  0.0,
1688  work_mem,
1689  -1);
1690  input_startup_cost += sort_path.startup_cost;
1691  input_total_cost += sort_path.total_cost;
1692  }
1693 
1694  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1695  input_startup_cost, input_total_cost, rows);
1696 
1697  return pathnode;
1698 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
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:388
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1645
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
Path * subpath
Definition: relation.h:1366
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
double Cost
Definition: nodes.h:641
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GatherPath* create_gather_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
Relids  required_outer,
double *  rows 
)

Definition at line 1738 of file pathnode.c.

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

Referenced by create_grouping_paths(), and generate_gather_paths().

1740 {
1741  GatherPath *pathnode = makeNode(GatherPath);
1742 
1743  Assert(subpath->parallel_safe);
1744 
1745  pathnode->path.pathtype = T_Gather;
1746  pathnode->path.parent = rel;
1747  pathnode->path.pathtarget = target;
1748  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1749  required_outer);
1750  pathnode->path.parallel_aware = false;
1751  pathnode->path.parallel_safe = false;
1752  pathnode->path.parallel_workers = 0;
1753  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1754 
1755  pathnode->subpath = subpath;
1756  pathnode->num_workers = subpath->parallel_workers;
1757  pathnode->single_copy = false;
1758 
1759  if (pathnode->num_workers == 0)
1760  {
1761  pathnode->path.pathkeys = subpath->pathkeys;
1762  pathnode->num_workers = 1;
1763  pathnode->single_copy = true;
1764  }
1765 
1766  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1767 
1768  return pathnode;
1769 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
bool single_copy
Definition: relation.h:1354
int num_workers
Definition: relation.h:1355
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1353
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
bool parallel_safe
Definition: relation.h:1048
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:350
Definition: nodes.h:80
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1352
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GroupPath* create_group_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List groupClause,
List qual,
double  numGroups 
)

Definition at line 2565 of file pathnode.c.

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

Referenced by create_grouping_paths().

2572 {
2573  GroupPath *pathnode = makeNode(GroupPath);
2574 
2575  pathnode->path.pathtype = T_Group;
2576  pathnode->path.parent = rel;
2577  pathnode->path.pathtarget = target;
2578  /* For now, assume we are above any joins, so no parameterization */
2579  pathnode->path.param_info = NULL;
2580  pathnode->path.parallel_aware = false;
2581  pathnode->path.parallel_safe = rel->consider_parallel &&
2582  subpath->parallel_safe;
2583  pathnode->path.parallel_workers = subpath->parallel_workers;
2584  /* Group doesn't change sort ordering */
2585  pathnode->path.pathkeys = subpath->pathkeys;
2586 
2587  pathnode->subpath = subpath;
2588 
2589  pathnode->groupClause = groupClause;
2590  pathnode->qual = qual;
2591 
2592  cost_group(&pathnode->path, root,
2593  list_length(groupClause),
2594  numGroups,
2595  subpath->startup_cost, subpath->total_cost,
2596  subpath->rows);
2597 
2598  /* add tlist eval cost for each output row */
2599  pathnode->path.startup_cost += target->cost.startup;
2600  pathnode->path.total_cost += target->cost.startup +
2601  target->cost.per_tuple * pathnode->path.rows;
2602 
2603  return pathnode;
2604 }
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2041
List * qual
Definition: relation.h:1522
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Definition: nodes.h:76
Path path
Definition: relation.h:1519
List * groupClause
Definition: relation.h:1521
Path * subpath
Definition: relation.h:1520
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GroupingSetsPath* create_groupingsets_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List having_qual,
AggStrategy  aggstrategy,
List rollups,
const AggClauseCosts agg_costs,
double  numGroups 
)

Definition at line 2740 of file pathnode.c.

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

Referenced by consider_groupingsets_paths().

2749 {
2751  ListCell *lc;
2752  bool is_first = true;
2753  bool is_first_sort = true;
2754 
2755  /* The topmost generated Plan node will be an Agg */
2756  pathnode->path.pathtype = T_Agg;
2757  pathnode->path.parent = rel;
2758  pathnode->path.pathtarget = target;
2759  pathnode->path.param_info = subpath->param_info;
2760  pathnode->path.parallel_aware = false;
2761  pathnode->path.parallel_safe = rel->consider_parallel &&
2762  subpath->parallel_safe;
2763  pathnode->path.parallel_workers = subpath->parallel_workers;
2764  pathnode->subpath = subpath;
2765 
2766  /*
2767  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
2768  * to AGG_HASHED, here if possible.
2769  */
2770  if (aggstrategy == AGG_SORTED &&
2771  list_length(rollups) == 1 &&
2772  ((RollupData *) linitial(rollups))->groupClause == NIL)
2773  aggstrategy = AGG_PLAIN;
2774 
2775  if (aggstrategy == AGG_MIXED &&
2776  list_length(rollups) == 1)
2777  aggstrategy = AGG_HASHED;
2778 
2779  /*
2780  * Output will be in sorted order by group_pathkeys if, and only if, there
2781  * is a single rollup operation on a non-empty list of grouping
2782  * expressions.
2783  */
2784  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
2785  pathnode->path.pathkeys = root->group_pathkeys;
2786  else
2787  pathnode->path.pathkeys = NIL;
2788 
2789  pathnode->aggstrategy = aggstrategy;
2790  pathnode->rollups = rollups;
2791  pathnode->qual = having_qual;
2792 
2793  Assert(rollups != NIL);
2794  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
2795  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
2796 
2797  foreach(lc, rollups)
2798  {
2799  RollupData *rollup = lfirst(lc);
2800  List *gsets = rollup->gsets;
2801  int numGroupCols = list_length(linitial(gsets));
2802 
2803  /*
2804  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
2805  * (already-sorted) input, and following ones do their own sort.
2806  *
2807  * In AGG_HASHED mode, there is one rollup for each grouping set.
2808  *
2809  * In AGG_MIXED mode, the first rollups are hashed, the first
2810  * non-hashed one takes the (already-sorted) input, and following ones
2811  * do their own sort.
2812  */
2813  if (is_first)
2814  {
2815  cost_agg(&pathnode->path, root,
2816  aggstrategy,
2817  agg_costs,
2818  numGroupCols,
2819  rollup->numGroups,
2820  subpath->startup_cost,
2821  subpath->total_cost,
2822  subpath->rows);
2823  is_first = false;
2824  if (!rollup->is_hashed)
2825  is_first_sort = false;
2826  }
2827  else
2828  {
2829  Path sort_path; /* dummy for result of cost_sort */
2830  Path agg_path; /* dummy for result of cost_agg */
2831 
2832  if (rollup->is_hashed || is_first_sort)
2833  {
2834  /*
2835  * Account for cost of aggregation, but don't charge input
2836  * cost again
2837  */
2838  cost_agg(&agg_path, root,
2839  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
2840  agg_costs,
2841  numGroupCols,
2842  rollup->numGroups,
2843  0.0, 0.0,
2844  subpath->rows);
2845  if (!rollup->is_hashed)
2846  is_first_sort = false;
2847  }
2848  else
2849  {
2850  /* Account for cost of sort, but don't charge input cost again */
2851  cost_sort(&sort_path, root, NIL,
2852  0.0,
2853  subpath->rows,
2854  subpath->pathtarget->width,
2855  0.0,
2856  work_mem,
2857  -1.0);
2858 
2859  /* Account for cost of aggregation */
2860 
2861  cost_agg(&agg_path, root,
2862  AGG_SORTED,
2863  agg_costs,
2864  numGroupCols,
2865  rollup->numGroups,
2866  sort_path.startup_cost,
2867  sort_path.total_cost,
2868  sort_path.rows);
2869  }
2870 
2871  pathnode->path.total_cost += agg_path.total_cost;
2872  pathnode->path.rows += agg_path.rows;
2873  }
2874  }
2875 
2876  /* add tlist eval cost for each output row */
2877  pathnode->path.startup_cost += target->cost.startup;
2878  pathnode->path.total_cost += target->cost.startup +
2879  target->cost.per_tuple * pathnode->path.rows;
2880 
2881  return pathnode;
2882 }
List * group_pathkeys
Definition: relation.h:264
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
bool is_hashed
Definition: relation.h:1575
ParamPathInfo * param_info
Definition: relation.h:1045
double numGroups
Definition: relation.h:1573
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
#define linitial(l)
Definition: pg_list.h:111
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1874
AggStrategy aggstrategy
Definition: relation.h:1586
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:1645
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
Definition: pg_list.h:45
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
List * gsets
Definition: relation.h:1571
HashPath* create_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
Relids  required_outer,
List hashclauses 
)

Definition at line 2223 of file pathnode.c.

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

Referenced by try_hashjoin_path(), and try_partial_hashjoin_path().

2233 {
2234  HashPath *pathnode = makeNode(HashPath);
2235 
2236  pathnode->jpath.path.pathtype = T_HashJoin;
2237  pathnode->jpath.path.parent = joinrel;
2238  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2239  pathnode->jpath.path.param_info =
2241  joinrel,
2242  outer_path,
2243  inner_path,
2244  extra->sjinfo,
2245  required_outer,
2246  &restrict_clauses);
2247  pathnode->jpath.path.parallel_aware = false;
2248  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2249  outer_path->parallel_safe && inner_path->parallel_safe;
2250  /* This is a foolish way to estimate parallel_workers, but for now... */
2251  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2252 
2253  /*
2254  * A hashjoin never has pathkeys, since its output ordering is
2255  * unpredictable due to possible batching. XXX If the inner relation is
2256  * small enough, we could instruct the executor that it must not batch,
2257  * and then we could assume that the output inherits the outer relation's
2258  * ordering, which might save a sort step. However there is considerable
2259  * downside if our estimate of the inner relation size is badly off. For
2260  * the moment we don't risk it. (Note also that if we wanted to take this
2261  * seriously, joinpath.c would have to consider many more paths for the
2262  * outer rel than it does now.)
2263  */
2264  pathnode->jpath.path.pathkeys = NIL;
2265  pathnode->jpath.jointype = jointype;
2266  pathnode->jpath.inner_unique = extra->inner_unique;
2267  pathnode->jpath.outerjoinpath = outer_path;
2268  pathnode->jpath.innerjoinpath = inner_path;
2269  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2270  pathnode->path_hashclauses = hashclauses;
2271  /* final_cost_hashjoin will fill in pathnode->num_batches */
2272 
2273  final_cost_hashjoin(root, pathnode, workspace, extra);
2274 
2275  return pathnode;
2276 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3013
JoinPath jpath
Definition: relation.h:1458
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1341
Path * innerjoinpath
Definition: relation.h:1385
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
SpecialJoinInfo * sjinfo
Definition: relation.h:2273
List * joinrestrictinfo
Definition: relation.h:1387
RelOptInfo * parent
Definition: relation.h:1042
Path * outerjoinpath
Definition: relation.h:1384
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
Path path
Definition: relation.h:1377
bool parallel_safe
Definition: relation.h:1048
bool inner_unique
Definition: relation.h:1381
bool consider_parallel
Definition: relation.h:593
JoinType jointype
Definition: relation.h:1379
bool parallel_aware
Definition: relation.h:1047
List * path_hashclauses
Definition: relation.h:1459
struct PathTarget * reltarget
Definition: relation.h:596
IndexPath* create_index_path ( PlannerInfo root,
IndexOptInfo index,
List indexclauses,
List indexclausecols,
List indexorderbys,
List indexorderbycols,
List pathkeys,
ScanDirection  indexscandir,
bool  indexonly,
Relids  required_outer,
double  loop_count,
bool  partial_path 
)

Definition at line 1016 of file pathnode.c.

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

Referenced by build_index_paths(), and plan_cluster_use_sort().

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

Definition at line 3283 of file pathnode.c.

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

Referenced by grouping_planner().

3287 {
3288  LimitPath *pathnode = makeNode(LimitPath);
3289 
3290  pathnode->path.pathtype = T_Limit;
3291  pathnode->path.parent = rel;
3292  /* Limit doesn't project, so use source path's pathtarget */
3293  pathnode->path.pathtarget = subpath->pathtarget;
3294  /* For now, assume we are above any joins, so no parameterization */
3295  pathnode->path.param_info = NULL;
3296  pathnode->path.parallel_aware = false;
3297  pathnode->path.parallel_safe = rel->consider_parallel &&
3298  subpath->parallel_safe;
3299  pathnode->path.parallel_workers = subpath->parallel_workers;
3300  pathnode->path.rows = subpath->rows;
3301  pathnode->path.startup_cost = subpath->startup_cost;
3302  pathnode->path.total_cost = subpath->total_cost;
3303  pathnode->path.pathkeys = subpath->pathkeys;
3304  pathnode->subpath = subpath;
3305  pathnode->limitOffset = limitOffset;
3306  pathnode->limitCount = limitCount;
3307 
3308  /*
3309  * Adjust the output rows count and costs according to the offset/limit.
3310  * This is only a cosmetic issue if we are at top level, but if we are
3311  * building a subquery then it's important to report correct info to the
3312  * outer planner.
3313  *
3314  * When the offset or count couldn't be estimated, use 10% of the
3315  * estimated number of rows emitted from the subpath.
3316  *
3317  * XXX we don't bother to add eval costs of the offset/limit expressions
3318  * themselves to the path costs. In theory we should, but in most cases
3319  * those expressions are trivial and it's just not worth the trouble.
3320  */
3321  if (offset_est != 0)
3322  {
3323  double offset_rows;
3324 
3325  if (offset_est > 0)
3326  offset_rows = (double) offset_est;
3327  else
3328  offset_rows = clamp_row_est(subpath->rows * 0.10);
3329  if (offset_rows > pathnode->path.rows)
3330  offset_rows = pathnode->path.rows;
3331  if (subpath->rows > 0)
3332  pathnode->path.startup_cost +=
3333  (subpath->total_cost - subpath->startup_cost)
3334  * offset_rows / subpath->rows;
3335  pathnode->path.rows -= offset_rows;
3336  if (pathnode->path.rows < 1)
3337  pathnode->path.rows = 1;
3338  }
3339 
3340  if (count_est != 0)
3341  {
3342  double count_rows;
3343 
3344  if (count_est > 0)
3345  count_rows = (double) count_est;
3346  else
3347  count_rows = clamp_row_est(subpath->rows * 0.10);
3348  if (count_rows > pathnode->path.rows)
3349  count_rows = pathnode->path.rows;
3350  if (subpath->rows > 0)
3351  pathnode->path.total_cost = pathnode->path.startup_cost +
3352  (subpath->total_cost - subpath->startup_cost)
3353  * count_rows / subpath->rows;
3354  pathnode->path.rows = count_rows;
3355  if (pathnode->path.rows < 1)
3356  pathnode->path.rows = 1;
3357  }
3358 
3359  return pathnode;
3360 }
PathTarget * pathtarget
Definition: relation.h:1043
Node * limitOffset
Definition: relation.h:1687
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
Path * subpath
Definition: relation.h:1686
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
Path path
Definition: relation.h:1685
bool parallel_aware
Definition: relation.h:1047
double clamp_row_est(double nrows)
Definition: costsize.c:174
Node * limitCount
Definition: relation.h:1688
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:85
LockRowsPath* create_lockrows_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List rowMarks,
int  epqParam 
)

Definition at line 3124 of file pathnode.c.

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

Referenced by grouping_planner().

3126 {
3127  LockRowsPath *pathnode = makeNode(LockRowsPath);
3128 
3129  pathnode->path.pathtype = T_LockRows;
3130  pathnode->path.parent = rel;
3131  /* LockRows doesn't project, so use source path's pathtarget */
3132  pathnode->path.pathtarget = subpath->pathtarget;
3133  /* For now, assume we are above any joins, so no parameterization */
3134  pathnode->path.param_info = NULL;
3135  pathnode->path.parallel_aware = false;
3136  pathnode->path.parallel_safe = false;
3137  pathnode->path.parallel_workers = 0;
3138  pathnode->path.rows = subpath->rows;
3139 
3140  /*
3141  * The result cannot be assumed sorted, since locking might cause the sort
3142  * key columns to be replaced with new values.
3143  */
3144  pathnode->path.pathkeys = NIL;
3145 
3146  pathnode->subpath = subpath;
3147  pathnode->rowMarks = rowMarks;
3148  pathnode->epqParam = epqParam;
3149 
3150  /*
3151  * We should charge something extra for the costs of row locking and
3152  * possible refetches, but it's hard to say how much. For now, use
3153  * cpu_tuple_cost per row.
3154  */
3155  pathnode->path.startup_cost = subpath->startup_cost;
3156  pathnode->path.total_cost = subpath->total_cost +
3157  cpu_tuple_cost * subpath->rows;
3158 
3159  return pathnode;
3160 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * rowMarks
Definition: relation.h:1651
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1650
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

Definition at line 1396 of file pathnode.c.

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

Referenced by match_unsorted_outer(), and set_tablesample_rel_pathlist().

1397 {
1398  MaterialPath *pathnode = makeNode(MaterialPath);
1399 
1400  Assert(subpath->parent == rel);
1401 
1402  pathnode->path.pathtype = T_Material;
1403  pathnode->path.parent = rel;
1404  pathnode->path.pathtarget = rel->reltarget;
1405  pathnode->path.param_info = subpath->param_info;
1406  pathnode->path.parallel_aware = false;
1407  pathnode->path.parallel_safe = rel->consider_parallel &&
1408  subpath->parallel_safe;
1409  pathnode->path.parallel_workers = subpath->parallel_workers;
1410  pathnode->path.pathkeys = subpath->pathkeys;
1411 
1412  pathnode->subpath = subpath;
1413 
1414  cost_material(&pathnode->path,
1415  subpath->startup_cost,
1416  subpath->total_cost,
1417  subpath->rows,
1418  subpath->pathtarget->width);
1419 
1420  return pathnode;
1421 }
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Path * subpath
Definition: relation.h:1314
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1820
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
MergeAppendPath* create_merge_append_path ( PlannerInfo root,
RelOptInfo rel,
List subpaths,
List pathkeys,
Relids  required_outer,
List partitioned_rels 
)

Definition at line 1265 of file pathnode.c.

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

Referenced by generate_mergeappend_paths().

1271 {
1273  Cost input_startup_cost;
1274  Cost input_total_cost;
1275  ListCell *l;
1276 
1277  pathnode->path.pathtype = T_MergeAppend;
1278  pathnode->path.parent = rel;
1279  pathnode->path.pathtarget = rel->reltarget;
1281  required_outer);
1282  pathnode->path.parallel_aware = false;
1283  pathnode->path.parallel_safe = rel->consider_parallel;
1284  pathnode->path.parallel_workers = 0;
1285  pathnode->path.pathkeys = pathkeys;
1286  pathnode->partitioned_rels = list_copy(partitioned_rels);
1287  pathnode->subpaths = subpaths;
1288 
1289  /*
1290  * Apply query-wide LIMIT if known and path is for sole base relation.
1291  * (Handling this at this low level is a bit klugy.)
1292  */
1293  if (bms_equal(rel->relids, root->all_baserels))
1294  pathnode->limit_tuples = root->limit_tuples;
1295  else
1296  pathnode->limit_tuples = -1.0;
1297 
1298  /*
1299  * Add up the sizes and costs of the input paths.
1300  */
1301  pathnode->path.rows = 0;
1302  input_startup_cost = 0;
1303  input_total_cost = 0;
1304  foreach(l, subpaths)
1305  {
1306  Path *subpath = (Path *) lfirst(l);
1307 
1308  pathnode->path.rows += subpath->rows;
1309  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1310  subpath->parallel_safe;
1311 
1312  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1313  {
1314  /* Subpath is adequately ordered, we won't need to sort it */
1315  input_startup_cost += subpath->startup_cost;
1316  input_total_cost += subpath->total_cost;
1317  }
1318  else
1319  {
1320  /* We'll need to insert a Sort node, so include cost for that */
1321  Path sort_path; /* dummy for result of cost_sort */
1322 
1323  cost_sort(&sort_path,
1324  root,
1325  pathkeys,
1326  subpath->total_cost,
1327  subpath->parent->tuples,
1328  subpath->pathtarget->width,
1329  0.0,
1330  work_mem,
1331  pathnode->limit_tuples);
1332  input_startup_cost += sort_path.startup_cost;
1333  input_total_cost += sort_path.total_cost;
1334  }
1335 
1336  /* All child paths must have same parameterization */
1337  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1338  }
1339 
1340  /* Now we can compute total costs of the MergeAppend */
1341  cost_merge_append(&pathnode->path, root,
1342  pathkeys, list_length(subpaths),
1343  input_startup_cost, input_total_cost,
1344  pathnode->path.rows);
1345 
1346  return pathnode;
1347 }
PathTarget * pathtarget
Definition: relation.h:1043
double tuples
Definition: relation.h:625
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partitioned_rels
Definition: relation.h:1287
NodeTag pathtype
Definition: relation.h:1040
Relids all_baserels
Definition: relation.h:196
double limit_tuples
Definition: relation.h:295
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1645
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
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:1769
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
List * subpaths
Definition: relation.h:1288
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1545
struct PathTarget * reltarget
Definition: relation.h:596
double limit_tuples
Definition: relation.h:1289
double Cost
Definition: nodes.h:641
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
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 2158 of file pathnode.c.

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

Referenced by try_mergejoin_path(), and try_partial_mergejoin_path().

2171 {
2172  MergePath *pathnode = makeNode(MergePath);
2173 
2174  pathnode->jpath.path.pathtype = T_MergeJoin;
2175  pathnode->jpath.path.parent = joinrel;
2176  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2177  pathnode->jpath.path.param_info =
2179  joinrel,
2180  outer_path,
2181  inner_path,
2182  extra->sjinfo,
2183  required_outer,
2184  &restrict_clauses);
2185  pathnode->jpath.path.parallel_aware = false;
2186  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2187  outer_path->parallel_safe && inner_path->parallel_safe;
2188  /* This is a foolish way to estimate parallel_workers, but for now... */
2189  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2190  pathnode->jpath.path.pathkeys = pathkeys;
2191  pathnode->jpath.jointype = jointype;
2192  pathnode->jpath.inner_unique = extra->inner_unique;
2193  pathnode->jpath.outerjoinpath = outer_path;
2194  pathnode->jpath.innerjoinpath = inner_path;
2195  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2196  pathnode->path_mergeclauses = mergeclauses;
2197  pathnode->outersortkeys = outersortkeys;
2198  pathnode->innersortkeys = innersortkeys;
2199  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2200  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2201 
2202  final_cost_mergejoin(root, pathnode, workspace, extra);
2203 
2204  return pathnode;
2205 }
List * path_mergeclauses
Definition: relation.h:1440
List * outersortkeys
Definition: relation.h:1441
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1341
Path * innerjoinpath
Definition: relation.h:1385
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
SpecialJoinInfo * sjinfo
Definition: relation.h:2273
List * joinrestrictinfo
Definition: relation.h:1387
RelOptInfo * parent
Definition: relation.h:1042
Path * outerjoinpath
Definition: relation.h:1384
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
Path path
Definition: relation.h:1377
bool parallel_safe
Definition: relation.h:1048
bool inner_unique
Definition: relation.h:1381
bool consider_parallel
Definition: relation.h:593
List * innersortkeys
Definition: relation.h:1442
JoinType jointype
Definition: relation.h:1379
JoinPath jpath
Definition: relation.h:1439
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2600
MinMaxAggPath* create_minmaxagg_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List mmaggregates,
List quals 
)

Definition at line 2894 of file pathnode.c.

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

Referenced by preprocess_minmax_aggregates().

2899 {
2900  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2901  Cost initplan_cost;
2902  ListCell *lc;
2903 
2904  /* The topmost generated Plan node will be a Result */
2905  pathnode->path.pathtype = T_Result;
2906  pathnode->path.parent = rel;
2907  pathnode->path.pathtarget = target;
2908  /* For now, assume we are above any joins, so no parameterization */
2909  pathnode->path.param_info = NULL;
2910  pathnode->path.parallel_aware = false;
2911  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2912  pathnode->path.parallel_safe = false;
2913  pathnode->path.parallel_workers = 0;
2914  /* Result is one unordered row */
2915  pathnode->path.rows = 1;
2916  pathnode->path.pathkeys = NIL;
2917 
2918  pathnode->mmaggregates = mmaggregates;
2919  pathnode->quals = quals;
2920 
2921  /* Calculate cost of all the initplans ... */
2922  initplan_cost = 0;
2923  foreach(lc, mmaggregates)
2924  {
2925  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2926 
2927  initplan_cost += mminfo->pathcost;
2928  }
2929 
2930  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
2931  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
2932  pathnode->path.total_cost = initplan_cost + target->cost.startup +
2933  target->cost.per_tuple + cpu_tuple_cost;
2934 
2935  return pathnode;
2936 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * quals
Definition: relation.h:1598
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * mmaggregates
Definition: relation.h:1597
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
double Cost
Definition: nodes.h:641
ModifyTablePath* create_modifytable_path ( PlannerInfo root,
RelOptInfo rel,
CmdType  operation,
bool  canSetTag,
Index  nominalRelation,
List partitioned_rels,
List resultRelations,
List subpaths,
List subroots,
List withCheckOptionLists,
List returningLists,
List rowMarks,
OnConflictExpr onconflict,
int  epqParam 
)

Definition at line 3183 of file pathnode.c.

References Assert, ModifyTablePath::canSetTag, ModifyTablePath::epqParam, lfirst, list_copy(), list_head(), list_length(), makeNode, NIL, ModifyTablePath::nominalRelation, ModifyTablePath::onconflict, ModifyTablePath::operation, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ModifyTablePath::partitioned_rels, ModifyTablePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, ModifyTablePath::resultRelations, ModifyTablePath::returningLists, rint(), ModifyTablePath::rowMarks, Path::rows, Path::startup_cost, subpath(), ModifyTablePath::subpaths, ModifyTablePath::subroots, T_ModifyTable, Path::total_cost, PathTarget::width, and ModifyTablePath::withCheckOptionLists.

Referenced by grouping_planner(), and inheritance_planner().

3191 {
3193  double total_size;
3194  ListCell *lc;
3195 
3196  Assert(list_length(resultRelations) == list_length(subpaths));
3197  Assert(list_length(resultRelations) == list_length(subroots));
3198  Assert(withCheckOptionLists == NIL ||
3199  list_length(resultRelations) == list_length(withCheckOptionLists));
3200  Assert(returningLists == NIL ||
3201  list_length(resultRelations) == list_length(returningLists));
3202 
3203  pathnode->path.pathtype = T_ModifyTable;
3204  pathnode->path.parent = rel;
3205  /* pathtarget is not interesting, just make it minimally valid */
3206  pathnode->path.pathtarget = rel->reltarget;
3207  /* For now, assume we are above any joins, so no parameterization */
3208  pathnode->path.param_info = NULL;
3209  pathnode->path.parallel_aware = false;
3210  pathnode->path.parallel_safe = false;
3211  pathnode->path.parallel_workers = 0;
3212  pathnode->path.pathkeys = NIL;
3213 
3214  /*
3215  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3216  *
3217  * Currently, we don't charge anything extra for the actual table
3218  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3219  * expressions if any. It would only be window dressing, since
3220  * ModifyTable is always a top-level node and there is no way for the
3221  * costs to change any higher-level planning choices. But we might want
3222  * to make it look better sometime.
3223  */
3224  pathnode->path.startup_cost = 0;
3225  pathnode->path.total_cost = 0;
3226  pathnode->path.rows = 0;
3227  total_size = 0;
3228  foreach(lc, subpaths)
3229  {
3230  Path *subpath = (Path *) lfirst(lc);
3231 
3232  if (lc == list_head(subpaths)) /* first node? */
3233  pathnode->path.startup_cost = subpath->startup_cost;
3234  pathnode->path.total_cost += subpath->total_cost;
3235  pathnode->path.rows += subpath->rows;
3236  total_size += subpath->pathtarget->width * subpath->rows;
3237  }
3238 
3239  /*
3240  * Set width to the average width of the subpath outputs. XXX this is
3241  * totally wrong: we should report zero if no RETURNING, else an average
3242  * of the RETURNING tlist widths. But it's what happened historically,
3243  * and improving it is a task for another day.
3244  */
3245  if (pathnode->path.rows > 0)
3246  total_size /= pathnode->path.rows;
3247  pathnode->path.pathtarget->width = rint(total_size);
3248 
3249  pathnode->operation = operation;
3250  pathnode->canSetTag = canSetTag;
3251  pathnode->nominalRelation = nominalRelation;
3252  pathnode->partitioned_rels = list_copy(partitioned_rels);
3253  pathnode->resultRelations = resultRelations;
3254  pathnode->subpaths = subpaths;
3255  pathnode->subroots = subroots;
3256  pathnode->withCheckOptionLists = withCheckOptionLists;
3257  pathnode->returningLists = returningLists;
3258  pathnode->rowMarks = rowMarks;
3259  pathnode->onconflict = onconflict;
3260  pathnode->epqParam = epqParam;
3261 
3262  return pathnode;
3263 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
List * returningLists
Definition: relation.h:1674
OnConflictExpr * onconflict
Definition: relation.h:1676
Index nominalRelation
Definition: relation.h:1667
List * rowMarks
Definition: relation.h:1675
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
List * subroots
Definition: relation.h:1672
RelOptInfo * parent
Definition: relation.h:1042
List * subpaths
Definition: relation.h:1671
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
double rint(double x)
Definition: rint.c:22
List * partitioned_rels
Definition: relation.h:1669
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1673
int width
Definition: relation.h:975
CmdType operation
Definition: relation.h:1665
List * resultRelations
Definition: relation.h:1670
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Path* create_namedtuplestorescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 1908 of file pathnode.c.

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

Referenced by set_namedtuplestore_pathlist().

1910 {
1911  Path *pathnode = makeNode(Path);
1912 
1913  pathnode->pathtype = T_NamedTuplestoreScan;
1914  pathnode->parent = rel;
1915  pathnode->pathtarget = rel->reltarget;
1916  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1917  required_outer);
1918  pathnode->parallel_aware = false;
1919  pathnode->parallel_safe = rel->consider_parallel;
1920  pathnode->parallel_workers = 0;
1921  pathnode->pathkeys = NIL; /* result is always unordered */
1922 
1923  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
1924 
1925  return pathnode;
1926 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1525
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
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 2070 of file pathnode.c.

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

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

2080 {
2081  NestPath *pathnode = makeNode(NestPath);
2082  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2083 
2084  /*
2085  * If the inner path is parameterized by the outer, we must drop any
2086  * restrict_clauses that are due to be moved into the inner path. We have
2087  * to do this now, rather than postpone the work till createplan time,
2088  * because the restrict_clauses list can affect the size and cost
2089  * estimates for this path.
2090  */
2091  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2092  {
2093  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2094  inner_req_outer);
2095  List *jclauses = NIL;
2096  ListCell *lc;
2097 
2098  foreach(lc, restrict_clauses)
2099  {
2100  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2101 
2102  if (!join_clause_is_movable_into(rinfo,
2103  inner_path->parent->relids,
2104  inner_and_outer))
2105  jclauses = lappend(jclauses, rinfo);
2106  }
2107  restrict_clauses = jclauses;
2108  }
2109 
2110  pathnode->path.pathtype = T_NestLoop;
2111  pathnode->path.parent = joinrel;
2112  pathnode->path.pathtarget = joinrel->reltarget;
2113  pathnode->path.param_info =
2115  joinrel,
2116  outer_path,
2117  inner_path,
2118  extra->sjinfo,
2119  required_outer,
2120  &restrict_clauses);
2121  pathnode->path.parallel_aware = false;
2122  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2123  outer_path->parallel_safe && inner_path->parallel_safe;
2124  /* This is a foolish way to estimate parallel_workers, but for now... */
2125  pathnode->path.parallel_workers = outer_path->parallel_workers;
2126  pathnode->path.pathkeys = pathkeys;
2127  pathnode->jointype = jointype;
2128  pathnode->inner_unique = extra->inner_unique;
2129  pathnode->outerjoinpath = outer_path;
2130  pathnode->innerjoinpath = inner_path;
2131  pathnode->joinrestrictinfo = restrict_clauses;
2132 
2133  final_cost_nestloop(root, pathnode, workspace, extra);
2134 
2135  return pathnode;
2136 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1341
Path * innerjoinpath
Definition: relation.h:1385
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2163
SpecialJoinInfo * sjinfo
Definition: relation.h:2273
List * joinrestrictinfo
Definition: relation.h:1387
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:510
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * outerjoinpath
Definition: relation.h:1384
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
Path path
Definition: relation.h:1377
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1048
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool inner_unique
Definition: relation.h:1381
bool consider_parallel
Definition: relation.h:593
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
JoinType jointype
Definition: relation.h:1379
bool parallel_aware
Definition: relation.h:1047
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
ProjectionPath* create_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

Definition at line 2287 of file pathnode.c.

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

Referenced by adjust_paths_for_srfs(), apply_projection_to_path(), and grouping_planner().

2291 {
2292  ProjectionPath *pathnode = makeNode(ProjectionPath);
2293  PathTarget *oldtarget = subpath->pathtarget;
2294 
2295  pathnode->path.pathtype = T_Result;
2296  pathnode->path.parent = rel;
2297  pathnode->path.pathtarget = target;
2298  /* For now, assume we are above any joins, so no parameterization */
2299  pathnode->path.param_info = NULL;
2300  pathnode->path.parallel_aware = false;
2301  pathnode->path.parallel_safe = rel->consider_parallel &&
2302  subpath->parallel_safe &&
2303  is_parallel_safe(root, (Node *) target->exprs);
2304  pathnode->path.parallel_workers = subpath->parallel_workers;
2305  /* Projection does not change the sort order */
2306  pathnode->path.pathkeys = subpath->pathkeys;
2307 
2308  pathnode->subpath = subpath;
2309 
2310  /*
2311  * We might not need a separate Result node. If the input plan node type
2312  * can project, we can just tell it to project something else. Or, if it
2313  * can't project but the desired target has the same expression list as
2314  * what the input will produce anyway, we can still give it the desired
2315  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2316  * Note: in the latter case, create_projection_plan has to recheck our
2317  * conclusion; see comments therein.
2318  */
2319  if (is_projection_capable_path(subpath) ||
2320  equal(oldtarget->exprs, target->exprs))
2321  {
2322  /* No separate Result node needed */
2323  pathnode->dummypp = true;
2324 
2325  /*
2326  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2327  */
2328  pathnode->path.rows = subpath->rows;
2329  pathnode->path.startup_cost = subpath->startup_cost +
2330  (target->cost.startup - oldtarget->cost.startup);
2331  pathnode->path.total_cost = subpath->total_cost +
2332  (target->cost.startup - oldtarget->cost.startup) +
2333  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2334  }
2335  else
2336  {
2337  /* We really do need the Result node */
2338  pathnode->dummypp = false;
2339 
2340  /*
2341  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2342  * evaluating the tlist. There is no qual to worry about.
2343  */
2344  pathnode->path.rows = subpath->rows;
2345  pathnode->path.startup_cost = subpath->startup_cost +
2346  target->cost.startup;
2347  pathnode->path.total_cost = subpath->total_cost +
2348  target->cost.startup +
2349  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2350  }
2351 
2352  return pathnode;
2353 }
PathTarget * pathtarget
Definition: relation.h:1043
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2972
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:510
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6559
bool parallel_aware
Definition: relation.h:1047
Path * subpath
Definition: relation.h:1480
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
RecursiveUnionPath* create_recursiveunion_path ( PlannerInfo root,
RelOptInfo rel,
Path leftpath,
Path rightpath,
PathTarget target,
List distinctList,
int  wtParam,
double  numGroups 
)

Definition at line 3079 of file pathnode.c.

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

Referenced by generate_recursion_path().

3087 {
3089 
3090  pathnode->path.pathtype = T_RecursiveUnion;
3091  pathnode->path.parent = rel;
3092  pathnode->path.pathtarget = target;
3093  /* For now, assume we are above any joins, so no parameterization */
3094  pathnode->path.param_info = NULL;
3095  pathnode->path.parallel_aware = false;
3096  pathnode->path.parallel_safe = rel->consider_parallel &&
3097  leftpath->parallel_safe && rightpath->parallel_safe;
3098  /* Foolish, but we'll do it like joins for now: */
3099  pathnode->path.parallel_workers = leftpath->parallel_workers;
3100  /* RecursiveUnion result is always unsorted */
3101  pathnode->path.pathkeys = NIL;
3102 
3103  pathnode->leftpath = leftpath;
3104  pathnode->rightpath = rightpath;
3105  pathnode->distinctList = distinctList;
3106  pathnode->wtParam = wtParam;
3107  pathnode->numGroups = numGroups;
3108 
3109  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3110 
3111  return pathnode;
3112 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1565
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
ResultPath* create_result_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List resconstantqual 
)

Definition at line 1357 of file pathnode.c.

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

Referenced by create_grouping_paths(), and query_planner().

1359 {
1360  ResultPath *pathnode = makeNode(ResultPath);
1361 
1362  pathnode->path.pathtype = T_Result;
1363  pathnode->path.parent = rel;
1364  pathnode->path.pathtarget = target;
1365  pathnode->path.param_info = NULL; /* there are no other rels... */
1366  pathnode->path.parallel_aware = false;
1367  pathnode->path.parallel_safe = rel->consider_parallel;
1368  pathnode->path.parallel_workers = 0;
1369  pathnode->path.pathkeys = NIL;
1370  pathnode->quals = resconstantqual;
1371 
1372  /* Hardly worth defining a cost_result() function ... just do it */
1373  pathnode->path.rows = 1;
1374  pathnode->path.startup_cost = target->cost.startup;
1375  pathnode->path.total_cost = target->cost.startup +
1376  cpu_tuple_cost + target->cost.per_tuple;
1377  if (resconstantqual)
1378  {
1379  QualCost qual_cost;
1380 
1381  cost_qual_eval(&qual_cost, resconstantqual, root);
1382  /* resconstantqual is evaluated once at startup */
1383  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1384  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1385  }
1386 
1387  return pathnode;
1388 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Path path
Definition: relation.h:1301
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3464
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
List * quals
Definition: relation.h:1302
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
Path* create_samplescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 971 of file pathnode.c.

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

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

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

Definition at line 946 of file pathnode.c.

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

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

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

Definition at line 2454 of file pathnode.c.

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

Referenced by adjust_paths_for_srfs().

2458 {
2459  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2460  double tlist_rows;
2461  ListCell *lc;
2462 
2463  pathnode->path.pathtype = T_ProjectSet;
2464  pathnode->path.parent = rel;
2465  pathnode->path.pathtarget = target;
2466  /* For now, assume we are above any joins, so no parameterization */
2467  pathnode->path.param_info = NULL;
2468  pathnode->path.parallel_aware = false;
2469  pathnode->path.parallel_safe = rel->consider_parallel &&
2470  subpath->parallel_safe &&
2471  is_parallel_safe(root, (Node *) target->exprs);
2472  pathnode->path.parallel_workers = subpath->parallel_workers;
2473  /* Projection does not change the sort order XXX? */
2474  pathnode->path.pathkeys = subpath->pathkeys;
2475 
2476  pathnode->subpath = subpath;
2477 
2478  /*
2479  * Estimate number of rows produced by SRFs for each row of input; if
2480  * there's more than one in this node, use the maximum.
2481  */
2482  tlist_rows = 1;
2483  foreach(lc, target->exprs)
2484  {
2485  Node *node = (Node *) lfirst(lc);
2486  double itemrows;
2487 
2488  itemrows = expression_returns_set_rows(node);
2489  if (tlist_rows < itemrows)
2490  tlist_rows = itemrows;
2491  }
2492 
2493  /*
2494  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2495  * per input row, and half of cpu_tuple_cost for each added output row.
2496  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2497  * this estimate later.
2498  */
2499  pathnode->path.rows = subpath->rows * tlist_rows;
2500  pathnode->path.startup_cost = subpath->startup_cost +
2501  target->cost.startup;
2502  pathnode->path.total_cost = subpath->total_cost +
2503  target->cost.startup +
2504  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2505  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2506 
2507  return pathnode;
2508 }
PathTarget * pathtarget
Definition: relation.h:1043
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:802
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:510
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * exprs
Definition: relation.h:972
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1492
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
bool consider_parallel
Definition: relation.h:593
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
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 3017 of file pathnode.c.

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

Referenced by generate_nonunion_path().

3027 {
3028  SetOpPath *pathnode = makeNode(SetOpPath);
3029 
3030  pathnode->path.pathtype = T_SetOp;
3031  pathnode->path.parent = rel;
3032  /* SetOp doesn't project, so use source path's pathtarget */
3033  pathnode->path.pathtarget = subpath->pathtarget;
3034  /* For now, assume we are above any joins, so no parameterization */
3035  pathnode->path.param_info = NULL;
3036  pathnode->path.parallel_aware = false;
3037  pathnode->path.parallel_safe = rel->consider_parallel &&
3038  subpath->parallel_safe;
3039  pathnode->path.parallel_workers = subpath->parallel_workers;
3040  /* SetOp preserves the input sort order if in sort mode */
3041  pathnode->path.pathkeys =
3042  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3043 
3044  pathnode->subpath = subpath;
3045  pathnode->cmd = cmd;
3046  pathnode->strategy = strategy;
3047  pathnode->distinctList = distinctList;
3048  pathnode->flagColIdx = flagColIdx;
3049  pathnode->firstFlag = firstFlag;
3050  pathnode->numGroups = numGroups;
3051 
3052  /*
3053  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3054  * all columns get compared at most of the tuples.
3055  */
3056  pathnode->path.startup_cost = subpath->startup_cost;
3057  pathnode->path.total_cost = subpath->total_cost +
3058  cpu_operator_cost * subpath->rows * list_length(distinctList);
3059  pathnode->path.rows = outputRows;
3060 
3061  return pathnode;
3062 }
#define NIL
Definition: pg_list.h:69
List * distinctList
Definition: relation.h:1625
PathTarget * pathtarget
Definition: relation.h:1043
SetOpStrategy strategy
Definition: relation.h:1624
Path * subpath
Definition: relation.h:1622
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
double numGroups
Definition: relation.h:1628
NodeTag pathtype
Definition: relation.h:1040
SetOpCmd cmd
Definition: relation.h:1623
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
AttrNumber flagColIdx
Definition: relation.h:1626
double cpu_operator_cost
Definition: costsize.c:108
Cost total_cost
Definition: relation.h:1054
int firstFlag
Definition: relation.h:1627
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Definition: nodes.h:83
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1621
SortPath* create_sort_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
double  limit_tuples 
)

Definition at line 2521 of file pathnode.c.

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

Referenced by create_distinct_paths(), create_grouping_paths(), create_one_window_path(), create_ordered_paths(), generate_nonunion_path(), and make_union_unique().

2526 {
2527  SortPath *pathnode = makeNode(SortPath);
2528 
2529  pathnode->path.pathtype = T_Sort;
2530  pathnode->path.parent = rel;
2531  /* Sort doesn't project, so use source path's pathtarget */
2532  pathnode->path.pathtarget = subpath->pathtarget;
2533  /* For now, assume we are above any joins, so no parameterization */
2534  pathnode->path.param_info = NULL;
2535  pathnode->path.parallel_aware = false;
2536  pathnode->path.parallel_safe = rel->consider_parallel &&
2537  subpath->parallel_safe;
2538  pathnode->path.parallel_workers = subpath->parallel_workers;
2539  pathnode->path.pathkeys = pathkeys;
2540 
2541  pathnode->subpath = subpath;
2542 
2543  cost_sort(&pathnode->path, root, pathkeys,
2544  subpath->total_cost,
2545  subpath->rows,
2546  subpath->pathtarget->width,
2547  0.0, /* XXX comparison_cost shouldn't be 0? */
2548  work_mem, limit_tuples);
2549 
2550  return pathnode;
2551 }
PathTarget * pathtarget
Definition: relation.h:1043
Path * subpath
Definition: relation.h:1506
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Definition: nodes.h:75
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1645
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:975
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1505
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
SubqueryScanPath* create_subqueryscan_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
Relids  required_outer 
)

Definition at line 1777 of file pathnode.c.

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

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

1779 {
1781 
1782  pathnode->path.pathtype = T_SubqueryScan;
1783  pathnode->path.parent = rel;
1784  pathnode->path.pathtarget = rel->reltarget;
1785  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1786  required_outer);
1787  pathnode->path.parallel_aware = false;
1788  pathnode->path.parallel_safe = rel->consider_parallel &&
1789  subpath->parallel_safe;
1790  pathnode->path.parallel_workers = subpath->parallel_workers;
1791  pathnode->path.pathkeys = pathkeys;
1792  pathnode->subpath = subpath;
1793 
1794  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info);
1795 
1796  return pathnode;
1797 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1268
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Path* create_tablefuncscan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 1831 of file pathnode.c.

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

Referenced by set_tablefunc_pathlist().

1833 {
1834  Path *pathnode = makeNode(Path);
1835 
1836  pathnode->pathtype = T_TableFuncScan;
1837  pathnode->parent = rel;
1838  pathnode->pathtarget = rel->reltarget;
1839  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1840  required_outer);
1841  pathnode->parallel_aware = false;
1842  pathnode->parallel_safe = rel->consider_parallel;
1843  pathnode->parallel_workers = 0;
1844  pathnode->pathkeys = NIL; /* result is always unordered */
1845 
1846  cost_tablefuncscan(pathnode, root, rel, pathnode->param_info);
1847 
1848  return pathnode;
1849 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
void cost_tablefuncscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1378
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
TidPath* create_tidscan_path ( PlannerInfo root,
RelOptInfo rel,
List tidquals,
Relids  required_outer 
)

Definition at line 1180 of file pathnode.c.

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

Referenced by create_tidscan_paths().

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

Definition at line 1435 of file pathnode.c.

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

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

1437 {
1438  UniquePath *pathnode;
1439  Path sort_path; /* dummy for result of cost_sort */
1440  Path agg_path; /* dummy for result of cost_agg */
1441  MemoryContext oldcontext;
1442  int numCols;
1443 
1444  /* Caller made a mistake if subpath isn't cheapest_total ... */
1445  Assert(subpath == rel->cheapest_total_path);
1446  Assert(subpath->parent == rel);
1447  /* ... or if SpecialJoinInfo is the wrong one */
1448  Assert(sjinfo->jointype == JOIN_SEMI);
1449  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1450 
1451  /* If result already cached, return it */
1452  if (rel->cheapest_unique_path)
1453  return (UniquePath *) rel->cheapest_unique_path;
1454 
1455  /* If it's not possible to unique-ify, return NULL */
1456  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1457  return NULL;
1458 
1459  /*
1460  * We must ensure path struct and subsidiary data are allocated in main
1461  * planning context; otherwise GEQO memory management causes trouble.
1462  */
1463  oldcontext = MemoryContextSwitchTo(root->planner_cxt);
1464 
1465  pathnode = makeNode(UniquePath);
1466 
1467  pathnode->path.pathtype = T_Unique;
1468  pathnode->path.parent = rel;
1469  pathnode->path.pathtarget = rel->reltarget;
1470  pathnode->path.param_info = subpath->param_info;
1471  pathnode->path.parallel_aware = false;
1472  pathnode->path.parallel_safe = rel->consider_parallel &&
1473  subpath->parallel_safe;
1474  pathnode->path.parallel_workers = subpath->parallel_workers;
1475 
1476  /*
1477  * Assume the output is unsorted, since we don't necessarily have pathkeys
1478  * to represent it. (This might get overridden below.)
1479  */
1480  pathnode->path.pathkeys = NIL;
1481 
1482  pathnode->subpath = subpath;
1483  pathnode->in_operators = sjinfo->semi_operators;
1484  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1485 
1486  /*
1487  * If the input is a relation and it has a unique index that proves the
1488  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1489  * that relation_has_unique_index_for automatically considers restriction
1490  * clauses for the rel, as well.
1491  */
1492  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1494  sjinfo->semi_rhs_exprs,
1495  sjinfo->semi_operators))
1496  {
1497  pathnode->umethod = UNIQUE_PATH_NOOP;
1498  pathnode->path.rows = rel->rows;
1499  pathnode->path.startup_cost = subpath->startup_cost;
1500  pathnode->path.total_cost = subpath->total_cost;
1501  pathnode->path.pathkeys = subpath->pathkeys;
1502 
1503  rel->cheapest_unique_path = (Path *) pathnode;
1504 
1505  MemoryContextSwitchTo(oldcontext);
1506 
1507  return pathnode;
1508  }
1509 
1510  /*
1511  * If the input is a subquery whose output must be unique already, then we
1512  * don't need to do anything. The test for uniqueness has to consider
1513  * exactly which columns we are extracting; for example "SELECT DISTINCT
1514  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1515  * this optimization unless semi_rhs_exprs consists only of simple Vars
1516  * referencing subquery outputs. (Possibly we could do something with
1517  * expressions in the subquery outputs, too, but for now keep it simple.)
1518  */
1519  if (rel->rtekind == RTE_SUBQUERY)
1520  {
1521  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1522 
1524  {
1525  List *sub_tlist_colnos;
1526 
1527  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1528  rel->relid);
1529 
1530  if (sub_tlist_colnos &&
1532  sub_tlist_colnos,
1533  sjinfo->semi_operators))
1534  {
1535  pathnode->umethod = UNIQUE_PATH_NOOP;
1536  pathnode->path.rows = rel->rows;
1537  pathnode->path.startup_cost = subpath->startup_cost;
1538  pathnode->path.total_cost = subpath->total_cost;
1539  pathnode->path.pathkeys = subpath->pathkeys;
1540 
1541  rel->cheapest_unique_path = (Path *) pathnode;
1542 
1543  MemoryContextSwitchTo(oldcontext);
1544 
1545  return pathnode;
1546  }
1547  }
1548  }
1549 
1550  /* Estimate number of output rows */
1551  pathnode->path.rows = estimate_num_groups(root,
1552  sjinfo->semi_rhs_exprs,
1553  rel->rows,
1554  NULL);
1555  numCols = list_length(sjinfo->semi_rhs_exprs);
1556 
1557  if (sjinfo->semi_can_btree)
1558  {
1559  /*
1560  * Estimate cost for sort+unique implementation
1561  */
1562  cost_sort(&sort_path, root, NIL,
1563  subpath->total_cost,
1564  rel->rows,
1565  subpath->pathtarget->width,
1566  0.0,
1567  work_mem,
1568  -1.0);
1569 
1570  /*
1571  * Charge one cpu_operator_cost per comparison per input tuple. We
1572  * assume all columns get compared at most of the tuples. (XXX
1573  * probably this is an overestimate.) This should agree with
1574  * create_upper_unique_path.
1575  */
1576  sort_path.total_cost += cpu_operator_cost * rel->rows * numCols;
1577  }
1578 
1579  if (sjinfo->semi_can_hash)
1580  {
1581  /*
1582  * Estimate the overhead per hashtable entry at 64 bytes (same as in
1583  * planner.c).
1584  */
1585  int hashentrysize = subpath->pathtarget->width + 64;
1586 
1587  if (hashentrysize * pathnode->path.rows > work_mem * 1024L)
1588  {
1589  /*
1590  * We should not try to hash. Hack the SpecialJoinInfo to
1591  * remember this, in case we come through here again.
1592  */
1593  sjinfo->semi_can_hash = false;
1594  }
1595  else
1596  cost_agg(&agg_path, root,
1597  AGG_HASHED, NULL,
1598  numCols, pathnode->path.rows,
1599  subpath->startup_cost,
1600  subpath->total_cost,
1601  rel->rows);
1602  }
1603 
1604  if (sjinfo->semi_can_btree && sjinfo->semi_can_hash)
1605  {
1606  if (agg_path.total_cost < sort_path.total_cost)
1607  pathnode->umethod = UNIQUE_PATH_HASH;
1608  else
1609  pathnode->umethod = UNIQUE_PATH_SORT;
1610  }
1611  else if (sjinfo->semi_can_btree)
1612  pathnode->umethod = UNIQUE_PATH_SORT;
1613  else if (sjinfo->semi_can_hash)
1614  pathnode->umethod = UNIQUE_PATH_HASH;
1615  else
1616  {
1617  /* we can get here only if we abandoned hashing above */
1618  MemoryContextSwitchTo(oldcontext);
1619  return NULL;
1620  }
1621 
1622  if (pathnode->umethod == UNIQUE_PATH_HASH)
1623  {
1624  pathnode->path.startup_cost = agg_path.startup_cost;
1625  pathnode->path.total_cost = agg_path.total_cost;
1626  }
1627  else
1628  {
1629  pathnode->path.startup_cost = sort_path.startup_cost;
1630  pathnode->path.total_cost = sort_path.total_cost;
1631  }
1632 
1633  rel->cheapest_unique_path = (Path *) pathnode;
1634 
1635  MemoryContextSwitchTo(oldcontext);
1636 
1637  return pathnode;
1638 }
struct Path * cheapest_unique_path
Definition: relation.h:604
#define NIL
Definition: pg_list.h:69
bool semi_can_btree
Definition: relation.h:2015
double estimate_num_groups(PlannerInfo *root, List *groupExprs, double input_rows, List **pgset)
Definition: selfuncs.c:3360
PathTarget * pathtarget
Definition: relation.h:1043
bool query_is_distinct_for(Query *query, List *colnos, List *opids)
Definition: analyzejoins.c:782
Definition: nodes.h:79
int parallel_workers
Definition: relation.h:1049
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
ParamPathInfo * param_info
Definition: relation.h:1045
UniquePathMethod umethod
Definition: relation.h:1340
NodeTag pathtype
Definition: relation.h:1040
Relids syn_righthand
Definition: relation.h:2010
#define planner_rt_fetch(rti, root)
Definition: relation.h:328
static List * translate_sub_tlist(List *tlist, int relid)
Definition: pathnode.c:1712
Cost startup_cost
Definition: relation.h:1053
List * semi_rhs_exprs
Definition: relation.h:2018
bool semi_can_hash
Definition: relation.h:2016
RelOptInfo * parent
Definition: relation.h:1042
List * uniq_exprs
Definition: relation.h:1342
struct Path * cheapest_total_path
Definition: relation.h:603
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1874
Relids relids
Definition: relation.h:585
double cpu_operator_cost
Definition: costsize.c:108
Index relid
Definition: relation.h:613
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1645
int work_mem
Definition: globals.c:113
RTEKind rtekind
Definition: relation.h:615
List * in_operators
Definition: relation.h:1341
double rows
Definition: relation.h:588
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
JoinType jointype
Definition: relation.h:2011
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
bool query_supports_distinctness(Query *query)
Definition: analyzejoins.c:745
int width
Definition: relation.h:975
Query * subquery
Definition: parsenodes.h:968
List * semi_operators
Definition: relation.h:2017
bool parallel_aware
Definition: relation.h:1047
MemoryContext planner_cxt
Definition: relation.h:290
bool relation_has_unique_index_for(PlannerInfo *root, RelOptInfo *rel, List *restrictlist, List *exprlist, List *oprlist)
Definition: indxpath.c:2960
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
Path path
Definition: relation.h:1338
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
Path * subpath
Definition: relation.h:1339
UpperUniquePath* create_upper_unique_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
int  numCols,
double  numGroups 
)

Definition at line 2623 of file pathnode.c.

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

Referenced by create_distinct_paths(), and make_union_unique().

2628 {
2630 
2631  pathnode->path.pathtype = T_Unique;
2632  pathnode->path.parent = rel;
2633  /* Unique doesn't project, so use source path's pathtarget */
2634  pathnode->path.pathtarget = subpath->pathtarget;
2635  /* For now, assume we are above any joins, so no parameterization */
2636  pathnode->path.param_info = NULL;
2637  pathnode->path.parallel_aware = false;
2638  pathnode->path.parallel_safe = rel->consider_parallel &&
2639  subpath->parallel_safe;
2640  pathnode->path.parallel_workers = subpath->parallel_workers;
2641  /* Unique doesn't change the input ordering */
2642  pathnode->path.pathkeys = subpath->pathkeys;
2643 
2644  pathnode->subpath = subpath;
2645  pathnode->numkeys = numCols;
2646 
2647  /*
2648  * Charge one cpu_operator_cost per comparison per input tuple. We assume
2649  * all columns get compared at most of the tuples. (XXX probably this is
2650  * an overestimate.)
2651  */
2652  pathnode->path.startup_cost = subpath->startup_cost;
2653  pathnode->path.total_cost = subpath->total_cost +
2654  cpu_operator_cost * subpath->rows * numCols;
2655  pathnode->path.rows = numGroups;
2656 
2657  return pathnode;
2658 }
PathTarget * pathtarget
Definition: relation.h:1043
Path * subpath
Definition: relation.h:1534
Definition: nodes.h:79
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
double cpu_operator_cost
Definition: costsize.c:108
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Path* create_valuesscan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 1857 of file pathnode.c.

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

Referenced by set_values_pathlist().

1859 {
1860  Path *pathnode = makeNode(Path);
1861 
1862  pathnode->pathtype = T_ValuesScan;
1863  pathnode->parent = rel;
1864  pathnode->pathtarget = rel->reltarget;
1865  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1866  required_outer);
1867  pathnode->parallel_aware = false;
1868  pathnode->parallel_safe = rel->consider_parallel;
1869  pathnode->parallel_workers = 0;
1870  pathnode->pathkeys = NIL; /* result is always unordered */
1871 
1872  cost_valuesscan(pathnode, root, rel, pathnode->param_info);
1873 
1874  return pathnode;
1875 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1254
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
void cost_valuesscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1434
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:558
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
WindowAggPath* create_windowagg_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,