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)
 
AppendPathcreate_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *partial_subpaths, List *pathkeys, Relids required_outer, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
 
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)
 
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, 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:659
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:401
void pfree(void *pointer)
Definition: mcxt.c:1056
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1122
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
bool consider_parallel
Definition: pathnodes.h:651
PathKeysComparison
Definition: paths.h:181
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
#define foreach_current_index(cell)
Definition: pg_list.h:381

◆ 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:659
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define lfirst(lc)
Definition: pg_list.h:190
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

References BMS_EQUAL, BMS_SUBSET1, BMS_SUBSET2, bms_subset_compare(), CHECK_FOR_INTERRUPTS, compare_path_costs_fuzzily(), compare_pathkeys(), COSTS_BETTER1, COSTS_BETTER2, COSTS_DIFFERENT, COSTS_EQUAL, 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(), 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:576
ParamPathInfo * param_info
Definition: pathnodes.h:1119
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
#define foreach_delete_current(lst, cell)
Definition: pg_list.h:368
List * list_insert_nth(List *list, int pos, void *datum)
Definition: list.c:401
void pfree(void *pointer)
Definition: mcxt.c:1056
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
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:1128
List * pathkeys
Definition: pathnodes.h:1130
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:99
List * pathlist
Definition: pathnodes.h:657
Definition: pg_list.h:50
BMS_Comparison
Definition: bitmapset.h:57
#define foreach_current_index(cell)
Definition: pg_list.h:381

◆ 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:650
ParamPathInfo * param_info
Definition: pathnodes.h:1119
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:285
bool consider_startup
Definition: pathnodes.h:649
Cost startup_cost
Definition: pathnodes.h:1127
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define lfirst(lc)
Definition: pg_list.h:190
#define STD_FUZZ_FACTOR
Definition: pathnode.c:51
PathKeysComparison
Definition: paths.h:181
List * pathlist
Definition: pathnodes.h:657
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 3598 of file pathnode.c.

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

3603 {
3604  double input_rows = *rows;
3605  Cost input_startup_cost = *startup_cost;
3606  Cost input_total_cost = *total_cost;
3607 
3608  if (offset_est != 0)
3609  {
3610  double offset_rows;
3611 
3612  if (offset_est > 0)
3613  offset_rows = (double) offset_est;
3614  else
3615  offset_rows = clamp_row_est(input_rows * 0.10);
3616  if (offset_rows > *rows)
3617  offset_rows = *rows;
3618  if (input_rows > 0)
3619  *startup_cost +=
3620  (input_total_cost - input_startup_cost)
3621  * offset_rows / input_rows;
3622  *rows -= offset_rows;
3623  if (*rows < 1)
3624  *rows = 1;
3625  }
3626 
3627  if (count_est != 0)
3628  {
3629  double count_rows;
3630 
3631  if (count_est > 0)
3632  count_rows = (double) count_est;
3633  else
3634  count_rows = clamp_row_est(input_rows * 0.10);
3635  if (count_rows > *rows)
3636  count_rows = *rows;
3637  if (input_rows > 0)
3638  *total_cost = *startup_cost +
3639  (input_total_cost - input_startup_cost)
3640  * count_rows / input_rows;
3641  *rows = count_rows;
3642  if (*rows < 1)
3643  *rows = 1;
3644  }
3645 }
double clamp_row_est(double nrows)
Definition: costsize.c:187
double Cost
Definition: nodes.h:659

◆ apply_projection_to_path()

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

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

2614 {
2615  QualCost oldcost;
2616 
2617  /*
2618  * If given path can't project, we might need a Result node, so make a
2619  * separate ProjectionPath.
2620  */
2621  if (!is_projection_capable_path(path))
2622  return (Path *) create_projection_path(root, rel, path, target);
2623 
2624  /*
2625  * We can just jam the desired tlist into the existing path, being sure to
2626  * update its cost estimates appropriately.
2627  */
2628  oldcost = path->pathtarget->cost;
2629  path->pathtarget = target;
2630 
2631  path->startup_cost += target->cost.startup - oldcost.startup;
2632  path->total_cost += target->cost.startup - oldcost.startup +
2633  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2634 
2635  /*
2636  * If the path happens to be a Gather or GatherMerge path, we'd like to
2637  * arrange for the subpath to return the required target list so that
2638  * workers can help project. But if there is something that is not
2639  * parallel-safe in the target expressions, then we can't.
2640  */
2641  if ((IsA(path, GatherPath) ||IsA(path, GatherMergePath)) &&
2642  is_parallel_safe(root, (Node *) target->exprs))
2643  {
2644  /*
2645  * We always use create_projection_path here, even if the subpath is
2646  * projection-capable, so as to avoid modifying the subpath in place.
2647  * It seems unlikely at present that there could be any other
2648  * references to the subpath, but better safe than sorry.
2649  *
2650  * Note that we don't change the parallel path's cost estimates; it
2651  * might be appropriate to do so, to reflect the fact that the bulk of
2652  * the target evaluation will happen in workers.
2653  */
2654  if (IsA(path, GatherPath))
2655  {
2656  GatherPath *gpath = (GatherPath *) path;
2657 
2658  gpath->subpath = (Path *)
2660  gpath->subpath->parent,
2661  gpath->subpath,
2662  target);
2663  }
2664  else
2665  {
2666  GatherMergePath *gmpath = (GatherMergePath *) path;
2667 
2668  gmpath->subpath = (Path *)
2670  gmpath->subpath->parent,
2671  gmpath->subpath,
2672  target);
2673  }
2674  }
2675  else if (path->parallel_safe &&
2676  !is_parallel_safe(root, (Node *) target->exprs))
2677  {
2678  /*
2679  * We're inserting a parallel-restricted target list into a path
2680  * currently marked parallel-safe, so we have to mark it as no longer
2681  * safe.
2682  */
2683  path->parallel_safe = false;
2684  }
2685 
2686  return path;
2687 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
PathTarget * pathtarget
Definition: pathnodes.h:1117
Definition: nodes.h:525
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2519
Cost startup
Definition: pathnodes.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:854
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * subpath
Definition: pathnodes.h:1467
List * exprs
Definition: pathnodes.h:1046
Cost total_cost
Definition: pathnodes.h:1128
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6766

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

References add_child_join_rel_equivalences(), add_join_rel(), adjust_appendrel_attrs(), RelOptInfo::allvisfrac, 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::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, RelOptInfo::partitioned_child_rels, 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().

776 {
777  RelOptInfo *joinrel = makeNode(RelOptInfo);
778  AppendRelInfo **appinfos;
779  int nappinfos;
780 
781  /* Only joins between "other" relations land here. */
782  Assert(IS_OTHER_REL(outer_rel) && IS_OTHER_REL(inner_rel));
783 
784  /* The parent joinrel should have consider_partitionwise_join set. */
785  Assert(parent_joinrel->consider_partitionwise_join);
786 
787  joinrel->reloptkind = RELOPT_OTHER_JOINREL;
788  joinrel->relids = bms_union(outer_rel->relids, inner_rel->relids);
789  joinrel->rows = 0;
790  /* cheap startup cost is interesting iff not all tuples to be retrieved */
791  joinrel->consider_startup = (root->tuple_fraction > 0);
792  joinrel->consider_param_startup = false;
793  joinrel->consider_parallel = false;
794  joinrel->reltarget = create_empty_pathtarget();
795  joinrel->pathlist = NIL;
796  joinrel->ppilist = NIL;
797  joinrel->partial_pathlist = NIL;
798  joinrel->cheapest_startup_path = NULL;
799  joinrel->cheapest_total_path = NULL;
800  joinrel->cheapest_unique_path = NULL;
802  joinrel->direct_lateral_relids = NULL;
803  joinrel->lateral_relids = NULL;
804  joinrel->relid = 0; /* indicates not a baserel */
805  joinrel->rtekind = RTE_JOIN;
806  joinrel->min_attr = 0;
807  joinrel->max_attr = 0;
808  joinrel->attr_needed = NULL;
809  joinrel->attr_widths = NULL;
810  joinrel->lateral_vars = NIL;
811  joinrel->lateral_referencers = NULL;
812  joinrel->indexlist = NIL;
813  joinrel->pages = 0;
814  joinrel->tuples = 0;
815  joinrel->allvisfrac = 0;
816  joinrel->eclass_indexes = NULL;
817  joinrel->subroot = NULL;
818  joinrel->subplan_params = NIL;
819  joinrel->serverid = InvalidOid;
820  joinrel->userid = InvalidOid;
821  joinrel->useridiscurrent = false;
822  joinrel->fdwroutine = NULL;
823  joinrel->fdw_private = NULL;
824  joinrel->baserestrictinfo = NIL;
825  joinrel->baserestrictcost.startup = 0;
826  joinrel->baserestrictcost.per_tuple = 0;
827  joinrel->joininfo = NIL;
828  joinrel->has_eclass_joins = false;
829  joinrel->consider_partitionwise_join = false; /* might get changed later */
830  joinrel->top_parent_relids = NULL;
831  joinrel->part_scheme = NULL;
832  joinrel->nparts = 0;
833  joinrel->boundinfo = NULL;
834  joinrel->partition_qual = NIL;
835  joinrel->part_rels = NULL;
836  joinrel->partexprs = NULL;
837  joinrel->nullable_partexprs = NULL;
838  joinrel->partitioned_child_rels = NIL;
839 
840  joinrel->top_parent_relids = bms_union(outer_rel->top_parent_relids,
841  inner_rel->top_parent_relids);
842 
843  /* Compute information relevant to foreign relations. */
844  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
845 
846  /* Compute information needed for mapping Vars to the child rel */
847  appinfos = find_appinfos_by_relids(root, joinrel->relids, &nappinfos);
848 
849  /* Set up reltarget struct */
850  build_child_join_reltarget(root, parent_joinrel, joinrel,
851  nappinfos, appinfos);
852 
853  /* Construct joininfo list. */
854  joinrel->joininfo = (List *) adjust_appendrel_attrs(root,
855  (Node *) parent_joinrel->joininfo,
856  nappinfos,
857  appinfos);
858 
859  /*
860  * Lateral relids referred in child join will be same as that referred in
861  * the parent relation.
862  */
863  joinrel->direct_lateral_relids = (Relids) bms_copy(parent_joinrel->direct_lateral_relids);
864  joinrel->lateral_relids = (Relids) bms_copy(parent_joinrel->lateral_relids);
865 
866  /*
867  * If the parent joinrel has pending equivalence classes, so does the
868  * child.
869  */
870  joinrel->has_eclass_joins = parent_joinrel->has_eclass_joins;
871 
872  /* Is the join between partitions itself partitioned? */
873  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
874  jointype);
875 
876  /* Child joinrel is parallel safe if parent is parallel safe. */
877  joinrel->consider_parallel = parent_joinrel->consider_parallel;
878 
879  /* Set estimates of the child-joinrel's size. */
880  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
881  sjinfo, restrictlist);
882 
883  /* We build the join only once. */
884  Assert(!find_join_rel(root, joinrel->relids));
885 
886  /* Add the relation to the PlannerInfo. */
887  add_join_rel(root, joinrel);
888 
889  /*
890  * We might need EquivalenceClass members corresponding to the child join,
891  * so that we can represent sort pathkeys for it. As with children of
892  * baserels, we shouldn't need this unless there are relevant eclass joins
893  * (implying that a merge join might be possible) or pathkeys to sort by.
894  */
895  if (joinrel->has_eclass_joins || has_useful_pathkeys(root, parent_joinrel))
897  nappinfos, appinfos,
898  parent_joinrel, joinrel);
899 
900  pfree(appinfos);
901 
902  return joinrel;
903 }
bool has_eclass_joins
Definition: pathnodes.h:711
struct Path * cheapest_unique_path
Definition: pathnodes.h:662
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:696
#define NIL
Definition: pg_list.h:65
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:640
Relids * attr_needed
Definition: pathnodes.h:676
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:428
#define IS_OTHER_REL(rel)
Definition: pathnodes.h:631
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4483
struct Path * cheapest_startup_path
Definition: pathnodes.h:660
Oid userid
Definition: pathnodes.h:693
double tuples
Definition: pathnodes.h:683
List * baserestrictinfo
Definition: pathnodes.h:705
bool consider_param_startup
Definition: pathnodes.h:650
Definition: nodes.h:525
List * partial_pathlist
Definition: pathnodes.h:659
List * cheapest_parameterized_paths
Definition: pathnodes.h:663
bool useridiscurrent
Definition: pathnodes.h:694
List ** nullable_partexprs
Definition: pathnodes.h:727
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:684
void add_child_join_rel_equivalences(PlannerInfo *root, int nappinfos, AppendRelInfo **appinfos, RelOptInfo *parent_joinrel, RelOptInfo *child_joinrel)
Definition: equivclass.c:2356
PlannerInfo * subroot
Definition: pathnodes.h:687
bool consider_startup
Definition: pathnodes.h:649
Relids lateral_relids
Definition: pathnodes.h:668
Cost per_tuple
Definition: pathnodes.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:491
double tuple_fraction
Definition: pathnodes.h:336
void pfree(void *pointer)
Definition: mcxt.c:1056
List ** partexprs
Definition: pathnodes.h:726
struct Path * cheapest_total_path
Definition: pathnodes.h:661
List * joininfo
Definition: pathnodes.h:709
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:696
int nparts
Definition: pathnodes.h:721
Relids relids
Definition: pathnodes.h:643
List * ppilist
Definition: pathnodes.h:658
Index relid
Definition: pathnodes.h:671
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:723
Relids lateral_referencers
Definition: pathnodes.h:679
Oid serverid
Definition: pathnodes.h:692
Relids direct_lateral_relids
Definition: pathnodes.h:667
bool consider_partitionwise_join
Definition: pathnodes.h:714
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:722
RTEKind rtekind
Definition: pathnodes.h:673
List * indexlist
Definition: pathnodes.h:680
double rows
Definition: pathnodes.h:646
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:697
#define makeNode(_type_)
Definition: nodes.h:573
BlockNumber pages
Definition: pathnodes.h:682
#define Assert(condition)
Definition: c.h:739
List * lateral_vars
Definition: pathnodes.h:678
struct RelOptInfo ** part_rels
Definition: pathnodes.h:724
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool consider_parallel
Definition: pathnodes.h:651
Bitmapset * Relids
Definition: pathnodes.h:28
List * partitioned_child_rels
Definition: pathnodes.h:728
AttrNumber max_attr
Definition: pathnodes.h:675
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1616
bool has_useful_pathkeys(PlannerInfo *root, RelOptInfo *rel)
Definition: pathkeys.c:1856
PartitionScheme part_scheme
Definition: pathnodes.h:720
List * pathlist
Definition: pathnodes.h:657
List * partition_qual
Definition: pathnodes.h:723
int32 * attr_widths
Definition: pathnodes.h:677
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:654
QualCost baserestrictcost
Definition: pathnodes.h:706
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:529
List * subplan_params
Definition: pathnodes.h:688
static void build_child_join_reltarget(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, int nappinfos, AppendRelInfo **appinfos)
Definition: relnode.c:1785
Bitmapset * eclass_indexes
Definition: pathnodes.h:685
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:194
Relids top_parent_relids
Definition: pathnodes.h:716
AttrNumber min_attr
Definition: pathnodes.h:674

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

References add_join_rel(), add_placeholders_to_joinrel(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_del_members(), bms_is_empty(), bms_num_members(), bms_union(), RelOptInfo::boundinfo, build_joinrel_joinlist(), build_joinrel_partition_info(), build_joinrel_restrictlist(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_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::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, RelOptInfo::partitioned_child_rels, 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().

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

◆ build_simple_rel()

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

Definition at line 185 of file relnode.c.

References RelOptInfo::allvisfrac, 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::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::partition_qual, RelOptInfo::partitioned_child_rels, 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().

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

◆ calc_nestloop_required_outer()

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

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

2237 {
2238  Relids required_outer;
2239 
2240  /* inner_path can require rels from outer path, but not vice versa */
2241  Assert(!bms_overlap(outer_paramrels, innerrelids));
2242  /* easy case if inner path is not parameterized */
2243  if (!inner_paramrels)
2244  return bms_copy(outer_paramrels);
2245  /* else, form the union ... */
2246  required_outer = bms_union(outer_paramrels, inner_paramrels);
2247  /* ... and remove any mention of now-satisfied outer rels */
2248  required_outer = bms_del_members(required_outer,
2249  outerrelids);
2250  /* maintain invariant that required_outer is exactly NULL if empty */
2251  if (bms_is_empty(required_outer))
2252  {
2253  bms_free(required_outer);
2254  required_outer = NULL;
2255  }
2256  return required_outer;
2257 }
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:739
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 2266 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().

2267 {
2268  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2269  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2270  Relids required_outer;
2271 
2272  /* neither path can require rels from the other */
2273  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2274  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2275  /* form the union ... */
2276  required_outer = bms_union(outer_paramrels, inner_paramrels);
2277  /* we do not need an explicit test for empty; bms_union gets it right */
2278  return required_outer;
2279 }
RelOptInfo * parent
Definition: pathnodes.h:1116
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
Relids relids
Definition: pathnodes.h:643
#define Assert(condition)
Definition: c.h:739
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:1127
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:71
Cost total_cost
Definition: pathnodes.h:1128
double Cost
Definition: nodes.h:659

◆ 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:1127
Cost total_cost
Definition: pathnodes.h:1128

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

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

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

2931 {
2932  AggPath *pathnode = makeNode(AggPath);
2933 
2934  pathnode->path.pathtype = T_Agg;
2935  pathnode->path.parent = rel;
2936  pathnode->path.pathtarget = target;
2937  /* For now, assume we are above any joins, so no parameterization */
2938  pathnode->path.param_info = NULL;
2939  pathnode->path.parallel_aware = false;
2940  pathnode->path.parallel_safe = rel->consider_parallel &&
2941  subpath->parallel_safe;
2942  pathnode->path.parallel_workers = subpath->parallel_workers;
2943  if (aggstrategy == AGG_SORTED)
2944  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2945  else
2946  pathnode->path.pathkeys = NIL; /* output is unordered */
2947  pathnode->subpath = subpath;
2948 
2949  pathnode->aggstrategy = aggstrategy;
2950  pathnode->aggsplit = aggsplit;
2951  pathnode->numGroups = numGroups;
2952  pathnode->groupClause = groupClause;
2953  pathnode->qual = qual;
2954 
2955  cost_agg(&pathnode->path, root,
2956  aggstrategy, aggcosts,
2957  list_length(groupClause), numGroups,
2958  qual,
2959  subpath->startup_cost, subpath->total_cost,
2960  subpath->rows);
2961 
2962  /* add tlist eval cost for each output row */
2963  pathnode->path.startup_cost += target->cost.startup;
2964  pathnode->path.total_cost += target->cost.startup +
2965  target->cost.per_tuple * pathnode->path.rows;
2966 
2967  return pathnode;
2968 }
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:78
PathTarget * pathtarget
Definition: pathnodes.h:1117
AggStrategy aggstrategy
Definition: pathnodes.h:1663
List * qual
Definition: pathnodes.h:1667
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2151
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
AggSplit aggsplit
Definition: pathnodes.h:1664
double numGroups
Definition: pathnodes.h:1665
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1114
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
List * groupClause
Definition: pathnodes.h:1666
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:651
Path * subpath
Definition: pathnodes.h:1662
bool parallel_aware
Definition: pathnodes.h:1121
Path path
Definition: pathnodes.h:1661
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,
List partitioned_rels,
double  rows 
)

Definition at line 1183 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(), lfirst, PlannerInfo::limit_tuples, AppendPath::limit_tuples, linitial, list_concat(), list_copy(), list_length(), list_sort(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, AppendPath::partitioned_rels, AppendPath::path, PATH_REQ_OUTER, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::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().

1189 {
1190  AppendPath *pathnode = makeNode(AppendPath);
1191  ListCell *l;
1192 
1193  Assert(!parallel_aware || parallel_workers > 0);
1194 
1195  pathnode->path.pathtype = T_Append;
1196  pathnode->path.parent = rel;
1197  pathnode->path.pathtarget = rel->reltarget;
1198 
1199  /*
1200  * When generating an Append path for a partitioned table, there may be
1201  * parameters that are useful so we can eliminate certain partitions
1202  * during execution. Here we'll go all the way and fully populate the
1203  * parameter info data as we do for normal base relations. However, we
1204  * need only bother doing this for RELOPT_BASEREL rels, as
1205  * RELOPT_OTHER_MEMBER_REL's Append paths are merged into the base rel's
1206  * Append subpaths. It would do no harm to do this, we just avoid it to
1207  * save wasting effort.
1208  */
1209  if (partitioned_rels != NIL && root && rel->reloptkind == RELOPT_BASEREL)
1210  pathnode->path.param_info = get_baserel_parampathinfo(root,
1211  rel,
1212  required_outer);
1213  else
1215  required_outer);
1216 
1217  pathnode->path.parallel_aware = parallel_aware;
1218  pathnode->path.parallel_safe = rel->consider_parallel;
1219  pathnode->path.parallel_workers = parallel_workers;
1220  pathnode->path.pathkeys = pathkeys;
1221  pathnode->partitioned_rels = list_copy(partitioned_rels);
1222 
1223  /*
1224  * For parallel append, non-partial paths are sorted by descending total
1225  * costs. That way, the total time to finish all non-partial paths is
1226  * minimized. Also, the partial paths are sorted by descending startup
1227  * costs. There may be some paths that require to do startup work by a
1228  * single worker. In such case, it's better for workers to choose the
1229  * expensive ones first, whereas the leader should choose the cheapest
1230  * startup plan.
1231  */
1232  if (pathnode->path.parallel_aware)
1233  {
1234  /*
1235  * We mustn't fiddle with the order of subpaths when the Append has
1236  * pathkeys. The order they're listed in is critical to keeping the
1237  * pathkeys valid.
1238  */
1239  Assert(pathkeys == NIL);
1240 
1242  list_sort(partial_subpaths, append_startup_cost_compare);
1243  }
1244  pathnode->first_partial_path = list_length(subpaths);
1245  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1246 
1247  /*
1248  * Apply query-wide LIMIT if known and path is for sole base relation.
1249  * (Handling this at this low level is a bit klugy.)
1250  */
1251  if (root != NULL && bms_equal(rel->relids, root->all_baserels))
1252  pathnode->limit_tuples = root->limit_tuples;
1253  else
1254  pathnode->limit_tuples = -1.0;
1255 
1256  foreach(l, pathnode->subpaths)
1257  {
1258  Path *subpath = (Path *) lfirst(l);
1259 
1260  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1261  subpath->parallel_safe;
1262 
1263  /* All child paths must have same parameterization */
1264  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1265  }
1266 
1267  Assert(!parallel_aware || pathnode->path.parallel_safe);
1268 
1269  /*
1270  * If there's exactly one child path, the Append is a no-op and will be
1271  * discarded later (in setrefs.c); therefore, we can inherit the child's
1272  * size and cost, as well as its pathkeys if any (overriding whatever the
1273  * caller might've said). Otherwise, we must do the normal costsize
1274  * calculation.
1275  */
1276  if (list_length(pathnode->subpaths) == 1)
1277  {
1278  Path *child = (Path *) linitial(pathnode->subpaths);
1279 
1280  pathnode->path.rows = child->rows;
1281  pathnode->path.startup_cost = child->startup_cost;
1282  pathnode->path.total_cost = child->total_cost;
1283  pathnode->path.pathkeys = child->pathkeys;
1284  }
1285  else
1286  cost_append(pathnode);
1287 
1288  /* If the caller provided a row estimate, override the computed value. */
1289  if (rows >= 0)
1290  pathnode->path.rows = rows;
1291 
1292  return pathnode;
1293 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
RelOptKind reloptkind
Definition: pathnodes.h:640
double limit_tuples
Definition: pathnodes.h:1379
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * list_copy(const List *oldlist)
Definition: list.c:1404
List * list_concat(List *list1, const List *list2)
Definition: list.c:516
Definition: nodes.h:49
static int append_total_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1305
int first_partial_path
Definition: pathnodes.h:1378
NodeTag pathtype
Definition: pathnodes.h:1114
List * subpaths
Definition: pathnodes.h:1376
static int append_startup_cost_compare(const ListCell *a, const ListCell *b)
Definition: pathnode.c:1327
#define linitial(l)
Definition: pg_list.h:195
Relids all_baserels
Definition: pathnodes.h:227
double limit_tuples
Definition: pathnodes.h:337
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
Relids relids
Definition: pathnodes.h:643
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
void cost_append(AppendPath *apath)
Definition: costsize.c:1875
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:651
List * partitioned_rels
Definition: pathnodes.h:1375
void list_sort(List *list, list_sort_comparator cmp)
Definition: list.c:1482
bool parallel_aware
Definition: pathnodes.h:1121
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1561
struct PathTarget * reltarget
Definition: pathnodes.h:654
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, RelOptInfo::consider_parallel, cost_bitmap_and_node(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, BitmapAndPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, and T_BitmapAnd.

Referenced by choose_bitmap_and().

1082 {
1083  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1084 
1085  pathnode->path.pathtype = T_BitmapAnd;
1086  pathnode->path.parent = rel;
1087  pathnode->path.pathtarget = rel->reltarget;
1088  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1089 
1090  /*
1091  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1092  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1093  * set the flag for this path based only on the relation-level flag,
1094  * without actually iterating over the list of children.
1095  */
1096  pathnode->path.parallel_aware = false;
1097  pathnode->path.parallel_safe = rel->consider_parallel;
1098  pathnode->path.parallel_workers = 0;
1099 
1100  pathnode->path.pathkeys = NIL; /* always unordered */
1101 
1102  pathnode->bitmapquals = bitmapquals;
1103 
1104  /* this sets bitmapselectivity as well as the regular cost fields: */
1105  cost_bitmap_and_node(pathnode, root);
1106 
1107  return pathnode;
1108 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1084
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * bitmapquals
Definition: pathnodes.h:1264
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * parent
Definition: pathnodes.h:1116
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ 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:1117
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:940
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
#define true
Definition: c.h:313
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * bitmapqual
Definition: pathnodes.h:1252
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ create_bitmap_or_path()

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

Definition at line 1115 of file pathnode.c.

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

Referenced by generate_bitmap_or_paths().

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

◆ create_ctescan_path()

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

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

1990 {
1991  Path *pathnode = makeNode(Path);
1992 
1993  pathnode->pathtype = T_CteScan;
1994  pathnode->parent = rel;
1995  pathnode->pathtarget = rel->reltarget;
1996  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1997  required_outer);
1998  pathnode->parallel_aware = false;
1999  pathnode->parallel_safe = rel->consider_parallel;
2000  pathnode->parallel_workers = 0;
2001  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
2002 
2003  cost_ctescan(pathnode, root, rel, pathnode->param_info);
2004 
2005  return pathnode;
2006 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1498
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * parent
Definition: pathnodes.h:1116
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

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

2150 {
2151  ForeignPath *pathnode = makeNode(ForeignPath);
2152 
2153  /*
2154  * We should use get_joinrel_parampathinfo to handle parameterized paths,
2155  * but the API of this function doesn't support it, and existing
2156  * extensions aren't yet trying to build such paths anyway. For the
2157  * moment just throw an error if someone tries it; eventually we should
2158  * revisit this.
2159  */
2160  if (!bms_is_empty(required_outer) || !bms_is_empty(rel->lateral_relids))
2161  elog(ERROR, "parameterized foreign joins are not supported yet");
2162 
2163  pathnode->path.pathtype = T_ForeignScan;
2164  pathnode->path.parent = rel;
2165  pathnode->path.pathtarget = target ? target : rel->reltarget;
2166  pathnode->path.param_info = NULL; /* XXX see above */
2167  pathnode->path.parallel_aware = false;
2168  pathnode->path.parallel_safe = rel->consider_parallel;
2169  pathnode->path.parallel_workers = 0;
2170  pathnode->path.rows = rows;
2171  pathnode->path.startup_cost = startup_cost;
2172  pathnode->path.total_cost = total_cost;
2173  pathnode->path.pathkeys = pathkeys;
2174 
2175  pathnode->fdw_outerpath = fdw_outerpath;
2176  pathnode->fdw_private = fdw_private;
2177 
2178  return pathnode;
2179 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
Path * fdw_outerpath
Definition: pathnodes.h:1321
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
Relids lateral_relids
Definition: pathnodes.h:668
#define ERROR
Definition: elog.h:43
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
List * fdw_private
Definition: pathnodes.h:1322
#define elog(elevel,...)
Definition: elog.h:228
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

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

2199 {
2200  ForeignPath *pathnode = makeNode(ForeignPath);
2201 
2202  /*
2203  * Upper relations should never have any lateral references, since joining
2204  * is complete.
2205  */
2207 
2208  pathnode->path.pathtype = T_ForeignScan;
2209  pathnode->path.parent = rel;
2210  pathnode->path.pathtarget = target ? target : rel->reltarget;
2211  pathnode->path.param_info = NULL;
2212  pathnode->path.parallel_aware = false;
2213  pathnode->path.parallel_safe = rel->consider_parallel;
2214  pathnode->path.parallel_workers = 0;
2215  pathnode->path.rows = rows;
2216  pathnode->path.startup_cost = startup_cost;
2217  pathnode->path.total_cost = total_cost;
2218  pathnode->path.pathkeys = pathkeys;
2219 
2220  pathnode->fdw_outerpath = fdw_outerpath;
2221  pathnode->fdw_private = fdw_private;
2222 
2223  return pathnode;
2224 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
Path * fdw_outerpath
Definition: pathnodes.h:1321
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
Relids lateral_relids
Definition: pathnodes.h:668
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
List * fdw_private
Definition: pathnodes.h:1322
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

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

2106 {
2107  ForeignPath *pathnode = makeNode(ForeignPath);
2108 
2109  /* Historically some FDWs were confused about when to use this */
2110  Assert(IS_SIMPLE_REL(rel));
2111 
2112  pathnode->path.pathtype = T_ForeignScan;
2113  pathnode->path.parent = rel;
2114  pathnode->path.pathtarget = target ? target : rel->reltarget;
2115  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2116  required_outer);
2117  pathnode->path.parallel_aware = false;
2118  pathnode->path.parallel_safe = rel->consider_parallel;
2119  pathnode->path.parallel_workers = 0;
2120  pathnode->path.rows = rows;
2121  pathnode->path.startup_cost = startup_cost;
2122  pathnode->path.total_cost = total_cost;
2123  pathnode->path.pathkeys = pathkeys;
2124 
2125  pathnode->fdw_outerpath = fdw_outerpath;
2126  pathnode->fdw_private = fdw_private;
2127 
2128  return pathnode;
2129 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
Path * fdw_outerpath
Definition: pathnodes.h:1321
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
#define IS_SIMPLE_REL(rel)
Definition: pathnodes.h:616
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
List * fdw_private
Definition: pathnodes.h:1322
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ create_functionscan_path()

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

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

1913 {
1914  Path *pathnode = makeNode(Path);
1915 
1916  pathnode->pathtype = T_FunctionScan;
1917  pathnode->parent = rel;
1918  pathnode->pathtarget = rel->reltarget;
1919  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1920  required_outer);
1921  pathnode->parallel_aware = false;
1922  pathnode->parallel_safe = rel->consider_parallel;
1923  pathnode->parallel_workers = 0;
1924  pathnode->pathkeys = pathkeys;
1925 
1926  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1927 
1928  return pathnode;
1929 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * parent
Definition: pathnodes.h:1116
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1331
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ 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 1753 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(), and generate_gather_paths().

1756 {
1758  Cost input_startup_cost = 0;
1759  Cost input_total_cost = 0;
1760 
1761  Assert(subpath->parallel_safe);
1762  Assert(pathkeys);
1763 
1764  pathnode->path.pathtype = T_GatherMerge;
1765  pathnode->path.parent = rel;
1766  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1767  required_outer);
1768  pathnode->path.parallel_aware = false;
1769 
1770  pathnode->subpath = subpath;
1771  pathnode->num_workers = subpath->parallel_workers;
1772  pathnode->path.pathkeys = pathkeys;
1773  pathnode->path.pathtarget = target ? target : rel->reltarget;
1774  pathnode->path.rows += subpath->rows;
1775 
1776  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1777  {
1778  /* Subpath is adequately ordered, we won't need to sort it */
1779  input_startup_cost += subpath->startup_cost;
1780  input_total_cost += subpath->total_cost;
1781  }
1782  else
1783  {
1784  /* We'll need to insert a Sort node, so include cost for that */
1785  Path sort_path; /* dummy for result of cost_sort */
1786 
1787  cost_sort(&sort_path,
1788  root,
1789  pathkeys,
1790  subpath->total_cost,
1791  subpath->rows,
1792  subpath->pathtarget->width,
1793  0.0,
1794  work_mem,
1795  -1);
1796  input_startup_cost += sort_path.startup_cost;
1797  input_total_cost += sort_path.total_cost;
1798  }
1799 
1800  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1801  input_startup_cost, input_total_cost, rows);
1802 
1803  return pathnode;
1804 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
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:401
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
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:1693
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654
double Cost
Definition: nodes.h:659
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 1844 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().

1846 {
1847  GatherPath *pathnode = makeNode(GatherPath);
1848 
1849  Assert(subpath->parallel_safe);
1850 
1851  pathnode->path.pathtype = T_Gather;
1852  pathnode->path.parent = rel;
1853  pathnode->path.pathtarget = target;
1854  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1855  required_outer);
1856  pathnode->path.parallel_aware = false;
1857  pathnode->path.parallel_safe = false;
1858  pathnode->path.parallel_workers = 0;
1859  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1860 
1861  pathnode->subpath = subpath;
1862  pathnode->num_workers = subpath->parallel_workers;
1863  pathnode->single_copy = false;
1864 
1865  if (pathnode->num_workers == 0)
1866  {
1867  pathnode->path.pathkeys = subpath->pathkeys;
1868  pathnode->num_workers = 1;
1869  pathnode->single_copy = true;
1870  }
1871 
1872  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1873 
1874  return pathnode;
1875 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
bool single_copy
Definition: pathnodes.h:1468
int num_workers
Definition: pathnodes.h:1469
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * subpath
Definition: pathnodes.h:1467
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
bool parallel_safe
Definition: pathnodes.h:1122
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:363
Definition: nodes.h:81
bool parallel_aware
Definition: pathnodes.h:1121
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 2810 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().

2816 {
2817  GroupPath *pathnode = makeNode(GroupPath);
2818  PathTarget *target = rel->reltarget;
2819 
2820  pathnode->path.pathtype = T_Group;
2821  pathnode->path.parent = rel;
2822  pathnode->path.pathtarget = target;
2823  /* For now, assume we are above any joins, so no parameterization */
2824  pathnode->path.param_info = NULL;
2825  pathnode->path.parallel_aware = false;
2826  pathnode->path.parallel_safe = rel->consider_parallel &&
2827  subpath->parallel_safe;
2828  pathnode->path.parallel_workers = subpath->parallel_workers;
2829  /* Group doesn't change sort ordering */
2830  pathnode->path.pathkeys = subpath->pathkeys;
2831 
2832  pathnode->subpath = subpath;
2833 
2834  pathnode->groupClause = groupClause;
2835  pathnode->qual = qual;
2836 
2837  cost_group(&pathnode->path, root,
2838  list_length(groupClause),
2839  numGroups,
2840  qual,
2841  subpath->startup_cost, subpath->total_cost,
2842  subpath->rows);
2843 
2844  /* add tlist eval cost for each output row */
2845  pathnode->path.startup_cost += target->cost.startup;
2846  pathnode->path.total_cost += target->cost.startup +
2847  target->cost.per_tuple * pathnode->path.rows;
2848 
2849  return pathnode;
2850 }
List * qual
Definition: pathnodes.h:1636
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1114
Cost per_tuple
Definition: pathnodes.h:46
Cost startup_cost
Definition: pathnodes.h:1127
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:2346
RelOptInfo * parent
Definition: pathnodes.h:1116
Definition: nodes.h:77
Path path
Definition: pathnodes.h:1633
List * groupClause
Definition: pathnodes.h:1635
Path * subpath
Definition: pathnodes.h:1634
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654
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 1447 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().

1449 {
1451 
1452  pathnode->path.pathtype = T_Result;
1453  pathnode->path.parent = rel;
1454  pathnode->path.pathtarget = target;
1455  pathnode->path.param_info = NULL; /* there are no other rels... */
1456  pathnode->path.parallel_aware = false;
1457  pathnode->path.parallel_safe = rel->consider_parallel;
1458  pathnode->path.parallel_workers = 0;
1459  pathnode->path.pathkeys = NIL;
1460  pathnode->quals = havingqual;
1461 
1462  /*
1463  * We can't quite use cost_resultscan() because the quals we want to
1464  * account for are not baserestrict quals of the rel. Might as well just
1465  * hack it here.
1466  */
1467  pathnode->path.rows = 1;
1468  pathnode->path.startup_cost = target->cost.startup;
1469  pathnode->path.total_cost = target->cost.startup +
1470  cpu_tuple_cost + target->cost.per_tuple;
1471 
1472  /*
1473  * Add cost of qual, if any --- but we ignore its selectivity, since our
1474  * rowcount estimate should be 1 no matter what the qual is.
1475  */
1476  if (havingqual)
1477  {
1478  QualCost qual_cost;
1479 
1480  cost_qual_eval(&qual_cost, havingqual, root);
1481  /* havingqual is evaluated once at startup */
1482  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1483  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1484  }
1485 
1486  return pathnode;
1487 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1114
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3819
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
bool consider_parallel
Definition: pathnodes.h:651
double cpu_tuple_cost
Definition: costsize.c:112
bool parallel_aware
Definition: pathnodes.h:1121

◆ 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 2987 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, PathTarget::width, and work_mem.

Referenced by consider_groupingsets_paths().

2995 {
2997  PathTarget *target = rel->reltarget;
2998  ListCell *lc;
2999  bool is_first = true;
3000  bool is_first_sort = true;
3001 
3002  /* The topmost generated Plan node will be an Agg */
3003  pathnode->path.pathtype = T_Agg;
3004  pathnode->path.parent = rel;
3005  pathnode->path.pathtarget = target;
3006  pathnode->path.param_info = subpath->param_info;
3007  pathnode->path.parallel_aware = false;
3008  pathnode->path.parallel_safe = rel->consider_parallel &&
3009  subpath->parallel_safe;
3010  pathnode->path.parallel_workers = subpath->parallel_workers;
3011  pathnode->subpath = subpath;
3012 
3013  /*
3014  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
3015  * to AGG_HASHED, here if possible.
3016  */
3017  if (aggstrategy == AGG_SORTED &&
3018  list_length(rollups) == 1 &&
3019  ((RollupData *) linitial(rollups))->groupClause == NIL)
3020  aggstrategy = AGG_PLAIN;
3021 
3022  if (aggstrategy == AGG_MIXED &&
3023  list_length(rollups) == 1)
3024  aggstrategy = AGG_HASHED;
3025 
3026  /*
3027  * Output will be in sorted order by group_pathkeys if, and only if, there
3028  * is a single rollup operation on a non-empty list of grouping
3029  * expressions.
3030  */
3031  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
3032  pathnode->path.pathkeys = root->group_pathkeys;
3033  else
3034  pathnode->path.pathkeys = NIL;
3035 
3036  pathnode->aggstrategy = aggstrategy;
3037  pathnode->rollups = rollups;
3038  pathnode->qual = having_qual;
3039 
3040  Assert(rollups != NIL);
3041  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
3042  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
3043 
3044  foreach(lc, rollups)
3045  {
3046  RollupData *rollup = lfirst(lc);
3047  List *gsets = rollup->gsets;
3048  int numGroupCols = list_length(linitial(gsets));
3049 
3050  /*
3051  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
3052  * (already-sorted) input, and following ones do their own sort.
3053  *
3054  * In AGG_HASHED mode, there is one rollup for each grouping set.
3055  *
3056  * In AGG_MIXED mode, the first rollups are hashed, the first
3057  * non-hashed one takes the (already-sorted) input, and following ones
3058  * do their own sort.
3059  */
3060  if (is_first)
3061  {
3062  cost_agg(&pathnode->path, root,
3063  aggstrategy,
3064  agg_costs,
3065  numGroupCols,
3066  rollup->numGroups,
3067  having_qual,
3068  subpath->startup_cost,
3069  subpath->total_cost,
3070  subpath->rows);
3071  is_first = false;
3072  if (!rollup->is_hashed)
3073  is_first_sort = false;
3074  }
3075  else
3076  {
3077  Path sort_path; /* dummy for result of cost_sort */
3078  Path agg_path; /* dummy for result of cost_agg */
3079 
3080  if (rollup->is_hashed || is_first_sort)
3081  {
3082  /*
3083  * Account for cost of aggregation, but don't charge input
3084  * cost again
3085  */
3086  cost_agg(&agg_path, root,
3087  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
3088  agg_costs,
3089  numGroupCols,
3090  rollup->numGroups,
3091  having_qual,
3092  0.0, 0.0,
3093  subpath->rows);
3094  if (!rollup->is_hashed)
3095  is_first_sort = false;
3096  }
3097  else
3098  {
3099  /* Account for cost of sort, but don't charge input cost again */
3100  cost_sort(&sort_path, root, NIL,
3101  0.0,
3102  subpath->rows,
3103  subpath->pathtarget->width,
3104  0.0,
3105  work_mem,
3106  -1.0);
3107 
3108  /* Account for cost of aggregation */
3109 
3110  cost_agg(&agg_path, root,
3111  AGG_SORTED,
3112  agg_costs,
3113  numGroupCols,
3114  rollup->numGroups,
3115  having_qual,
3116  sort_path.startup_cost,
3117  sort_path.total_cost,
3118  sort_path.rows);
3119  }
3120 
3121  pathnode->path.total_cost += agg_path.total_cost;
3122  pathnode->path.rows += agg_path.rows;
3123  }
3124  }
3125 
3126  /* add tlist eval cost for each output row */
3127  pathnode->path.startup_cost += target->cost.startup;
3128  pathnode->path.total_cost += target->cost.startup +
3129  target->cost.per_tuple * pathnode->path.rows;
3130 
3131  return pathnode;
3132 }
List * group_pathkeys
Definition: pathnodes.h:300
#define NIL
Definition: pg_list.h:65
Definition: nodes.h:78
PathTarget * pathtarget
Definition: pathnodes.h:1117
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, List *quals, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2151
int parallel_workers
Definition: pathnodes.h:1123
bool is_hashed
Definition: pathnodes.h:1689
ParamPathInfo * param_info
Definition: pathnodes.h:1119
double numGroups
Definition: pathnodes.h:1687
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1114
Cost per_tuple
Definition: pathnodes.h:46
#define linitial(l)
Definition: pg_list.h:195
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
AggStrategy aggstrategy
Definition: pathnodes.h:1700
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:1693
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:654
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
List * gsets
Definition: pathnodes.h:1685

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

2464 {
2465  HashPath *pathnode = makeNode(HashPath);
2466 
2467  pathnode->jpath.path.pathtype = T_HashJoin;
2468  pathnode->jpath.path.parent = joinrel;
2469  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2470  pathnode->jpath.path.param_info =
2472  joinrel,
2473  outer_path,
2474  inner_path,
2475  extra->sjinfo,
2476  required_outer,
2477  &restrict_clauses);
2478  pathnode->jpath.path.parallel_aware =
2479  joinrel->consider_parallel && parallel_hash;
2480  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2481  outer_path->parallel_safe && inner_path->parallel_safe;
2482  /* This is a foolish way to estimate parallel_workers, but for now... */
2483  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2484 
2485  /*
2486  * A hashjoin never has pathkeys, since its output ordering is
2487  * unpredictable due to possible batching. XXX If the inner relation is
2488  * small enough, we could instruct the executor that it must not batch,
2489  * and then we could assume that the output inherits the outer relation's
2490  * ordering, which might save a sort step. However there is considerable
2491  * downside if our estimate of the inner relation size is badly off. For
2492  * the moment we don't risk it. (Note also that if we wanted to take this
2493  * seriously, joinpath.c would have to consider many more paths for the
2494  * outer rel than it does now.)
2495  */
2496  pathnode->jpath.path.pathkeys = NIL;
2497  pathnode->jpath.jointype = jointype;
2498  pathnode->jpath.inner_unique = extra->inner_unique;
2499  pathnode->jpath.outerjoinpath = outer_path;
2500  pathnode->jpath.innerjoinpath = inner_path;
2501  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2502  pathnode->path_hashclauses = hashclauses;
2503  /* final_cost_hashjoin will fill in pathnode->num_batches */
2504 
2505  final_cost_hashjoin(root, pathnode, workspace, extra);
2506 
2507  return pathnode;
2508 }
#define NIL
Definition: pg_list.h:65
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3364
JoinPath jpath
Definition: pathnodes.h:1571
PathTarget * pathtarget
Definition: pathnodes.h:1117
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:1354
Path * innerjoinpath
Definition: pathnodes.h:1498
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2387
List * joinrestrictinfo
Definition: pathnodes.h:1500
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * outerjoinpath
Definition: pathnodes.h:1497
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
Path path
Definition: pathnodes.h:1490
bool parallel_safe
Definition: pathnodes.h:1122
bool inner_unique
Definition: pathnodes.h:1494
bool consider_parallel
Definition: pathnodes.h:651
JoinType jointype
Definition: pathnodes.h:1492
bool parallel_aware
Definition: pathnodes.h:1121
List * path_hashclauses
Definition: pathnodes.h:1572
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ 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:1182
PathTarget * pathtarget
Definition: pathnodes.h:1117
Path path
Definition: pathnodes.h:1178
IndexOptInfo * indexinfo
Definition: pathnodes.h:1179
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * indexclauses
Definition: pathnodes.h:1180
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * rel
Definition: pathnodes.h:793
RelOptInfo * parent
Definition: pathnodes.h:1116
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:476
List * indexorderbys
Definition: pathnodes.h:1181
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
ScanDirection indexscandir
Definition: pathnodes.h:1183
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ create_limit_path()

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

Definition at line 3545 of file pathnode.c.

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

Referenced by grouping_planner().

3549 {
3550  LimitPath *pathnode = makeNode(LimitPath);
3551 
3552  pathnode->path.pathtype = T_Limit;
3553  pathnode->path.parent = rel;
3554  /* Limit doesn't project, so use source path's pathtarget */
3555  pathnode->path.pathtarget = subpath->pathtarget;
3556  /* For now, assume we are above any joins, so no parameterization */
3557  pathnode->path.param_info = NULL;
3558  pathnode->path.parallel_aware = false;
3559  pathnode->path.parallel_safe = rel->consider_parallel &&
3560  subpath->parallel_safe;
3561  pathnode->path.parallel_workers = subpath->parallel_workers;
3562  pathnode->path.rows = subpath->rows;
3563  pathnode->path.startup_cost = subpath->startup_cost;
3564  pathnode->path.total_cost = subpath->total_cost;
3565  pathnode->path.pathkeys = subpath->pathkeys;
3566  pathnode->subpath = subpath;
3567  pathnode->limitOffset = limitOffset;
3568  pathnode->limitCount = limitCount;
3569 
3570  /*
3571  * Adjust the output rows count and costs according to the offset/limit.
3572  */
3573  adjust_limit_rows_costs(&pathnode->path.rows,
3574  &pathnode->path.startup_cost,
3575  &pathnode->path.total_cost,
3576  offset_est, count_est);
3577 
3578  return pathnode;
3579 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
Node * limitOffset
Definition: pathnodes.h:1796
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
void adjust_limit_rows_costs(double *rows, Cost *startup_cost, Cost *total_cost, int64 offset_est, int64 count_est)
Definition: pathnode.c:3598
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
Path * subpath
Definition: pathnodes.h:1795
RelOptInfo * parent
Definition: pathnodes.h:1116
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
Path path
Definition: pathnodes.h:1794
bool parallel_aware
Definition: pathnodes.h:1121
Node * limitCount
Definition: pathnodes.h:1797
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241
Definition: nodes.h:86

◆ create_lockrows_path()

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

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

3386 {
3387  LockRowsPath *pathnode = makeNode(LockRowsPath);
3388 
3389  pathnode->path.pathtype = T_LockRows;
3390  pathnode->path.parent = rel;
3391  /* LockRows doesn't project, so use source path's pathtarget */
3392  pathnode->path.pathtarget = subpath->pathtarget;
3393  /* For now, assume we are above any joins, so no parameterization */
3394  pathnode->path.param_info = NULL;
3395  pathnode->path.parallel_aware = false;
3396  pathnode->path.parallel_safe = false;
3397  pathnode->path.parallel_workers = 0;
3398  pathnode->path.rows = subpath->rows;
3399 
3400  /*
3401  * The result cannot be assumed sorted, since locking might cause the sort
3402  * key columns to be replaced with new values.
3403  */
3404  pathnode->path.pathkeys = NIL;
3405 
3406  pathnode->subpath = subpath;
3407  pathnode->rowMarks = rowMarks;
3408  pathnode->epqParam = epqParam;
3409 
3410  /*
3411  * We should charge something extra for the costs of row locking and
3412  * possible refetches, but it's hard to say how much. For now, use
3413  * cpu_tuple_cost per row.
3414  */
3415  pathnode->path.startup_cost = subpath->startup_cost;
3416  pathnode->path.total_cost = subpath->total_cost +
3417  cpu_tuple_cost * subpath->rows;
3418 
3419  return pathnode;
3420 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * rowMarks
Definition: pathnodes.h:1760
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * subpath
Definition: pathnodes.h:1759
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
double cpu_tuple_cost
Definition: costsize.c:112
bool parallel_aware
Definition: pathnodes.h:1121
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:241

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1496 {
1497  MaterialPath *pathnode = makeNode(MaterialPath);
1498 
1499  Assert(subpath->parent == rel);
1500 
1501  pathnode->path.pathtype = T_Material;
1502  pathnode->path.parent = rel;
1503  pathnode->path.pathtarget = rel->reltarget;
1504  pathnode->path.param_info = subpath->param_info;
1505  pathnode->path.parallel_aware = false;
1506  pathnode->path.parallel_safe = rel->consider_parallel &&
1507  subpath->parallel_safe;
1508  pathnode->path.parallel_workers = subpath->parallel_workers;
1509  pathnode->path.pathkeys = subpath->pathkeys;
1510 
1511  pathnode->subpath = subpath;
1512 
1513  cost_material(&pathnode->path,
1514  subpath->startup_cost,
1515  subpath->total_cost,
1516  subpath->rows,
1517  subpath->pathtarget->width);
1518 
1519  return pathnode;
1520 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
Path * subpath
Definition: pathnodes.h:1428
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
Cost total_cost
Definition: pathnodes.h:1128
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2097
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654
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,
List partitioned_rels 
)

Definition at line 1345 of file pathnode.c.

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

Referenced by generate_orderedappend_paths().

1351 {
1353  Cost input_startup_cost;
1354  Cost input_total_cost;
1355  ListCell *l;
1356 
1357  pathnode->path.pathtype = T_MergeAppend;
1358  pathnode->path.parent = rel;
1359  pathnode->path.pathtarget = rel->reltarget;
1361  required_outer);
1362  pathnode->path.parallel_aware = false;
1363  pathnode->path.parallel_safe = rel->consider_parallel;
1364  pathnode->path.parallel_workers = 0;
1365  pathnode->path.pathkeys = pathkeys;
1366  pathnode->partitioned_rels = list_copy(partitioned_rels);
1367  pathnode->subpaths = subpaths;
1368 
1369  /*
1370  * Apply query-wide LIMIT if known and path is for sole base relation.
1371  * (Handling this at this low level is a bit klugy.)
1372  */
1373  if (bms_equal(rel->relids, root->all_baserels))
1374  pathnode->limit_tuples = root->limit_tuples;
1375  else
1376  pathnode->limit_tuples = -1.0;
1377 
1378  /*
1379  * Add up the sizes and costs of the input paths.
1380  */
1381  pathnode->path.rows = 0;
1382  input_startup_cost = 0;
1383  input_total_cost = 0;
1384  foreach(l, subpaths)
1385  {
1386  Path *subpath = (Path *) lfirst(l);
1387 
1388  pathnode->path.rows += subpath->rows;
1389  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1390  subpath->parallel_safe;
1391 
1392  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1393  {
1394  /* Subpath is adequately ordered, we won't need to sort it */
1395  input_startup_cost += subpath->startup_cost;
1396  input_total_cost += subpath->total_cost;
1397  }
1398  else
1399  {
1400  /* We'll need to insert a Sort node, so include cost for that */
1401  Path sort_path; /* dummy for result of cost_sort */
1402 
1403  cost_sort(&sort_path,
1404  root,
1405  pathkeys,
1406  subpath->total_cost,
1407  subpath->parent->tuples,
1408  subpath->pathtarget->width,
1409  0.0,
1410  work_mem,
1411  pathnode->limit_tuples);
1412  input_startup_cost += sort_path.startup_cost;
1413  input_total_cost += sort_path.total_cost;
1414  }
1415 
1416  /* All child paths must have same parameterization */
1417  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1418  }
1419 
1420  /*
1421  * Now we can compute total costs of the MergeAppend. If there's exactly
1422  * one child path, the MergeAppend is a no-op and will be discarded later
1423  * (in setrefs.c); otherwise we do the normal cost calculation.
1424  */
1425  if (list_length(subpaths) == 1)
1426  {
1427  pathnode->path.startup_cost = input_startup_cost;
1428  pathnode->path.total_cost = input_total_cost;
1429  }
1430  else
1431  cost_merge_append(&pathnode->path, root,
1432  pathkeys, list_length(subpaths),
1433  input_startup_cost, input_total_cost,
1434  pathnode->path.rows);
1435 
1436  return pathnode;
1437 }
PathTarget * pathtarget
Definition: pathnodes.h:1117
double tuples
Definition: pathnodes.h:683
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * list_copy(const List *oldlist)
Definition: list.c:1404
List * partitioned_rels
Definition: pathnodes.h:1401
NodeTag pathtype
Definition: pathnodes.h:1114
Relids all_baserels
Definition: pathnodes.h:227
double limit_tuples
Definition: pathnodes.h:337
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
Relids relids
Definition: pathnodes.h:643
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:1693
int work_mem
Definition: globals.c:121
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
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:2048
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1561
struct PathTarget * reltarget
Definition: pathnodes.h:654
double limit_tuples
Definition: pathnodes.h:1403
double Cost
Definition: nodes.h:659
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 2387 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().

2400 {
2401  MergePath *pathnode = makeNode(MergePath);
2402 
2403  pathnode->jpath.path.pathtype = T_MergeJoin;
2404  pathnode->jpath.path.parent = joinrel;
2405  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2406  pathnode->jpath.path.param_info =
2408  joinrel,
2409  outer_path,
2410  inner_path,
2411  extra->sjinfo,
2412  required_outer,
2413  &restrict_clauses);
2414  pathnode->jpath.path.parallel_aware = false;
2415  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2416  outer_path->parallel_safe && inner_path->parallel_safe;
2417  /* This is a foolish way to estimate parallel_workers, but for now... */
2418  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2419  pathnode->jpath.path.pathkeys = pathkeys;
2420  pathnode->jpath.jointype = jointype;
2421  pathnode->jpath.inner_unique = extra->inner_unique;
2422  pathnode->jpath.outerjoinpath = outer_path;
2423  pathnode->jpath.innerjoinpath = inner_path;
2424  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2425  pathnode->path_mergeclauses = mergeclauses;
2426  pathnode->outersortkeys = outersortkeys;
2427  pathnode->innersortkeys = innersortkeys;
2428  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2429  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2430 
2431  final_cost_mergejoin(root, pathnode, workspace, extra);
2432 
2433  return pathnode;
2434 }
List * path_mergeclauses
Definition: pathnodes.h:1553
List * outersortkeys
Definition: pathnodes.h:1554
PathTarget * pathtarget
Definition: pathnodes.h:1117
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:1354
Path * innerjoinpath
Definition: pathnodes.h:1498
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2387
List * joinrestrictinfo
Definition: pathnodes.h:1500
RelOptInfo * parent
Definition: pathnodes.h:1116
Path * outerjoinpath
Definition: pathnodes.h:1497
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
Path path
Definition: pathnodes.h:1490
bool parallel_safe
Definition: pathnodes.h:1122
bool inner_unique
Definition: pathnodes.h:1494
bool consider_parallel
Definition: pathnodes.h:651
List * innersortkeys
Definition: pathnodes.h:1555
JoinType jointype
Definition: pathnodes.h:1492
JoinPath jpath
Definition: pathnodes.h:1552
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2928

◆ create_minmaxagg_path()

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

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

3149 {
3150  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3151  Cost initplan_cost;
3152  ListCell *lc;
3153 
3154  /* The topmost generated Plan node will be a Result */
3155  pathnode->path.pathtype = T_Result;
3156  pathnode->path.parent = rel;
3157  pathnode->path.pathtarget = target;
3158  /* For now, assume we are above any joins, so no parameterization */
3159  pathnode->path.param_info = NULL;
3160  pathnode->path.parallel_aware = false;
3161  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3162  pathnode->path.parallel_safe = false;
3163  pathnode->path.parallel_workers = 0;
3164  /* Result is one unordered row */
3165  pathnode->path.rows = 1;
3166  pathnode->path.pathkeys = NIL;
3167 
3168  pathnode->mmaggregates = mmaggregates;
3169  pathnode->quals = quals;
3170 
3171  /* Calculate cost of all the initplans ... */
3172  initplan_cost = 0;
3173  foreach(lc, mmaggregates)
3174  {
3175  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3176 
3177  initplan_cost += mminfo->pathcost;
3178  }
3179 
3180  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3181  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3182  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3183  target->cost.per_tuple + cpu_tuple_cost;
3184 
3185  /*
3186  * Add cost of qual, if any --- but we ignore its selectivity, since our
3187  * rowcount estimate should be 1 no matter what the qual is.
3188  */
3189  if (quals)
3190  {
3191  QualCost qual_cost;
3192 
3193  cost_qual_eval(&qual_cost, quals, root);
3194  pathnode->path.startup_cost += qual_cost.startup;
3195  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3196  }
3197 
3198  return pathnode;
3199 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
List * quals
Definition: pathnodes.h:1712
Cost startup
Definition: pathnodes.h:45
NodeTag pathtype
Definition: pathnodes.h:1114
Cost per_tuple
Definition: pathnodes.h:46
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3819
Cost startup_cost
Definition: pathnodes.h:1127
RelOptInfo * parent
Definition: pathnodes.h:1116
List * mmaggregates
Definition: pathnodes.h:1711
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
QualCost cost
Definition: pathnodes.h:1048
double cpu_tuple_cost
Definition: costsize.c:112
bool parallel_aware
Definition: pathnodes.h:1121
double Cost
Definition: nodes.h:659

◆ 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 3443 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, rint(), 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().

3452 {
3454  double total_size;
3455  ListCell *lc;
3456 
3457  Assert(list_length(resultRelations) == list_length(subpaths));
3458  Assert(list_length(resultRelations) == list_length(subroots));
3459  Assert(withCheckOptionLists == NIL ||
3460  list_length(resultRelations) == list_length(withCheckOptionLists));
3461  Assert(returningLists == NIL ||
3462  list_length(resultRelations) == list_length(returningLists));
3463 
3464  pathnode->path.pathtype = T_ModifyTable;
3465  pathnode->path.parent = rel;
3466  /* pathtarget is not interesting, just make it minimally valid */
3467  pathnode->path.pathtarget = rel->reltarget;
3468  /* For now, assume we are above any joins, so no parameterization */
3469  pathnode->path.param_info = NULL;
3470  pathnode->path.parallel_aware = false;
3471  pathnode->path.parallel_safe = false;
3472  pathnode->path.parallel_workers = 0;
3473  pathnode->path.pathkeys = NIL;
3474 
3475  /*
3476  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3477  *
3478  * Currently, we don't charge anything extra for the actual table
3479  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3480  * expressions if any. It would only be window dressing, since
3481  * ModifyTable is always a top-level node and there is no way for the
3482  * costs to change any higher-level planning choices. But we might want
3483  * to make it look better sometime.
3484  */
3485  pathnode->path.startup_cost = 0;
3486  pathnode->path.total_cost = 0;
3487  pathnode->path.rows = 0;
3488  total_size = 0;
3489  foreach(lc, subpaths)
3490  {
3491  Path *subpath = (Path *) lfirst(lc);
3492 
3493  if (lc == list_head(subpaths)) /* first node? */
3494  pathnode->path.startup_cost = subpath->startup_cost;
3495  pathnode->path.total_cost += subpath->total_cost;
3496  pathnode->path.rows += subpath->rows;
3497  total_size += subpath->pathtarget->width * subpath->rows;
3498  }
3499 
3500  /*
3501  * Set width to the average width of the subpath outputs. XXX this is
3502  * totally wrong: we should report zero if no RETURNING, else an average
3503  * of the RETURNING tlist widths. But it's what happened historically,
3504  * and improving it is a task for another day.
3505  */
3506  if (pathnode->path.rows > 0)
3507  total_size /= pathnode->path.rows;
3508  pathnode->path.pathtarget->width = rint(total_size);
3509 
3510  pathnode->operation = operation;
3511  pathnode->canSetTag = canSetTag;
3512  pathnode->nominalRelation = nominalRelation;
3513  pathnode->rootRelation = rootRelation;
3514  pathnode->partColsUpdated = partColsUpdated;
3515  pathnode->resultRelations = resultRelations;
3516  pathnode->subpaths = subpaths;
3517  pathnode->subroots = subroots;
3518  pathnode->withCheckOptionLists = withCheckOptionLists;
3519  pathnode->returningLists = returningLists;
3520  pathnode->rowMarks = rowMarks;
3521  pathnode->onconflict = onconflict;
3522  pathnode->epqParam = epqParam;
3523 
3524  return pathnode;
3525 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
List * returningLists
Definition: pathnodes.h:1783
OnConflictExpr * onconflict
Definition: pathnodes.h:1785
Index nominalRelation
Definition: pathnodes.h:1776
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
Cost startup_cost
Definition: pathnodes.h:1127
bool partColsUpdated
Definition: pathnodes.h:1778
RelOptInfo * parent
Definition: pathnodes.h:1116
static ListCell * list_head(const List *l)
Definition: pg_list.h:125
double rint(double x)
Definition: rint.c:21
int64 total_size
Definition: pg_checksums.c:68
Cost total_cost
Definition: pathnodes.h:1128
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:739
#define lfirst(lc)
Definition: pg_list.h:190
double rows
Definition: pathnodes.h:1126
bool parallel_safe
Definition: pathnodes.h:1122
Index rootRelation
Definition: pathnodes.h:1777
static int list_length(const List *l)
Definition: pg_list.h:169
List * withCheckOptionLists
Definition: pathnodes.h:1782
CmdType operation
Definition: pathnodes.h:1774
List * resultRelations
Definition: pathnodes.h:1779
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654
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 2014 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().

2016 {
2017  Path *pathnode = makeNode(Path);
2018 
2019  pathnode->pathtype = T_NamedTuplestoreScan;
2020  pathnode->parent = rel;
2021  pathnode->pathtarget = rel->reltarget;
2022  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2023  required_outer);
2024  pathnode->parallel_aware = false;
2025  pathnode->parallel_safe = rel->consider_parallel;
2026  pathnode->parallel_workers = 0;
2027  pathnode->pathkeys = NIL; /* result is always unordered */
2028 
2029  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2030 
2031  return pathnode;
2032 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1264
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1539
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
RelOptInfo * parent
Definition: pathnodes.h:1116
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1122
bool consider_parallel
Definition: pathnodes.h:651
bool parallel_aware
Definition: pathnodes.h:1121
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ create_nestloop_path()

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

Definition at line 2299 of file pathnode.c.

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

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

2309 {
2310  NestPath *pathnode = makeNode(NestPath);
2311  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2312 
2313  /*
2314  * If the inner path is parameterized by the outer, we must drop any
2315  * restrict_clauses that are due to be moved into the inner path. We have
2316  * to do this now, rather than postpone the work till createplan time,
2317  * because the restrict_clauses list can affect the size and cost
2318  * estimates for this path.
2319  */
2320  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2321  {
2322  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2323  inner_req_outer);
2324  List *jclauses = NIL;
2325  ListCell *lc;
2326 
2327  foreach(lc, restrict_clauses)
2328  {
2329  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2330 
2331  if (!join_clause_is_movable_into(rinfo,
2332  inner_path->parent->relids,
2333  inner_and_outer))
2334  jclauses = lappend(jclauses, rinfo);
2335  }
2336  restrict_clauses = jclauses;
2337  }
2338 
2339  pathnode->path.pathtype = T_NestLoop;
2340  pathnode->path.parent = joinrel;
2341  pathnode->path.pathtarget = joinrel->reltarget;
2342  pathnode->path.param_info =
2344  joinrel,
2345  outer_path,
2346  inner_path,
2347  extra->sjinfo,
2348  required_outer,
2349  &restrict_clauses);
2350  pathnode->path.parallel_aware = false;
2351  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2352  outer_path->parallel_safe && inner_path->parallel_safe;
2353  /* This is a foolish way to estimate parallel_workers, but for now... */
2354  pathnode->path.parallel_workers = outer_path->parallel_workers;
2355  pathnode->path.pathkeys = pathkeys;
2356  pathnode->jointype = jointype;
2357  pathnode->inner_unique = extra->inner_unique;
2358  pathnode->outerjoinpath = outer_path;
2359  pathnode->innerjoinpath = inner_path;
2360  pathnode->joinrestrictinfo = restrict_clauses;
2361 
2362  final_cost_nestloop(root, pathnode, workspace, extra);
2363 
2364  return pathnode;
2365 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1117
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:1354
Path * innerjoinpath
Definition: pathnodes.h:1498
int parallel_workers
Definition: pathnodes.h:1123
ParamPathInfo * param_info
Definition: pathnodes.h:1119
NodeTag pathtype
Definition: pathnodes.h:1114
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2491
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2387
List * joinrestrictinfo
Definition: pathnodes.h:1500
RelOptInfo * parent
Definition: pathnodes.h:1116
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1135
Relids relids
Definition: pathnodes.h:643
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:577
List * lappend(List *list, void *datum)
Definition: list.c:322
Path * outerjoinpath
Definition: pathnodes.h:1497
List * pathkeys
Definition: pathnodes.h:1130
#define makeNode(_type_)
Definition: nodes.h:573
Path path
Definition: pathnodes.h:1490
#define lfirst(lc)
Definition: pg_list.h:190
bool parallel_safe
Definition: pathnodes.h:1122
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool inner_unique
Definition: pathnodes.h:1494
bool consider_parallel
Definition: pathnodes.h:651
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
JoinType jointype
Definition: pathnodes.h:1492
bool parallel_aware
Definition: pathnodes.h:1121
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:654

◆ create_projection_path()

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

Definition at line 2519 of file pathnode.c.

References RelOptInfo::consider_parallel, Path