PostgreSQL Source Code  git master
pathnode.h File Reference
#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, Relids required_outer, int parallel_workers, List *partitioned_rels)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
 
ResultPathcreate_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *resconstantqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
UniquePathcreate_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
 
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, List *restrict_clauses, Relids required_outer, List *hashclauses)
 
ProjectionPathcreate_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
Pathapply_projection_to_path (PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
 
ProjectSetPathcreate_set_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
SortPathcreate_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
 
GroupPathcreate_group_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *groupClause, List *qual, double numGroups)
 
UpperUniquePathcreate_upper_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
 
AggPathcreate_agg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
 
GroupingSetsPathcreate_groupingsets_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs, double numGroups)
 
MinMaxAggPathcreate_minmaxagg_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *mmaggregates, List *quals)
 
WindowAggPathcreate_windowagg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, WindowClause *winclause, List *winpathkeys)
 
SetOpPathcreate_setop_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SetOpCmd cmd, SetOpStrategy strategy, List *distinctList, AttrNumber flagColIdx, int firstFlag, double numGroups, double outputRows)
 
RecursiveUnionPathcreate_recursiveunion_path (PlannerInfo *root, RelOptInfo *rel, Path *leftpath, Path *rightpath, PathTarget *target, List *distinctList, int wtParam, double numGroups)
 
LockRowsPathcreate_lockrows_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
 
ModifyTablePathcreate_modifytable_path (PlannerInfo *root, RelOptInfo *rel, CmdType operation, bool canSetTag, Index nominalRelation, List *partitioned_rels, List *resultRelations, List *subpaths, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
LimitPathcreate_limit_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, int64 offset_est, int64 count_est)
 
Pathreparameterize_path (PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
 
Pathreparameterize_path_by_child (PlannerInfo *root, Path *path, RelOptInfo *child_rel)
 
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 760 of file pathnode.c.

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

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

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

◆ add_partial_path_precheck()

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

Definition at line 884 of file pathnode.c.

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

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 420 of file pathnode.c.

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

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

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

◆ add_path_precheck()

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

Definition at line 655 of file pathnode.c.

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

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

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

◆ apply_projection_to_path()

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

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

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

◆ 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_partition_wise_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:4165
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:511
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:949
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:1945
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:2516
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:201
#define makeNode(_type_)
Definition: nodes.h:559
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:670
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:218
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:559
#define Assert(condition)
Definition: c.h:670
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:4165
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:511
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:1087
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:605
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:663
Oid serverid
Definition: relation.h:632
List * exprs
Definition: relation.h:972
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:559
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:670
List ** join_rel_level
Definition: relation.h:225
List * lateral_vars
Definition: relation.h:620
JoinType jointype
Definition: relation.h:2011
struct RelOptInfo ** part_rels
Definition: relation.h:660
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool consider_parallel
Definition: relation.h:593
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
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(), 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:1064
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:284
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:179
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:877
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:796
#define makeNode(_type_)
Definition: nodes.h:559
BlockNumber pages
Definition: relation.h:624
#define Assert(condition)
Definition: c.h:670
#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:951
AttrNumber max_attr
Definition: relation.h:617
void * palloc(Size size)
Definition: mcxt.c:848
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:2066
Alias * eref
Definition: parsenodes.h:1055
Index parent_relid
Definition: relation.h:2065
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 2010 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().

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

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2044 {
2045  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2046  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2047  Relids required_outer;
2048 
2049  /* neither path can require rels from the other */
2050  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2051  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2052  /* form the union ... */
2053  required_outer = bms_union(outer_paramrels, inner_paramrels);
2054  /* we do not need an explicit test for empty; bms_union gets it right */
2055  return required_outer;
2056 }
RelOptInfo * parent
Definition: relation.h:1042
Relids relids
Definition: relation.h:585
#define Assert(condition)
Definition: c.h:670
#define PATH_REQ_OUTER(path)
Definition: relation.h:1061
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443

◆ compare_fractional_path_costs()

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

Definition at line 115 of file pathnode.c.

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

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

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

◆ compare_path_costs()

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

Definition at line 69 of file pathnode.c.

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

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

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

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

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

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

2705 {
2706  AggPath *pathnode = makeNode(AggPath);
2707 
2708  pathnode->path.pathtype = T_Agg;
2709  pathnode->path.parent = rel;
2710  pathnode->path.pathtarget = target;
2711  /* For now, assume we are above any joins, so no parameterization */
2712  pathnode->path.param_info = NULL;
2713  pathnode->path.parallel_aware = false;
2714  pathnode->path.parallel_safe = rel->consider_parallel &&
2715  subpath->parallel_safe;
2716  pathnode->path.parallel_workers = subpath->parallel_workers;
2717  if (aggstrategy == AGG_SORTED)
2718  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2719  else
2720  pathnode->path.pathkeys = NIL; /* output is unordered */
2721  pathnode->subpath = subpath;
2722 
2723  pathnode->aggstrategy = aggstrategy;
2724  pathnode->aggsplit = aggsplit;
2725  pathnode->numGroups = numGroups;
2726  pathnode->groupClause = groupClause;
2727  pathnode->qual = qual;
2728 
2729  cost_agg(&pathnode->path, root,
2730  aggstrategy, aggcosts,
2731  list_length(groupClause), numGroups,
2732  qual,
2733  subpath->startup_cost, subpath->total_cost,
2734  subpath->rows);
2735 
2736  /* add tlist eval cost for each output row */
2737  pathnode->path.startup_cost += target->cost.startup;
2738  pathnode->path.total_cost += target->cost.startup +
2739  target->cost.per_tuple * pathnode->path.rows;
2740 
2741  return pathnode;
2742 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:1043
AggStrategy aggstrategy
Definition: relation.h:1549
List * qual
Definition: relation.h:1553
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:1874
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
AggSplit aggsplit
Definition: relation.h:1550
double numGroups
Definition: relation.h:1551
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * groupClause
Definition: relation.h:1552
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
Path * subpath
Definition: relation.h:1548
bool parallel_aware
Definition: relation.h:1047
Path path
Definition: relation.h:1547
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_append_path()

AppendPath* create_append_path ( RelOptInfo rel,
List subpaths,
Relids  required_outer,
int  parallel_workers,
List partitioned_rels 
)

Definition at line 1211 of file pathnode.c.

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

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

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

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

Referenced by choose_bitmap_and().

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

◆ create_bitmap_heap_path()

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

Definition at line 1075 of file pathnode.c.

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

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

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

◆ create_bitmap_or_path()

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

Definition at line 1144 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

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

◆ create_ctescan_path()

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

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

1890 {
1891  Path *pathnode = makeNode(Path);
1892 
1893  pathnode->pathtype = T_CteScan;
1894  pathnode->parent = rel;
1895  pathnode->pathtarget = rel->reltarget;
1896  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1897  required_outer);
1898  pathnode->parallel_aware = false;
1899  pathnode->parallel_safe = rel->consider_parallel;
1900  pathnode->parallel_workers = 0;
1901  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1902 
1903  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1904 
1905  return pathnode;
1906 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1484
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_foreignscan_path()

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

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

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

◆ create_functionscan_path()

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

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

1813 {
1814  Path *pathnode = makeNode(Path);
1815 
1816  pathnode->pathtype = T_FunctionScan;
1817  pathnode->parent = rel;
1818  pathnode->pathtarget = rel->reltarget;
1819  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1820  required_outer);
1821  pathnode->parallel_aware = false;
1822  pathnode->parallel_safe = rel->consider_parallel;
1823  pathnode->parallel_workers = 0;
1824  pathnode->pathkeys = pathkeys;
1825 
1826  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1827 
1828  return pathnode;
1829 }
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1317
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

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

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

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

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

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

Referenced by create_grouping_paths(), and generate_gather_paths().

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

◆ create_group_path()

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

Definition at line 2584 of file pathnode.c.

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

Referenced by create_grouping_paths().

2591 {
2592  GroupPath *pathnode = makeNode(GroupPath);
2593 
2594  pathnode->path.pathtype = T_Group;
2595  pathnode->path.parent = rel;
2596  pathnode->path.pathtarget = target;
2597  /* For now, assume we are above any joins, so no parameterization */
2598  pathnode->path.param_info = NULL;
2599  pathnode->path.parallel_aware = false;
2600  pathnode->path.parallel_safe = rel->consider_parallel &&
2601  subpath->parallel_safe;
2602  pathnode->path.parallel_workers = subpath->parallel_workers;
2603  /* Group doesn't change sort ordering */
2604  pathnode->path.pathkeys = subpath->pathkeys;
2605 
2606  pathnode->subpath = subpath;
2607 
2608  pathnode->groupClause = groupClause;
2609  pathnode->qual = qual;
2610 
2611  cost_group(&pathnode->path, root,
2612  list_length(groupClause),
2613  numGroups,
2614  qual,
2615  subpath->startup_cost, subpath->total_cost,
2616  subpath->rows);
2617 
2618  /* add tlist eval cost for each output row */
2619  pathnode->path.startup_cost += target->cost.startup;
2620  pathnode->path.total_cost += target->cost.startup +
2621  target->cost.per_tuple * pathnode->path.rows;
2622 
2623  return pathnode;
2624 }
List * qual
Definition: relation.h:1522
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:1053
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:2062
RelOptInfo * parent
Definition: relation.h:1042
Definition: nodes.h:76
Path path
Definition: relation.h:1519
List * groupClause
Definition: relation.h:1521
Path * subpath
Definition: relation.h:1520
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_groupingsets_path()

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

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

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

◆ create_hashjoin_path()

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

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

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

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

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

Referenced by build_index_paths(), and plan_cluster_use_sort().

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

◆ create_limit_path()

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

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

3324 {
3325  LimitPath *pathnode = makeNode(LimitPath);
3326 
3327  pathnode->path.pathtype = T_Limit;
3328  pathnode->path.parent = rel;
3329  /* Limit doesn't project, so use source path's pathtarget */
3330  pathnode->path.pathtarget = subpath->pathtarget;
3331  /* For now, assume we are above any joins, so no parameterization */
3332  pathnode->path.param_info = NULL;
3333  pathnode->path.parallel_aware = false;
3334  pathnode->path.parallel_safe = rel->consider_parallel &&
3335  subpath->parallel_safe;
3336  pathnode->path.parallel_workers = subpath->parallel_workers;
3337  pathnode->path.rows = subpath->rows;
3338  pathnode->path.startup_cost = subpath->startup_cost;
3339  pathnode->path.total_cost = subpath->total_cost;
3340  pathnode->path.pathkeys = subpath->pathkeys;
3341  pathnode->subpath = subpath;
3342  pathnode->limitOffset = limitOffset;
3343  pathnode->limitCount = limitCount;
3344 
3345  /*
3346  * Adjust the output rows count and costs according to the offset/limit.
3347  * This is only a cosmetic issue if we are at top level, but if we are
3348  * building a subquery then it's important to report correct info to the
3349  * outer planner.
3350  *
3351  * When the offset or count couldn't be estimated, use 10% of the
3352  * estimated number of rows emitted from the subpath.
3353  *
3354  * XXX we don't bother to add eval costs of the offset/limit expressions
3355  * themselves to the path costs. In theory we should, but in most cases
3356  * those expressions are trivial and it's just not worth the trouble.
3357  */
3358  if (offset_est != 0)
3359  {
3360  double offset_rows;
3361 
3362  if (offset_est > 0)
3363  offset_rows = (double) offset_est;
3364  else
3365  offset_rows = clamp_row_est(subpath->rows * 0.10);
3366  if (offset_rows > pathnode->path.rows)
3367  offset_rows = pathnode->path.rows;
3368  if (subpath->rows > 0)
3369  pathnode->path.startup_cost +=
3370  (subpath->total_cost - subpath->startup_cost)
3371  * offset_rows / subpath->rows;
3372  pathnode->path.rows -= offset_rows;
3373  if (pathnode->path.rows < 1)
3374  pathnode->path.rows = 1;
3375  }
3376 
3377  if (count_est != 0)
3378  {
3379  double count_rows;
3380 
3381  if (count_est > 0)
3382  count_rows = (double) count_est;
3383  else
3384  count_rows = clamp_row_est(subpath->rows * 0.10);
3385  if (count_rows > pathnode->path.rows)
3386  count_rows = pathnode->path.rows;
3387  if (subpath->rows > 0)
3388  pathnode->path.total_cost = pathnode->path.startup_cost +
3389  (subpath->total_cost - subpath->startup_cost)
3390  * count_rows / subpath->rows;
3391  pathnode->path.rows = count_rows;
3392  if (pathnode->path.rows < 1)
3393  pathnode->path.rows = 1;
3394  }
3395 
3396  return pathnode;
3397 }
PathTarget * pathtarget
Definition: relation.h:1043
Node * limitOffset
Definition: relation.h:1687
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
Path * subpath
Definition: relation.h:1686
RelOptInfo * parent
Definition: relation.h:1042
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
Path path
Definition: relation.h:1685
bool parallel_aware
Definition: relation.h:1047
double clamp_row_est(double nrows)
Definition: costsize.c:174
Node * limitCount
Definition: relation.h:1688
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:85

◆ create_lockrows_path()

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

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

3163 {
3164  LockRowsPath *pathnode = makeNode(LockRowsPath);
3165 
3166  pathnode->path.pathtype = T_LockRows;
3167  pathnode->path.parent = rel;
3168  /* LockRows doesn't project, so use source path's pathtarget */
3169  pathnode->path.pathtarget = subpath->pathtarget;
3170  /* For now, assume we are above any joins, so no parameterization */
3171  pathnode->path.param_info = NULL;
3172  pathnode->path.parallel_aware = false;
3173  pathnode->path.parallel_safe = false;
3174  pathnode->path.parallel_workers = 0;
3175  pathnode->path.rows = subpath->rows;
3176 
3177  /*
3178  * The result cannot be assumed sorted, since locking might cause the sort
3179  * key columns to be replaced with new values.
3180  */
3181  pathnode->path.pathkeys = NIL;
3182 
3183  pathnode->subpath = subpath;
3184  pathnode->rowMarks = rowMarks;
3185  pathnode->epqParam = epqParam;
3186 
3187  /*
3188  * We should charge something extra for the costs of row locking and
3189  * possible refetches, but it's hard to say how much. For now, use
3190  * cpu_tuple_cost per row.
3191  */
3192  pathnode->path.startup_cost = subpath->startup_cost;
3193  pathnode->path.total_cost = subpath->total_cost +
3194  cpu_tuple_cost * subpath->rows;
3195 
3196  return pathnode;
3197 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * rowMarks
Definition: relation.h:1651
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
Path * subpath
Definition: relation.h:1650
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

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

◆ create_merge_append_path()

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

Definition at line 1265 of file pathnode.c.

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

Referenced by generate_mergeappend_paths().

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

2177 {
2178  MergePath *pathnode = makeNode(MergePath);
2179 
2180  pathnode->jpath.path.pathtype = T_MergeJoin;
2181  pathnode->jpath.path.parent = joinrel;
2182  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2183  pathnode->jpath.path.param_info =
2185  joinrel,
2186  outer_path,
2187  inner_path,
2188  extra->sjinfo,
2189  required_outer,
2190  &restrict_clauses);
2191  pathnode->jpath.path.parallel_aware = false;
2192  pathnode->jpath.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->jpath.path.parallel_workers = outer_path->parallel_workers;
2196  pathnode->jpath.path.pathkeys = pathkeys;
2197  pathnode->jpath.jointype = jointype;
2198  pathnode->jpath.inner_unique = extra->inner_unique;
2199  pathnode->jpath.outerjoinpath = outer_path;
2200  pathnode->jpath.innerjoinpath = inner_path;
2201  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2202  pathnode->path_mergeclauses = mergeclauses;
2203  pathnode->outersortkeys = outersortkeys;
2204  pathnode->innersortkeys = innersortkeys;
2205  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2206  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2207 
2208  final_cost_mergejoin(root, pathnode, workspace, extra);
2209 
2210  return pathnode;
2211 }
List * path_mergeclauses
Definition: relation.h:1440
List * outersortkeys
Definition: relation.h:1441
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1340
Path * innerjoinpath
Definition: relation.h:1385
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
SpecialJoinInfo * sjinfo
Definition: relation.h:2273
List * joinrestrictinfo
Definition: relation.h:1387
RelOptInfo * parent
Definition: relation.h:1042
Path * outerjoinpath
Definition: relation.h:1384
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
Path path
Definition: relation.h:1377
bool parallel_safe
Definition: relation.h:1048
bool inner_unique
Definition: relation.h:1381
bool consider_parallel
Definition: relation.h:593
List * innersortkeys
Definition: relation.h:1442
JoinType jointype
Definition: relation.h:1379
JoinPath jpath
Definition: relation.h:1439
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2644

◆ create_minmaxagg_path()

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

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

2923 {
2924  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2925  Cost initplan_cost;
2926  ListCell *lc;
2927 
2928  /* The topmost generated Plan node will be a Result */
2929  pathnode->path.pathtype = T_Result;
2930  pathnode->path.parent = rel;
2931  pathnode->path.pathtarget = target;
2932  /* For now, assume we are above any joins, so no parameterization */
2933  pathnode->path.param_info = NULL;
2934  pathnode->path.parallel_aware = false;
2935  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2936  pathnode->path.parallel_safe = false;
2937  pathnode->path.parallel_workers = 0;
2938  /* Result is one unordered row */
2939  pathnode->path.rows = 1;
2940  pathnode->path.pathkeys = NIL;
2941 
2942  pathnode->mmaggregates = mmaggregates;
2943  pathnode->quals = quals;
2944 
2945  /* Calculate cost of all the initplans ... */
2946  initplan_cost = 0;
2947  foreach(lc, mmaggregates)
2948  {
2949  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2950 
2951  initplan_cost += mminfo->pathcost;
2952  }
2953 
2954  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
2955  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
2956  pathnode->path.total_cost = initplan_cost + target->cost.startup +
2957  target->cost.per_tuple + cpu_tuple_cost;
2958 
2959  /*
2960  * Add cost of qual, if any --- but we ignore its selectivity, since our
2961  * rowcount estimate should be 1 no matter what the qual is.
2962  */
2963  if (quals)
2964  {
2965  QualCost qual_cost;
2966 
2967  cost_qual_eval(&qual_cost, quals, root);
2968  pathnode->path.startup_cost += qual_cost.startup;
2969  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
2970  }
2971 
2972  return pathnode;
2973 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * quals
Definition: relation.h:1598
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:1040
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3508
Cost startup_cost
Definition: relation.h:1053
RelOptInfo * parent
Definition: relation.h:1042
List * mmaggregates
Definition: relation.h:1597
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
QualCost cost
Definition: relation.h:974
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:1047
double Cost
Definition: nodes.h:642

◆ create_modifytable_path()

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

Definition at line 3220 of file pathnode.c.

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

Referenced by grouping_planner(), and inheritance_planner().

3228 {
3230  double total_size;
3231  ListCell *lc;
3232 
3233  Assert(list_length(resultRelations) == list_length(subpaths));
3234  Assert(list_length(resultRelations) == list_length(subroots));
3235  Assert(withCheckOptionLists == NIL ||
3236  list_length(resultRelations) == list_length(withCheckOptionLists));
3237  Assert(returningLists == NIL ||
3238  list_length(resultRelations) == list_length(returningLists));
3239 
3240  pathnode->path.pathtype = T_ModifyTable;
3241  pathnode->path.parent = rel;
3242  /* pathtarget is not interesting, just make it minimally valid */
3243  pathnode->path.pathtarget = rel->reltarget;
3244  /* For now, assume we are above any joins, so no parameterization */
3245  pathnode->path.param_info = NULL;
3246  pathnode->path.parallel_aware = false;
3247  pathnode->path.parallel_safe = false;
3248  pathnode->path.parallel_workers = 0;
3249  pathnode->path.pathkeys = NIL;
3250 
3251  /*
3252  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3253  *
3254  * Currently, we don't charge anything extra for the actual table
3255  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3256  * expressions if any. It would only be window dressing, since
3257  * ModifyTable is always a top-level node and there is no way for the
3258  * costs to change any higher-level planning choices. But we might want
3259  * to make it look better sometime.
3260  */
3261  pathnode->path.startup_cost = 0;
3262  pathnode->path.total_cost = 0;
3263  pathnode->path.rows = 0;
3264  total_size = 0;
3265  foreach(lc, subpaths)
3266  {
3267  Path *subpath = (Path *) lfirst(lc);
3268 
3269  if (lc == list_head(subpaths)) /* first node? */
3270  pathnode->path.startup_cost = subpath->startup_cost;
3271  pathnode->path.total_cost += subpath->total_cost;
3272  pathnode->path.rows += subpath->rows;
3273  total_size += subpath->pathtarget->width * subpath->rows;
3274  }
3275 
3276  /*
3277  * Set width to the average width of the subpath outputs. XXX this is
3278  * totally wrong: we should report zero if no RETURNING, else an average
3279  * of the RETURNING tlist widths. But it's what happened historically,
3280  * and improving it is a task for another day.
3281  */
3282  if (pathnode->path.rows > 0)
3283  total_size /= pathnode->path.rows;
3284  pathnode->path.pathtarget->width = rint(total_size);
3285 
3286  pathnode->operation = operation;
3287  pathnode->canSetTag = canSetTag;
3288  pathnode->nominalRelation = nominalRelation;
3289  pathnode->partitioned_rels = list_copy(partitioned_rels);
3290  pathnode->resultRelations = resultRelations;
3291  pathnode->subpaths = subpaths;
3292  pathnode->subroots = subroots;
3293  pathnode->withCheckOptionLists = withCheckOptionLists;
3294  pathnode->returningLists = returningLists;
3295  pathnode->rowMarks = rowMarks;
3296  pathnode->onconflict = onconflict;
3297  pathnode->epqParam = epqParam;
3298 
3299  return pathnode;
3300 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
List * returningLists
Definition: relation.h:1674
OnConflictExpr * onconflict
Definition: relation.h:1676
Index nominalRelation
Definition: relation.h:1667
List * rowMarks
Definition: relation.h:1675
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:1040
Cost startup_cost
Definition: relation.h:1053
List * subroots
Definition: relation.h:1672
RelOptInfo * parent
Definition: relation.h:1042
List * subpaths
Definition: relation.h:1671
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
double rint(double x)
Definition: rint.c:22
List * partitioned_rels
Definition: relation.h:1669
Cost total_cost
Definition: relation.h:1054
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
#define Assert(condition)
Definition: c.h:670
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1052
bool parallel_safe
Definition: relation.h:1048
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1673
int width
Definition: relation.h:975
CmdType operation
Definition: relation.h:1665
List * resultRelations
Definition: relation.h:1670
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_namedtuplestorescan_path()

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

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

1916 {
1917  Path *pathnode = makeNode(Path);
1918 
1919  pathnode->pathtype = T_NamedTuplestoreScan;
1920  pathnode->parent = rel;
1921  pathnode->pathtarget = rel->reltarget;
1922  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1923  required_outer);
1924  pathnode->parallel_aware = false;
1925  pathnode->parallel_safe = rel->consider_parallel;
1926  pathnode->parallel_workers = 0;
1927  pathnode->pathkeys = NIL; /* result is always unordered */
1928 
1929  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
1930 
1931  return pathnode;
1932 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1253
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1525
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047
struct PathTarget * reltarget
Definition: relation.h:596

◆ create_nestloop_path()

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

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

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

◆ create_projection_path()

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

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

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

3124 {
3126 
3127  pathnode->path.pathtype = T_RecursiveUnion;
3128  pathnode->path.parent = rel;
3129  pathnode->path.pathtarget = target;
3130  /* For now, assume we are above any joins, so no parameterization */
3131  pathnode->path.param_info = NULL;
3132  pathnode->path.parallel_aware = false;
3133  pathnode->path.parallel_safe = rel->consider_parallel &&
3134  leftpath->parallel_safe && rightpath->parallel_safe;
3135  /* Foolish, but we'll do it like joins for now: */
3136  pathnode->path.parallel_workers = leftpath->parallel_workers;
3137  /* RecursiveUnion result is always unsorted */
3138  pathnode->path.pathkeys = NIL;
3139 
3140  pathnode->leftpath = leftpath;
3141  pathnode->rightpath = rightpath;
3142  pathnode->distinctList = distinctList;
3143  pathnode->wtParam = wtParam;
3144  pathnode->numGroups = numGroups;
3145 
3146  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3147 
3148  return pathnode;
3149 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1043
int parallel_workers
Definition: relation.h:1049
ParamPathInfo * param_info
Definition: relation.h:1045
NodeTag pathtype
Definition: relation.h:1040
RelOptInfo * parent
Definition: relation.h:1042
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1565
List * pathkeys
Definition: relation.h:1056
#define makeNode(_type_)
Definition: nodes.h:559
bool parallel_safe
Definition: relation.h:1048
bool consider_parallel
Definition: relation.h:593
bool parallel_aware
Definition: relation.h:1047

◆ create_result_path()

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

Definition at line 1357 of file pathnode.c.

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

Referenced by create_grouping_paths(), and query_planner().

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

◆ create_samplescan_path()

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

Definition at line 971 of file pathnode.c.

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

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

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

◆ create_seqscan_path()

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

Definition at line 946 of file pathnode.c.

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

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

948 {
949  Path *pathnode = makeNode(Path);
950 
951  pathnode->pathtype = T_SeqScan;
952  pathnode->parent = rel;
953  pathnode->pathtarget = rel->reltarget;
954  pathnode->param_info = get_baserel_parampathinfo(root, rel,
955  required_outer);
956  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
957  pathnode->parallel_safe = rel->consider_parallel;
958  pathnode->parallel_workers = parallel_workers;
959  pathnode->pathkeys = NIL; /* seqscan has unordered result */