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

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

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

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

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

References clamp_row_est().

Referenced by create_limit_path(), and estimate_path_cost_size().

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

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

◆ 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_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, 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  appinfos = find_appinfos_by_relids(root, joinrel->relids, &nappinfos);
847 
848  /* Set up reltarget struct */
849  build_child_join_reltarget(root, parent_joinrel, joinrel,
850  nappinfos, appinfos);
851 
852  /* Construct joininfo list. */
853  joinrel->joininfo = (List *) adjust_appendrel_attrs(root,
854  (Node *) parent_joinrel->joininfo,
855  nappinfos,
856  appinfos);
857  pfree(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  return joinrel;
890 }
bool has_eclass_joins
Definition: pathnodes.h:709
struct Path * cheapest_unique_path
Definition: pathnodes.h:660
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:638
Relids * attr_needed
Definition: pathnodes.h:674
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:428
#define IS_OTHER_REL(rel)
Definition: pathnodes.h:629
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:658
Oid userid
Definition: pathnodes.h:691
double tuples
Definition: pathnodes.h:681
List * baserestrictinfo
Definition: pathnodes.h:703
bool consider_param_startup
Definition: pathnodes.h:648
Definition: nodes.h:525
List * partial_pathlist
Definition: pathnodes.h:657
List * cheapest_parameterized_paths
Definition: pathnodes.h:661
bool useridiscurrent
Definition: pathnodes.h:692
List ** nullable_partexprs
Definition: pathnodes.h:725
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:682
PlannerInfo * subroot
Definition: pathnodes.h:685
bool consider_startup
Definition: pathnodes.h:647
Relids lateral_relids
Definition: pathnodes.h:666
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:334
void pfree(void *pointer)
Definition: mcxt.c:1056
List ** partexprs
Definition: pathnodes.h:724
struct Path * cheapest_total_path
Definition: pathnodes.h:659
List * joininfo
Definition: pathnodes.h:707
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:694
int nparts
Definition: pathnodes.h:719
Relids relids
Definition: pathnodes.h:641
List * ppilist
Definition: pathnodes.h:656
Index relid
Definition: pathnodes.h:669
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: appendinfo.c:709
Relids lateral_referencers
Definition: pathnodes.h:677
Oid serverid
Definition: pathnodes.h:690
Relids direct_lateral_relids
Definition: pathnodes.h:665
bool consider_partitionwise_join
Definition: pathnodes.h:712
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:720
RTEKind rtekind
Definition: pathnodes.h:671
List * indexlist
Definition: pathnodes.h:678
double rows
Definition: pathnodes.h:644
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:695
#define makeNode(_type_)
Definition: nodes.h:573
BlockNumber pages
Definition: pathnodes.h:680
#define Assert(condition)
Definition: c.h:732
List * lateral_vars
Definition: pathnodes.h:676
struct RelOptInfo ** part_rels
Definition: pathnodes.h:722
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool consider_parallel
Definition: pathnodes.h:649
Bitmapset * Relids
Definition: pathnodes.h:28
List * partitioned_child_rels
Definition: pathnodes.h:726
AttrNumber max_attr
Definition: pathnodes.h:673
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1603
PartitionScheme part_scheme
Definition: pathnodes.h:718
List * pathlist
Definition: pathnodes.h:655
List * partition_qual
Definition: pathnodes.h:721
int32 * attr_widths
Definition: pathnodes.h:675
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:652
QualCost baserestrictcost
Definition: pathnodes.h:704
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:529
List * subplan_params
Definition: pathnodes.h:686
static void build_child_join_reltarget(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, int nappinfos, AppendRelInfo **appinfos)
Definition: relnode.c:1772
Bitmapset * eclass_indexes
Definition: pathnodes.h:683
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: appendinfo.c:180
Relids top_parent_relids
Definition: pathnodes.h:714
AttrNumber min_attr
Definition: pathnodes.h:672

◆ 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:709
struct Path * cheapest_unique_path
Definition: pathnodes.h:660
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:696
#define NIL
Definition: pg_list.h:65
int join_cur_level
Definition: pathnodes.h:255
List * unique_for_rels
Definition: pathnodes.h:698
List * statlist
Definition: pathnodes.h:679
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:638
Relids * attr_needed
Definition: pathnodes.h:674
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:428
#define IS_OTHER_REL(rel)
Definition: pathnodes.h:629
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:658
Oid userid
Definition: pathnodes.h:691
double tuples
Definition: pathnodes.h:681
List * baserestrictinfo
Definition: pathnodes.h:703
bool consider_param_startup
Definition: pathnodes.h:648
Definition: nodes.h:525
List * partial_pathlist
Definition: pathnodes.h:657
List * cheapest_parameterized_paths
Definition: pathnodes.h:661
Index baserestrict_min_security
Definition: pathnodes.h:705
bool useridiscurrent
Definition: pathnodes.h:692
List ** nullable_partexprs
Definition: pathnodes.h:725
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:682
PlannerInfo * subroot
Definition: pathnodes.h:685
bool consider_startup
Definition: pathnodes.h:647
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:854
Relids lateral_relids
Definition: pathnodes.h:666
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:334
List ** partexprs
Definition: pathnodes.h:724
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:944
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:901
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:646
struct Path * cheapest_total_path
Definition: pathnodes.h:659
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:1030
List * joininfo
Definition: pathnodes.h:707
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:694
int nparts
Definition: pathnodes.h:719
Relids relids
Definition: pathnodes.h:641
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2559
List * non_unique_for_rels
Definition: pathnodes.h:700
List * ppilist
Definition: pathnodes.h:656
Index relid
Definition: pathnodes.h:669
List * lappend(List *list, void *datum)
Definition: list.c:322
Relids lateral_referencers
Definition: pathnodes.h:677
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:701
Oid serverid
Definition: pathnodes.h:690
List * exprs
Definition: pathnodes.h:1044
Relids direct_lateral_relids
Definition: pathnodes.h:665
bool consider_partitionwise_join
Definition: pathnodes.h:712
int rel_parallel_workers
Definition: pathnodes.h:687
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:720
RTEKind rtekind
Definition: pathnodes.h:671
List * indexlist
Definition: pathnodes.h:678
double rows
Definition: pathnodes.h:644
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:695
#define makeNode(_type_)
Definition: nodes.h:573
BlockNumber pages
Definition: pathnodes.h:680
#define Assert(condition)
Definition: c.h:732
List ** join_rel_level
Definition: pathnodes.h:254
List * lateral_vars
Definition: pathnodes.h:676
JoinType jointype
Definition: pathnodes.h:2137
struct RelOptInfo ** part_rels
Definition: pathnodes.h:722
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:225
bool consider_parallel
Definition: pathnodes.h:649
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:928
List * partitioned_child_rels
Definition: pathnodes.h:726
AttrNumber max_attr
Definition: pathnodes.h:673
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1603
PartitionScheme part_scheme
Definition: pathnodes.h:718
List * pathlist
Definition: pathnodes.h:655
List * partition_qual
Definition: pathnodes.h:721
int32 * attr_widths
Definition: pathnodes.h:675
Definition: pg_list.h:50
struct PathTarget * reltarget
Definition: pathnodes.h:652
QualCost baserestrictcost
Definition: pathnodes.h:704
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:529
List * subplan_params
Definition: pathnodes.h:686
Bitmapset * eclass_indexes
Definition: pathnodes.h:683
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:1060
Relids top_parent_relids
Definition: pathnodes.h:714
AttrNumber min_attr
Definition: pathnodes.h:672

◆ 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:709
struct Path * cheapest_unique_path
Definition: pathnodes.h:660
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:696
#define NIL
Definition: pg_list.h:65
List * unique_for_rels
Definition: pathnodes.h:698
List * statlist
Definition: pathnodes.h:679
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:74
RelOptKind reloptkind
Definition: pathnodes.h:638
Relids * attr_needed
Definition: pathnodes.h:674
List * colnames
Definition: primnodes.h:43
struct Path * cheapest_startup_path
Definition: pathnodes.h:658
Oid userid
Definition: pathnodes.h:691
double tuples
Definition: pathnodes.h:681
List * baserestrictinfo
Definition: pathnodes.h:703
bool consider_param_startup
Definition: pathnodes.h:648
List * partial_pathlist
Definition: pathnodes.h:657
List * cheapest_parameterized_paths
Definition: pathnodes.h:661
Index baserestrict_min_security
Definition: pathnodes.h:705
bool useridiscurrent
Definition: pathnodes.h:692
List ** nullable_partexprs
Definition: pathnodes.h:725
Cost startup
Definition: pathnodes.h:45
double allvisfrac
Definition: pathnodes.h:682
signed int int32
Definition: c.h:346
struct RelOptInfo ** simple_rel_array
Definition: pathnodes.h:201
PlannerInfo * subroot
Definition: pathnodes.h:685
bool consider_startup
Definition: pathnodes.h:647
bool apply_child_basequals(PlannerInfo *root, RelOptInfo *parentrel, RelOptInfo *childrel, RangeTblEntry *childRTE, AppendRelInfo *appinfo)
Definition: inherit.c:627
Relids lateral_relids
Definition: pathnodes.h:666
Cost per_tuple
Definition: pathnodes.h:46
double tuple_fraction
Definition: pathnodes.h:334
List ** partexprs
Definition: pathnodes.h:724
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: pathnodes.h:659
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:186
List * joininfo
Definition: pathnodes.h:707
struct FdwRoutine * fdwroutine
Definition: pathnodes.h:694
int nparts
Definition: pathnodes.h:719
Relids relids
Definition: pathnodes.h:641
List * non_unique_for_rels
Definition: pathnodes.h:700
List * ppilist
Definition: pathnodes.h:656
Index relid
Definition: pathnodes.h:669
RangeTblEntry ** simple_rte_array
Definition: pathnodes.h:209
Relids lateral_referencers
Definition: pathnodes.h:677
Oid serverid
Definition: pathnodes.h:690
Relids direct_lateral_relids
Definition: pathnodes.h:665
bool consider_partitionwise_join
Definition: pathnodes.h:712
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:687
struct AppendRelInfo ** append_rel_array
Definition: pathnodes.h:217
struct PartitionBoundInfoData * boundinfo
Definition: pathnodes.h:720
RTEKind rtekind
Definition: pathnodes.h:671
List * indexlist
Definition: pathnodes.h:678
double rows
Definition: pathnodes.h:644
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: pathnodes.h:695
#define makeNode(_type_)
Definition: nodes.h:573
BlockNumber pages
Definition: pathnodes.h:680
#define Assert(condition)
Definition: c.h:732
List * lateral_vars
Definition: pathnodes.h:676
struct RelOptInfo ** part_rels
Definition: pathnodes.h:722
static int list_length(const List *l)
Definition: pg_list.h:169
bool consider_parallel
Definition: pathnodes.h:649
Bitmapset * Relids
Definition: pathnodes.h:28
RTEKind rtekind
Definition: parsenodes.h:974
List * partitioned_child_rels
Definition: pathnodes.h:726
AttrNumber max_attr
Definition: pathnodes.h:673
#define elog(elevel,...)
Definition: elog.h:226
PartitionScheme part_scheme
Definition: pathnodes.h:718
List * pathlist
Definition: pathnodes.h:655
Alias * eref
Definition: parsenodes.h:1092
List * partition_qual
Definition: pathnodes.h:721
int32 * attr_widths
Definition: pathnodes.h:675
struct PathTarget * reltarget
Definition: pathnodes.h:652
QualCost baserestrictcost
Definition: pathnodes.h:704
List * subplan_params
Definition: pathnodes.h:686
Bitmapset * eclass_indexes
Definition: pathnodes.h:683
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:114
Relids top_parent_relids
Definition: pathnodes.h:714
AttrNumber min_attr
Definition: pathnodes.h:672

◆ calc_nestloop_required_outer()

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

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

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

2268 {
2269  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2270  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2271  Relids required_outer;
2272 
2273  /* neither path can require rels from the other */
2274  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2275  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2276  /* form the union ... */
2277  required_outer = bms_union(outer_paramrels, inner_paramrels);
2278  /* we do not need an explicit test for empty; bms_union gets it right */
2279  return required_outer;
2280 }
RelOptInfo * parent
Definition: pathnodes.h:1114
#define PATH_REQ_OUTER(path)
Definition: pathnodes.h:1133
Relids relids
Definition: pathnodes.h:641
#define Assert(condition)
Definition: c.h:732
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 118 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().

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

◆ compare_path_costs()

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

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

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

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

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

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

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

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

1053 {
1054  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1055 
1056  pathnode->path.pathtype = T_BitmapHeapScan;
1057  pathnode->path.parent = rel;
1058  pathnode->path.pathtarget = rel->reltarget;
1059  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1060  required_outer);
1061  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1062  pathnode->path.parallel_safe = rel->consider_parallel;
1063  pathnode->path.parallel_workers = parallel_degree;
1064  pathnode->path.pathkeys = NIL; /* always unordered */
1065 
1066  pathnode->bitmapqual = bitmapqual;
1067 
1068  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1069  pathnode->path.param_info,
1070  bitmapqual, loop_count);
1071 
1072  return pathnode;
1073 }
#define NIL
Definition: pg_list.h:65
PathTarget * pathtarget
Definition: pathnodes.h:1115
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:1251
int parallel_workers
Definition: pathnodes.h:1121
ParamPathInfo * param_info
Definition: pathnodes.h:1117
NodeTag pathtype
Definition: pathnodes.h:1112
#define true
Definition: c.h:312
RelOptInfo * parent
Definition: pathnodes.h:1114
Path * bitmapqual
Definition: pathnodes.h:1250
List * pathkeys
Definition: pathnodes.h:1128
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1120
bool consider_parallel
Definition: pathnodes.h:649
bool parallel_aware
Definition: pathnodes.h:1119
struct PathTarget * reltarget
Definition: pathnodes.h:652

◆ create_bitmap_or_path()

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

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

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

◆ create_ctescan_path()

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

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

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

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

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

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

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

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

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

◆ create_functionscan_path()

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

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

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

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

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

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

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

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

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

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

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

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

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

1009 {
1010  IndexPath *pathnode = makeNode(IndexPath);
1011  RelOptInfo *rel = index->rel;
1012 
1013  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1014  pathnode->path.parent = rel;
1015  pathnode->path.pathtarget = rel->reltarget;
1016  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1017  required_outer);
1018  pathnode->path.parallel_aware = false;
1019  pathnode->path.parallel_safe = rel->consider_parallel;
1020  pathnode->path.parallel_workers = 0;
1021  pathnode->path.pathkeys = pathkeys;
1022 
1023  pathnode->indexinfo = index;
1024  pathnode->indexclauses = indexclauses;
1025  pathnode->indexorderbys = indexorderbys;
1026  pathnode->indexorderbycols = indexorderbycols;
1027  pathnode->indexscandir = indexscandir;
1028 
1029  cost_index(pathnode, root, loop_count, partial_path);
1030 
1031  return pathnode;
1032 }
List * indexorderbycols
Definition: pathnodes.h:1180
PathTarget * pathtarget
Definition: pathnodes.h:1115
Path path
Definition: pathnodes.h:1176
IndexOptInfo * indexinfo
Definition: pathnodes.h:1177
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1251
int parallel_workers
Definition: pathnodes.h:1121
ParamPathInfo * param_info
Definition: pathnodes.h:1117
List * indexclauses
Definition: pathnodes.h:1178
NodeTag pathtype
Definition: pathnodes.h:1112
RelOptInfo * rel
Definition: pathnodes.h:791
RelOptInfo * parent
Definition: pathnodes.h:1114
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:476
List * indexorderbys
Definition: pathnodes.h:1179
List * pathkeys
Definition: pathnodes.h:1128
#define makeNode(_type_)
Definition: nodes.h:573
bool parallel_safe
Definition: pathnodes.h:1120
bool consider_parallel
Definition: pathnodes.h:649
ScanDirection indexscandir
Definition: pathnodes.h:1181
bool parallel_aware
Definition: pathnodes.h:1119
struct PathTarget * reltarget
Definition: pathnodes.h:652

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

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

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

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1497 {
1498  MaterialPath *pathnode = makeNode(MaterialPath);
1499 
1500  Assert(subpath->parent == rel);
1501 
1502  pathnode->path.pathtype = T_Material;
1503  pathnode->path.parent = rel;
1504  pathnode->path.pathtarget = rel->reltarget;
1505  pathnode->path.param_info = subpath->param_info;
1506  pathnode->path.parallel_aware = false;
1507  pathnode->path.parallel_safe = rel->consider_parallel &&
1508  subpath->parallel_safe;
1509  pathnode->path.parallel_workers = subpath->parallel_workers;
1510  pathnode->path.pathkeys = subpath->pathkeys;
1511 
1512  pathnode->subpath = subpath;
1513 
1514  cost_material(&pathnode->path,
1515  subpath->startup_cost,
1516  subpath->total_cost,
1517  subpath->rows,
1518  subpath->pathtarget->width);
1519 
1520  return pathnode;
1521 }
PathTarget * pathtarget
Definition: pathnodes.h:1115
int parallel_workers
Definition: pathnodes.h:1121
ParamPathInfo * param_info
Definition: pathnodes.h:1117
Path * subpath
Definition: pathnodes.h:1426
NodeTag pathtype
Definition: pathnodes.h:1112
Cost startup_cost
Definition: pathnodes.h:1125
RelOptInfo * parent
Definition: pathnodes.h:1114
Cost total_cost
Definition: pathnodes.h:1126
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:1128
#define makeNode(_type_)
Definition: nodes.h:573
#define Assert(condition)
Definition: c.h:732
double rows
Definition: pathnodes.h:1124
bool parallel_safe
Definition: pathnodes.h:1120
bool consider_parallel
Definition: pathnodes.h:649
bool parallel_aware
Definition: pathnodes.h:1119
struct PathTarget * reltarget
Definition: pathnodes.h:652
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 1346 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().

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

2401 {
2402  MergePath *pathnode = makeNode(MergePath);
2403 
2404  pathnode->jpath.path.pathtype = T_MergeJoin;
2405  pathnode->jpath.path.parent = joinrel;
2406  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2407  pathnode->jpath.path.param_info =
2409  joinrel,
2410  outer_path,
2411  inner_path,
2412  extra->sjinfo,
2413  required_outer,
2414  &restrict_clauses);
2415  pathnode->jpath.path.parallel_aware = false;
2416  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2417  outer_path->parallel_safe && inner_path->parallel_safe;
2418  /* This is a foolish way to estimate parallel_workers, but for now... */
2419  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2420  pathnode->jpath.path.pathkeys = pathkeys;
2421  pathnode->jpath.jointype = jointype;
2422  pathnode->jpath.inner_unique = extra->inner_unique;
2423  pathnode->jpath.outerjoinpath = outer_path;
2424  pathnode->jpath.innerjoinpath = inner_path;
2425  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2426  pathnode->path_mergeclauses = mergeclauses;
2427  pathnode->outersortkeys = outersortkeys;
2428  pathnode->innersortkeys = innersortkeys;
2429  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2430  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2431 
2432  final_cost_mergejoin(root, pathnode, workspace, extra);
2433 
2434  return pathnode;
2435 }
List * path_mergeclauses
Definition: pathnodes.h:1551
List * outersortkeys
Definition: pathnodes.h:1552
PathTarget * pathtarget
Definition: pathnodes.h:1115
ParamPathInfo * get_joinrel_parampathinfo(PlannerInfo *root, RelOptInfo *joinrel, Path *outer_path, Path *inner_path, SpecialJoinInfo *sjinfo, Relids required_outer, List **restrict_clauses)
Definition: relnode.c:1341
Path * innerjoinpath
Definition: pathnodes.h:1496
int parallel_workers
Definition: pathnodes.h:1121
ParamPathInfo * param_info
Definition: pathnodes.h:1117
NodeTag pathtype
Definition: pathnodes.h:1112
SpecialJoinInfo * sjinfo
Definition: pathnodes.h:2380
List * joinrestrictinfo
Definition: pathnodes.h:1498
RelOptInfo * parent
Definition: pathnodes.h:1114
Path * outerjoinpath
Definition: pathnodes.h:1495
List * pathkeys
Definition: pathnodes.h:1128
#define makeNode(_type_)
Definition: nodes.h:573
Path path
Definition: pathnodes.h:1488
bool parallel_safe
Definition: pathnodes.h:1120
bool inner_unique
Definition: pathnodes.h:1492
bool consider_parallel
Definition: pathnodes.h:649
List * innersortkeys
Definition: pathnodes.h:1553
JoinType jointype
Definition: pathnodes.h:1490
JoinPath jpath
Definition: pathnodes.h:1550
bool parallel_aware
Definition: pathnodes.h:1119
struct PathTarget * reltarget
Definition: pathnodes.h:652
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 3145 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().

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

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

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

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

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

◆ create_projection_path()