PostgreSQL Source Code  git master
pathnode.h File Reference
#include "nodes/bitmapset.h"
#include "nodes/pathnodes.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 *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
 
BitmapHeapPathcreate_bitmap_heap_path (PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
 
BitmapAndPathcreate_bitmap_and_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
BitmapOrPathcreate_bitmap_or_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
TidPathcreate_tidscan_path (PlannerInfo *root, RelOptInfo *rel, List *tidquals, Relids required_outer)
 
TidRangePathcreate_tidrangescan_path (PlannerInfo *root, RelOptInfo *rel, List *tidrangequals, Relids required_outer)
 
AppendPathcreate_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, double rows)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer)
 
GroupResultPathcreate_group_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *havingqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
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_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_resultscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_worktablescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
ForeignPathcreate_foreignscan_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
ForeignPathcreate_foreign_join_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
ForeignPathcreate_foreign_upper_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Path *fdw_outerpath, List *fdw_private)
 
Relids calc_nestloop_required_outer (Relids outerrelids, Relids outer_paramrels, Relids innerrelids, Relids inner_paramrels)
 
Relids calc_non_nestloop_required_outer (Path *outer_path, Path *inner_path)
 
NestPathcreate_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
 
MergePathcreate_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
 
HashPathcreate_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, bool parallel_hash, List *restrict_clauses, Relids required_outer, List *hashclauses)
 
ProjectionPathcreate_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
Pathapply_projection_to_path (PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
 
ProjectSetPathcreate_set_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
SortPathcreate_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
 
IncrementalSortPathcreate_incremental_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, int presorted_keys, double limit_tuples)
 
GroupPathcreate_group_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *groupClause, List *qual, double numGroups)
 
UpperUniquePathcreate_upper_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
 
AggPathcreate_agg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
 
GroupingSetsPathcreate_groupingsets_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs, 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)
 
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, Index rootRelation, bool partColsUpdated, List *resultRelations, List *subpaths, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
LimitPathcreate_limit_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, LimitOption limitOption, int64 offset_est, int64 count_est)
 
void adjust_limit_rows_costs (double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
 
Pathreparameterize_path (PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
 
Pathreparameterize_path_by_child (PlannerInfo *root, Path *path, RelOptInfo *child_rel)
 
void setup_simple_rel_arrays (PlannerInfo *root)
 
void expand_planner_arrays (PlannerInfo *root, int add_size)
 
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)
 
RelOptInfofetch_upper_rel (PlannerInfo *root, UpperRelationKind kind, Relids relids)
 
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 749 of file pathnode.c.

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

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

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

◆ add_partial_path_precheck()

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

Definition at line 867 of file pathnode.c.

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

References BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, bms_subset_compare(), CHECK_FOR_INTERRUPTS, compare_path_costs_fuzzily(), compare_pathkeys(), COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT, COSTS_EQUAL, foreach_current_index, foreach_delete_current, IsA, lfirst, list_insert_nth(), 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_final_paths(), add_foreign_grouping_paths(), add_foreign_ordered_paths(), add_paths_to_append_rel(), add_paths_to_grouping_rel(), add_paths_with_pathkeys_for_rel(), BuildParameterizedTidPaths(), consider_groupingsets_paths(), create_degenerate_grouping_paths(), create_distinct_paths(), create_index_paths(), create_one_window_path(), create_ordered_paths(), create_partial_grouping_paths(), create_tidscan_paths(), fileGetForeignPaths(), gather_grouping_paths(), generate_gather_paths(), generate_nonunion_paths(), generate_orderedappend_paths(), generate_recursion_path(), generate_union_paths(), generate_useful_gather_paths(), get_index_paths(), grouping_planner(), inheritance_planner(), mark_dummy_rel(), postgresGetForeignJoinPaths(), postgresGetForeignPaths(), preprocess_minmax_aggregates(), query_planner(), recurse_set_operations(), set_cte_pathlist(), set_dummy_rel_pathlist(), set_function_pathlist(), set_namedtuplestore_pathlist(), set_plain_rel_pathlist(), set_result_pathlist(), set_subquery_pathlist(), set_tablefunc_pathlist(), set_tablesample_rel_pathlist(), set_values_pathlist(), set_worktable_pathlist(), try_hashjoin_path(), try_mergejoin_path(), and try_nestloop_path().

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

◆ add_path_precheck()

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

Definition at line 644 of file pathnode.c.

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

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

◆ adjust_limit_rows_costs()

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

Definition at line 3718 of file pathnode.c.

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

3723 {
3724  double input_rows = *rows;
3725  Cost input_startup_cost = *startup_cost;
3726  Cost input_total_cost = *total_cost;
3727 
3728  if (offset_est != 0)
3729  {
3730  double offset_rows;
3731 
3732  if (offset_est > 0)
3733  offset_rows = (double) offset_est;
3734  else
3735  offset_rows = clamp_row_est(input_rows * 0.10);
3736  if (offset_rows > *rows)
3737  offset_rows = *rows;
3738  if (input_rows > 0)
3739  *startup_cost +=
3740  (input_total_cost - input_startup_cost)
3741  * offset_rows / input_rows;
3742  *rows -= offset_rows;
3743  if (*rows < 1)
3744  *rows = 1;
3745  }
3746 
3747  if (count_est != 0)
3748  {
3749  double count_rows;
3750 
3751  if (count_est > 0)
3752  count_rows = (double) count_est;
3753  else
3754  count_rows = clamp_row_est(input_rows * 0.10);
3755  if (count_rows > *rows)
3756  count_rows = *rows;
3757  if (input_rows > 0)
3758  *total_cost = *startup_cost +
3759  (input_total_cost - input_startup_cost)
3760  * count_rows / input_rows;
3761  *rows = count_rows;
3762  if (*rows < 1)
3763  *rows = 1;
3764  }
3765 }
double clamp_row_est(double nrows)
Definition: costsize.c:196
double Cost
Definition: nodes.h:667

◆ apply_projection_to_path()

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

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

2673 {
2674  QualCost oldcost;
2675 
2676  /*
2677  * If given path can't project, we might need a Result node, so make a
2678  * separate ProjectionPath.
2679  */
2680  if (!is_projection_capable_path(path))
2681  return (Path *) create_projection_path(root, rel, path, target);
2682 
2683  /*
2684  * We can just jam the desired tlist into the existing path, being sure to
2685  * update its cost estimates appropriately.
2686  */
2687  oldcost = path->pathtarget->cost;
2688  path->pathtarget = target;
2689 
2690  path->startup_cost += target->cost.startup - oldcost.startup;
2691  path->total_cost += target->cost.startup - oldcost.startup +
2692  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2693 
2694  /*
2695  * If the path happens to be a Gather or GatherMerge path, we'd like to
2696  * arrange for the subpath to return the required target list so that
2697  * workers can help project. But if there is something that is not
2698  * parallel-safe in the target expressions, then we can't.
2699  */
2700  if ((IsA(path, GatherPath) || IsA(path, GatherMergePath)) &&
2701  is_parallel_safe(root, (Node *) target->exprs))
2702  {
2703  /*
2704  * We always use create_projection_path here, even if the subpath is
2705  * projection-capable, so as to avoid modifying the subpath in place.
2706  * It seems unlikely at present that there could be any other
2707  * references to the subpath, but better safe than sorry.
2708  *
2709  * Note that we don't change the parallel path's cost estimates; it
2710  * might be appropriate to do so, to reflect the fact that the bulk of
2711  * the target evaluation will happen in workers.
2712  */
2713  if (IsA(path, GatherPath))
2714  {
2715  GatherPath *gpath = (GatherPath *) path;
2716 
2717  gpath->subpath = (Path *)
2719  gpath->subpath->parent,
2720  gpath->subpath,
2721  target);
2722  }
2723  else
2724  {
2725  GatherMergePath *gmpath = (GatherMergePath *) path;
2726 
2727  gmpath->subpath = (Path *)
2729  gmpath->subpath->parent,
2730  gmpath->subpath,
2731  target);
2732  }
2733  }
2734  else if (path->parallel_safe &&
2735  !is_parallel_safe(root, (Node *) target->exprs))
2736  {
2737  /*
2738  * We're inserting a parallel-restricted target list into a path
2739  * currently marked parallel-safe, so we have to mark it as no longer
2740  * safe.
2741  */
2742  path->parallel_safe = false;
2743  }
2744 
2745  return path;
2746 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:584
PathTarget * pathtarget
Definition: pathnodes.h:1155
Definition: nodes.h:533
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2578
Cost startup
Definition: pathnodes.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:567
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * subpath
Definition: pathnodes.h:1513
List * exprs
Definition: pathnodes.h:1084
Cost total_cost
Definition: pathnodes.h:1166
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
bool is_projection_capable_path(Path *path)
Definition: createplan.c:7024

◆ 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 784 of file relnode.c.

References add_child_join_rel_equivalences(), add_join_rel(), adjust_appendrel_attrs(), RelOptInfo::all_partrels, RelOptInfo::allvisfrac, RelOptInfo::amflags, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_union(), RelOptInfo::boundinfo, build_child_join_reltarget(), build_joinrel_partition_info(), 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_partitionwise_join, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, RelOptInfo::eclass_indexes, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_appinfos_by_relids(), find_join_rel(), RelOptInfo::has_eclass_joins, has_useful_pathkeys(), 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::nparts, RelOptInfo::nullable_partexprs, RelOptInfo::pages, RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partbounds_merged, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, RelOptInfo::pathlist, QualCost::per_tuple, pfree(), RelOptInfo::ppilist, RelOptInfo::relid, RelOptInfo::relids, RELOPT_OTHER_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, RelOptInfo::rtekind, RelOptInfo::serverid, set_foreign_rel_properties(), set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by try_partitionwise_join().

788 {
789  RelOptInfo *joinrel = makeNode(RelOptInfo);
790  AppendRelInfo **appinfos;
791  int nappinfos;
792 
793  /* Only joins between "other" relations land here. */
794  Assert(IS_OTHER_REL(outer_rel) && IS_OTHER_REL(inner_rel));
795 
796  /* The parent joinrel should have consider_partitionwise_join set. */
797  Assert(parent_joinrel->consider_partitionwise_join);
798 
799  joinrel->reloptkind = RELOPT_OTHER_JOINREL;
800  joinrel->relids = bms_union(outer_rel->relids, inner_rel->relids);
801  joinrel->rows = 0;
802  /* cheap startup cost is interesting iff not all tuples to be retrieved */
803  joinrel->consider_startup = (root->tuple_fraction > 0);
804  joinrel->consider_param_startup = false;
805  joinrel->consider_parallel = false;
806  joinrel->reltarget = create_empty_pathtarget();
807  joinrel->pathlist = NIL;
808  joinrel->ppilist = NIL;
809  joinrel->partial_pathlist = NIL;
810  joinrel->cheapest_startup_path = NULL;
811  joinrel->cheapest_total_path = NULL;
812  joinrel->cheapest_unique_path = NULL;
814  joinrel->direct_lateral_relids = NULL;
815  joinrel->lateral_relids = NULL;
816  joinrel->relid = 0; /* indicates not a baserel */
817  joinrel->rtekind = RTE_JOIN;
818  joinrel->min_attr = 0;
819  joinrel->max_attr = 0;
820  joinrel->attr_needed = NULL;
821  joinrel->attr_widths = NULL;
822  joinrel->lateral_vars = NIL;
823  joinrel->lateral_referencers = NULL;
824  joinrel->indexlist = NIL;
825  joinrel->pages = 0;
826  joinrel->tuples = 0;
827  joinrel->allvisfrac = 0;
828  joinrel->eclass_indexes = NULL;
829  joinrel->subroot = NULL;
830  joinrel->subplan_params = NIL;
831  joinrel->amflags = 0;
832  joinrel->serverid = InvalidOid;
833  joinrel->userid = InvalidOid;
834  joinrel->useridiscurrent = false;
835  joinrel->fdwroutine = NULL;
836  joinrel->fdw_private = NULL;
837  joinrel->baserestrictinfo = NIL;
838  joinrel->baserestrictcost.startup = 0;
839  joinrel->baserestrictcost.per_tuple = 0;
840  joinrel->joininfo = NIL;
841  joinrel->has_eclass_joins = false;
842  joinrel->consider_partitionwise_join = false; /* might get changed later */
843  joinrel->top_parent_relids = NULL;
844  joinrel->part_scheme = NULL;
845  joinrel->nparts = -1;
846  joinrel->boundinfo = NULL;
847  joinrel->partbounds_merged = false;
848  joinrel->partition_qual = NIL;
849  joinrel->part_rels = NULL;
850  joinrel->all_partrels = NULL;
851  joinrel->partexprs = NULL;
852  joinrel->nullable_partexprs = NULL;
853 
854  joinrel->top_parent_relids = bms_union(outer_rel->top_parent_relids,
855  inner_rel->top_parent_relids);
856 
857  /* Compute information relevant to foreign relations. */
858  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
859 
860  /* Compute information needed for mapping Vars to the child rel */
861  appinfos = find_appinfos_by_relids(root, joinrel->relids, &nappinfos);
862 
863  /* Set up reltarget struct */
864  build_child_join_reltarget(root, parent_joinrel, joinrel,
865  nappinfos, appinfos);
866 
867  /* Construct joininfo list. */
868  joinrel->joininfo = (List *) adjust_appendrel_attrs(root,
869  (Node *) parent_joinrel->joininfo,
870  nappinfos,
871  appinfos);
872 
873  /*
874  * Lateral relids referred in child join will be same as that referred in
875  * the parent relation.
876  */
877  joinrel->direct_lateral_relids = (Relids) bms_copy(parent_joinrel->direct_lateral_relids);
878  joinrel->lateral_relids = (Relids) bms_copy(parent_joinrel->lateral_relids);
879 
880  /*
881  * If the parent joinrel has pending equivalence classes, so does the
882  * child.
883  */
884  joinrel->has_eclass_joins = parent_joinrel->has_eclass_joins;
885 
886  /* Is the join between partitions itself partitioned? */
887  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
888  jointype);
889 
890  /* Child joinrel is parallel safe if parent is parallel safe. */
891  joinrel->consider_parallel = parent_joinrel->consider_parallel;
892 
893  /* Set estimates of the child-joinrel's size. */
894  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
895  sjinfo, restrictlist);
896 
897  /* We build the join only once. */
898  Assert(!find_join_rel(root, joinrel->relids));
899 
900  /* Add the relation to the PlannerInfo. */
901  add_join_rel(root, joinrel);
902 
903  /*
904  * We might need EquivalenceClass members corresponding to the child join,
905  * so that we can represent sort pathkeys for it. As with children of
906  * baserels, we shouldn't need this unless there are relevant eclass joins
907  * (implying that a merge join might be possible) or pathkeys to sort by.
908  */
909  if (joinrel->has_eclass_joins || has_useful_pathkeys(root, parent_joinrel))
911  nappinfos, appinfos,
912  parent_joinrel, joinrel);
913 
914  pfree(appinfos);
915 
916  return joinrel;
917 }
bool has_eclass_joins
Definition: pathnodes.h:740
struct Path * cheapest_unique_path
Definition: pathnodes.h:689
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:691
#define NIL
Definition: pg_list.h:65
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:667
Relids * attr_needed
Definition: pathnodes.h:703
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:438
#define IS_OTHER_REL(rel)
Definition: pathnodes.h:658
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4825
struct Path * cheapest_startup_path
Definition: pathnodes.h:687
Oid userid
Definition: pathnodes.h:722
double tuples
Definition: pathnodes.h:710
List * baserestrictinfo
Definition: pathnodes.h:734
bool consider_param_startup
Definition: pathnodes.h:677
Definition: nodes.h:533
List * partial_pathlist
Definition: pathnodes.h:686
List * cheapest_parameterized_paths
Definition: pathnodes.h:690
Relids all_partrels
Definition: pathnodes.h:759
bool useridiscurrent
Definition: pathnodes.h:723
List ** nullable_partexprs
Definition: pathnodes.h:761
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:711
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
Definition: equivclass.c:2524
PlannerInfo * subroot
Definition: pathnodes.h:714
bool consider_startup
Definition: pathnodes.h:676
Relids lateral_relids
Definition: pathnodes.h:695
Cost per_tuple
Definition: pathnodes.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:501
uint32 amflags
Definition: pathnodes.h:717
double tuple_fraction
Definition: pathnodes.h:330
void pfree(void *pointer)
Definition: mcxt.c:1057
List ** partexprs
Definition: pathnodes.h:760
struct Path * cheapest_total_path
Definition: pathnodes.h:688
List * joininfo
Definition: pathnodes.h:738
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:725
int nparts
Definition: pathnodes.h:750
Relids relids
Definition: pathnodes.h:670
bool partbounds_merged
Definition: pathnodes.h:754
List * ppilist
Definition: pathnodes.h:685
Index relid
Definition: pathnodes.h:698
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:728
Relids lateral_referencers
Definition: pathnodes.h:706
Oid serverid
Definition: pathnodes.h:721
Relids direct_lateral_relids
Definition: pathnodes.h:694
bool consider_partitionwise_join
Definition: pathnodes.h:743
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:753
RTEKind rtekind
Definition: pathnodes.h:700
List * indexlist
Definition: pathnodes.h:707
double rows
Definition: pathnodes.h:673
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:726
#define makeNode(_type_)
Definition: nodes.h:581
BlockNumber pages
Definition: pathnodes.h:709
#define Assert(condition)
Definition: c.h:804
List * lateral_vars
Definition: pathnodes.h:705
struct RelOptInfo ** part_rels
Definition: pathnodes.h:757
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool consider_parallel
Definition: pathnodes.h:678
Bitmapset * Relids
Definition: pathnodes.h:28
AttrNumber max_attr
Definition: pathnodes.h:702
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1629
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1910
PartitionScheme part_scheme
Definition: pathnodes.h:749
List * pathlist
Definition: pathnodes.h:684
List * partition_qual
Definition: pathnodes.h:756
int32 * attr_widths
Definition: pathnodes.h:704
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:681
QualCost baserestrictcost
Definition: pathnodes.h:735
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:539
List * subplan_params
Definition: pathnodes.h:715
static void build_child_join_reltarget(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, int nappinfos, AppendRelInfo **appinfos)
Definition: relnode.c:2012
Bitmapset * eclass_indexes
Definition: pathnodes.h:712
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:194
Relids top_parent_relids
Definition: pathnodes.h:745
AttrNumber min_attr
Definition: pathnodes.h:701

◆ 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 576 of file relnode.c.

References add_join_rel(), add_placeholders_to_joinrel(), RelOptInfo::all_partrels, RelOptInfo::allvisfrac, RelOptInfo::amflags, 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_partitionwise_join, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, RelOptInfo::eclass_indexes, 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::partbounds_merged, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, 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().

582 {
583  RelOptInfo *joinrel;
584  List *restrictlist;
585 
586  /* This function should be used only for join between parents. */
587  Assert(!IS_OTHER_REL(outer_rel) && !IS_OTHER_REL(inner_rel));
588 
589  /*
590  * See if we already have a joinrel for this set of base rels.
591  */
592  joinrel = find_join_rel(root, joinrelids);
593 
594  if (joinrel)
595  {
596  /*
597  * Yes, so we only need to figure the restrictlist for this particular
598  * pair of component relations.
599  */
600  if (restrictlist_ptr)
601  *restrictlist_ptr = build_joinrel_restrictlist(root,
602  joinrel,
603  outer_rel,
604  inner_rel);
605  return joinrel;
606  }
607 
608  /*
609  * Nope, so make one.
610  */
611  joinrel = makeNode(RelOptInfo);
612  joinrel->reloptkind = RELOPT_JOINREL;
613  joinrel->relids = bms_copy(joinrelids);
614  joinrel->rows = 0;
615  /* cheap startup cost is interesting iff not all tuples to be retrieved */
616  joinrel->consider_startup = (root->tuple_fraction > 0);
617  joinrel->consider_param_startup = false;
618  joinrel->consider_parallel = false;
619  joinrel->reltarget = create_empty_pathtarget();
620  joinrel->pathlist = NIL;
621  joinrel->ppilist = NIL;
622  joinrel->partial_pathlist = NIL;
623  joinrel->cheapest_startup_path = NULL;
624  joinrel->cheapest_total_path = NULL;
625  joinrel->cheapest_unique_path = NULL;
627  /* init direct_lateral_relids from children; we'll finish it up below */
628  joinrel->direct_lateral_relids =
629  bms_union(outer_rel->direct_lateral_relids,
630  inner_rel->direct_lateral_relids);
631  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
632  outer_rel, inner_rel);
633  joinrel->relid = 0; /* indicates not a baserel */
634  joinrel->rtekind = RTE_JOIN;
635  joinrel->min_attr = 0;
636  joinrel->max_attr = 0;
637  joinrel->attr_needed = NULL;
638  joinrel->attr_widths = NULL;
639  joinrel->lateral_vars = NIL;
640  joinrel->lateral_referencers = NULL;
641  joinrel->indexlist = NIL;
642  joinrel->statlist = NIL;
643  joinrel->pages = 0;
644  joinrel->tuples = 0;
645  joinrel->allvisfrac = 0;
646  joinrel->eclass_indexes = NULL;
647  joinrel->subroot = NULL;
648  joinrel->subplan_params = NIL;
649  joinrel->rel_parallel_workers = -1;
650  joinrel->amflags = 0;
651  joinrel->serverid = InvalidOid;
652  joinrel->userid = InvalidOid;
653  joinrel->useridiscurrent = false;
654  joinrel->fdwroutine = NULL;
655  joinrel->fdw_private = NULL;
656  joinrel->unique_for_rels = NIL;
657  joinrel->non_unique_for_rels = NIL;
658  joinrel->baserestrictinfo = NIL;
659  joinrel->baserestrictcost.startup = 0;
660  joinrel->baserestrictcost.per_tuple = 0;
661  joinrel->baserestrict_min_security = UINT_MAX;
662  joinrel->joininfo = NIL;
663  joinrel->has_eclass_joins = false;
664  joinrel->consider_partitionwise_join = false; /* might get changed later */
665  joinrel->top_parent_relids = NULL;
666  joinrel->part_scheme = NULL;
667  joinrel->nparts = -1;
668  joinrel->boundinfo = NULL;
669  joinrel->partbounds_merged = false;
670  joinrel->partition_qual = NIL;
671  joinrel->part_rels = NULL;
672  joinrel->all_partrels = NULL;
673  joinrel->partexprs = NULL;
674  joinrel->nullable_partexprs = NULL;
675 
676  /* Compute information relevant to the foreign relations. */
677  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
678 
679  /*
680  * Create a new tlist containing just the vars that need to be output from
681  * this join (ie, are needed for higher joinclauses or final output).
682  *
683  * NOTE: the tlist order for a join rel will depend on which pair of outer
684  * and inner rels we first try to build it from. But the contents should
685  * be the same regardless.
686  */
687  build_joinrel_tlist(root, joinrel, outer_rel);
688  build_joinrel_tlist(root, joinrel, inner_rel);
689  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
690 
691  /*
692  * add_placeholders_to_joinrel also took care of adding the ph_lateral
693  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
694  * now we can finish computing that. This is much like the computation of
695  * the transitively-closed lateral_relids in min_join_parameterization,
696  * except that here we *do* have to consider the added PHVs.
697  */
698  joinrel->direct_lateral_relids =
699  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
700  if (bms_is_empty(joinrel->direct_lateral_relids))
701  joinrel->direct_lateral_relids = NULL;
702 
703  /*
704  * Construct restrict and join clause lists for the new joinrel. (The
705  * caller might or might not need the restrictlist, but I need it anyway
706  * for set_joinrel_size_estimates().)
707  */
708  restrictlist = build_joinrel_restrictlist(root, joinrel,
709  outer_rel, inner_rel);
710  if (restrictlist_ptr)
711  *restrictlist_ptr = restrictlist;
712  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
713 
714  /*
715  * This is also the right place to check whether the joinrel has any
716  * pending EquivalenceClass joins.
717  */
718  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
719 
720  /* Store the partition information. */
721  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
722  sjinfo->jointype);
723 
724  /*
725  * Set estimates of the joinrel's size.
726  */
727  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
728  sjinfo, restrictlist);
729 
730  /*
731  * Set the consider_parallel flag if this joinrel could potentially be
732  * scanned within a parallel worker. If this flag is false for either
733  * inner_rel or outer_rel, then it must be false for the joinrel also.
734  * Even if both are true, there might be parallel-restricted expressions
735  * in the targetlist or quals.
736  *
737  * Note that if there are more than two rels in this relation, they could
738  * be divided between inner_rel and outer_rel in any arbitrary way. We
739  * assume this doesn't matter, because we should hit all the same baserels
740  * and joinclauses while building up to this joinrel no matter which we
741  * take; therefore, we should make the same decision here however we get
742  * here.
743  */
744  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
745  is_parallel_safe(root, (Node *) restrictlist) &&
746  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
747  joinrel->consider_parallel = true;
748 
749  /* Add the joinrel to the PlannerInfo. */
750  add_join_rel(root, joinrel);
751 
752  /*
753  * Also, if dynamic-programming join search is active, add the new joinrel
754  * to the appropriate sublist. Note: you might think the Assert on number
755  * of members should be for equality, but some of the level 1 rels might
756  * have been joinrels already, so we can only assert <=.
757  */
758  if (root->join_rel_level)
759  {
760  Assert(root->join_cur_level > 0);
761  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
762  root->join_rel_level[root->join_cur_level] =
763  lappend(root->join_rel_level[root->join_cur_level], joinrel);
764  }
765 
766  return joinrel;
767 }
bool has_eclass_joins
Definition: pathnodes.h:740
struct Path * cheapest_unique_path
Definition: pathnodes.h:689
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:691
#define NIL
Definition: pg_list.h:65
int join_cur_level
Definition: pathnodes.h:251
List * unique_for_rels
Definition: pathnodes.h:729
List * statlist
Definition: pathnodes.h:708
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:667
Relids * attr_needed
Definition: pathnodes.h:703
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:438
#define IS_OTHER_REL(rel)
Definition: pathnodes.h:658
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4825
struct Path * cheapest_startup_path
Definition: pathnodes.h:687
Oid userid
Definition: pathnodes.h:722
double tuples
Definition: pathnodes.h:710
List * baserestrictinfo
Definition: pathnodes.h:734
bool consider_param_startup
Definition: pathnodes.h:677
Definition: nodes.h:533
List * partial_pathlist
Definition: pathnodes.h:686
List * cheapest_parameterized_paths
Definition: pathnodes.h:690
Index baserestrict_min_security
Definition: pathnodes.h:736
Relids all_partrels
Definition: pathnodes.h:759
bool useridiscurrent
Definition: pathnodes.h:723
List ** nullable_partexprs
Definition: pathnodes.h:761
void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: placeholder.c:413
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:711
PlannerInfo * subroot
Definition: pathnodes.h:714
bool consider_startup
Definition: pathnodes.h:676
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:567
Relids lateral_relids
Definition: pathnodes.h:695
Cost per_tuple
Definition: pathnodes.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:501
uint32 amflags
Definition: pathnodes.h:717
double tuple_fraction
Definition: pathnodes.h:330
List ** partexprs
Definition: pathnodes.h:760
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:971
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:928
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:646
struct Path * cheapest_total_path
Definition: pathnodes.h:688
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:1057
List * joininfo
Definition: pathnodes.h:738
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:725
int nparts
Definition: pathnodes.h:750
Relids relids
Definition: pathnodes.h:670
bool partbounds_merged
Definition: pathnodes.h:754
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2875
List * non_unique_for_rels
Definition: pathnodes.h:731
List * ppilist
Definition: pathnodes.h:685
Index relid
Definition: pathnodes.h:698
List * lappend(List *list, void *datum)
Definition: list.c:336
Relids lateral_referencers
Definition: pathnodes.h:706
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Oid serverid
Definition: pathnodes.h:721
List * exprs
Definition: pathnodes.h:1084
Relids direct_lateral_relids
Definition: pathnodes.h:694
bool consider_partitionwise_join
Definition: pathnodes.h:743
int rel_parallel_workers
Definition: pathnodes.h:716
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:753
RTEKind rtekind
Definition: pathnodes.h:700
List * indexlist
Definition: pathnodes.h:707
double rows
Definition: pathnodes.h:673
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:726
#define makeNode(_type_)
Definition: nodes.h:581
BlockNumber pages
Definition: pathnodes.h:709
#define Assert(condition)
Definition: c.h:804
List ** join_rel_level
Definition: pathnodes.h:250
List * lateral_vars
Definition: pathnodes.h:705
JoinType jointype
Definition: pathnodes.h:2200
struct RelOptInfo ** part_rels
Definition: pathnodes.h:757
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool consider_parallel
Definition: pathnodes.h:678
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:928
AttrNumber max_attr
Definition: pathnodes.h:702
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1629
PartitionScheme part_scheme
Definition: pathnodes.h:749
List * pathlist
Definition: pathnodes.h:684
List * partition_qual
Definition: pathnodes.h:756
int32 * attr_widths
Definition: pathnodes.h:704
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:681
QualCost baserestrictcost
Definition: pathnodes.h:735
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:539
List * subplan_params
Definition: pathnodes.h:715
Bitmapset * eclass_indexes
Definition: pathnodes.h:712
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:1087
Relids top_parent_relids
Definition: pathnodes.h:745
AttrNumber min_attr
Definition: pathnodes.h:701

◆ build_simple_rel()

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

Definition at line 194 of file relnode.c.

References RelOptInfo::all_partrels, RelOptInfo::allvisfrac, RelOptInfo::amflags, PlannerInfo::append_rel_array, apply_child_basequals(), Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_make_singleton(), RelOptInfo::boundinfo, RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RangeTblEntry::checkAsUser, Alias::colnames, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_partitionwise_join, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, RelOptInfo::eclass_indexes, 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, list_length(), makeNode, mark_dummy_rel(), RelOptInfo::max_attr, RelOptInfo::min_attr, NIL, RelOptInfo::non_unique_for_rels, RelOptInfo::nparts, RelOptInfo::nullable_partexprs, RelOptInfo::pages, palloc0(), RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partbounds_merged, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, 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_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, 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(), expand_appendrel_subquery(), expand_inherited_rtentry(), expand_partitioned_rtentry(), plan_cluster_use_sort(), plan_create_index_workers(), query_planner(), and recurse_set_operations().

195 {
196  RelOptInfo *rel;
197  RangeTblEntry *rte;
198 
199  /* Rel should not exist already */
200  Assert(relid > 0 && relid < root->simple_rel_array_size);
201  if (root->simple_rel_array[relid] != NULL)
202  elog(ERROR, "rel %d already exists", relid);
203 
204  /* Fetch RTE for relation */
205  rte = root->simple_rte_array[relid];
206  Assert(rte != NULL);
207 
208  rel = makeNode(RelOptInfo);
210  rel->relids = bms_make_singleton(relid);
211  rel->rows = 0;
212  /* cheap startup cost is interesting iff not all tuples to be retrieved */
213  rel->consider_startup = (root->tuple_fraction > 0);
214  rel->consider_param_startup = false; /* might get changed later */
215  rel->consider_parallel = false; /* might get changed later */
217  rel->pathlist = NIL;
218  rel->ppilist = NIL;
219  rel->partial_pathlist = NIL;
220  rel->cheapest_startup_path = NULL;
221  rel->cheapest_total_path = NULL;
222  rel->cheapest_unique_path = NULL;
224  rel->relid = relid;
225  rel->rtekind = rte->rtekind;
226  /* min_attr, max_attr, attr_needed, attr_widths are set below */
227  rel->lateral_vars = NIL;
228  rel->indexlist = NIL;
229  rel->statlist = NIL;
230  rel->pages = 0;
231  rel->tuples = 0;
232  rel->allvisfrac = 0;
233  rel->eclass_indexes = NULL;
234  rel->subroot = NULL;
235  rel->subplan_params = NIL;
236  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
237  rel->amflags = 0;
238  rel->serverid = InvalidOid;
239  rel->userid = rte->checkAsUser;
240  rel->useridiscurrent = false;
241  rel->fdwroutine = NULL;
242  rel->fdw_private = NULL;
243  rel->unique_for_rels = NIL;
244  rel->non_unique_for_rels = NIL;
245  rel->baserestrictinfo = NIL;
246  rel->baserestrictcost.startup = 0;
247  rel->baserestrictcost.per_tuple = 0;
248  rel->baserestrict_min_security = UINT_MAX;
249  rel->joininfo = NIL;
250  rel->has_eclass_joins = false;
251  rel->consider_partitionwise_join = false; /* might get changed later */
252  rel->part_scheme = NULL;
253  rel->nparts = -1;
254  rel->boundinfo = NULL;
255  rel->partbounds_merged = false;
256  rel->partition_qual = NIL;
257  rel->part_rels = NULL;
258  rel->all_partrels = NULL;
259  rel->partexprs = NULL;
260  rel->nullable_partexprs = NULL;
261 
262  /*
263  * Pass assorted information down the inheritance hierarchy.
264  */
265  if (parent)
266  {
267  /*
268  * Each direct or indirect child wants to know the relids of its
269  * topmost parent.
270  */
271  if (parent->top_parent_relids)
272  rel->top_parent_relids = parent->top_parent_relids;
273  else
274  rel->top_parent_relids = bms_copy(parent->relids);
275 
276  /*
277  * Also propagate lateral-reference information from appendrel parent
278  * rels to their child rels. We intentionally give each child rel the
279  * same minimum parameterization, even though it's quite possible that
280  * some don't reference all the lateral rels. This is because any
281  * append path for the parent will have to have the same
282  * parameterization for every child anyway, and there's no value in
283  * forcing extra reparameterize_path() calls. Similarly, a lateral
284  * reference to the parent prevents use of otherwise-movable join rels
285  * for each child.
286  *
287  * It's possible for child rels to have their own children, in which
288  * case the topmost parent's lateral info propagates all the way down.
289  */
291  rel->lateral_relids = parent->lateral_relids;
293  }
294  else
295  {
296  rel->top_parent_relids = NULL;
297  rel->direct_lateral_relids = NULL;
298  rel->lateral_relids = NULL;
299  rel->lateral_referencers = NULL;
300  }
301 
302  /* Check type of rtable entry */
303  switch (rte->rtekind)
304  {
305  case RTE_RELATION:
306  /* Table --- retrieve statistics from the system catalogs */
307  get_relation_info(root, rte->relid, rte->inh, rel);
308  break;
309  case RTE_SUBQUERY:
310  case RTE_FUNCTION:
311  case RTE_TABLEFUNC:
312  case RTE_VALUES:
313  case RTE_CTE:
314  case RTE_NAMEDTUPLESTORE:
315 
316  /*
317  * Subquery, function, tablefunc, values list, CTE, or ENR --- set
318  * up attr range and arrays
319  *
320  * Note: 0 is included in range to support whole-row Vars
321  */
322  rel->min_attr = 0;
323  rel->max_attr = list_length(rte->eref->colnames);
324  rel->attr_needed = (Relids *)
325  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
326  rel->attr_widths = (int32 *)
327  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
328  break;
329  case RTE_RESULT:
330  /* RTE_RESULT has no columns, nor could it have whole-row Var */
331  rel->min_attr = 0;
332  rel->max_attr = -1;
333  rel->attr_needed = NULL;
334  rel->attr_widths = NULL;
335  break;
336  default:
337  elog(ERROR, "unrecognized RTE kind: %d",
338  (int) rte->rtekind);
339  break;
340  }
341 
342  /*
343  * Copy the parent's quals to the child, with appropriate substitution of
344  * variables. If any constant false or NULL clauses turn up, we can mark
345  * the child as dummy right away. (We must do this immediately so that
346  * pruning works correctly when recursing in expand_partitioned_rtentry.)
347  */
348  if (parent)
349  {
350  AppendRelInfo *appinfo = root->append_rel_array[relid];
351 
352  Assert(appinfo != NULL);
353  if (!apply_child_basequals(root, parent, rel, rte, appinfo))
354  {
355  /*
356  * Some restriction clause reduced to constant FALSE or NULL after
357  * substitution, so this child need not be scanned.
358  */
359  mark_dummy_rel(rel);
360  }
361  }
362 
363  /* Save the finished struct in the query's simple_rel_array */
364  root->simple_rel_array[relid] = rel;
365 
366  return rel;
367 }
bool has_eclass_joins
Definition: pathnodes.h:740
struct Path * cheapest_unique_path
Definition: pathnodes.h:689
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:691
#define NIL
Definition: pg_list.h:65
List * unique_for_rels
Definition: pathnodes.h:729
List * statlist
Definition: pathnodes.h:708
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:667
Relids * attr_needed
Definition: pathnodes.h:703
List * colnames
Definition: primnodes.h:43
struct Path * cheapest_startup_path
Definition: pathnodes.h:687
Oid userid
Definition: pathnodes.h:722
double tuples
Definition: pathnodes.h:710
List * baserestrictinfo
Definition: pathnodes.h:734
bool consider_param_startup
Definition: pathnodes.h:677
List * partial_pathlist
Definition: pathnodes.h:686
List * cheapest_parameterized_paths
Definition: pathnodes.h:690
Index baserestrict_min_security
Definition: pathnodes.h:736
Relids all_partrels
Definition: pathnodes.h:759
bool useridiscurrent
Definition: pathnodes.h:723
List ** nullable_partexprs
Definition: pathnodes.h:761
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:711
signed int int32
Definition: c.h:429
struct RelOptInfo ** simple_rel_array
Definition: pathnodes.h:197
PlannerInfo * subroot
Definition: pathnodes.h:714
bool consider_startup
Definition: pathnodes.h:676
bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, RangeTblEntry *childRTE, AppendRelInfo *appinfo)
Definition: inherit.c:693
Relids lateral_relids
Definition: pathnodes.h:695
Cost per_tuple
Definition: pathnodes.h:46
uint32 amflags
Definition: pathnodes.h:717
double tuple_fraction
Definition: pathnodes.h:330
List ** partexprs
Definition: pathnodes.h:760
#define ERROR
Definition: elog.h:45
struct Path * cheapest_total_path
Definition: pathnodes.h:688
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:186
List * joininfo
Definition: pathnodes.h:738
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:725
int nparts
Definition: pathnodes.h:750
Relids relids
Definition: pathnodes.h:670
bool partbounds_merged
Definition: pathnodes.h:754
List * non_unique_for_rels
Definition: pathnodes.h:731
List * ppilist
Definition: pathnodes.h:685
Index relid
Definition: pathnodes.h:698
RangeTblEntry ** simple_rte_array
Definition: pathnodes.h:205
Relids lateral_referencers
Definition: pathnodes.h:706
Oid serverid
Definition: pathnodes.h:721
Relids direct_lateral_relids
Definition: pathnodes.h:694
bool consider_partitionwise_join
Definition: pathnodes.h:743
void * palloc0(Size size)
Definition: mcxt.c:981
void mark_dummy_rel(RelOptInfo *rel)
Definition: joinrels.c:1261
int rel_parallel_workers
Definition: pathnodes.h:716
struct AppendRelInfo ** append_rel_array
Definition: pathnodes.h:213
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:753
RTEKind rtekind
Definition: pathnodes.h:700
List * indexlist
Definition: pathnodes.h:707
double rows
Definition: pathnodes.h:673
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:726
#define makeNode(_type_)
Definition: nodes.h:581
BlockNumber pages
Definition: pathnodes.h:709
#define Assert(condition)
Definition: c.h:804
List * lateral_vars
Definition: pathnodes.h:705
struct RelOptInfo ** part_rels
Definition: pathnodes.h:757
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
Bitmapset * Relids
Definition: pathnodes.h:28
RTEKind rtekind
Definition: parsenodes.h:981
AttrNumber max_attr
Definition: pathnodes.h:702
#define elog(elevel,...)
Definition: elog.h:227
PartitionScheme part_scheme
Definition: pathnodes.h:749
List * pathlist
Definition: pathnodes.h:684
Alias * eref
Definition: parsenodes.h:1120
List * partition_qual
Definition: pathnodes.h:756
int32 * attr_widths
Definition: pathnodes.h:704
struct PathTarget * reltarget
Definition: pathnodes.h:681
QualCost baserestrictcost
Definition: pathnodes.h:735
List * subplan_params
Definition: pathnodes.h:715
Bitmapset * eclass_indexes
Definition: pathnodes.h:712
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:113
Relids top_parent_relids
Definition: pathnodes.h:745
AttrNumber min_attr
Definition: pathnodes.h:701

◆ calc_nestloop_required_outer()

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

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

2296 {
2297  Relids required_outer;
2298 
2299  /* inner_path can require rels from outer path, but not vice versa */
2300  Assert(!bms_overlap(outer_paramrels, innerrelids));
2301  /* easy case if inner path is not parameterized */
2302  if (!inner_paramrels)
2303  return bms_copy(outer_paramrels);
2304  /* else, form the union ... */
2305  required_outer = bms_union(outer_paramrels, inner_paramrels);
2306  /* ... and remove any mention of now-satisfied outer rels */
2307  required_outer = bms_del_members(required_outer,
2308  outerrelids);
2309  /* maintain invariant that required_outer is exactly NULL if empty */
2310  if (bms_is_empty(required_outer))
2311  {
2312  bms_free(required_outer);
2313  required_outer = NULL;
2314  }
2315  return required_outer;
2316 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
void bms_free(Bitmapset *a)
Definition: bitmapset.c:208
#define Assert(condition)
Definition: c.h:804
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:928
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2326 {
2327  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2328  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2329  Relids required_outer;
2330 
2331  /* neither path can require rels from the other */
2332  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2333  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2334  /* form the union ... */
2335  required_outer = bms_union(outer_paramrels, inner_paramrels);
2336  /* we do not need an explicit test for empty; bms_union gets it right */
2337  return required_outer;
2338 }
RelOptInfo * parent
Definition: pathnodes.h:1154
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1173
Relids relids
Definition: pathnodes.h:670
#define Assert(condition)
Definition: c.h:804
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494

◆ compare_fractional_path_costs()

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

Definition at line 117 of file pathnode.c.

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

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

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

◆ compare_path_costs()

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

Definition at line 71 of file pathnode.c.

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

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

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

◆ 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 3031 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, Path::total_cost, AggClauseCosts::transitionSpace, AggPath::transitionSpace, and PathTarget::width.

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

3041 {
3042  AggPath *pathnode = makeNode(AggPath);
3043 
3044  pathnode->path.pathtype = T_Agg;
3045  pathnode->path.parent = rel;
3046  pathnode->path.pathtarget = target;
3047  /* For now, assume we are above any joins, so no parameterization */
3048  pathnode->path.param_info = NULL;
3049  pathnode->path.parallel_aware = false;
3050  pathnode->path.parallel_safe = rel->consider_parallel &&
3051  subpath->parallel_safe;
3052  pathnode->path.parallel_workers = subpath->parallel_workers;
3053  if (aggstrategy == AGG_SORTED)
3054  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
3055  else
3056  pathnode->path.pathkeys = NIL; /* output is unordered */
3057  pathnode->subpath = subpath;
3058 
3059  pathnode->aggstrategy = aggstrategy;
3060  pathnode->aggsplit = aggsplit;
3061  pathnode->numGroups = numGroups;
3062  pathnode->transitionSpace = aggcosts ? aggcosts->transitionSpace : 0;
3063  pathnode->groupClause = groupClause;
3064  pathnode->qual = qual;
3065 
3066  cost_agg(&pathnode->path, root,
3067  aggstrategy, aggcosts,
3068  list_length(groupClause), numGroups,
3069  qual,
3070  subpath->startup_cost, subpath->total_cost,
3071  subpath->rows, subpath->pathtarget->width);
3072 
3073  /* add tlist eval cost for each output row */
3074  pathnode->path.startup_cost += target->cost.startup;
3075  pathnode->path.total_cost += target->cost.startup +
3076  target->cost.per_tuple * pathnode->path.rows;
3077 
3078  return pathnode;
3079 }
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:80
PathTarget * pathtarget
Definition: pathnodes.h:1155
AggStrategy aggstrategy
Definition: pathnodes.h:1721
List * qual
Definition: pathnodes.h:1726
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2415
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
AggSplit aggsplit
Definition: pathnodes.h:1722
double numGroups
Definition: pathnodes.h:1723
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1152
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
List * groupClause
Definition: pathnodes.h:1725
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
uint64 transitionSpace
Definition: pathnodes.h:1724
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
Path * subpath
Definition: pathnodes.h:1720
Size transitionSpace
Definition: pathnodes.h:60
bool parallel_aware
Definition: pathnodes.h:1159
Path path
Definition: pathnodes.h:1719
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_append_path()

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

Definition at line 1244 of file pathnode.c.

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

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

1250 {
1251  AppendPath *pathnode = makeNode(AppendPath);
1252  ListCell *l;
1253 
1254  Assert(!parallel_aware || parallel_workers > 0);
1255 
1256  pathnode->path.pathtype = T_Append;
1257  pathnode->path.parent = rel;
1258  pathnode->path.pathtarget = rel->reltarget;
1259 
1260  /*
1261  * When generating an Append path for a partitioned table, there may be
1262  * parameterized quals that are useful for run-time pruning. Hence,
1263  * compute path.param_info the same way as for any other baserel, so that
1264  * such quals will be available for make_partition_pruneinfo(). (This
1265  * would not work right for a non-baserel, ie a scan on a non-leaf child
1266  * partition, and it's not necessary anyway in that case. Must skip it if
1267  * we don't have "root", too.)
1268  */
1269  if (root && rel->reloptkind == RELOPT_BASEREL && IS_PARTITIONED_REL(rel))
1270  pathnode->path.param_info = get_baserel_parampathinfo(root,
1271  rel,
1272  required_outer);
1273  else
1275  required_outer);
1276 
1277  pathnode->path.parallel_aware = parallel_aware;
1278  pathnode->path.parallel_safe = rel->consider_parallel;
1279  pathnode->path.parallel_workers = parallel_workers;
1280  pathnode->path.pathkeys = pathkeys;
1281 
1282  /*
1283  * For parallel append, non-partial paths are sorted by descending total
1284  * costs. That way, the total time to finish all non-partial paths is
1285  * minimized. Also, the partial paths are sorted by descending startup
1286  * costs. There may be some paths that require to do startup work by a
1287  * single worker. In such case, it's better for workers to choose the
1288  * expensive ones first, whereas the leader should choose the cheapest
1289  * startup plan.
1290  */
1291  if (pathnode->path.parallel_aware)
1292  {
1293  /*
1294  * We mustn't fiddle with the order of subpaths when the Append has
1295  * pathkeys. The order they're listed in is critical to keeping the
1296  * pathkeys valid.
1297  */
1298  Assert(pathkeys == NIL);
1299 
1301  list_sort(partial_subpaths, append_startup_cost_compare);
1302  }
1303  pathnode->first_partial_path = list_length(subpaths);
1304  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1305 
1306  /*
1307  * Apply query-wide LIMIT if known and path is for sole base relation.
1308  * (Handling this at this low level is a bit klugy.)
1309  */
1310  if (root != NULL && bms_equal(rel->relids, root->all_baserels))
1311  pathnode->limit_tuples = root->limit_tuples;
1312  else
1313  pathnode->limit_tuples = -1.0;
1314 
1315  foreach(l, pathnode->subpaths)
1316  {
1317  Path *subpath = (Path *) lfirst(l);
1318 
1319  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1320  subpath->parallel_safe;
1321 
1322  /* All child paths must have same parameterization */
1323  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1324  }
1325 
1326  Assert(!parallel_aware || pathnode->path.parallel_safe);
1327 
1328  /*
1329  * If there's exactly one child path, the Append is a no-op and will be
1330  * discarded later (in setrefs.c); therefore, we can inherit the child's
1331  * size and cost, as well as its pathkeys if any (overriding whatever the
1332  * caller might've said). Otherwise, we must do the normal costsize
1333  * calculation.
1334  */
1335  if (list_length(pathnode->subpaths) == 1)
1336  {
1337  Path *child = (Path *) linitial(pathnode->subpaths);
1338 
1339  pathnode->path.rows = child->rows;
1340  pathnode->path.startup_cost = child->startup_cost;
1341  pathnode->path.total_cost = child->total_cost;
1342  pathnode->path.pathkeys = child->pathkeys;
1343  }
1344  else
1345  cost_append(pathnode);
1346 
1347  /* If the caller provided a row estimate, override the computed value. */
1348  if (rows >= 0)
1349  pathnode->path.rows = rows;
1350 
1351  return pathnode;
1352 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
RelOptKind reloptkind
Definition: pathnodes.h:667
double limit_tuples
Definition: pathnodes.h:1427
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
List * list_concat(List *list1, const List *list2)
Definition: list.c:530
Definition: nodes.h:49
static int append_total_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1364
int first_partial_path
Definition: pathnodes.h:1426
NodeTag pathtype
Definition: pathnodes.h:1152
List * subpaths
Definition: pathnodes.h:1424
static int append_startup_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1386
#define linitial(l)
Definition: pg_list.h:174
Relids all_baserels
Definition: pathnodes.h:221
double limit_tuples
Definition: pathnodes.h:331
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1173
Relids relids
Definition: pathnodes.h:670
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
void cost_append(AppendPath *apath)
Definition: costsize.c:2139
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1496
#define IS_PARTITIONED_REL(rel)
Definition: pathnodes.h:772
bool parallel_aware
Definition: pathnodes.h:1159
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1575
struct PathTarget * reltarget
Definition: pathnodes.h:681
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

◆ create_bitmap_and_path()

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

Definition at line 1079 of file pathnode.c.

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

Referenced by bitmap_and_cost_est(), and choose_bitmap_and().

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

◆ create_bitmap_heap_path()

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

Definition at line 1046 of file pathnode.c.

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

1052 {
1053  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1054 
1055  pathnode->path.pathtype = T_BitmapHeapScan;
1056  pathnode->path.parent = rel;
1057  pathnode->path.pathtarget = rel->reltarget;
1058  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1059  required_outer);
1060  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1061  pathnode->path.parallel_safe = rel->consider_parallel;
1062  pathnode->path.parallel_workers = parallel_degree;
1063  pathnode->path.pathkeys = NIL; /* always unordered */
1064 
1065  pathnode->bitmapqual = bitmapqual;
1066 
1067  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1068  pathnode->path.param_info,
1069  bitmapqual, loop_count);
1070 
1071  return pathnode;
1072 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:952
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
#define true
Definition: c.h:395
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * bitmapqual
Definition: pathnodes.h:1290
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_bitmap_or_path()

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

Definition at line 1131 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

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

◆ create_ctescan_path()

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

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

2049 {
2050  Path *pathnode = makeNode(Path);
2051 
2052  pathnode->pathtype = T_CteScan;
2053  pathnode->parent = rel;
2054  pathnode->pathtarget = rel->reltarget;
2055  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2056  required_outer);
2057  pathnode->parallel_aware = false;
2058  pathnode->parallel_safe = rel->consider_parallel;
2059  pathnode->parallel_workers = 0;
2060  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
2061 
2062  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2063 
2064  return pathnode;
2065 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1605
NodeTag pathtype
Definition: pathnodes.h:1152
RelOptInfo * parent
Definition: pathnodes.h:1154
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_foreign_join_path()

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

Definition at line 2202 of file pathnode.c.

References bms_is_empty(), RelOptInfo::consider_parallel, elog, ERROR, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, RelOptInfo::lateral_relids, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, 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_paths_with_pathkeys_for_rel(), and postgresGetForeignJoinPaths().

2209 {
2210  ForeignPath *pathnode = makeNode(ForeignPath);
2211 
2212  /*
2213  * We should use get_joinrel_parampathinfo to handle parameterized paths,
2214  * but the API of this function doesn't support it, and existing
2215  * extensions aren't yet trying to build such paths anyway. For the
2216  * moment just throw an error if someone tries it; eventually we should
2217  * revisit this.
2218  */
2219  if (!bms_is_empty(required_outer) || !bms_is_empty(rel->lateral_relids))
2220  elog(ERROR, "parameterized foreign joins are not supported yet");
2221 
2222  pathnode->path.pathtype = T_ForeignScan;
2223  pathnode->path.parent = rel;
2224  pathnode->path.pathtarget = target ? target : rel->reltarget;
2225  pathnode->path.param_info = NULL; /* XXX see above */
2226  pathnode->path.parallel_aware = false;
2227  pathnode->path.parallel_safe = rel->consider_parallel;
2228  pathnode->path.parallel_workers = 0;
2229  pathnode->path.rows = rows;
2230  pathnode->path.startup_cost = startup_cost;
2231  pathnode->path.total_cost = total_cost;
2232  pathnode->path.pathkeys = pathkeys;
2233 
2234  pathnode->fdw_outerpath = fdw_outerpath;
2235  pathnode->fdw_private = fdw_private;
2236 
2237  return pathnode;
2238 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
Path * fdw_outerpath
Definition: pathnodes.h:1371
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Relids lateral_relids
Definition: pathnodes.h:695
#define ERROR
Definition: elog.h:45
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
List * fdw_private
Definition: pathnodes.h:1372
#define elog(elevel,...)
Definition: elog.h:227
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_foreign_upper_path()

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

Definition at line 2252 of file pathnode.c.

References Assert, bms_is_empty(), RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, RelOptInfo::lateral_relids, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, 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_final_paths(), add_foreign_grouping_paths(), and add_foreign_ordered_paths().

2258 {
2259  ForeignPath *pathnode = makeNode(ForeignPath);
2260 
2261  /*
2262  * Upper relations should never have any lateral references, since joining
2263  * is complete.
2264  */
2266 
2267  pathnode->path.pathtype = T_ForeignScan;
2268  pathnode->path.parent = rel;
2269  pathnode->path.pathtarget = target ? target : rel->reltarget;
2270  pathnode->path.param_info = NULL;
2271  pathnode->path.parallel_aware = false;
2272  pathnode->path.parallel_safe = rel->consider_parallel;
2273  pathnode->path.parallel_workers = 0;
2274  pathnode->path.rows = rows;
2275  pathnode->path.startup_cost = startup_cost;
2276  pathnode->path.total_cost = total_cost;
2277  pathnode->path.pathkeys = pathkeys;
2278 
2279  pathnode->fdw_outerpath = fdw_outerpath;
2280  pathnode->fdw_private = fdw_private;
2281 
2282  return pathnode;
2283 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
Path * fdw_outerpath
Definition: pathnodes.h:1371
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Relids lateral_relids
Definition: pathnodes.h:695
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
List * fdw_private
Definition: pathnodes.h:1372
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

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

References Assert, RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, get_baserel_parampathinfo(), IS_SIMPLE_REL, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, 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_paths_with_pathkeys_for_rel(), fileGetForeignPaths(), and postgresGetForeignPaths().

2165 {
2166  ForeignPath *pathnode = makeNode(ForeignPath);
2167 
2168  /* Historically some FDWs were confused about when to use this */
2169  Assert(IS_SIMPLE_REL(rel));
2170 
2171  pathnode->path.pathtype = T_ForeignScan;
2172  pathnode->path.parent = rel;
2173  pathnode->path.pathtarget = target ? target : rel->reltarget;
2174  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2175  required_outer);
2176  pathnode->path.parallel_aware = false;
2177  pathnode->path.parallel_safe = rel->consider_parallel;
2178  pathnode->path.parallel_workers = 0;
2179  pathnode->path.rows = rows;
2180  pathnode->path.startup_cost = startup_cost;
2181  pathnode->path.total_cost = total_cost;
2182  pathnode->path.pathkeys = pathkeys;
2183 
2184  pathnode->fdw_outerpath = fdw_outerpath;
2185  pathnode->fdw_private = fdw_private;
2186 
2187  return pathnode;
2188 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
Path * fdw_outerpath
Definition: pathnodes.h:1371
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:643
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
List * fdw_private
Definition: pathnodes.h:1372
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_functionscan_path()

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

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

1972 {
1973  Path *pathnode = makeNode(Path);
1974 
1975  pathnode->pathtype = T_FunctionScan;
1976  pathnode->parent = rel;
1977  pathnode->pathtarget = rel->reltarget;
1978  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1979  required_outer);
1980  pathnode->parallel_aware = false;
1981  pathnode->parallel_safe = rel->consider_parallel;
1982  pathnode->parallel_workers = 0;
1983  pathnode->pathkeys = pathkeys;
1984 
1985  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1986 
1987  return pathnode;
1988 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
RelOptInfo * parent
Definition: pathnodes.h:1154
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1438
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ 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 1812 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_ordered_paths(), gather_grouping_paths(), generate_gather_paths(), and generate_useful_gather_paths().

1815 {
1817  Cost input_startup_cost = 0;
1818  Cost input_total_cost = 0;
1819 
1820  Assert(subpath->parallel_safe);
1821  Assert(pathkeys);
1822 
1823  pathnode->path.pathtype = T_GatherMerge;
1824  pathnode->path.parent = rel;
1825  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1826  required_outer);
1827  pathnode->path.parallel_aware = false;
1828 
1829  pathnode->subpath = subpath;
1830  pathnode->num_workers = subpath->parallel_workers;
1831  pathnode->path.pathkeys = pathkeys;
1832  pathnode->path.pathtarget = target ? target : rel->reltarget;
1833  pathnode->path.rows += subpath->rows;
1834 
1835  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1836  {
1837  /* Subpath is adequately ordered, we won't need to sort it */
1838  input_startup_cost += subpath->startup_cost;
1839  input_total_cost += subpath->total_cost;
1840  }
1841  else
1842  {
1843  /* We'll need to insert a Sort node, so include cost for that */
1844  Path sort_path; /* dummy for result of cost_sort */
1845 
1846  cost_sort(&sort_path,
1847  root,
1848  pathkeys,
1849  subpath->total_cost,
1850  subpath->rows,
1851  subpath->pathtarget->width,
1852  0.0,
1853  work_mem,
1854  -1);
1855  input_startup_cost += sort_path.startup_cost;
1856  input_total_cost += sort_path.total_cost;
1857  }
1858 
1859  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1860  input_startup_cost, input_total_cost, rows);
1861 
1862  return pathnode;
1863 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
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:413
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
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:2032
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681
double Cost
Definition: nodes.h:667
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_gather_path()

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

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

1905 {
1906  GatherPath *pathnode = makeNode(GatherPath);
1907 
1908  Assert(subpath->parallel_safe);
1909 
1910  pathnode->path.pathtype = T_Gather;
1911  pathnode->path.parent = rel;
1912  pathnode->path.pathtarget = target;
1913  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1914  required_outer);
1915  pathnode->path.parallel_aware = false;
1916  pathnode->path.parallel_safe = false;
1917  pathnode->path.parallel_workers = 0;
1918  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1919 
1920  pathnode->subpath = subpath;
1921  pathnode->num_workers = subpath->parallel_workers;
1922  pathnode->single_copy = false;
1923 
1924  if (pathnode->num_workers == 0)
1925  {
1926  pathnode->path.pathkeys = subpath->pathkeys;
1927  pathnode->num_workers = 1;
1928  pathnode->single_copy = true;
1929  }
1930 
1931  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1932 
1933  return pathnode;
1934 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
bool single_copy
Definition: pathnodes.h:1514
int num_workers
Definition: pathnodes.h:1515
NodeTag pathtype
Definition: pathnodes.h:1152
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * subpath
Definition: pathnodes.h:1513
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
bool parallel_safe
Definition: pathnodes.h:1160
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:375
Definition: nodes.h:83
bool parallel_aware
Definition: pathnodes.h:1159
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_group_path()

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

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

Referenced by add_paths_to_grouping_rel(), and create_partial_grouping_paths().

2926 {
2927  GroupPath *pathnode = makeNode(GroupPath);
2928  PathTarget *target = rel->reltarget;
2929 
2930  pathnode->path.pathtype = T_Group;
2931  pathnode->path.parent = rel;
2932  pathnode->path.pathtarget = target;
2933  /* For now, assume we are above any joins, so no parameterization */
2934  pathnode->path.param_info = NULL;
2935  pathnode->path.parallel_aware = false;
2936  pathnode->path.parallel_safe = rel->consider_parallel &&
2937  subpath->parallel_safe;
2938  pathnode->path.parallel_workers = subpath->parallel_workers;
2939  /* Group doesn't change sort ordering */
2940  pathnode->path.pathkeys = subpath->pathkeys;
2941 
2942  pathnode->subpath = subpath;
2943 
2944  pathnode->groupClause = groupClause;
2945  pathnode->qual = qual;
2946 
2947  cost_group(&pathnode->path, root,
2948  list_length(groupClause),
2949  numGroups,
2950  qual,
2951  subpath->startup_cost, subpath->total_cost,
2952  subpath->rows);
2953 
2954  /* add tlist eval cost for each output row */
2955  pathnode->path.startup_cost += target->cost.startup;
2956  pathnode->path.total_cost += target->cost.startup +
2957  target->cost.per_tuple * pathnode->path.rows;
2958 
2959  return pathnode;
2960 }
List * qual
Definition: pathnodes.h:1694
PathTarget * pathtarget
Definition: pathnodes.h:1155
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1152
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1165
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:2687
RelOptInfo * parent
Definition: pathnodes.h:1154
Definition: nodes.h:79
Path path
Definition: pathnodes.h:1691
List * groupClause
Definition: pathnodes.h:1693
Path * subpath
Definition: pathnodes.h:1692
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_group_result_path()

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

Definition at line 1504 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, GroupResultPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, GroupResultPath::quals, Path::rows, QualCost::startup, Path::startup_cost, T_Result, and Path::total_cost.

Referenced by create_degenerate_grouping_paths(), and query_planner().

1506 {
1508 
1509  pathnode->path.pathtype = T_Result;
1510  pathnode->path.parent = rel;
1511  pathnode->path.pathtarget = target;
1512  pathnode->path.param_info = NULL; /* there are no other rels... */
1513  pathnode->path.parallel_aware = false;
1514  pathnode->path.parallel_safe = rel->consider_parallel;
1515  pathnode->path.parallel_workers = 0;
1516  pathnode->path.pathkeys = NIL;
1517  pathnode->quals = havingqual;
1518 
1519  /*
1520  * We can't quite use cost_resultscan() because the quals we want to
1521  * account for are not baserestrict quals of the rel. Might as well just
1522  * hack it here.
1523  */
1524  pathnode->path.rows = 1;
1525  pathnode->path.startup_cost = target->cost.startup;
1526  pathnode->path.total_cost = target->cost.startup +
1527  cpu_tuple_cost + target->cost.per_tuple;
1528 
1529  /*
1530  * Add cost of qual, if any --- but we ignore its selectivity, since our
1531  * rowcount estimate should be 1 no matter what the qual is.
1532  */
1533  if (havingqual)
1534  {
1535  QualCost qual_cost;
1536 
1537  cost_qual_eval(&qual_cost, havingqual, root);
1538  /* havingqual is evaluated once at startup */
1539  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1540  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1541  }
1542 
1543  return pathnode;
1544 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1152
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4161
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
bool consider_parallel
Definition: pathnodes.h:678
double cpu_tuple_cost
Definition: costsize.c:120
bool parallel_aware
Definition: pathnodes.h:1159

◆ create_groupingsets_path()

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

Definition at line 3098 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, RelOptInfo::reltarget, GroupingSetsPath::rollups, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupingSetsPath::subpath, T_Agg, Path::total_cost, AggClauseCosts::transitionSpace, GroupingSetsPath::transitionSpace, PathTarget::width, and work_mem.

Referenced by consider_groupingsets_paths().

3106 {
3108  PathTarget *target = rel->reltarget;
3109  ListCell *lc;
3110  bool is_first = true;
3111  bool is_first_sort = true;
3112 
3113  /* The topmost generated Plan node will be an Agg */
3114  pathnode->path.pathtype = T_Agg;
3115  pathnode->path.parent = rel;
3116  pathnode->path.pathtarget = target;
3117  pathnode->path.param_info = subpath->param_info;
3118  pathnode->path.parallel_aware = false;
3119  pathnode->path.parallel_safe = rel->consider_parallel &&
3120  subpath->parallel_safe;
3121  pathnode->path.parallel_workers = subpath->parallel_workers;
3122  pathnode->subpath = subpath;
3123 
3124  /*
3125  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
3126  * to AGG_HASHED, here if possible.
3127  */
3128  if (aggstrategy == AGG_SORTED &&
3129  list_length(rollups) == 1 &&
3130  ((RollupData *) linitial(rollups))->groupClause == NIL)
3131  aggstrategy = AGG_PLAIN;
3132 
3133  if (aggstrategy == AGG_MIXED &&
3134  list_length(rollups) == 1)
3135  aggstrategy = AGG_HASHED;
3136 
3137  /*
3138  * Output will be in sorted order by group_pathkeys if, and only if, there
3139  * is a single rollup operation on a non-empty list of grouping
3140  * expressions.
3141  */
3142  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
3143  pathnode->path.pathkeys = root->group_pathkeys;
3144  else
3145  pathnode->path.pathkeys = NIL;
3146 
3147  pathnode->aggstrategy = aggstrategy;
3148  pathnode->rollups = rollups;
3149  pathnode->qual = having_qual;
3150  pathnode->transitionSpace = agg_costs ? agg_costs->transitionSpace : 0;
3151 
3152  Assert(rollups != NIL);
3153  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
3154  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
3155 
3156  foreach(lc, rollups)
3157  {
3158  RollupData *rollup = lfirst(lc);
3159  List *gsets = rollup->gsets;
3160  int numGroupCols = list_length(linitial(gsets));
3161 
3162  /*
3163  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
3164  * (already-sorted) input, and following ones do their own sort.
3165  *
3166  * In AGG_HASHED mode, there is one rollup for each grouping set.
3167  *
3168  * In AGG_MIXED mode, the first rollups are hashed, the first
3169  * non-hashed one takes the (already-sorted) input, and following ones
3170  * do their own sort.
3171  */
3172  if (is_first)
3173  {
3174  cost_agg(&pathnode->path, root,
3175  aggstrategy,
3176  agg_costs,
3177  numGroupCols,
3178  rollup->numGroups,
3179  having_qual,
3180  subpath->startup_cost,
3181  subpath->total_cost,
3182  subpath->rows,
3183  subpath->pathtarget->width);
3184  is_first = false;
3185  if (!rollup->is_hashed)
3186  is_first_sort = false;
3187  }
3188  else
3189  {
3190  Path sort_path; /* dummy for result of cost_sort */
3191  Path agg_path; /* dummy for result of cost_agg */
3192 
3193  if (rollup->is_hashed || is_first_sort)
3194  {
3195  /*
3196  * Account for cost of aggregation, but don't charge input
3197  * cost again
3198  */
3199  cost_agg(&agg_path, root,
3200  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
3201  agg_costs,
3202  numGroupCols,
3203  rollup->numGroups,
3204  having_qual,
3205  0.0, 0.0,
3206  subpath->rows,
3207  subpath->pathtarget->width);
3208  if (!rollup->is_hashed)
3209  is_first_sort = false;
3210  }
3211  else
3212  {
3213  /* Account for cost of sort, but don't charge input cost again */
3214  cost_sort(&sort_path, root, NIL,
3215  0.0,
3216  subpath->rows,
3217  subpath->pathtarget->width,
3218  0.0,
3219  work_mem,
3220  -1.0);
3221 
3222  /* Account for cost of aggregation */
3223 
3224  cost_agg(&agg_path, root,
3225  AGG_SORTED,
3226  agg_costs,
3227  numGroupCols,
3228  rollup->numGroups,
3229  having_qual,
3230  sort_path.startup_cost,
3231  sort_path.total_cost,
3232  sort_path.rows,
3233  subpath->pathtarget->width);
3234  }
3235 
3236  pathnode->path.total_cost += agg_path.total_cost;
3237  pathnode->path.rows += agg_path.rows;
3238  }
3239  }
3240 
3241  /* add tlist eval cost for each output row */
3242  pathnode->path.startup_cost += target->cost.startup;
3243  pathnode->path.total_cost += target->cost.startup +
3244  target->cost.per_tuple * pathnode->path.rows;
3245 
3246  return pathnode;
3247 }
List * group_pathkeys
Definition: pathnodes.h:294
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:80
PathTarget * pathtarget
Definition: pathnodes.h:1155
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples, double input_width)
Definition: costsize.c:2415
int parallel_workers
Definition: pathnodes.h:1161
bool is_hashed
Definition: pathnodes.h:1748
ParamPathInfo * param_info
Definition: pathnodes.h:1157
double numGroups
Definition: pathnodes.h:1746
Cost startup
Definition: pathnodes.h:45
uint64 transitionSpace
Definition: pathnodes.h:1762
NodeTag pathtype
Definition: pathnodes.h:1152
Cost per_tuple
Definition: pathnodes.h:46
#define linitial(l)
Definition: pg_list.h:174
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
AggStrategy aggstrategy
Definition: pathnodes.h:1759
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:2032
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
Size transitionSpace
Definition: pathnodes.h:60
bool parallel_aware
Definition: pathnodes.h:1159
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:681
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
List * gsets
Definition: pathnodes.h:1744

◆ create_hashjoin_path()

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

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

2523 {
2524  HashPath *pathnode = makeNode(HashPath);
2525 
2526  pathnode->jpath.path.pathtype = T_HashJoin;
2527  pathnode->jpath.path.parent = joinrel;
2528  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2529  pathnode->jpath.path.param_info =
2531  joinrel,
2532  outer_path,
2533  inner_path,
2534  extra->sjinfo,
2535  required_outer,
2536  &restrict_clauses);
2537  pathnode->jpath.path.parallel_aware =
2538  joinrel->consider_parallel && parallel_hash;
2539  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2540  outer_path->parallel_safe && inner_path->parallel_safe;
2541  /* This is a foolish way to estimate parallel_workers, but for now... */
2542  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2543 
2544  /*
2545  * A hashjoin never has pathkeys, since its output ordering is
2546  * unpredictable due to possible batching. XXX If the inner relation is
2547  * small enough, we could instruct the executor that it must not batch,
2548  * and then we could assume that the output inherits the outer relation's
2549  * ordering, which might save a sort step. However there is considerable
2550  * downside if our estimate of the inner relation size is badly off. For
2551  * the moment we don't risk it. (Note also that if we wanted to take this
2552  * seriously, joinpath.c would have to consider many more paths for the
2553  * outer rel than it does now.)
2554  */
2555  pathnode->jpath.path.pathkeys = NIL;
2556  pathnode->jpath.jointype = jointype;
2557  pathnode->jpath.inner_unique = extra->inner_unique;
2558  pathnode->jpath.outerjoinpath = outer_path;
2559  pathnode->jpath.innerjoinpath = inner_path;
2560  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2561  pathnode->path_hashclauses = hashclauses;
2562  /* final_cost_hashjoin will fill in pathnode->num_batches */
2563 
2564  final_cost_hashjoin(root, pathnode, workspace, extra);
2565 
2566  return pathnode;
2567 }
#define NIL
Definition: pg_list.h:65
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3704
JoinPath jpath
Definition: pathnodes.h:1617
PathTarget * pathtarget
Definition: pathnodes.h:1155
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:1368
Path * innerjoinpath
Definition: pathnodes.h:1544
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2448
List * joinrestrictinfo
Definition: pathnodes.h:1546
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * outerjoinpath
Definition: pathnodes.h:1543
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
Path path
Definition: pathnodes.h:1536
bool parallel_safe
Definition: pathnodes.h:1160
bool inner_unique
Definition: pathnodes.h:1540
bool consider_parallel
Definition: pathnodes.h:678
JoinType jointype
Definition: pathnodes.h:1538
bool parallel_aware
Definition: pathnodes.h:1159
List * path_hashclauses
Definition: pathnodes.h:1618
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_incremental_sort_path()

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

Definition at line 2827 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_incremental_sort(), makeNode, IncrementalSortPath::nPresortedCols, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SortPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, sort(), IncrementalSortPath::spath, Path::startup_cost, subpath(), SortPath::subpath, T_IncrementalSort, Path::total_cost, PathTarget::width, and work_mem.

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

2833 {
2835  SortPath *pathnode = &sort->spath;
2836 
2837  pathnode->path.pathtype = T_IncrementalSort;
2838  pathnode->path.parent = rel;
2839  /* Sort doesn't project, so use source path's pathtarget */
2840  pathnode->path.pathtarget = subpath->pathtarget;
2841  /* For now, assume we are above any joins, so no parameterization */
2842  pathnode->path.param_info = NULL;
2843  pathnode->path.parallel_aware = false;
2844  pathnode->path.parallel_safe = rel->consider_parallel &&
2845  subpath->parallel_safe;
2846  pathnode->path.parallel_workers = subpath->parallel_workers;
2847  pathnode->path.pathkeys = pathkeys;
2848 
2849  pathnode->subpath = subpath;
2850 
2851  cost_incremental_sort(&pathnode->path,
2852  root, pathkeys, presorted_keys,
2853  subpath->startup_cost,
2854  subpath->total_cost,
2855  subpath->rows,
2856  subpath->pathtarget->width,
2857  0.0, /* XXX comparison_cost shouldn't be 0? */
2858  work_mem, limit_tuples);
2859 
2860  sort->nPresortedCols = presorted_keys;
2861 
2862  return sort;
2863 }
void cost_incremental_sort(Path *path, PlannerInfo *root, List *pathkeys, int presorted_keys, Cost input_startup_cost, Cost input_total_cost, double input_tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1893
PathTarget * pathtarget
Definition: pathnodes.h:1155
Path * subpath
Definition: pathnodes.h:1666
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Datum sort(PG_FUNCTION_ARGS)
Definition: _int_op.c:195
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
Path path
Definition: pathnodes.h:1665
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_index_path()

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

Definition at line 997 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_index(), get_baserel_parampathinfo(), IndexPath::indexclauses, IndexPath::indexinfo, IndexPath::indexorderbycols, IndexPath::indexorderbys, IndexPath::indexscandir, makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, 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().

1008 {
1009  IndexPath *pathnode = makeNode(IndexPath);
1010  RelOptInfo *rel = index->rel;
1011 
1012  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1013  pathnode->path.parent = rel;
1014  pathnode->path.pathtarget = rel->reltarget;
1015  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1016  required_outer);
1017  pathnode->path.parallel_aware = false;
1018  pathnode->path.parallel_safe = rel->consider_parallel;
1019  pathnode->path.parallel_workers = 0;
1020  pathnode->path.pathkeys = pathkeys;
1021 
1022  pathnode->indexinfo = index;
1023  pathnode->indexclauses = indexclauses;
1024  pathnode->indexorderbys = indexorderbys;
1025  pathnode->indexorderbycols = indexorderbycols;
1026  pathnode->indexscandir = indexscandir;
1027 
1028  cost_index(pathnode, root, loop_count, partial_path);
1029 
1030  return pathnode;
1031 }
List * indexorderbycols
Definition: pathnodes.h:1220
PathTarget * pathtarget
Definition: pathnodes.h:1155
Path path
Definition: pathnodes.h:1216
IndexOptInfo * indexinfo
Definition: pathnodes.h:1217
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1278
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
List * indexclauses
Definition: pathnodes.h:1218
NodeTag pathtype
Definition: pathnodes.h:1152
RelOptInfo * rel
Definition: pathnodes.h:826
RelOptInfo * parent
Definition: pathnodes.h:1154
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:488
List * indexorderbys
Definition: pathnodes.h:1219
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
ScanDirection indexscandir
Definition: pathnodes.h:1221
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681

◆ create_limit_path()

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

Definition at line 3663 of file pathnode.c.

References adjust_limit_rows_costs(), RelOptInfo::consider_parallel, LimitPath::limitCount, LimitPath::limitOffset, LimitPath::limitOption, 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().

3668 {
3669  LimitPath *pathnode = makeNode(LimitPath);
3670 
3671  pathnode->path.pathtype = T_Limit;
3672  pathnode->path.parent = rel;
3673  /* Limit doesn't project, so use source path's pathtarget */
3674  pathnode->path.pathtarget = subpath->pathtarget;
3675  /* For now, assume we are above any joins, so no parameterization */
3676  pathnode->path.param_info = NULL;
3677  pathnode->path.parallel_aware = false;
3678  pathnode->path.parallel_safe = rel->consider_parallel &&
3679  subpath->parallel_safe;
3680  pathnode->path.parallel_workers = subpath->parallel_workers;
3681  pathnode->path.rows = subpath->rows;
3682  pathnode->path.startup_cost = subpath->startup_cost;
3683  pathnode->path.total_cost = subpath->total_cost;
3684  pathnode->path.pathkeys = subpath->pathkeys;
3685  pathnode->subpath = subpath;
3686  pathnode->limitOffset = limitOffset;
3687  pathnode->limitCount = limitCount;
3688  pathnode->limitOption = limitOption;
3689 
3690  /*
3691  * Adjust the output rows count and costs according to the offset/limit.
3692  */
3693  adjust_limit_rows_costs(&pathnode->path.rows,
3694  &pathnode->path.startup_cost,
3695  &pathnode->path.total_cost,
3696  offset_est, count_est);
3697 
3698  return pathnode;
3699 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
LimitOption limitOption
Definition: pathnodes.h:1858
Node * limitOffset
Definition: pathnodes.h:1856
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
void adjust_limit_rows_costs(double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
Definition: pathnode.c:3718
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
Path * subpath
Definition: pathnodes.h:1855
RelOptInfo * parent
Definition: pathnodes.h:1154
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
Path path
Definition: pathnodes.h:1854
bool parallel_aware
Definition: pathnodes.h:1159
Node * limitCount
Definition: pathnodes.h:1857
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
Definition: nodes.h:88

◆ create_lockrows_path()

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

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

3501 {
3502  LockRowsPath *pathnode = makeNode(LockRowsPath);
3503 
3504  pathnode->path.pathtype = T_LockRows;
3505  pathnode->path.parent = rel;
3506  /* LockRows doesn't project, so use source path's pathtarget */
3507  pathnode->path.pathtarget = subpath->pathtarget;
3508  /* For now, assume we are above any joins, so no parameterization */
3509  pathnode->path.param_info = NULL;
3510  pathnode->path.parallel_aware = false;
3511  pathnode->path.parallel_safe = false;
3512  pathnode->path.parallel_workers = 0;
3513  pathnode->path.rows = subpath->rows;
3514 
3515  /*
3516  * The result cannot be assumed sorted, since locking might cause the sort
3517  * key columns to be replaced with new values.
3518  */
3519  pathnode->path.pathkeys = NIL;
3520 
3521  pathnode->subpath = subpath;
3522  pathnode->rowMarks = rowMarks;
3523  pathnode->epqParam = epqParam;
3524 
3525  /*
3526  * We should charge something extra for the costs of row locking and
3527  * possible refetches, but it's hard to say how much. For now, use
3528  * cpu_tuple_cost per row.
3529  */
3530  pathnode->path.startup_cost = subpath->startup_cost;
3531  pathnode->path.total_cost = subpath->total_cost +
3532  cpu_tuple_cost * subpath->rows;
3533 
3534  return pathnode;
3535 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
List * rowMarks
Definition: pathnodes.h:1820
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * subpath
Definition: pathnodes.h:1819
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
double cpu_tuple_cost
Definition: costsize.c:120
bool parallel_aware
Definition: pathnodes.h:1159
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1553 {
1554  MaterialPath *pathnode = makeNode(MaterialPath);
1555 
1556  Assert(subpath->parent == rel);
1557 
1558  pathnode->path.pathtype = T_Material;
1559  pathnode->path.parent = rel;
1560  pathnode->path.pathtarget = rel->reltarget;
1561  pathnode->path.param_info = subpath->param_info;
1562  pathnode->path.parallel_aware = false;
1563  pathnode->path.parallel_safe = rel->consider_parallel &&
1564  subpath->parallel_safe;
1565  pathnode->path.parallel_workers = subpath->parallel_workers;
1566  pathnode->path.pathkeys = subpath->pathkeys;
1567 
1568  pathnode->subpath = subpath;
1569 
1570  cost_material(&pathnode->path,
1571  subpath->startup_cost,
1572  subpath->total_cost,
1573  subpath->rows,
1574  subpath->pathtarget->width);
1575 
1576  return pathnode;
1577 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
Path * subpath
Definition: pathnodes.h:1474
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
Cost total_cost
Definition: pathnodes.h:1166
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2361
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_merge_append_path()

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

Definition at line 1404 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_length(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, 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_orderedappend_paths().

1409 {
1411  Cost input_startup_cost;
1412  Cost input_total_cost;
1413  ListCell *l;
1414 
1415  pathnode->path.pathtype = T_MergeAppend;
1416  pathnode->path.parent = rel;
1417  pathnode->path.pathtarget = rel->reltarget;
1419  required_outer);
1420  pathnode->path.parallel_aware = false;
1421  pathnode->path.parallel_safe = rel->consider_parallel;
1422  pathnode->path.parallel_workers = 0;
1423  pathnode->path.pathkeys = pathkeys;
1424  pathnode->subpaths = subpaths;
1425 
1426  /*
1427  * Apply query-wide LIMIT if known and path is for sole base relation.
1428  * (Handling this at this low level is a bit klugy.)
1429  */
1430  if (bms_equal(rel->relids, root->all_baserels))
1431  pathnode->limit_tuples = root->limit_tuples;
1432  else
1433  pathnode->limit_tuples = -1.0;
1434 
1435  /*
1436  * Add up the sizes and costs of the input paths.
1437  */
1438  pathnode->path.rows = 0;
1439  input_startup_cost = 0;
1440  input_total_cost = 0;
1441  foreach(l, subpaths)
1442  {
1443  Path *subpath = (Path *) lfirst(l);
1444 
1445  pathnode->path.rows += subpath->rows;
1446  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1447  subpath->parallel_safe;
1448 
1449  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1450  {
1451  /* Subpath is adequately ordered, we won't need to sort it */
1452  input_startup_cost += subpath->startup_cost;
1453  input_total_cost += subpath->total_cost;
1454  }
1455  else
1456  {
1457  /* We'll need to insert a Sort node, so include cost for that */
1458  Path sort_path; /* dummy for result of cost_sort */
1459 
1460  cost_sort(&sort_path,
1461  root,
1462  pathkeys,
1463  subpath->total_cost,
1464  subpath->parent->tuples,
1465  subpath->pathtarget->width,
1466  0.0,
1467  work_mem,
1468  pathnode->limit_tuples);
1469  input_startup_cost += sort_path.startup_cost;
1470  input_total_cost += sort_path.total_cost;
1471  }
1472 
1473  /* All child paths must have same parameterization */
1474  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1475  }
1476 
1477  /*
1478  * Now we can compute total costs of the MergeAppend. If there's exactly
1479  * one child path, the MergeAppend is a no-op and will be discarded later
1480  * (in setrefs.c); otherwise we do the normal cost calculation.
1481  */
1482  if (list_length(subpaths) == 1)
1483  {
1484  pathnode->path.startup_cost = input_startup_cost;
1485  pathnode->path.total_cost = input_total_cost;
1486  }
1487  else
1488  cost_merge_append(&pathnode->path, root,
1489  pathkeys, list_length(subpaths),
1490  input_startup_cost, input_total_cost,
1491  pathnode->path.rows);
1492 
1493  return pathnode;
1494 }
PathTarget * pathtarget
Definition: pathnodes.h:1155
double tuples
Definition: pathnodes.h:710
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Relids all_baserels
Definition: pathnodes.h:221
double limit_tuples
Definition: pathnodes.h:331
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1173
Relids relids
Definition: pathnodes.h:670
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:324
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:2032
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
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:2312
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
static int list_length(const List *l)
Definition: pg_list.h:149
bool consider_parallel
Definition: pathnodes.h:678
bool parallel_aware
Definition: pathnodes.h:1159
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1575
struct PathTarget * reltarget
Definition: pathnodes.h:681
double limit_tuples
Definition: pathnodes.h:1449
double Cost
Definition: nodes.h:667
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:94

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

2459 {
2460  MergePath *pathnode = makeNode(MergePath);
2461 
2462  pathnode->jpath.path.pathtype = T_MergeJoin;
2463  pathnode->jpath.path.parent = joinrel;
2464  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2465  pathnode->jpath.path.param_info =
2467  joinrel,
2468  outer_path,
2469  inner_path,
2470  extra->sjinfo,
2471  required_outer,
2472  &restrict_clauses);
2473  pathnode->jpath.path.parallel_aware = false;
2474  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2475  outer_path->parallel_safe && inner_path->parallel_safe;
2476  /* This is a foolish way to estimate parallel_workers, but for now... */
2477  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2478  pathnode->jpath.path.pathkeys = pathkeys;
2479  pathnode->jpath.jointype = jointype;
2480  pathnode->jpath.inner_unique = extra->inner_unique;
2481  pathnode->jpath.outerjoinpath = outer_path;
2482  pathnode->jpath.innerjoinpath = inner_path;
2483  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2484  pathnode->path_mergeclauses = mergeclauses;
2485  pathnode->outersortkeys = outersortkeys;
2486  pathnode->innersortkeys = innersortkeys;
2487  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2488  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2489 
2490  final_cost_mergejoin(root, pathnode, workspace, extra);
2491 
2492  return pathnode;
2493 }
List * path_mergeclauses
Definition: pathnodes.h:1599
List * outersortkeys
Definition: pathnodes.h:1600
PathTarget * pathtarget
Definition: pathnodes.h:1155
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:1368
Path * innerjoinpath
Definition: pathnodes.h:1544
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2448
List * joinrestrictinfo
Definition: pathnodes.h:1546
RelOptInfo * parent
Definition: pathnodes.h:1154
Path * outerjoinpath
Definition: pathnodes.h:1543
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
Path path
Definition: pathnodes.h:1536
bool parallel_safe
Definition: pathnodes.h:1160
bool inner_unique
Definition: pathnodes.h:1540
bool consider_parallel
Definition: pathnodes.h:678
List * innersortkeys
Definition: pathnodes.h:1601
JoinType jointype
Definition: pathnodes.h:1538
JoinPath jpath
Definition: pathnodes.h:1598
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3268

◆ create_minmaxagg_path()

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

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

3264 {
3265  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3266  Cost initplan_cost;
3267  ListCell *lc;
3268 
3269  /* The topmost generated Plan node will be a Result */
3270  pathnode->path.pathtype = T_Result;
3271  pathnode->path.parent = rel;
3272  pathnode->path.pathtarget = target;
3273  /* For now, assume we are above any joins, so no parameterization */
3274  pathnode->path.param_info = NULL;
3275  pathnode->path.parallel_aware = false;
3276  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3277  pathnode->path.parallel_safe = false;
3278  pathnode->path.parallel_workers = 0;
3279  /* Result is one unordered row */
3280  pathnode->path.rows = 1;
3281  pathnode->path.pathkeys = NIL;
3282 
3283  pathnode->mmaggregates = mmaggregates;
3284  pathnode->quals = quals;
3285 
3286  /* Calculate cost of all the initplans ... */
3287  initplan_cost = 0;
3288  foreach(lc, mmaggregates)
3289  {
3290  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3291 
3292  initplan_cost += mminfo->pathcost;
3293  }
3294 
3295  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3296  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3297  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3298  target->cost.per_tuple + cpu_tuple_cost;
3299 
3300  /*
3301  * Add cost of qual, if any --- but we ignore its selectivity, since our
3302  * rowcount estimate should be 1 no matter what the qual is.
3303  */
3304  if (quals)
3305  {
3306  QualCost qual_cost;
3307 
3308  cost_qual_eval(&qual_cost, quals, root);
3309  pathnode->path.startup_cost += qual_cost.startup;
3310  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3311  }
3312 
3313  return pathnode;
3314 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
List * quals
Definition: pathnodes.h:1772
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1152
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:4161
Cost startup_cost
Definition: pathnodes.h:1165
RelOptInfo * parent
Definition: pathnodes.h:1154
List * mmaggregates
Definition: pathnodes.h:1771
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
QualCost cost
Definition: pathnodes.h:1086
double cpu_tuple_cost
Definition: costsize.c:120
bool parallel_aware
Definition: pathnodes.h:1159
double Cost
Definition: nodes.h:667

◆ create_modifytable_path()

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

Definition at line 3558 of file pathnode.c.

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

Referenced by grouping_planner(), and inheritance_planner().

3567 {
3569  double total_size;
3570  ListCell *lc;
3571 
3572  Assert(list_length(resultRelations) == list_length(subpaths));
3573  Assert(list_length(resultRelations) == list_length(subroots));
3574  Assert(withCheckOptionLists == NIL ||
3575  list_length(resultRelations) == list_length(withCheckOptionLists));
3576  Assert(returningLists == NIL ||
3577  list_length(resultRelations) == list_length(returningLists));
3578 
3579  pathnode->path.pathtype = T_ModifyTable;
3580  pathnode->path.parent = rel;
3581  /* pathtarget is not interesting, just make it minimally valid */
3582  pathnode->path.pathtarget = rel->reltarget;
3583  /* For now, assume we are above any joins, so no parameterization */
3584  pathnode->path.param_info = NULL;
3585  pathnode->path.parallel_aware = false;
3586  pathnode->path.parallel_safe = false;
3587  pathnode->path.parallel_workers = 0;
3588  pathnode->path.pathkeys = NIL;
3589 
3590  /*
3591  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3592  *
3593  * Currently, we don't charge anything extra for the actual table
3594  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3595  * expressions if any. It would only be window dressing, since
3596  * ModifyTable is always a top-level node and there is no way for the
3597  * costs to change any higher-level planning choices. But we might want
3598  * to make it look better sometime.
3599  */
3600  pathnode->path.startup_cost = 0;
3601  pathnode->path.total_cost = 0;
3602  pathnode->path.rows = 0;
3603  total_size = 0;
3604  foreach(lc, subpaths)
3605  {
3606  Path *subpath = (Path *) lfirst(lc);
3607 
3608  if (lc == list_head(subpaths)) /* first node? */
3609  pathnode->path.startup_cost = subpath->startup_cost;
3610  pathnode->path.total_cost += subpath->total_cost;
3611  if (returningLists != NIL)
3612  {
3613  pathnode->path.rows += subpath->rows;
3614  total_size += subpath->pathtarget->width * subpath->rows;
3615  }
3616  }
3617 
3618  /*
3619  * Set width to the average width of the subpath outputs. XXX this is
3620  * totally wrong: we should return an average of the RETURNING tlist
3621  * widths. But it's what happened historically, and improving it is a task
3622  * for another day.
3623  */
3624  if (pathnode->path.rows > 0)
3625  total_size /= pathnode->path.rows;
3626  pathnode->path.pathtarget->width = rint(total_size);
3627 
3628  pathnode->operation = operation;
3629  pathnode->canSetTag = canSetTag;
3630  pathnode->nominalRelation = nominalRelation;
3631  pathnode->rootRelation = rootRelation;
3632  pathnode->partColsUpdated = partColsUpdated;
3633  pathnode->resultRelations = resultRelations;
3634  pathnode->subpaths = subpaths;
3635  pathnode->subroots = subroots;
3636  pathnode->withCheckOptionLists = withCheckOptionLists;
3637  pathnode->returningLists = returningLists;
3638  pathnode->rowMarks = rowMarks;
3639  pathnode->onconflict = onconflict;
3640  pathnode->epqParam = epqParam;
3641 
3642  return pathnode;
3643 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1155
List * returningLists
Definition: pathnodes.h:1843
OnConflictExpr * onconflict
Definition: pathnodes.h:1845
Index nominalRelation
Definition: pathnodes.h:1836
int parallel_workers
Definition: pathnodes.h:1161
ParamPathInfo * param_info
Definition: pathnodes.h:1157
NodeTag pathtype
Definition: pathnodes.h:1152
Cost startup_cost
Definition: pathnodes.h:1165
bool partColsUpdated
Definition: pathnodes.h:1838
RelOptInfo * parent
Definition: pathnodes.h:1154
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
int64 total_size
Definition: pg_checksums.c:68
Cost total_cost
Definition: pathnodes.h:1166
List * pathkeys
Definition: pathnodes.h:1168
#define makeNode(_type_)
Definition: nodes.h:581
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
double rows
Definition: pathnodes.h:1164
bool parallel_safe
Definition: pathnodes.h:1160
Index rootRelation
Definition: pathnodes.h:1837
static int list_length(const List *l)
Definition: pg_list.h:149
List * withCheckOptionLists
Definition: pathnodes.h:1842
CmdType operation
Definition: pathnodes.h:1834
List * resultRelations
Definition: pathnodes.h:1839
bool parallel_aware
Definition: pathnodes.h:1159
struct PathTarget * reltarget
Definition: pathnodes.h:681
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_namedtuplestorescan_path()

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

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

2075 {
2076  Path *pathnode = makeNode(Path);
2077 
2078  pathnode->pathtype = T_NamedTuplestoreScan;
2079  pathnode->parent = rel;
2080  pathnode->pathtarget = rel->reltarget;
2081  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2082  required_outer);
2083  pathnode->parallel_aware = false;
2084  pathnode->parallel_safe = rel->consider_parallel;