PostgreSQL Source Code  git master
pathnode.h File Reference
#include "nodes/bitmapset.h"
#include "nodes/relation.h"
Include dependency graph for pathnode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int compare_path_costs (Path *path1, Path *path2, CostSelector criterion)
 
int compare_fractional_path_costs (Path *path1, Path *path2, double fraction)
 
void set_cheapest (RelOptInfo *parent_rel)
 
void add_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_path_precheck (RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
 
void add_partial_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_partial_path_precheck (RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
 
Pathcreate_seqscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
 
Pathcreate_samplescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
IndexPathcreate_index_path (PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexclausecols, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
 
BitmapHeapPathcreate_bitmap_heap_path (PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
 
BitmapAndPathcreate_bitmap_and_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
BitmapOrPathcreate_bitmap_or_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
TidPathcreate_tidscan_path (PlannerInfo *root, RelOptInfo *rel, List *tidquals, Relids required_outer)
 
AppendPathcreate_append_path (RelOptInfo *rel, List *subpaths, List *partial_subpaths, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
 
ResultPathcreate_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *resconstantqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
UniquePathcreate_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
 
GatherPathcreate_gather_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
 
GatherMergePathcreate_gather_merge_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, 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_tablexprscan_path (PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
 
Pathcreate_valuesscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_tablefuncscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_ctescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_namedtuplestorescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_worktablescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
ForeignPathcreate_foreignscan_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
Relids calc_nestloop_required_outer (Relids outerrelids, Relids outer_paramrels, Relids innerrelids, Relids inner_paramrels)
 
Relids calc_non_nestloop_required_outer (Path *outer_path, Path *inner_path)
 
NestPathcreate_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
 
MergePathcreate_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
 
HashPathcreate_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, bool parallel_hash, List *restrict_clauses, Relids required_outer, List *hashclauses)
 
ProjectionPathcreate_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
Pathapply_projection_to_path (PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
 
ProjectSetPathcreate_set_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
SortPathcreate_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
 
GroupPathcreate_group_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, 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, bool partColsUpdated, List *resultRelations, List *subpaths, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
LimitPathcreate_limit_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, int64 offset_est, int64 count_est)
 
Pathreparameterize_path (PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
 
Pathreparameterize_path_by_child (PlannerInfo *root, Path *path, RelOptInfo *child_rel)
 
void setup_simple_rel_arrays (PlannerInfo *root)
 
RelOptInfobuild_simple_rel (PlannerInfo *root, int relid, RelOptInfo *parent)
 
RelOptInfofind_base_rel (PlannerInfo *root, int relid)
 
RelOptInfofind_join_rel (PlannerInfo *root, Relids relids)
 
RelOptInfobuild_join_rel (PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List **restrictlist_ptr)
 
Relids min_join_parameterization (PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
 
RelOptInfobuild_empty_join_rel (PlannerInfo *root)
 
RelOptInfofetch_upper_rel (PlannerInfo *root, UpperRelationKind kind, Relids relids)
 
AppendRelInfofind_childrel_appendrelinfo (PlannerInfo *root, RelOptInfo *rel)
 
Relids find_childrel_parents (PlannerInfo *root, RelOptInfo *rel)
 
ParamPathInfoget_baserel_parampathinfo (PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
 
ParamPathInfoget_joinrel_parampathinfo (PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
 
ParamPathInfoget_appendrel_parampathinfo (RelOptInfo *appendrel, Relids required_outer)
 
ParamPathInfofind_param_path_info (RelOptInfo *rel, Relids required_outer)
 
RelOptInfobuild_child_join_rel (PlannerInfo *root, RelOptInfo *outer_rel, RelOptInfo *inner_rel, RelOptInfo *parent_joinrel, List *restrictlist, SpecialJoinInfo *sjinfo, JoinType jointype)
 

Function Documentation

◆ add_partial_path()

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 762 of file pathnode.c.

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

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

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

◆ add_partial_path_precheck()

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

Definition at line 886 of file pathnode.c.

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

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

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

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

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

◆ add_path_precheck()

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

Definition at line 657 of file pathnode.c.

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

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

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

◆ apply_projection_to_path()

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

Definition at line 2451 of file pathnode.c.

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

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

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

◆ build_child_join_rel()

RelOptInfo* build_child_join_rel ( PlannerInfo root,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
RelOptInfo parent_joinrel,
List restrictlist,
SpecialJoinInfo sjinfo,
JoinType  jointype 
)

Definition at line 682 of file relnode.c.

References add_join_rel(), add_placeholders_to_child_joinrel(), adjust_appendrel_attrs(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_free(), bms_union(), build_joinrel_partition_info(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_appinfos_by_relids(), find_join_rel(), RelOptInfo::has_eclass_joins, RelOptInfo::indexlist, InvalidOid, IS_OTHER_REL, RelOptInfo::joininfo, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, NIL, RelOptInfo::nullable_partexprs, RelOptInfo::pages, RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, pfree(), RelOptInfo::ppilist, RelOptInfo::relid, RelOptInfo::relids, RELOPT_OTHER_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, RelOptInfo::rtekind, RelOptInfo::serverid, set_foreign_rel_properties(), set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by try_partitionwise_join().

686 {
687  RelOptInfo *joinrel = makeNode(RelOptInfo);
688  AppendRelInfo **appinfos;
689  int nappinfos;
690 
691  /* Only joins between "other" relations land here. */
692  Assert(IS_OTHER_REL(outer_rel) && IS_OTHER_REL(inner_rel));
693 
694  joinrel->reloptkind = RELOPT_OTHER_JOINREL;
695  joinrel->relids = bms_union(outer_rel->relids, inner_rel->relids);
696  joinrel->rows = 0;
697  /* cheap startup cost is interesting iff not all tuples to be retrieved */
698  joinrel->consider_startup = (root->tuple_fraction > 0);
699  joinrel->consider_param_startup = false;
700  joinrel->consider_parallel = false;
701  joinrel->reltarget = create_empty_pathtarget();
702  joinrel->pathlist = NIL;
703  joinrel->ppilist = NIL;
704  joinrel->partial_pathlist = NIL;
705  joinrel->cheapest_startup_path = NULL;
706  joinrel->cheapest_total_path = NULL;
707  joinrel->cheapest_unique_path = NULL;
709  joinrel->direct_lateral_relids = NULL;
710  joinrel->lateral_relids = NULL;
711  joinrel->relid = 0; /* indicates not a baserel */
712  joinrel->rtekind = RTE_JOIN;
713  joinrel->min_attr = 0;
714  joinrel->max_attr = 0;
715  joinrel->attr_needed = NULL;
716  joinrel->attr_widths = NULL;
717  joinrel->lateral_vars = NIL;
718  joinrel->lateral_referencers = NULL;
719  joinrel->indexlist = NIL;
720  joinrel->pages = 0;
721  joinrel->tuples = 0;
722  joinrel->allvisfrac = 0;
723  joinrel->subroot = NULL;
724  joinrel->subplan_params = NIL;
725  joinrel->serverid = InvalidOid;
726  joinrel->userid = InvalidOid;
727  joinrel->useridiscurrent = false;
728  joinrel->fdwroutine = NULL;
729  joinrel->fdw_private = NULL;
730  joinrel->baserestrictinfo = NIL;
731  joinrel->baserestrictcost.startup = 0;
732  joinrel->baserestrictcost.per_tuple = 0;
733  joinrel->joininfo = NIL;
734  joinrel->has_eclass_joins = false;
735  joinrel->top_parent_relids = NULL;
736  joinrel->part_scheme = NULL;
737  joinrel->part_rels = NULL;
738  joinrel->partexprs = NULL;
739  joinrel->nullable_partexprs = NULL;
740 
741  joinrel->top_parent_relids = bms_union(outer_rel->top_parent_relids,
742  inner_rel->top_parent_relids);
743 
744  /* Compute information relevant to foreign relations. */
745  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
746 
747  /* Build targetlist */
748  build_joinrel_tlist(root, joinrel, outer_rel);
749  build_joinrel_tlist(root, joinrel, inner_rel);
750  /* Add placeholder variables. */
751  add_placeholders_to_child_joinrel(root, joinrel, parent_joinrel);
752 
753  /* Construct joininfo list. */
754  appinfos = find_appinfos_by_relids(root, joinrel->relids, &nappinfos);
755  joinrel->joininfo = (List *) adjust_appendrel_attrs(root,
756  (Node *) parent_joinrel->joininfo,
757  nappinfos,
758  appinfos);
759  pfree(appinfos);
760 
761  /*
762  * Lateral relids referred in child join will be same as that referred in
763  * the parent relation. Throw any partial result computed while building
764  * the targetlist.
765  */
767  bms_free(joinrel->lateral_relids);
768  joinrel->direct_lateral_relids = (Relids) bms_copy(parent_joinrel->direct_lateral_relids);
769  joinrel->lateral_relids = (Relids) bms_copy(parent_joinrel->lateral_relids);
770 
771  /*
772  * If the parent joinrel has pending equivalence classes, so does the
773  * child.
774  */
775  joinrel->has_eclass_joins = parent_joinrel->has_eclass_joins;
776 
777  /* Is the join between partitions itself partitioned? */
778  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
779  jointype);
780 
781  /* Child joinrel is parallel safe if parent is parallel safe. */
782  joinrel->consider_parallel = parent_joinrel->consider_parallel;
783 
784 
785  /* Set estimates of the child-joinrel's size. */
786  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
787  sjinfo, restrictlist);
788 
789  /* We build the join only once. */
790  Assert(!find_join_rel(root, joinrel->relids));
791 
792  /* Add the relation to the PlannerInfo. */
793  add_join_rel(root, joinrel);
794 
795  return joinrel;
796 }
bool has_eclass_joins
Definition: relation.h:651
struct Path * cheapest_unique_path
Definition: relation.h:604
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:582
Relids * attr_needed
Definition: relation.h:618
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:342
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4368
struct Path * cheapest_startup_path
Definition: relation.h:602
Oid userid
Definition: relation.h:633
double tuples
Definition: relation.h:625
List * baserestrictinfo
Definition: relation.h:645
bool consider_param_startup
Definition: relation.h:592
Definition: nodes.h:513
List * partial_pathlist
Definition: relation.h:601
#define IS_OTHER_REL(rel)
Definition: relation.h:574
List * cheapest_parameterized_paths
Definition: relation.h:605
bool useridiscurrent
Definition: relation.h:634
List ** nullable_partexprs
Definition: relation.h:663
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:626
PlannerInfo * subroot
Definition: relation.h:627
bool consider_startup
Definition: relation.h:591
Relids lateral_relids
Definition: relation.h:610
Cost per_tuple
Definition: relation.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:405
double tuple_fraction
Definition: relation.h:294
void pfree(void *pointer)
Definition: mcxt.c:936
List ** partexprs
Definition: relation.h:662
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:850
struct Path * cheapest_total_path
Definition: relation.h:603
List * joininfo
Definition: relation.h:649
struct FdwRoutine * fdwroutine
Definition: relation.h:636
Relids relids
Definition: relation.h:585
List * ppilist
Definition: relation.h:600
Index relid
Definition: relation.h:613
Bitmapset * Relids
Definition: relation.h:28
Relids lateral_referencers
Definition: relation.h:621
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: prepunion.c:1958
Oid serverid
Definition: relation.h:632
Relids direct_lateral_relids
Definition: relation.h:609
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: prepunion.c:2529
RTEKind rtekind
Definition: relation.h:615
List * indexlist
Definition: relation.h:622
double rows
Definition: relation.h:588
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:637
void bms_free(Bitmapset *a)
Definition: bitmapset.c:245
#define makeNode(_type_)
Definition: nodes.h:561
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:688
List * lateral_vars
Definition: relation.h:620
void add_placeholders_to_child_joinrel(PlannerInfo *root, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: placeholder.c:474
struct RelOptInfo ** part_rels
Definition: relation.h:660
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:262
bool consider_parallel
Definition: relation.h:593
AttrNumber max_attr
Definition: relation.h:617
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1596
PartitionScheme part_scheme
Definition: relation.h:657
List * pathlist
Definition: relation.h:599
int32 * attr_widths
Definition: relation.h:619
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
QualCost baserestrictcost
Definition: relation.h:646
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:443
List * subplan_params
Definition: relation.h:628
Relids top_parent_relids
Definition: relation.h:654
AttrNumber min_attr
Definition: relation.h:616

◆ build_empty_join_rel()

RelOptInfo* build_empty_join_rel ( PlannerInfo root)

Definition at line 1103 of file relnode.c.

References Assert, create_empty_pathtarget(), PlannerInfo::join_rel_list, lappend(), makeNode, NIL, RelOptInfo::relids, RELOPT_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, and RelOptInfo::rtekind.

Referenced by query_planner().

1104 {
1105  RelOptInfo *joinrel;
1106 
1107  /* The dummy join relation should be the only one ... */
1108  Assert(root->join_rel_list == NIL);
1109 
1110  joinrel = makeNode(RelOptInfo);
1111  joinrel->reloptkind = RELOPT_JOINREL;
1112  joinrel->relids = NULL; /* empty set */
1113  joinrel->rows = 1; /* we produce one row for such cases */
1114  joinrel->rtekind = RTE_JOIN;
1115  joinrel->reltarget = create_empty_pathtarget();
1116 
1117  root->join_rel_list = lappend(root->join_rel_list, joinrel);
1118 
1119  return joinrel;
1120 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:582
List * join_rel_list
Definition: relation.h:215
Relids relids
Definition: relation.h:585
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:615
double rows
Definition: relation.h:588
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
struct PathTarget * reltarget
Definition: relation.h:596

◆ build_join_rel()

RelOptInfo* build_join_rel ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
SpecialJoinInfo sjinfo,
List **  restrictlist_ptr 
)

Definition at line 480 of file relnode.c.

References add_join_rel(), add_placeholders_to_joinrel(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_del_members(), bms_is_empty(), bms_num_members(), bms_union(), RelOptInfo::boundinfo, build_joinrel_joinlist(), build_joinrel_partition_info(), build_joinrel_restrictlist(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, PathTarget::exprs, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_join_rel(), RelOptInfo::has_eclass_joins, has_relevant_eclass_joinclause(), RelOptInfo::indexlist, InvalidOid, IS_OTHER_REL, is_parallel_safe(), PlannerInfo::join_cur_level, PlannerInfo::join_rel_level, RelOptInfo::joininfo, SpecialJoinInfo::jointype, lappend(), RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, min_join_parameterization(), NIL, RelOptInfo::non_unique_for_rels, RelOptInfo::nparts, RelOptInfo::nullable_partexprs, RelOptInfo::pages, RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RelOptInfo::relids, RELOPT_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, RelOptInfo::rtekind, RelOptInfo::serverid, set_foreign_rel_properties(), set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by make_join_rel().

486 {
487  RelOptInfo *joinrel;
488  List *restrictlist;
489 
490  /* This function should be used only for join between parents. */
491  Assert(!IS_OTHER_REL(outer_rel) && !IS_OTHER_REL(inner_rel));
492 
493  /*
494  * See if we already have a joinrel for this set of base rels.
495  */
496  joinrel = find_join_rel(root, joinrelids);
497 
498  if (joinrel)
499  {
500  /*
501  * Yes, so we only need to figure the restrictlist for this particular
502  * pair of component relations.
503  */
504  if (restrictlist_ptr)
505  *restrictlist_ptr = build_joinrel_restrictlist(root,
506  joinrel,
507  outer_rel,
508  inner_rel);
509  return joinrel;
510  }
511 
512  /*
513  * Nope, so make one.
514  */
515  joinrel = makeNode(RelOptInfo);
516  joinrel->reloptkind = RELOPT_JOINREL;
517  joinrel->relids = bms_copy(joinrelids);
518  joinrel->rows = 0;
519  /* cheap startup cost is interesting iff not all tuples to be retrieved */
520  joinrel->consider_startup = (root->tuple_fraction > 0);
521  joinrel->consider_param_startup = false;
522  joinrel->consider_parallel = false;
523  joinrel->reltarget = create_empty_pathtarget();
524  joinrel->pathlist = NIL;
525  joinrel->ppilist = NIL;
526  joinrel->partial_pathlist = NIL;
527  joinrel->cheapest_startup_path = NULL;
528  joinrel->cheapest_total_path = NULL;
529  joinrel->cheapest_unique_path = NULL;
531  /* init direct_lateral_relids from children; we'll finish it up below */
532  joinrel->direct_lateral_relids =
533  bms_union(outer_rel->direct_lateral_relids,
534  inner_rel->direct_lateral_relids);
535  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
536  outer_rel, inner_rel);
537  joinrel->relid = 0; /* indicates not a baserel */
538  joinrel->rtekind = RTE_JOIN;
539  joinrel->min_attr = 0;
540  joinrel->max_attr = 0;
541  joinrel->attr_needed = NULL;
542  joinrel->attr_widths = NULL;
543  joinrel->lateral_vars = NIL;
544  joinrel->lateral_referencers = NULL;
545  joinrel->indexlist = NIL;
546  joinrel->statlist = NIL;
547  joinrel->pages = 0;
548  joinrel->tuples = 0;
549  joinrel->allvisfrac = 0;
550  joinrel->subroot = NULL;
551  joinrel->subplan_params = NIL;
552  joinrel->rel_parallel_workers = -1;
553  joinrel->serverid = InvalidOid;
554  joinrel->userid = InvalidOid;
555  joinrel->useridiscurrent = false;
556  joinrel->fdwroutine = NULL;
557  joinrel->fdw_private = NULL;
558  joinrel->unique_for_rels = NIL;
559  joinrel->non_unique_for_rels = NIL;
560  joinrel->baserestrictinfo = NIL;
561  joinrel->baserestrictcost.startup = 0;
562  joinrel->baserestrictcost.per_tuple = 0;
563  joinrel->baserestrict_min_security = UINT_MAX;
564  joinrel->joininfo = NIL;
565  joinrel->has_eclass_joins = false;
566  joinrel->top_parent_relids = NULL;
567  joinrel->part_scheme = NULL;
568  joinrel->nparts = 0;
569  joinrel->boundinfo = NULL;
570  joinrel->part_rels = NULL;
571  joinrel->partexprs = NULL;
572  joinrel->nullable_partexprs = NULL;
573 
574  /* Compute information relevant to the foreign relations. */
575  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
576 
577  /*
578  * Create a new tlist containing just the vars that need to be output from
579  * this join (ie, are needed for higher joinclauses or final output).
580  *
581  * NOTE: the tlist order for a join rel will depend on which pair of outer
582  * and inner rels we first try to build it from. But the contents should
583  * be the same regardless.
584  */
585  build_joinrel_tlist(root, joinrel, outer_rel);
586  build_joinrel_tlist(root, joinrel, inner_rel);
587  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
588 
589  /*
590  * add_placeholders_to_joinrel also took care of adding the ph_lateral
591  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
592  * now we can finish computing that. This is much like the computation of
593  * the transitively-closed lateral_relids in min_join_parameterization,
594  * except that here we *do* have to consider the added PHVs.
595  */
596  joinrel->direct_lateral_relids =
597  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
598  if (bms_is_empty(joinrel->direct_lateral_relids))
599  joinrel->direct_lateral_relids = NULL;
600 
601  /*
602  * Construct restrict and join clause lists for the new joinrel. (The
603  * caller might or might not need the restrictlist, but I need it anyway
604  * for set_joinrel_size_estimates().)
605  */
606  restrictlist = build_joinrel_restrictlist(root, joinrel,
607  outer_rel, inner_rel);
608  if (restrictlist_ptr)
609  *restrictlist_ptr = restrictlist;
610  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
611 
612  /*
613  * This is also the right place to check whether the joinrel has any
614  * pending EquivalenceClass joins.
615  */
616  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
617 
618  /* Store the partition information. */
619  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
620  sjinfo->jointype);
621 
622  /*
623  * Set estimates of the joinrel's size.
624  */
625  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
626  sjinfo, restrictlist);
627 
628  /*
629  * Set the consider_parallel flag if this joinrel could potentially be
630  * scanned within a parallel worker. If this flag is false for either
631  * inner_rel or outer_rel, then it must be false for the joinrel also.
632  * Even if both are true, there might be parallel-restricted expressions
633  * in the targetlist or quals.
634  *
635  * Note that if there are more than two rels in this relation, they could
636  * be divided between inner_rel and outer_rel in any arbitrary way. We
637  * assume this doesn't matter, because we should hit all the same baserels
638  * and joinclauses while building up to this joinrel no matter which we
639  * take; therefore, we should make the same decision here however we get
640  * here.
641  */
642  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
643  is_parallel_safe(root, (Node *) restrictlist) &&
644  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
645  joinrel->consider_parallel = true;
646 
647  /* Add the joinrel to the PlannerInfo. */
648  add_join_rel(root, joinrel);
649 
650  /*
651  * Also, if dynamic-programming join search is active, add the new joinrel
652  * to the appropriate sublist. Note: you might think the Assert on number
653  * of members should be for equality, but some of the level 1 rels might
654  * have been joinrels already, so we can only assert <=.
655  */
656  if (root->join_rel_level)
657  {
658  Assert(root->join_cur_level > 0);
659  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
660  root->join_rel_level[root->join_cur_level] =
661  lappend(root->join_rel_level[root->join_cur_level], joinrel);
662  }
663 
664  return joinrel;
665 }
bool has_eclass_joins
Definition: relation.h:651
struct Path * cheapest_unique_path
Definition: relation.h:604
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:226
List * unique_for_rels
Definition: relation.h:640
List * statlist
Definition: relation.h:623
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:582
Relids * attr_needed
Definition: relation.h:618
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:342
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4368
struct Path * cheapest_startup_path
Definition: relation.h:602
Oid userid
Definition: relation.h:633
double tuples
Definition: relation.h:625
List * baserestrictinfo
Definition: relation.h:645
bool consider_param_startup
Definition: relation.h:592
Definition: nodes.h:513
List * partial_pathlist
Definition: relation.h:601
#define IS_OTHER_REL(rel)
Definition: relation.h:574
List * cheapest_parameterized_paths
Definition: relation.h:605
Index baserestrict_min_security
Definition: relation.h:647
bool useridiscurrent
Definition: relation.h:634
List ** nullable_partexprs
Definition: relation.h:663
void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: placeholder.c:412
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:626
PlannerInfo * subroot
Definition: relation.h:627
bool consider_startup
Definition: relation.h:591
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1090
Relids lateral_relids
Definition: relation.h:610
Cost per_tuple
Definition: relation.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:405
double tuple_fraction
Definition: relation.h:294
List ** partexprs
Definition: relation.h:662
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:850
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:807
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:649
struct Path * cheapest_total_path
Definition: relation.h:603
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:973
List * joininfo
Definition: relation.h:649
struct FdwRoutine * fdwroutine
Definition: relation.h:636
int nparts
Definition: relation.h:658
Relids relids
Definition: relation.h:585
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2397
List * non_unique_for_rels
Definition: relation.h:642
List * ppilist
Definition: relation.h:600
Index relid
Definition: relation.h:613
List * lappend(List *list, void *datum)
Definition: list.c:128
Relids lateral_referencers
Definition: relation.h:621
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
Oid serverid
Definition: relation.h:632
List * exprs
Definition: relation.h:976
Relids direct_lateral_relids
Definition: relation.h:609
int rel_parallel_workers
Definition: relation.h:629
struct PartitionBoundInfoData * boundinfo
Definition: relation.h:659
RTEKind rtekind
Definition: relation.h:615
List * indexlist
Definition: relation.h:622
double rows
Definition: relation.h:588
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:637
#define makeNode(_type_)
Definition: nodes.h:561
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:688
List ** join_rel_level
Definition: relation.h:225
List * lateral_vars
Definition: relation.h:620
JoinType jointype
Definition: relation.h:2023
struct RelOptInfo ** part_rels
Definition: relation.h:660
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:262
bool consider_parallel
Definition: relation.h:593
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:933
AttrNumber max_attr
Definition: relation.h:617
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1596
PartitionScheme part_scheme
Definition: relation.h:657
List * pathlist
Definition: relation.h:599
int32 * attr_widths
Definition: relation.h:619
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596
QualCost baserestrictcost
Definition: relation.h:646
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:443
List * subplan_params
Definition: relation.h:628
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:1003
Relids top_parent_relids
Definition: relation.h:654
AttrNumber min_attr
Definition: relation.h:616

◆ build_simple_rel()

RelOptInfo* build_simple_rel ( PlannerInfo root,
int  relid,
RelOptInfo parent 
)

Definition at line 96 of file relnode.c.

References RelOptInfo::allvisfrac, PlannerInfo::append_rel_list, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_make_singleton(), RelOptInfo::boundinfo, build_simple_rel(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RangeTblEntry::checkAsUser, AppendRelInfo::child_relid, Alias::colnames, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, elog, RangeTblEntry::eref, ERROR, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, get_relation_info(), RelOptInfo::has_eclass_joins, RelOptInfo::indexlist, RangeTblEntry::inh, InvalidOid, RelOptInfo::joininfo, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, lfirst, list_length(), makeNode, Max, RelOptInfo::max_attr, RelOptInfo::min_attr, NIL, RelOptInfo::non_unique_for_rels, RelOptInfo::nparts, RelOptInfo::nullable_partexprs, RelOptInfo::pages, palloc(), palloc0(), AppendRelInfo::parent_relid, RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, PlannerInfo::qual_security_level, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RangeTblEntry::relid, RelOptInfo::relids, RELOPT_BASEREL, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, RelOptInfo::serverid, PlannerInfo::simple_rel_array, PlannerInfo::simple_rte_array, QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by add_base_rels_to_query(), build_simple_rel(), plan_cluster_use_sort(), plan_create_index_workers(), and recurse_set_operations().

97 {
98  RelOptInfo *rel;
99  RangeTblEntry *rte;
100 
101  /* Rel should not exist already */
102  Assert(relid > 0 && relid < root->simple_rel_array_size);
103  if (root->simple_rel_array[relid] != NULL)
104  elog(ERROR, "rel %d already exists", relid);
105 
106  /* Fetch RTE for relation */
107  rte = root->simple_rte_array[relid];
108  Assert(rte != NULL);
109 
110  rel = makeNode(RelOptInfo);
112  rel->relids = bms_make_singleton(relid);
113  rel->rows = 0;
114  /* cheap startup cost is interesting iff not all tuples to be retrieved */
115  rel->consider_startup = (root->tuple_fraction > 0);
116  rel->consider_param_startup = false; /* might get changed later */
117  rel->consider_parallel = false; /* might get changed later */
119  rel->pathlist = NIL;
120  rel->ppilist = NIL;
121  rel->partial_pathlist = NIL;
122  rel->cheapest_startup_path = NULL;
123  rel->cheapest_total_path = NULL;
124  rel->cheapest_unique_path = NULL;
126  rel->direct_lateral_relids = NULL;
127  rel->lateral_relids = NULL;
128  rel->relid = relid;
129  rel->rtekind = rte->rtekind;
130  /* min_attr, max_attr, attr_needed, attr_widths are set below */
131  rel->lateral_vars = NIL;
132  rel->lateral_referencers = NULL;
133  rel->indexlist = NIL;
134  rel->statlist = NIL;
135  rel->pages = 0;
136  rel->tuples = 0;
137  rel->allvisfrac = 0;
138  rel->subroot = NULL;
139  rel->subplan_params = NIL;
140  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
141  rel->serverid = InvalidOid;
142  rel->userid = rte->checkAsUser;
143  rel->useridiscurrent = false;
144  rel->fdwroutine = NULL;
145  rel->fdw_private = NULL;
146  rel->unique_for_rels = NIL;
147  rel->non_unique_for_rels = NIL;
148  rel->baserestrictinfo = NIL;
149  rel->baserestrictcost.startup = 0;
150  rel->baserestrictcost.per_tuple = 0;
151  rel->baserestrict_min_security = UINT_MAX;
152  rel->joininfo = NIL;
153  rel->has_eclass_joins = false;
154  rel->part_scheme = NULL;
155  rel->nparts = 0;
156  rel->boundinfo = NULL;
157  rel->part_rels = NULL;
158  rel->partexprs = NULL;
159  rel->nullable_partexprs = NULL;
160 
161  /*
162  * Pass top parent's relids down the inheritance hierarchy. If the parent
163  * has top_parent_relids set, it's a direct or an indirect child of the
164  * top parent indicated by top_parent_relids. By extension this child is
165  * also an indirect child of that parent.
166  */
167  if (parent)
168  {
169  if (parent->top_parent_relids)
170  rel->top_parent_relids = parent->top_parent_relids;
171  else
172  rel->top_parent_relids = bms_copy(parent->relids);
173  }
174  else
175  rel->top_parent_relids = NULL;
176 
177  /* Check type of rtable entry */
178  switch (rte->rtekind)
179  {
180  case RTE_RELATION:
181  /* Table --- retrieve statistics from the system catalogs */
182  get_relation_info(root, rte->relid, rte->inh, rel);
183  break;
184  case RTE_SUBQUERY:
185  case RTE_FUNCTION:
186  case RTE_TABLEFUNC:
187  case RTE_VALUES:
188  case RTE_CTE:
189  case RTE_NAMEDTUPLESTORE:
190 
191  /*
192  * Subquery, function, tablefunc, values list, CTE, or ENR --- set
193  * up attr range and arrays
194  *
195  * Note: 0 is included in range to support whole-row Vars
196  */
197  rel->min_attr = 0;
198  rel->max_attr = list_length(rte->eref->colnames);
199  rel->attr_needed = (Relids *)
200  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
201  rel->attr_widths = (int32 *)
202  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
203  break;
204  default:
205  elog(ERROR, "unrecognized RTE kind: %d",
206  (int) rte->rtekind);
207  break;
208  }
209 
210  /* Save the finished struct in the query's simple_rel_array */
211  root->simple_rel_array[relid] = rel;
212 
213  /*
214  * This is a convenient spot at which to note whether rels participating
215  * in the query have any securityQuals attached. If so, increase
216  * root->qual_security_level to ensure it's larger than the maximum
217  * security level needed for securityQuals.
218  */
219  if (rte->securityQuals)
221  list_length(rte->securityQuals));
222 
223  /*
224  * If this rel is an appendrel parent, recurse to build "other rel"
225  * RelOptInfos for its children. They are "other rels" because they are
226  * not in the main join tree, but we will need RelOptInfos to plan access
227  * to them.
228  */
229  if (rte->inh)
230  {
231  ListCell *l;
232  int nparts = rel->nparts;
233  int cnt_parts = 0;
234 
235  if (nparts > 0)
236  rel->part_rels = (RelOptInfo **)
237  palloc(sizeof(RelOptInfo *) * nparts);
238 
239  foreach(l, root->append_rel_list)
240  {
241  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
242  RelOptInfo *childrel;
243 
244  /* append_rel_list contains all append rels; ignore others */
245  if (appinfo->parent_relid != relid)
246  continue;
247 
248  childrel = build_simple_rel(root, appinfo->child_relid,
249  rel);
250 
251  /* Nothing more to do for an unpartitioned table. */
252  if (!rel->part_scheme)
253  continue;
254 
255  /*
256  * The order of partition OIDs in append_rel_list is the same as
257  * the order in the PartitionDesc, so the order of part_rels will
258  * also match the PartitionDesc. See expand_partitioned_rtentry.
259  */
260  Assert(cnt_parts < nparts);
261  rel->part_rels[cnt_parts] = childrel;
262  cnt_parts++;
263  }
264 
265  /* We should have seen all the child partitions. */
266  Assert(cnt_parts == nparts);
267  }
268 
269  return rel;
270 }
bool has_eclass_joins
Definition: relation.h:651
struct Path * cheapest_unique_path
Definition: relation.h:604
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
List * unique_for_rels
Definition: relation.h:640
List * statlist
Definition: relation.h:623
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:582
Relids * attr_needed
Definition: relation.h:618
List * colnames
Definition: primnodes.h:43
struct Path * cheapest_startup_path
Definition: relation.h:602
Oid userid
Definition: relation.h:633
List * securityQuals
Definition: parsenodes.h:1072
double tuples
Definition: relation.h:625
List * baserestrictinfo
Definition: relation.h:645
bool consider_param_startup
Definition: relation.h:592
List * partial_pathlist
Definition: relation.h:601
List * cheapest_parameterized_paths
Definition: relation.h:605
Index baserestrict_min_security
Definition: relation.h:647
bool useridiscurrent
Definition: relation.h:634
List ** nullable_partexprs
Definition: relation.h:663
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:626
signed int int32
Definition: c.h:302
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
PlannerInfo * subroot
Definition: relation.h:627
bool consider_startup
Definition: relation.h:591
Relids lateral_relids
Definition: relation.h:610
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:294
List ** partexprs
Definition: relation.h:662
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:603
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:223
List * joininfo
Definition: relation.h:649
struct FdwRoutine * fdwroutine
Definition: relation.h:636
int nparts
Definition: relation.h:658
Relids relids
Definition: relation.h:585
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
Definition: relnode.c:96
List * non_unique_for_rels
Definition: relation.h:642
List * ppilist
Definition: relation.h:600
Index relid
Definition: relation.h:613
Bitmapset * Relids
Definition: relation.h:28
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
Relids lateral_referencers
Definition: relation.h:621
Oid serverid
Definition: relation.h:632
Relids direct_lateral_relids
Definition: relation.h:609
void * palloc0(Size size)
Definition: mcxt.c:864
int rel_parallel_workers
Definition: relation.h:629
List * append_rel_list
Definition: relation.h:252
struct PartitionBoundInfoData * boundinfo
Definition: relation.h:659
RTEKind rtekind
Definition: relation.h:615
List * indexlist
Definition: relation.h:622
double rows
Definition: relation.h:588
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:637
#define Max(x, y)
Definition: c.h:840
#define makeNode(_type_)
Definition: nodes.h:561
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:688
#define lfirst(lc)
Definition: pg_list.h:106
List * lateral_vars
Definition: relation.h:620
struct RelOptInfo ** part_rels
Definition: relation.h:660
static int list_length(const List *l)
Definition: pg_list.h:89
Index qual_security_level
Definition: relation.h:297
bool consider_parallel
Definition: relation.h:593
RTEKind rtekind
Definition: parsenodes.h:959
AttrNumber max_attr
Definition: relation.h:617
void * palloc(Size size)
Definition: mcxt.c:835
PartitionScheme part_scheme
Definition: relation.h:657
List * pathlist
Definition: relation.h:599
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:2078
Alias * eref
Definition: parsenodes.h:1063
Index parent_relid
Definition: relation.h:2077
int32 * attr_widths
Definition: relation.h:619
struct PathTarget * reltarget
Definition: relation.h:596
QualCost baserestrictcost
Definition: relation.h:646
List * subplan_params
Definition: relation.h:628
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:106
Relids top_parent_relids
Definition: relation.h:654
AttrNumber min_attr
Definition: relation.h:616

◆ calc_nestloop_required_outer()

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

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

2078 {
2079  Relids required_outer;
2080 
2081  /* inner_path can require rels from outer path, but not vice versa */
2082  Assert(!bms_overlap(outer_paramrels, innerrelids));
2083  /* easy case if inner path is not parameterized */
2084  if (!inner_paramrels)
2085  return bms_copy(outer_paramrels);
2086  /* else, form the union ... */
2087  required_outer = bms_union(outer_paramrels, inner_paramrels);
2088  /* ... and remove any mention of now-satisfied outer rels */
2089  required_outer = bms_del_members(required_outer,
2090  outerrelids);
2091  /* maintain invariant that required_outer is exactly NULL if empty */
2092  if (bms_is_empty(required_outer))
2093  {
2094  bms_free(required_outer);
2095  required_outer = NULL;
2096  }
2097  return required_outer;
2098 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:707
void bms_free(Bitmapset *a)
Definition: bitmapset.c:245
#define Assert(condition)
Definition: c.h:688
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:262
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:933
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2108 {
2109  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2110  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2111  Relids required_outer;
2112 
2113  /* neither path can require rels from the other */
2114  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2115  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2116  /* form the union ... */
2117  required_outer = bms_union(outer_paramrels, inner_paramrels);
2118  /* we do not need an explicit test for empty; bms_union gets it right */
2119  return required_outer;
2120 }
RelOptInfo * parent
Definition: relation.h:1046
Relids relids
Definition: relation.h:585
#define Assert(condition)
Definition: c.h:688
#define PATH_REQ_OUTER(path)
Definition: relation.h:1065
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:262
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487

◆ compare_fractional_path_costs()

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

Definition at line 117 of file pathnode.c.

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

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

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

◆ compare_path_costs()

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

Definition at line 71 of file pathnode.c.

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

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

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

◆ create_agg_path()

AggPath* create_agg_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
AggStrategy  aggstrategy,
AggSplit  aggsplit,
List groupClause,
List qual,
const AggClauseCosts aggcosts,
double  numGroups 
)

Definition at line 2762 of file pathnode.c.

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

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

2772 {
2773  AggPath *pathnode = makeNode(AggPath);
2774 
2775  pathnode->path.pathtype = T_Agg;
2776  pathnode->path.parent = rel;
2777  pathnode->path.pathtarget = target;
2778  /* For now, assume we are above any joins, so no parameterization */
2779  pathnode->path.param_info = NULL;
2780  pathnode->path.parallel_aware = false;
2781  pathnode->path.parallel_safe = rel->consider_parallel &&
2782  subpath->parallel_safe;
2783  pathnode->path.parallel_workers = subpath->parallel_workers;
2784  if (aggstrategy == AGG_SORTED)
2785  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2786  else
2787  pathnode->path.pathkeys = NIL; /* output is unordered */
2788  pathnode->subpath = subpath;
2789 
2790  pathnode->aggstrategy = aggstrategy;
2791  pathnode->aggsplit = aggsplit;
2792  pathnode->numGroups = numGroups;
2793  pathnode->groupClause = groupClause;
2794  pathnode->qual = qual;
2795 
2796  cost_agg(&pathnode->path, root,
2797  aggstrategy, aggcosts,
2798  list_length(groupClause), numGroups,
2799  qual,
2800  subpath->startup_cost, subpath->total_cost,
2801  subpath->rows);
2802 
2803  /* add tlist eval cost for each output row */
2804  pathnode->path.startup_cost += target->cost.startup;
2805  pathnode->path.total_cost += target->cost.startup +
2806  target->cost.per_tuple * pathnode->path.rows;
2807 
2808  return pathnode;
2809 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1047
AggStrategy aggstrategy
Definition: relation.h:1560
List * qual
Definition: relation.h:1564
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2057
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
AggSplit aggsplit
Definition: relation.h:1561
double numGroups
Definition: relation.h:1562
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1044
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1057
RelOptInfo * parent
Definition: relation.h:1046
List * groupClause
Definition: relation.h:1563
Cost total_cost
Definition: relation.h:1058
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
double rows
Definition: relation.h:1056
bool parallel_safe
Definition: relation.h:1052
QualCost cost
Definition: relation.h:978
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Path * subpath
Definition: relation.h:1559
bool parallel_aware
Definition: relation.h:1051
Path path
Definition: relation.h:1558
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_append_path()

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

Definition at line 1213 of file pathnode.c.

References append_startup_cost_compare(), append_total_cost_compare(), Assert, bms_equal(), RelOptInfo::consider_parallel, cost_append(), AppendPath::first_partial_path, get_appendrel_parampathinfo(), lfirst, list_concat(), list_copy(), list_length(), list_qsort(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AppendPath::partitioned_rels, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, subpath(), AppendPath::subpaths, and T_Append.

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

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

◆ create_bitmap_and_path()

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

Definition at line 1110 of file pathnode.c.

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

Referenced by choose_bitmap_and().

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

◆ create_bitmap_heap_path()

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

Definition at line 1077 of file pathnode.c.

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

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

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

◆ create_bitmap_or_path()

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

Definition at line 1146 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

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

◆ create_ctescan_path()

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

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

1954 {
1955  Path *pathnode = makeNode(Path);
1956 
1957  pathnode->pathtype = T_CteScan;
1958  pathnode->parent = rel;
1959  pathnode->pathtarget = rel->reltarget;
1960  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1961  required_outer);
1962  pathnode->parallel_aware = false;
1963  pathnode->parallel_safe = rel->consider_parallel;
1964  pathnode->parallel_workers = 0;
1965  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1966 
1967  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1968 
1969  return pathnode;
1970 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1497
NodeTag pathtype
Definition: relation.h:1044
RelOptInfo * parent
Definition: relation.h:1046
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_foreignscan_path()

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

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

2045 {
2046  ForeignPath *pathnode = makeNode(ForeignPath);
2047 
2048  pathnode->path.pathtype = T_ForeignScan;
2049  pathnode->path.parent = rel;
2050  pathnode->path.pathtarget = target ? target : rel->reltarget;
2051  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2052  required_outer);
2053  pathnode->path.parallel_aware = false;
2054  pathnode->path.parallel_safe = rel->consider_parallel;
2055  pathnode->path.parallel_workers = 0;
2056  pathnode->path.rows = rows;
2057  pathnode->path.startup_cost = startup_cost;
2058  pathnode->path.total_cost = total_cost;
2059  pathnode->path.pathkeys = pathkeys;
2060 
2061  pathnode->fdw_outerpath = fdw_outerpath;
2062  pathnode->fdw_private = fdw_private;
2063 
2064  return pathnode;
2065 }
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
Path * fdw_outerpath
Definition: relation.h:1223
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
Cost startup_cost
Definition: relation.h:1057
RelOptInfo * parent
Definition: relation.h:1046
Cost total_cost
Definition: relation.h:1058
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
double rows
Definition: relation.h:1056
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
List * fdw_private
Definition: relation.h:1224
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_functionscan_path()

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

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

1877 {
1878  Path *pathnode = makeNode(Path);
1879 
1880  pathnode->pathtype = T_FunctionScan;
1881  pathnode->parent = rel;
1882  pathnode->pathtarget = rel->reltarget;
1883  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1884  required_outer);
1885  pathnode->parallel_aware = false;
1886  pathnode->parallel_safe = rel->consider_parallel;
1887  pathnode->parallel_workers = 0;
1888  pathnode->pathkeys = pathkeys;
1889 
1890  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1891 
1892  return pathnode;
1893 }
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
RelOptInfo * parent
Definition: relation.h:1046
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1330
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_gather_merge_path()

GatherMergePath* create_gather_merge_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List pathkeys,
Relids  required_outer,
double *  rows 
)

Definition at line 1717 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 add_paths_to_grouping_rel(), create_ordered_paths(), and generate_gather_paths().

1720 {
1722  Cost input_startup_cost = 0;
1723  Cost input_total_cost = 0;
1724 
1725  Assert(subpath->parallel_safe);
1726  Assert(pathkeys);
1727 
1728  pathnode->path.pathtype = T_GatherMerge;
1729  pathnode->path.parent = rel;
1730  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1731  required_outer);
1732  pathnode->path.parallel_aware = false;
1733 
1734  pathnode->subpath = subpath;
1735  pathnode->num_workers = subpath->parallel_workers;
1736  pathnode->path.pathkeys = pathkeys;
1737  pathnode->path.pathtarget = target ? target : rel->reltarget;
1738  pathnode->path.rows += subpath->rows;
1739 
1740  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1741  {
1742  /* Subpath is adequately ordered, we won't need to sort it */
1743  input_startup_cost += subpath->startup_cost;
1744  input_total_cost += subpath->total_cost;
1745  }
1746  else
1747  {
1748  /* We'll need to insert a Sort node, so include cost for that */
1749  Path sort_path; /* dummy for result of cost_sort */
1750 
1751  cost_sort(&sort_path,
1752  root,
1753  pathkeys,
1754  subpath->total_cost,
1755  subpath->rows,
1756  subpath->pathtarget->width,
1757  0.0,
1758  work_mem,
1759  -1);
1760  input_startup_cost += sort_path.startup_cost;
1761  input_total_cost += sort_path.total_cost;
1762  }
1763 
1764  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1765  input_startup_cost, input_total_cost, rows);
1766 
1767  return pathnode;
1768 }
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
void cost_gather_merge(GatherMergePath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, Cost input_startup_cost, Cost input_total_cost, double *rows)
Definition: costsize.c:399
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
Cost startup_cost
Definition: relation.h:1057
RelOptInfo * parent
Definition: relation.h:1046
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:1658
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:1058
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
double rows
Definition: relation.h:1056
bool parallel_safe
Definition: relation.h:1052
Path * subpath
Definition: relation.h:1376
int width
Definition: relation.h:979
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596
double Cost
Definition: nodes.h:644
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_gather_path()

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

Definition at line 1808 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 add_paths_to_grouping_rel(), and generate_gather_paths().

1810 {
1811  GatherPath *pathnode = makeNode(GatherPath);
1812 
1813  Assert(subpath->parallel_safe);
1814 
1815  pathnode->path.pathtype = T_Gather;
1816  pathnode->path.parent = rel;
1817  pathnode->path.pathtarget = target;
1818  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1819  required_outer);
1820  pathnode->path.parallel_aware = false;
1821  pathnode->path.parallel_safe = false;
1822  pathnode->path.parallel_workers = 0;
1823  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1824 
1825  pathnode->subpath = subpath;
1826  pathnode->num_workers = subpath->parallel_workers;
1827  pathnode->single_copy = false;
1828 
1829  if (pathnode->num_workers == 0)
1830  {
1831  pathnode->path.pathkeys = subpath->pathkeys;
1832  pathnode->num_workers = 1;
1833  pathnode->single_copy = true;
1834  }
1835 
1836  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1837 
1838  return pathnode;
1839 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
bool single_copy
Definition: relation.h:1364
int num_workers
Definition: relation.h:1365
NodeTag pathtype
Definition: relation.h:1044
RelOptInfo * parent
Definition: relation.h:1046
Path * subpath
Definition: relation.h:1363
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
bool parallel_safe
Definition: relation.h:1052
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:361
Definition: nodes.h:80
bool parallel_aware
Definition: relation.h:1051
Path path
Definition: relation.h:1362
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_group_path()

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

Definition at line 2651 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 add_partial_paths_to_grouping_rel(), and add_paths_to_grouping_rel().

2658 {
2659  GroupPath *pathnode = makeNode(GroupPath);
2660 
2661  pathnode->path.pathtype = T_Group;
2662  pathnode->path.parent = rel;
2663  pathnode->path.pathtarget = target;
2664  /* For now, assume we are above any joins, so no parameterization */
2665  pathnode->path.param_info = NULL;
2666  pathnode->path.parallel_aware = false;
2667  pathnode->path.parallel_safe = rel->consider_parallel &&
2668  subpath->parallel_safe;
2669  pathnode->path.parallel_workers = subpath->parallel_workers;
2670  /* Group doesn't change sort ordering */
2671  pathnode->path.pathkeys = subpath->pathkeys;
2672 
2673  pathnode->subpath = subpath;
2674 
2675  pathnode->groupClause = groupClause;
2676  pathnode->qual = qual;
2677 
2678  cost_group(&pathnode->path, root,
2679  list_length(groupClause),
2680  numGroups,
2681  qual,
2682  subpath->startup_cost, subpath->total_cost,
2683  subpath->rows);
2684 
2685  /* add tlist eval cost for each output row */
2686  pathnode->path.startup_cost += target->cost.startup;
2687  pathnode->path.total_cost += target->cost.startup +
2688  target->cost.per_tuple * pathnode->path.rows;
2689 
2690  return pathnode;
2691 }
List * qual
Definition: relation.h:1533
PathTarget * pathtarget
Definition: relation.h:1047
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1044
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1057
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2245
RelOptInfo * parent
Definition: relation.h:1046
Definition: nodes.h:76
Path path
Definition: relation.h:1530
List * groupClause
Definition: relation.h:1532
Path * subpath
Definition: relation.h:1531
Cost total_cost
Definition: relation.h:1058
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
double rows
Definition: relation.h:1056
bool parallel_safe
Definition: relation.h:1052
QualCost cost
Definition: relation.h:978
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:1051
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_groupingsets_path()

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

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

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

◆ create_hashjoin_path()

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

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

2305 {
2306  HashPath *pathnode = makeNode(HashPath);
2307 
2308  pathnode->jpath.path.pathtype = T_HashJoin;
2309  pathnode->jpath.path.parent = joinrel;
2310  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2311  pathnode->jpath.path.param_info =
2313  joinrel,
2314  outer_path,
2315  inner_path,
2316  extra->sjinfo,
2317  required_outer,
2318  &restrict_clauses);
2319  pathnode->jpath.path.parallel_aware =
2320  joinrel->consider_parallel && parallel_hash;
2321  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2322  outer_path->parallel_safe && inner_path->parallel_safe;
2323  /* This is a foolish way to estimate parallel_workers, but for now... */
2324  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2325 
2326  /*
2327  * A hashjoin never has pathkeys, since its output ordering is
2328  * unpredictable due to possible batching. XXX If the inner relation is
2329  * small enough, we could instruct the executor that it must not batch,
2330  * and then we could assume that the output inherits the outer relation's
2331  * ordering, which might save a sort step. However there is considerable
2332  * downside if our estimate of the inner relation size is badly off. For
2333  * the moment we don't risk it. (Note also that if we wanted to take this
2334  * seriously, joinpath.c would have to consider many more paths for the
2335  * outer rel than it does now.)
2336  */
2337  pathnode->jpath.path.pathkeys = NIL;
2338  pathnode->jpath.jointype = jointype;
2339  pathnode->jpath.inner_unique = extra->inner_unique;
2340  pathnode->jpath.outerjoinpath = outer_path;
2341  pathnode->jpath.innerjoinpath = inner_path;
2342  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2343  pathnode->path_hashclauses = hashclauses;
2344  /* final_cost_hashjoin will fill in pathnode->num_batches */
2345 
2346  final_cost_hashjoin(root, pathnode, workspace, extra);
2347 
2348  return pathnode;
2349 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3256
JoinPath jpath
Definition: relation.h:1468
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1340
Path * innerjoinpath
Definition: relation.h:1395
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
SpecialJoinInfo * sjinfo
Definition: relation.h:2287
List * joinrestrictinfo
Definition: relation.h:1397
RelOptInfo * parent
Definition: relation.h:1046
Path * outerjoinpath
Definition: relation.h:1394
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
Path path
Definition: relation.h:1387
bool parallel_safe
Definition: relation.h:1052
bool inner_unique
Definition: relation.h:1391
bool consider_parallel
Definition: relation.h:593
JoinType jointype
Definition: relation.h:1389
bool parallel_aware
Definition: relation.h:1051
List * path_hashclauses
Definition: relation.h:1469
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_index_path()

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

Definition at line 1018 of file pathnode.c.

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

Referenced by build_index_paths(), and plan_cluster_use_sort().

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

◆ create_limit_path()

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

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

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

◆ create_lockrows_path()

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

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

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

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1460 {
1461  MaterialPath *pathnode = makeNode(MaterialPath);
1462 
1463  Assert(subpath->parent == rel);
1464 
1465  pathnode->path.pathtype = T_Material;
1466  pathnode->path.parent = rel;
1467  pathnode->path.pathtarget = rel->reltarget;
1468  pathnode->path.param_info = subpath->param_info;
1469  pathnode->path.parallel_aware = false;
1470  pathnode->path.parallel_safe = rel->consider_parallel &&
1471  subpath->parallel_safe;
1472  pathnode->path.parallel_workers = subpath->parallel_workers;
1473  pathnode->path.pathkeys = subpath->pathkeys;
1474 
1475  pathnode->subpath = subpath;
1476 
1477  cost_material(&pathnode->path,
1478  subpath->startup_cost,
1479  subpath->total_cost,
1480  subpath->rows,
1481  subpath->pathtarget->width);
1482 
1483  return pathnode;
1484 }
PathTarget * pathtarget
Definition: relation.h:1047
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
Path * subpath
Definition: relation.h:1324
NodeTag pathtype
Definition: relation.h:1044
Cost startup_cost
Definition: relation.h:1057
RelOptInfo * parent
Definition: relation.h:1046
Cost total_cost
Definition: relation.h:1058
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2003
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
#define Assert(condition)
Definition: c.h:688
double rows
Definition: relation.h:1056
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
int width
Definition: relation.h:979
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_merge_append_path()

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

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

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

◆ create_mergejoin_path()

MergePath* create_mergejoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer,
List mergeclauses,
List outersortkeys,
List innersortkeys 
)

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

2241 {
2242  MergePath *pathnode = makeNode(MergePath);
2243 
2244  pathnode->jpath.path.pathtype = T_MergeJoin;
2245  pathnode->jpath.path.parent = joinrel;
2246  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2247  pathnode->jpath.path.param_info =
2249  joinrel,
2250  outer_path,
2251  inner_path,
2252  extra->sjinfo,
2253  required_outer,
2254  &restrict_clauses);
2255  pathnode->jpath.path.parallel_aware = false;
2256  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2257  outer_path->parallel_safe && inner_path->parallel_safe;
2258  /* This is a foolish way to estimate parallel_workers, but for now... */
2259  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2260  pathnode->jpath.path.pathkeys = pathkeys;
2261  pathnode->jpath.jointype = jointype;
2262  pathnode->jpath.inner_unique = extra->inner_unique;
2263  pathnode->jpath.outerjoinpath = outer_path;
2264  pathnode->jpath.innerjoinpath = inner_path;
2265  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2266  pathnode->path_mergeclauses = mergeclauses;
2267  pathnode->outersortkeys = outersortkeys;
2268  pathnode->innersortkeys = innersortkeys;
2269  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2270  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2271 
2272  final_cost_mergejoin(root, pathnode, workspace, extra);
2273 
2274  return pathnode;
2275 }
List * path_mergeclauses
Definition: relation.h:1450
List * outersortkeys
Definition: relation.h:1451
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1340
Path * innerjoinpath
Definition: relation.h:1395
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
SpecialJoinInfo * sjinfo
Definition: relation.h:2287
List * joinrestrictinfo
Definition: relation.h:1397
RelOptInfo * parent
Definition: relation.h:1046
Path * outerjoinpath
Definition: relation.h:1394
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
Path path
Definition: relation.h:1387
bool parallel_safe
Definition: relation.h:1052
bool inner_unique
Definition: relation.h:1391
bool consider_parallel
Definition: relation.h:593
List * innersortkeys
Definition: relation.h:1452
JoinType jointype
Definition: relation.h:1389
JoinPath jpath
Definition: relation.h:1449
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2827

◆ create_minmaxagg_path()

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

Definition at line 2985 of file pathnode.c.

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

Referenced by preprocess_minmax_aggregates().

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

◆ create_modifytable_path()

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

Definition at line 3289 of file pathnode.c.

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

Referenced by grouping_planner(), and inheritance_planner().

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

◆ create_namedtuplestorescan_path()

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

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

1980 {
1981  Path *pathnode = makeNode(Path);
1982 
1983  pathnode->pathtype = T_NamedTuplestoreScan;
1984  pathnode->parent = rel;
1985  pathnode->pathtarget = rel->reltarget;
1986  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1987  required_outer);
1988  pathnode->parallel_aware = false;
1989  pathnode->parallel_safe = rel->consider_parallel;
1990  pathnode->parallel_workers = 0;
1991  pathnode->pathkeys = NIL; /* result is always unordered */
1992 
1993  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
1994 
1995  return pathnode;
1996 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1538
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
RelOptInfo * parent
Definition: relation.h:1046
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1051
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_nestloop_path()

NestPath* create_nestloop_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer 
)

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

2150 {
2151  NestPath *pathnode = makeNode(NestPath);
2152  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2153 
2154  /*
2155  * If the inner path is parameterized by the outer, we must drop any
2156  * restrict_clauses that are due to be moved into the inner path. We have
2157  * to do this now, rather than postpone the work till createplan time,
2158  * because the restrict_clauses list can affect the size and cost
2159  * estimates for this path.
2160  */
2161  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2162  {
2163  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2164  inner_req_outer);
2165  List *jclauses = NIL;
2166  ListCell *lc;
2167 
2168  foreach(lc, restrict_clauses)
2169  {
2170  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2171 
2172  if (!join_clause_is_movable_into(rinfo,
2173  inner_path->parent->relids,
2174  inner_and_outer))
2175  jclauses = lappend(jclauses, rinfo);
2176  }
2177  restrict_clauses = jclauses;
2178  }
2179 
2180  pathnode->path.pathtype = T_NestLoop;
2181  pathnode->path.parent = joinrel;
2182  pathnode->path.pathtarget = joinrel->reltarget;
2183  pathnode->path.param_info =
2185  joinrel,
2186  outer_path,
2187  inner_path,
2188  extra->sjinfo,
2189  required_outer,
2190  &restrict_clauses);
2191  pathnode->path.parallel_aware = false;
2192  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2193  outer_path->parallel_safe && inner_path->parallel_safe;
2194  /* This is a foolish way to estimate parallel_workers, but for now... */
2195  pathnode->path.parallel_workers = outer_path->parallel_workers;
2196  pathnode->path.pathkeys = pathkeys;
2197  pathnode->jointype = jointype;
2198  pathnode->inner_unique = extra->inner_unique;
2199  pathnode->outerjoinpath = outer_path;
2200  pathnode->innerjoinpath = inner_path;
2201  pathnode->joinrestrictinfo = restrict_clauses;
2202 
2203  final_cost_nestloop(root, pathnode, workspace, extra);
2204 
2205  return pathnode;
2206 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1047
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1340
Path * innerjoinpath
Definition: relation.h:1395
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2390
SpecialJoinInfo * sjinfo
Definition: relation.h:2287
List * joinrestrictinfo
Definition: relation.h:1397
RelOptInfo * parent
Definition: relation.h:1046
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:1394
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
Path path
Definition: relation.h:1387
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1052
#define PATH_REQ_OUTER(path)
Definition: relation.h:1065
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:262
bool inner_unique
Definition: relation.h:1391
bool consider_parallel
Definition: relation.h:593
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:487
JoinType jointype
Definition: relation.h:1389
bool parallel_aware
Definition: relation.h:1051
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_projection_path()

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

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

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

◆ create_recursiveunion_path()

RecursiveUnionPath* create_recursiveunion_path ( PlannerInfo root,
RelOptInfo rel,
Path leftpath,
Path rightpath,
PathTarget target,
List distinctList,
int  wtParam,
double  numGroups 
)

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

3191 {
3193 
3194  pathnode->path.pathtype = T_RecursiveUnion;
3195  pathnode->path.parent = rel;
3196  pathnode->path.pathtarget = target;
3197  /* For now, assume we are above any joins, so no parameterization */
3198  pathnode->path.param_info = NULL;
3199  pathnode->path.parallel_aware = false;
3200  pathnode->path.parallel_safe = rel->consider_parallel &&
3201  leftpath->parallel_safe && rightpath->parallel_safe;
3202  /* Foolish, but we'll do it like joins for now: */
3203  pathnode->path.parallel_workers = leftpath->parallel_workers;
3204  /* RecursiveUnion result is always unsorted */
3205  pathnode->path.pathkeys = NIL;
3206 
3207  pathnode->leftpath = leftpath;
3208  pathnode->rightpath = rightpath;
3209  pathnode->distinctList = distinctList;
3210  pathnode->wtParam = wtParam;
3211  pathnode->numGroups = numGroups;
3212 
3213  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3214 
3215  return pathnode;
3216 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1047
int parallel_workers
Definition: relation.h:1053
ParamPathInfo * param_info
Definition: relation.h:1049
NodeTag pathtype
Definition: relation.h:1044
RelOptInfo * parent
Definition: relation.h:1046
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1578
List * pathkeys
Definition: relation.h:1060
#define makeNode(_type_)
Definition: nodes.h:561
bool parallel_safe
Definition: relation.h:1052
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1051

◆ create_result_path()

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

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

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

◆ create_samplescan_path()

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

Definition at line 973 of file pathnode.c.

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

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

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