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

Go to the source code of this file.

Functions

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

Function Documentation

◆ add_partial_path()

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 762 of file pathnode.c.

References Assert, CHECK_FOR_INTERRUPTS, compare_pathkeys(), RelOptInfo::consider_parallel, lappend_cell(), lcons(), lfirst, list_delete_cell(), list_head(), lnext, 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().

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

◆ add_partial_path_precheck()

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

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

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

◆ add_path()

void add_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 422 of file pathnode.c.

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

Referenced by add_foreign_grouping_paths(), add_paths_to_append_rel(), add_paths_to_grouping_rel(), add_paths_with_pathkeys_for_rel(), consider_groupingsets_paths(), create_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_mergeappend_paths(), generate_nonunion_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_subquery_pathlist(), set_tablefunc_pathlist(), set_tablesample_rel_pathlist(), set_values_pathlist(), set_worktable_pathlist(), try_hashjoin_path(), try_mergejoin_path(), and try_nestloop_path().

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

◆ add_path_precheck()

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

Definition at line 657 of file pathnode.c.

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

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

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

◆ apply_projection_to_path()

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

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

2479 {
2480  QualCost oldcost;
2481 
2482  /*
2483  * If given path can't project, we might need a Result node, so make a
2484  * separate ProjectionPath.
2485  */
2486  if (!is_projection_capable_path(path))
2487  return (Path *) create_projection_path(root, rel, path, target);
2488 
2489  /*
2490  * We can just jam the desired tlist into the existing path, being sure to
2491  * update its cost estimates appropriately.
2492  */
2493  oldcost = path->pathtarget->cost;
2494  path->pathtarget = target;
2495 
2496  path->startup_cost += target->cost.startup - oldcost.startup;
2497  path->total_cost += target->cost.startup - oldcost.startup +
2498  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2499 
2500  /*
2501  * If the path happens to be a Gather or GatherMerge path, we'd like to
2502  * arrange for the subpath to return the required target list so that
2503  * workers can help project. But if there is something that is not
2504  * parallel-safe in the target expressions, then we can't.
2505  */
2506  if ((IsA(path, GatherPath) ||IsA(path, GatherMergePath)) &&
2507  is_parallel_safe(root, (Node *) target->exprs))
2508  {
2509  /*
2510  * We always use create_projection_path here, even if the subpath is
2511  * projection-capable, so as to avoid modifying the subpath in place.
2512  * It seems unlikely at present that there could be any other
2513  * references to the subpath, but better safe than sorry.
2514  *
2515  * Note that we don't change the parallel path's cost estimates; it
2516  * might be appropriate to do so, to reflect the fact that the bulk of
2517  * the target evaluation will happen in workers.
2518  */
2519  if (IsA(path, GatherPath))
2520  {
2521  GatherPath *gpath = (GatherPath *) path;
2522 
2523  gpath->subpath = (Path *)
2525  gpath->subpath->parent,
2526  gpath->subpath,
2527  target);
2528  }
2529  else
2530  {
2531  GatherMergePath *gmpath = (GatherMergePath *) path;
2532 
2533  gmpath->subpath = (Path *)
2535  gmpath->subpath->parent,
2536  gmpath->subpath,
2537  target);
2538  }
2539  }
2540  else if (path->parallel_safe &&
2541  !is_parallel_safe(root, (Node *) target->exprs))
2542  {
2543  /*
2544  * We're inserting a parallel-restricted target list into a path
2545  * currently marked parallel-safe, so we have to mark it as no longer
2546  * safe.
2547  */
2548  path->parallel_safe = false;
2549  }
2550 
2551  return path;
2552 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:568
PathTarget * pathtarget
Definition: relation.h:1079
Definition: nodes.h:517
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2384
Cost startup
Definition: relation.h:46
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1088
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1395
List * exprs
Definition: relation.h:1008
Cost total_cost
Definition: relation.h:1090
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
Path * subpath
Definition: relation.h:1408
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6700

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

References add_join_rel(), add_placeholders_to_child_joinrel(), adjust_appendrel_attrs(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_free(), bms_union(), RelOptInfo::boundinfo, build_joinrel_partition_info(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_appinfos_by_relids(), find_join_rel(), RelOptInfo::has_eclass_joins, RelOptInfo::indexlist, InvalidOid, IS_OTHER_REL, RelOptInfo::joininfo, RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, NIL, RelOptInfo::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().

690 {
691  RelOptInfo *joinrel = makeNode(RelOptInfo);
692  AppendRelInfo **appinfos;
693  int nappinfos;
694 
695  /* Only joins between "other" relations land here. */
696  Assert(IS_OTHER_REL(outer_rel) && IS_OTHER_REL(inner_rel));
697 
698  joinrel->reloptkind = RELOPT_OTHER_JOINREL;
699  joinrel->relids = bms_union(outer_rel->relids, inner_rel->relids);
700  joinrel->rows = 0;
701  /* cheap startup cost is interesting iff not all tuples to be retrieved */
702  joinrel->consider_startup = (root->tuple_fraction > 0);
703  joinrel->consider_param_startup = false;
704  joinrel->consider_parallel = false;
705  joinrel->reltarget = create_empty_pathtarget();
706  joinrel->pathlist = NIL;
707  joinrel->ppilist = NIL;
708  joinrel->partial_pathlist = NIL;
709  joinrel->cheapest_startup_path = NULL;
710  joinrel->cheapest_total_path = NULL;
711  joinrel->cheapest_unique_path = NULL;
713  joinrel->direct_lateral_relids = NULL;
714  joinrel->lateral_relids = NULL;
715  joinrel->relid = 0; /* indicates not a baserel */
716  joinrel->rtekind = RTE_JOIN;
717  joinrel->min_attr = 0;
718  joinrel->max_attr = 0;
719  joinrel->attr_needed = NULL;
720  joinrel->attr_widths = NULL;
721  joinrel->lateral_vars = NIL;
722  joinrel->lateral_referencers = NULL;
723  joinrel->indexlist = NIL;
724  joinrel->pages = 0;
725  joinrel->tuples = 0;
726  joinrel->allvisfrac = 0;
727  joinrel->subroot = NULL;
728  joinrel->subplan_params = NIL;
729  joinrel->serverid = InvalidOid;
730  joinrel->userid = InvalidOid;
731  joinrel->useridiscurrent = false;
732  joinrel->fdwroutine = NULL;
733  joinrel->fdw_private = NULL;
734  joinrel->baserestrictinfo = NIL;
735  joinrel->baserestrictcost.startup = 0;
736  joinrel->baserestrictcost.per_tuple = 0;
737  joinrel->joininfo = NIL;
738  joinrel->has_eclass_joins = false;
739  joinrel->top_parent_relids = NULL;
740  joinrel->part_scheme = NULL;
741  joinrel->nparts = 0;
742  joinrel->boundinfo = NULL;
743  joinrel->partition_qual = NIL;
744  joinrel->part_rels = NULL;
745  joinrel->partexprs = NULL;
746  joinrel->nullable_partexprs = NULL;
747  joinrel->partitioned_child_rels = NIL;
748 
749  joinrel->top_parent_relids = bms_union(outer_rel->top_parent_relids,
750  inner_rel->top_parent_relids);
751 
752  /* Compute information relevant to foreign relations. */
753  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
754 
755  /* Build targetlist */
756  build_joinrel_tlist(root, joinrel, outer_rel);
757  build_joinrel_tlist(root, joinrel, inner_rel);
758  /* Add placeholder variables. */
759  add_placeholders_to_child_joinrel(root, joinrel, parent_joinrel);
760 
761  /* Construct joininfo list. */
762  appinfos = find_appinfos_by_relids(root, joinrel->relids, &nappinfos);
763  joinrel->joininfo = (List *) adjust_appendrel_attrs(root,
764  (Node *) parent_joinrel->joininfo,
765  nappinfos,
766  appinfos);
767  pfree(appinfos);
768 
769  /*
770  * Lateral relids referred in child join will be same as that referred in
771  * the parent relation. Throw any partial result computed while building
772  * the targetlist.
773  */
775  bms_free(joinrel->lateral_relids);
776  joinrel->direct_lateral_relids = (Relids) bms_copy(parent_joinrel->direct_lateral_relids);
777  joinrel->lateral_relids = (Relids) bms_copy(parent_joinrel->lateral_relids);
778 
779  /*
780  * If the parent joinrel has pending equivalence classes, so does the
781  * child.
782  */
783  joinrel->has_eclass_joins = parent_joinrel->has_eclass_joins;
784 
785  /* Is the join between partitions itself partitioned? */
786  build_joinrel_partition_info(joinrel, outer_rel, inner_rel, restrictlist,
787  jointype);
788 
789  /* Child joinrel is parallel safe if parent is parallel safe. */
790  joinrel->consider_parallel = parent_joinrel->consider_parallel;
791 
792 
793  /* Set estimates of the child-joinrel's size. */
794  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
795  sjinfo, restrictlist);
796 
797  /* We build the join only once. */
798  Assert(!find_join_rel(root, joinrel->relids));
799 
800  /* Add the relation to the PlannerInfo. */
801  add_join_rel(root, joinrel);
802 
803  return joinrel;
804 }
bool has_eclass_joins
Definition: relation.h:678
struct Path * cheapest_unique_path
Definition: relation.h:631
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:133
RelOptKind reloptkind
Definition: relation.h:609
Relids * attr_needed
Definition: relation.h:645
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:344
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4375
struct Path * cheapest_startup_path
Definition: relation.h:629
Oid userid
Definition: relation.h:660
double tuples
Definition: relation.h:652
List * baserestrictinfo
Definition: relation.h:672
bool consider_param_startup
Definition: relation.h:619
Definition: nodes.h:517
List * partial_pathlist
Definition: relation.h:628
#define IS_OTHER_REL(rel)
Definition: relation.h:600
List * cheapest_parameterized_paths
Definition: relation.h:632
bool useridiscurrent
Definition: relation.h:661
List ** nullable_partexprs
Definition: relation.h:691
Cost startup
Definition: relation.h:46
double allvisfrac
Definition: relation.h:653
PlannerInfo * subroot
Definition: relation.h:654
bool consider_startup
Definition: relation.h:618
Relids lateral_relids
Definition: relation.h:637
Cost per_tuple
Definition: relation.h:47
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:407
double tuple_fraction
Definition: relation.h:306
void pfree(void *pointer)
Definition: mcxt.c:1031
List ** partexprs
Definition: relation.h:690
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:858
struct Path * cheapest_total_path
Definition: relation.h:630
List * joininfo
Definition: relation.h:676
struct FdwRoutine * fdwroutine
Definition: relation.h:663
int nparts
Definition: relation.h:685
Relids relids
Definition: relation.h:612
List * ppilist
Definition: relation.h:627
Index relid
Definition: relation.h:640
Bitmapset * Relids
Definition: relation.h:29
Relids lateral_referencers
Definition: relation.h:648
Node * adjust_appendrel_attrs(PlannerInfo *root, Node *node, int nappinfos, AppendRelInfo **appinfos)
Definition: prepunion.c:2047
Oid serverid
Definition: relation.h:659
Relids direct_lateral_relids
Definition: relation.h:636
struct PartitionBoundInfoData * boundinfo
Definition: relation.h:686
AppendRelInfo ** find_appinfos_by_relids(PlannerInfo *root, Relids relids, int *nappinfos)
Definition: prepunion.c:2618
RTEKind rtekind
Definition: relation.h:642
List * indexlist
Definition: relation.h:649
double rows
Definition: relation.h:615
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:664
void bms_free(Bitmapset *a)
Definition: bitmapset.c:267
#define makeNode(_type_)
Definition: nodes.h:565
BlockNumber pages
Definition: relation.h:651
#define Assert(condition)
Definition: c.h:699
List * lateral_vars
Definition: relation.h:647
void add_placeholders_to_child_joinrel(PlannerInfo *root, RelOptInfo *childrel, RelOptInfo *parentrel)
Definition: placeholder.c:474
struct RelOptInfo ** part_rels
Definition: relation.h:688
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
bool consider_parallel
Definition: relation.h:620
List * partitioned_child_rels
Definition: relation.h:692
AttrNumber max_attr
Definition: relation.h:644
static void build_joinrel_partition_info(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, List *restrictlist, JoinType jointype)
Definition: relnode.c:1604
PartitionScheme part_scheme
Definition: relation.h:684
List * pathlist
Definition: relation.h:626
List * partition_qual
Definition: relation.h:687
int32 * attr_widths
Definition: relation.h:646
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623
QualCost baserestrictcost
Definition: relation.h:673
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:445
List * subplan_params
Definition: relation.h:655
Relids top_parent_relids
Definition: relation.h:681
AttrNumber min_attr
Definition: relation.h:643

◆ build_empty_join_rel()

RelOptInfo* build_empty_join_rel ( PlannerInfo root)

Definition at line 1111 of file relnode.c.

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

Referenced by query_planner().

1112 {
1113  RelOptInfo *joinrel;
1114 
1115  /* The dummy join relation should be the only one ... */
1116  Assert(root->join_rel_list == NIL);
1117 
1118  joinrel = makeNode(RelOptInfo);
1119  joinrel->reloptkind = RELOPT_JOINREL;
1120  joinrel->relids = NULL; /* empty set */
1121  joinrel->rows = 1; /* we produce one row for such cases */
1122  joinrel->rtekind = RTE_JOIN;
1123  joinrel->reltarget = create_empty_pathtarget();
1124 
1125  root->join_rel_list = lappend(root->join_rel_list, joinrel);
1126 
1127  return joinrel;
1128 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:609
List * join_rel_list
Definition: relation.h:229
Relids relids
Definition: relation.h:612
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:642
double rows
Definition: relation.h:615
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
struct PathTarget * reltarget
Definition: relation.h:623

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

References add_join_rel(), add_placeholders_to_joinrel(), RelOptInfo::allvisfrac, Assert, RelOptInfo::attr_needed, RelOptInfo::attr_widths, RelOptInfo::baserestrict_min_security, RelOptInfo::baserestrictcost, RelOptInfo::baserestrictinfo, bms_copy(), bms_del_members(), bms_is_empty(), bms_num_members(), bms_union(), RelOptInfo::boundinfo, build_joinrel_joinlist(), build_joinrel_partition_info(), build_joinrel_restrictlist(), build_joinrel_tlist(), RelOptInfo::cheapest_parameterized_paths, RelOptInfo::cheapest_startup_path, RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, RelOptInfo::consider_param_startup, RelOptInfo::consider_startup, create_empty_pathtarget(), RelOptInfo::direct_lateral_relids, PathTarget::exprs, RelOptInfo::fdw_private, RelOptInfo::fdwroutine, find_join_rel(), RelOptInfo::has_eclass_joins, has_relevant_eclass_joinclause(), RelOptInfo::indexlist, InvalidOid, IS_OTHER_REL, is_parallel_safe(), PlannerInfo::join_cur_level, PlannerInfo::join_rel_level, RelOptInfo::joininfo, SpecialJoinInfo::jointype, lappend(), RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, min_join_parameterization(), NIL, RelOptInfo::non_unique_for_rels, RelOptInfo::nparts, RelOptInfo::nullable_partexprs, RelOptInfo::pages, RelOptInfo::part_rels, RelOptInfo::part_scheme, RelOptInfo::partexprs, RelOptInfo::partial_pathlist, RelOptInfo::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().

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

◆ build_simple_rel()

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

Definition at line 96 of file relnode.c.

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

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

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

◆ calc_nestloop_required_outer()

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

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

2102 {
2103  Relids required_outer;
2104 
2105  /* inner_path can require rels from outer path, but not vice versa */
2106  Assert(!bms_overlap(outer_paramrels, innerrelids));
2107  /* easy case if inner path is not parameterized */
2108  if (!inner_paramrels)
2109  return bms_copy(outer_paramrels);
2110  /* else, form the union ... */
2111  required_outer = bms_union(outer_paramrels, inner_paramrels);
2112  /* ... and remove any mention of now-satisfied outer rels */
2113  required_outer = bms_del_members(required_outer,
2114  outerrelids);
2115  /* maintain invariant that required_outer is exactly NULL if empty */
2116  if (bms_is_empty(required_outer))
2117  {
2118  bms_free(required_outer);
2119  required_outer = NULL;
2120  }
2121  return required_outer;
2122 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:133
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:729
void bms_free(Bitmapset *a)
Definition: bitmapset.c:267
#define Assert(condition)
Definition: c.h:699
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:955
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509

◆ calc_non_nestloop_required_outer()

Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2132 {
2133  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2134  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2135  Relids required_outer;
2136 
2137  /* neither path can require rels from the other */
2138  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2139  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2140  /* form the union ... */
2141  required_outer = bms_union(outer_paramrels, inner_paramrels);
2142  /* we do not need an explicit test for empty; bms_union gets it right */
2143  return required_outer;
2144 }
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
#define Assert(condition)
Definition: c.h:699
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509

◆ compare_fractional_path_costs()

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

Definition at line 117 of file pathnode.c.

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

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

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

◆ compare_path_costs()

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

Definition at line 71 of file pathnode.c.

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

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

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

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

2796 {
2797  AggPath *pathnode = makeNode(AggPath);
2798 
2799  pathnode->path.pathtype = T_Agg;
2800  pathnode->path.parent = rel;
2801  pathnode->path.pathtarget = target;
2802  /* For now, assume we are above any joins, so no parameterization */
2803  pathnode->path.param_info = NULL;
2804  pathnode->path.parallel_aware = false;
2805  pathnode->path.parallel_safe = rel->consider_parallel &&
2806  subpath->parallel_safe;
2807  pathnode->path.parallel_workers = subpath->parallel_workers;
2808  if (aggstrategy == AGG_SORTED)
2809  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2810  else
2811  pathnode->path.pathkeys = NIL; /* output is unordered */
2812  pathnode->subpath = subpath;
2813 
2814  pathnode->aggstrategy = aggstrategy;
2815  pathnode->aggsplit = aggsplit;
2816  pathnode->numGroups = numGroups;
2817  pathnode->groupClause = groupClause;
2818  pathnode->qual = qual;
2819 
2820  cost_agg(&pathnode->path, root,
2821  aggstrategy, aggcosts,
2822  list_length(groupClause), numGroups,
2823  qual,
2824  subpath->startup_cost, subpath->total_cost,
2825  subpath->rows);
2826 
2827  /* add tlist eval cost for each output row */
2828  pathnode->path.startup_cost += target->cost.startup;
2829  pathnode->path.total_cost += target->cost.startup +
2830  target->cost.per_tuple * pathnode->path.rows;
2831 
2832  return pathnode;
2833 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:78
PathTarget * pathtarget
Definition: relation.h:1079
AggStrategy aggstrategy
Definition: relation.h:1592
List * qual
Definition: relation.h:1596
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:2060
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
AggSplit aggsplit
Definition: relation.h:1593
double numGroups
Definition: relation.h:1594
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * groupClause
Definition: relation.h:1595
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
Path * subpath
Definition: relation.h:1591
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1590
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_append_path()

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

Definition at line 1219 of file pathnode.c.

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

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

1225 {
1226  AppendPath *pathnode = makeNode(AppendPath);
1227  ListCell *l;
1228 
1229  Assert(!parallel_aware || parallel_workers > 0);
1230 
1231  pathnode->path.pathtype = T_Append;
1232  pathnode->path.parent = rel;
1233  pathnode->path.pathtarget = rel->reltarget;
1234 
1235  /*
1236  * When generating an Append path for a partitioned table, there may be
1237  * parameters that are useful so we can eliminate certain partitions
1238  * during execution. Here we'll go all the way and fully populate the
1239  * parameter info data as we do for normal base relations. However, we
1240  * need only bother doing this for RELOPT_BASEREL rels, as
1241  * RELOPT_OTHER_MEMBER_REL's Append paths are merged into the base rel's
1242  * Append subpaths. It would do no harm to do this, we just avoid it to
1243  * save wasting effort.
1244  */
1245  if (partitioned_rels != NIL && root && rel->reloptkind == RELOPT_BASEREL)
1246  pathnode->path.param_info = get_baserel_parampathinfo(root,
1247  rel,
1248  required_outer);
1249  else
1251  required_outer);
1252 
1253  pathnode->path.parallel_aware = parallel_aware;
1254  pathnode->path.parallel_safe = rel->consider_parallel;
1255  pathnode->path.parallel_workers = parallel_workers;
1256  pathnode->path.pathkeys = NIL; /* result is always considered unsorted */
1257  pathnode->partitioned_rels = list_copy(partitioned_rels);
1258 
1259  /*
1260  * For parallel append, non-partial paths are sorted by descending total
1261  * costs. That way, the total time to finish all non-partial paths is
1262  * minimized. Also, the partial paths are sorted by descending startup
1263  * costs. There may be some paths that require to do startup work by a
1264  * single worker. In such case, it's better for workers to choose the
1265  * expensive ones first, whereas the leader should choose the cheapest
1266  * startup plan.
1267  */
1268  if (pathnode->path.parallel_aware)
1269  {
1270  subpaths = list_qsort(subpaths, append_total_cost_compare);
1271  partial_subpaths = list_qsort(partial_subpaths,
1273  }
1274  pathnode->first_partial_path = list_length(subpaths);
1275  pathnode->subpaths = list_concat(subpaths, partial_subpaths);
1276 
1277  foreach(l, subpaths)
1278  {
1279  Path *subpath = (Path *) lfirst(l);
1280 
1281  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1282  subpath->parallel_safe;
1283 
1284  /* All child paths must have same parameterization */
1285  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1286  }
1287 
1288  Assert(!parallel_aware || pathnode->path.parallel_safe);
1289 
1290  cost_append(pathnode);
1291 
1292  /* If the caller provided a row estimate, override the computed value. */
1293  if (rows >= 0)
1294  pathnode->path.rows = rows;
1295 
1296  return pathnode;
1297 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
RelOptKind reloptkind
Definition: relation.h:609
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:49
List * list_concat(List *list1, List *list2)
Definition: list.c:321
Path path
Definition: relation.h:1304
int first_partial_path
Definition: relation.h:1310
NodeTag pathtype
Definition: relation.h:1076
List * subpaths
Definition: relation.h:1307
RelOptInfo * parent
Definition: relation.h:1078
static int append_total_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1308
static int append_startup_cost_compare(const void *a, const void *b)
Definition: pathnode.c:1329
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
void cost_append(AppendPath *apath)
Definition: costsize.c:1843
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
List * partitioned_rels
Definition: relation.h:1306
List * list_qsort(const List *list, list_qsort_comparator cmp)
Definition: list.c:1261
bool parallel_aware
Definition: relation.h:1083
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1552
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:153

◆ create_bitmap_and_path()

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

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

1119 {
1120  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1121 
1122  pathnode->path.pathtype = T_BitmapAnd;
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_and_node(pathnode, root);
1143 
1144  return pathnode;
1145 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1089
ParamPathInfo * param_info
Definition: relation.h:1081
List * bitmapquals
Definition: relation.h:1198
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

1089 {
1090  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1091 
1092  pathnode->path.pathtype = T_BitmapHeapScan;
1093  pathnode->path.parent = rel;
1094  pathnode->path.pathtarget = rel->reltarget;
1095  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1096  required_outer);
1097  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1098  pathnode->path.parallel_safe = rel->consider_parallel;
1099  pathnode->path.parallel_workers = parallel_degree;
1100  pathnode->path.pathkeys = NIL; /* always unordered */
1101 
1102  pathnode->bitmapqual = bitmapqual;
1103 
1104  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1105  pathnode->path.param_info,
1106  bitmapqual, loop_count);
1107 
1108  return pathnode;
1109 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:945
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
#define true
Definition: c.h:279
RelOptInfo * parent
Definition: relation.h:1078
Path * bitmapqual
Definition: relation.h:1186
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_bitmap_or_path()

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

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

1155 {
1156  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1157 
1158  pathnode->path.pathtype = T_BitmapOr;
1159  pathnode->path.parent = rel;
1160  pathnode->path.pathtarget = rel->reltarget;
1161  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1162 
1163  /*
1164  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1165  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1166  * set the flag for this path based only on the relation-level flag,
1167  * without actually iterating over the list of children.
1168  */
1169  pathnode->path.parallel_aware = false;
1170  pathnode->path.parallel_safe = rel->consider_parallel;
1171  pathnode->path.parallel_workers = 0;
1172 
1173  pathnode->path.pathkeys = NIL; /* always unordered */
1174 
1175  pathnode->bitmapquals = bitmapquals;
1176 
1177  /* this sets bitmapselectivity as well as the regular cost fields: */
1178  cost_bitmap_or_node(pathnode, root);
1179 
1180  return pathnode;
1181 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * bitmapquals
Definition: relation.h:1211
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1133
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_ctescan_path()

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

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

1978 {
1979  Path *pathnode = makeNode(Path);
1980 
1981  pathnode->pathtype = T_CteScan;
1982  pathnode->parent = rel;
1983  pathnode->pathtarget = rel->reltarget;
1984  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1985  required_outer);
1986  pathnode->parallel_aware = false;
1987  pathnode->parallel_safe = rel->consider_parallel;
1988  pathnode->parallel_workers = 0;
1989  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1990 
1991  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1992 
1993  return pathnode;
1994 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1500
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

References RelOptInfo::consider_parallel, ForeignPath::fdw_outerpath, ForeignPath::fdw_private, get_baserel_parampathinfo(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ForeignPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, Path::rows, Path::startup_cost, T_ForeignScan, and Path::total_cost.

Referenced by add_foreign_grouping_paths(), add_paths_with_pathkeys_for_rel(), fileGetForeignPaths(), postgresGetForeignJoinPaths(), and postgresGetForeignPaths().

2069 {
2070  ForeignPath *pathnode = makeNode(ForeignPath);
2071 
2072  pathnode->path.pathtype = T_ForeignScan;
2073  pathnode->path.parent = rel;
2074  pathnode->path.pathtarget = target ? target : rel->reltarget;
2075  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
2076  required_outer);
2077  pathnode->path.parallel_aware = false;
2078  pathnode->path.parallel_safe = rel->consider_parallel;
2079  pathnode->path.parallel_workers = 0;
2080  pathnode->path.rows = rows;
2081  pathnode->path.startup_cost = startup_cost;
2082  pathnode->path.total_cost = total_cost;
2083  pathnode->path.pathkeys = pathkeys;
2084 
2085  pathnode->fdw_outerpath = fdw_outerpath;
2086  pathnode->fdw_private = fdw_private;
2087 
2088  return pathnode;
2089 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
Path * fdw_outerpath
Definition: relation.h:1255
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
List * fdw_private
Definition: relation.h:1256
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_functionscan_path()

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

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

1901 {
1902  Path *pathnode = makeNode(Path);
1903 
1904  pathnode->pathtype = T_FunctionScan;
1905  pathnode->parent = rel;
1906  pathnode->pathtarget = rel->reltarget;
1907  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1908  required_outer);
1909  pathnode->parallel_aware = false;
1910  pathnode->parallel_safe = rel->consider_parallel;
1911  pathnode->parallel_workers = 0;
1912  pathnode->pathkeys = pathkeys;
1913 
1914  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1915 
1916  return pathnode;
1917 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1333
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

1744 {
1746  Cost input_startup_cost = 0;
1747  Cost input_total_cost = 0;
1748 
1749  Assert(subpath->parallel_safe);
1750  Assert(pathkeys);
1751 
1752  pathnode->path.pathtype = T_GatherMerge;
1753  pathnode->path.parent = rel;
1754  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1755  required_outer);
1756  pathnode->path.parallel_aware = false;
1757 
1758  pathnode->subpath = subpath;
1759  pathnode->num_workers = subpath->parallel_workers;
1760  pathnode->path.pathkeys = pathkeys;
1761  pathnode->path.pathtarget = target ? target : rel->reltarget;
1762  pathnode->path.rows += subpath->rows;
1763 
1764  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1765  {
1766  /* Subpath is adequately ordered, we won't need to sort it */
1767  input_startup_cost += subpath->startup_cost;
1768  input_total_cost += subpath->total_cost;
1769  }
1770  else
1771  {
1772  /* We'll need to insert a Sort node, so include cost for that */
1773  Path sort_path; /* dummy for result of cost_sort */
1774 
1775  cost_sort(&sort_path,
1776  root,
1777  pathkeys,
1778  subpath->total_cost,
1779  subpath->rows,
1780  subpath->pathtarget->width,
1781  0.0,
1782  work_mem,
1783  -1);
1784  input_startup_cost += sort_path.startup_cost;
1785  input_total_cost += sort_path.total_cost;
1786  }
1787 
1788  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1789  input_startup_cost, input_total_cost, rows);
1790 
1791  return pathnode;
1792 }
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
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:402
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1661
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
Path * subpath
Definition: relation.h:1408
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
double Cost
Definition: nodes.h:648
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_gather_path()

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

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

1834 {
1835  GatherPath *pathnode = makeNode(GatherPath);
1836 
1837  Assert(subpath->parallel_safe);
1838 
1839  pathnode->path.pathtype = T_Gather;
1840  pathnode->path.parent = rel;
1841  pathnode->path.pathtarget = target;
1842  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1843  required_outer);
1844  pathnode->path.parallel_aware = false;
1845  pathnode->path.parallel_safe = false;
1846  pathnode->path.parallel_workers = 0;
1847  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1848 
1849  pathnode->subpath = subpath;
1850  pathnode->num_workers = subpath->parallel_workers;
1851  pathnode->single_copy = false;
1852 
1853  if (pathnode->num_workers == 0)
1854  {
1855  pathnode->path.pathkeys = subpath->pathkeys;
1856  pathnode->num_workers = 1;
1857  pathnode->single_copy = true;
1858  }
1859 
1860  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1861 
1862  return pathnode;
1863 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
bool single_copy
Definition: relation.h:1396
int num_workers
Definition: relation.h:1397
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1395
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
bool parallel_safe
Definition: relation.h:1084
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:364
Definition: nodes.h:81
bool parallel_aware
Definition: relation.h:1083
Path path
Definition: relation.h:1394
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_group_path()

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

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

2681 {
2682  GroupPath *pathnode = makeNode(GroupPath);
2683  PathTarget *target = rel->reltarget;
2684 
2685  pathnode->path.pathtype = T_Group;
2686  pathnode->path.parent = rel;
2687  pathnode->path.pathtarget = target;
2688  /* For now, assume we are above any joins, so no parameterization */
2689  pathnode->path.param_info = NULL;
2690  pathnode->path.parallel_aware = false;
2691  pathnode->path.parallel_safe = rel->consider_parallel &&
2692  subpath->parallel_safe;
2693  pathnode->path.parallel_workers = subpath->parallel_workers;
2694  /* Group doesn't change sort ordering */
2695  pathnode->path.pathkeys = subpath->pathkeys;
2696 
2697  pathnode->subpath = subpath;
2698 
2699  pathnode->groupClause = groupClause;
2700  pathnode->qual = qual;
2701 
2702  cost_group(&pathnode->path, root,
2703  list_length(groupClause),
2704  numGroups,
2705  qual,
2706  subpath->startup_cost, subpath->total_cost,
2707  subpath->rows);
2708 
2709  /* add tlist eval cost for each output row */
2710  pathnode->path.startup_cost += target->cost.startup;
2711  pathnode->path.total_cost += target->cost.startup +
2712  target->cost.per_tuple * pathnode->path.rows;
2713 
2714  return pathnode;
2715 }
List * qual
Definition: relation.h:1565
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Cost startup_cost
Definition: relation.h:1089
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:2248
RelOptInfo * parent
Definition: relation.h:1078
Definition: nodes.h:77
Path path
Definition: relation.h:1562
List * groupClause
Definition: relation.h:1564
Path * subpath
Definition: relation.h:1563
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

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

2860 {
2862  PathTarget *target = rel->reltarget;
2863  ListCell *lc;
2864  bool is_first = true;
2865  bool is_first_sort = true;
2866 
2867  /* The topmost generated Plan node will be an Agg */
2868  pathnode->path.pathtype = T_Agg;
2869  pathnode->path.parent = rel;
2870  pathnode->path.pathtarget = target;
2871  pathnode->path.param_info = subpath->param_info;
2872  pathnode->path.parallel_aware = false;
2873  pathnode->path.parallel_safe = rel->consider_parallel &&
2874  subpath->parallel_safe;
2875  pathnode->path.parallel_workers = subpath->parallel_workers;
2876  pathnode->subpath = subpath;
2877 
2878  /*
2879  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
2880  * to AGG_HASHED, here if possible.
2881  */
2882  if (aggstrategy == AGG_SORTED &&
2883  list_length(rollups) == 1 &&
2884  ((RollupData *) linitial(rollups))->groupClause == NIL)
2885  aggstrategy = AGG_PLAIN;
2886 
2887  if (aggstrategy == AGG_MIXED &&
2888  list_length(rollups) == 1)
2889  aggstrategy = AGG_HASHED;
2890 
2891  /*
2892  * Output will be in sorted order by group_pathkeys if, and only if, there
2893  * is a single rollup operation on a non-empty list of grouping
2894  * expressions.
2895  */
2896  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
2897  pathnode->path.pathkeys = root->group_pathkeys;
2898  else
2899  pathnode->path.pathkeys = NIL;
2900 
2901  pathnode->aggstrategy = aggstrategy;
2902  pathnode->rollups = rollups;
2903  pathnode->qual = having_qual;
2904 
2905  Assert(rollups != NIL);
2906  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
2907  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
2908 
2909  foreach(lc, rollups)
2910  {
2911  RollupData *rollup = lfirst(lc);
2912  List *gsets = rollup->gsets;
2913  int numGroupCols = list_length(linitial(gsets));
2914 
2915  /*
2916  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
2917  * (already-sorted) input, and following ones do their own sort.
2918  *
2919  * In AGG_HASHED mode, there is one rollup for each grouping set.
2920  *
2921  * In AGG_MIXED mode, the first rollups are hashed, the first
2922  * non-hashed one takes the (already-sorted) input, and following ones
2923  * do their own sort.
2924  */
2925  if (is_first)
2926  {
2927  cost_agg(&pathnode->path, root,
2928  aggstrategy,
2929  agg_costs,
2930  numGroupCols,
2931  rollup->numGroups,
2932  having_qual,
2933  subpath->startup_cost,
2934  subpath->total_cost,
2935  subpath->rows);
2936  is_first = false;
2937  if (!rollup->is_hashed)
2938  is_first_sort = false;
2939  }
2940  else
2941  {
2942  Path sort_path; /* dummy for result of cost_sort */
2943  Path agg_path; /* dummy for result of cost_agg */
2944 
2945  if (rollup->is_hashed || is_first_sort)
2946  {
2947  /*
2948  * Account for cost of aggregation, but don't charge input
2949  * cost again
2950  */
2951  cost_agg(&agg_path, root,
2952  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
2953  agg_costs,
2954  numGroupCols,
2955  rollup->numGroups,
2956  having_qual,
2957  0.0, 0.0,
2958  subpath->rows);
2959  if (!rollup->is_hashed)
2960  is_first_sort = false;
2961  }
2962  else
2963  {
2964  /* Account for cost of sort, but don't charge input cost again */
2965  cost_sort(&sort_path, root, NIL,
2966  0.0,
2967  subpath->rows,
2968  subpath->pathtarget->width,
2969  0.0,
2970  work_mem,
2971  -1.0);
2972 
2973  /* Account for cost of aggregation */
2974 
2975  cost_agg(&agg_path, root,
2976  AGG_SORTED,
2977  agg_costs,
2978  numGroupCols,
2979  rollup->numGroups,
2980  having_qual,
2981  sort_path.startup_cost,
2982  sort_path.total_cost,
2983  sort_path.rows);
2984  }
2985 
2986  pathnode->path.total_cost += agg_path.total_cost;
2987  pathnode->path.rows += agg_path.rows;
2988  }
2989  }
2990 
2991  /* add tlist eval cost for each output row */
2992  pathnode->path.startup_cost += target->cost.startup;
2993  pathnode->path.total_cost += target->cost.startup +
2994  target->cost.per_tuple * pathnode->path.rows;
2995 
2996  return pathnode;
2997 }
List * group_pathkeys
Definition: relation.h:276
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:78
PathTarget * pathtarget
Definition: relation.h:1079
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:2060
int parallel_workers
Definition: relation.h:1085
bool is_hashed
Definition: relation.h:1618
ParamPathInfo * param_info
Definition: relation.h:1081
double numGroups
Definition: relation.h:1616
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
#define linitial(l)
Definition: pg_list.h:111
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
AggStrategy aggstrategy
Definition: relation.h:1629
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:1661
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
List * gsets
Definition: relation.h:1614

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

2329 {
2330  HashPath *pathnode = makeNode(HashPath);
2331 
2332  pathnode->jpath.path.pathtype = T_HashJoin;
2333  pathnode->jpath.path.parent = joinrel;
2334  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2335  pathnode->jpath.path.param_info =
2337  joinrel,
2338  outer_path,
2339  inner_path,
2340  extra->sjinfo,
2341  required_outer,
2342  &restrict_clauses);
2343  pathnode->jpath.path.parallel_aware =
2344  joinrel->consider_parallel && parallel_hash;
2345  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2346  outer_path->parallel_safe && inner_path->parallel_safe;
2347  /* This is a foolish way to estimate parallel_workers, but for now... */
2348  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2349 
2350  /*
2351  * A hashjoin never has pathkeys, since its output ordering is
2352  * unpredictable due to possible batching. XXX If the inner relation is
2353  * small enough, we could instruct the executor that it must not batch,
2354  * and then we could assume that the output inherits the outer relation's
2355  * ordering, which might save a sort step. However there is considerable
2356  * downside if our estimate of the inner relation size is badly off. For
2357  * the moment we don't risk it. (Note also that if we wanted to take this
2358  * seriously, joinpath.c would have to consider many more paths for the
2359  * outer rel than it does now.)
2360  */
2361  pathnode->jpath.path.pathkeys = NIL;
2362  pathnode->jpath.jointype = jointype;
2363  pathnode->jpath.inner_unique = extra->inner_unique;
2364  pathnode->jpath.outerjoinpath = outer_path;
2365  pathnode->jpath.innerjoinpath = inner_path;
2366  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2367  pathnode->path_hashclauses = hashclauses;
2368  /* final_cost_hashjoin will fill in pathnode->num_batches */
2369 
2370  final_cost_hashjoin(root, pathnode, workspace, extra);
2371 
2372  return pathnode;
2373 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3261
JoinPath jpath
Definition: relation.h:1500
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
bool parallel_safe
Definition: relation.h:1084
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
JoinType jointype
Definition: relation.h:1421
bool parallel_aware
Definition: relation.h:1083
List * path_hashclauses
Definition: relation.h:1501
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_index_path()

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

Definition at line 1024 of file pathnode.c.

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

Referenced by build_index_paths(), and plan_cluster_use_sort().

1036 {
1037  IndexPath *pathnode = makeNode(IndexPath);
1038  RelOptInfo *rel = index->rel;
1039  List *indexquals,
1040  *indexqualcols;
1041 
1042  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1043  pathnode->path.parent = rel;
1044  pathnode->path.pathtarget = rel->reltarget;
1045  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1046  required_outer);
1047  pathnode->path.parallel_aware = false;
1048  pathnode->path.parallel_safe = rel->consider_parallel;
1049  pathnode->path.parallel_workers = 0;
1050  pathnode->path.pathkeys = pathkeys;
1051 
1052  /* Convert clauses to indexquals the executor can handle */
1053  expand_indexqual_conditions(index, indexclauses, indexclausecols,
1054  &indexquals, &indexqualcols);
1055 
1056  /* Fill in the pathnode */
1057  pathnode->indexinfo = index;
1058  pathnode->indexclauses = indexclauses;
1059  pathnode->indexquals = indexquals;
1060  pathnode->indexqualcols = indexqualcols;
1061  pathnode->indexorderbys = indexorderbys;
1062  pathnode->indexorderbycols = indexorderbycols;
1063  pathnode->indexscandir = indexscandir;
1064 
1065  cost_index(pathnode, root, loop_count, partial_path);
1066 
1067  return pathnode;
1068 }
List * indexorderbycols
Definition: relation.h:1160
PathTarget * pathtarget
Definition: relation.h:1079
Path path
Definition: relation.h:1154
IndexOptInfo * indexinfo
Definition: relation.h:1155
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * indexclauses
Definition: relation.h:1156
NodeTag pathtype
Definition: relation.h:1076
List * indexquals
Definition: relation.h:1157
RelOptInfo * rel
Definition: relation.h:755
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3551
RelOptInfo * parent
Definition: relation.h:1078
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:477
List * indexorderbys
Definition: relation.h:1159
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
List * indexqualcols
Definition: relation.h:1158
ScanDirection indexscandir
Definition: relation.h:1161
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623

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

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

Referenced by grouping_planner().

3419 {
3420  LimitPath *pathnode = makeNode(LimitPath);
3421 
3422  pathnode->path.pathtype = T_Limit;
3423  pathnode->path.parent = rel;
3424  /* Limit doesn't project, so use source path's pathtarget */
3425  pathnode->path.pathtarget = subpath->pathtarget;
3426  /* For now, assume we are above any joins, so no parameterization */
3427  pathnode->path.param_info = NULL;
3428  pathnode->path.parallel_aware = false;
3429  pathnode->path.parallel_safe = rel->consider_parallel &&
3430  subpath->parallel_safe;
3431  pathnode->path.parallel_workers = subpath->parallel_workers;
3432  pathnode->path.rows = subpath->rows;
3433  pathnode->path.startup_cost = subpath->startup_cost;
3434  pathnode->path.total_cost = subpath->total_cost;
3435  pathnode->path.pathkeys = subpath->pathkeys;
3436  pathnode->subpath = subpath;
3437  pathnode->limitOffset = limitOffset;
3438  pathnode->limitCount = limitCount;
3439 
3440  /*
3441  * Adjust the output rows count and costs according to the offset/limit.
3442  * This is only a cosmetic issue if we are at top level, but if we are
3443  * building a subquery then it's important to report correct info to the
3444  * outer planner.
3445  *
3446  * When the offset or count couldn't be estimated, use 10% of the
3447  * estimated number of rows emitted from the subpath.
3448  *
3449  * XXX we don't bother to add eval costs of the offset/limit expressions
3450  * themselves to the path costs. In theory we should, but in most cases
3451  * those expressions are trivial and it's just not worth the trouble.
3452  */
3453  if (offset_est != 0)
3454  {
3455  double offset_rows;
3456 
3457  if (offset_est > 0)
3458  offset_rows = (double) offset_est;
3459  else
3460  offset_rows = clamp_row_est(subpath->rows * 0.10);
3461  if (offset_rows > pathnode->path.rows)
3462  offset_rows = pathnode->path.rows;
3463  if (subpath->rows > 0)
3464  pathnode->path.startup_cost +=
3465  (subpath->total_cost - subpath->startup_cost)
3466  * offset_rows / subpath->rows;
3467  pathnode->path.rows -= offset_rows;
3468  if (pathnode->path.rows < 1)
3469  pathnode->path.rows = 1;
3470  }
3471 
3472  if (count_est != 0)
3473  {
3474  double count_rows;
3475 
3476  if (count_est > 0)
3477  count_rows = (double) count_est;
3478  else
3479  count_rows = clamp_row_est(subpath->rows * 0.10);
3480  if (count_rows > pathnode->path.rows)
3481  count_rows = pathnode->path.rows;
3482  if (subpath->rows > 0)
3483  pathnode->path.total_cost = pathnode->path.startup_cost +
3484  (subpath->total_cost - subpath->startup_cost)
3485  * count_rows / subpath->rows;
3486  pathnode->path.rows = count_rows;
3487  if (pathnode->path.rows < 1)
3488  pathnode->path.rows = 1;
3489  }
3490 
3491  return pathnode;
3492 }
PathTarget * pathtarget
Definition: relation.h:1079
Node * limitOffset
Definition: relation.h:1731
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
Path * subpath
Definition: relation.h:1730
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
Path path
Definition: relation.h:1729
bool parallel_aware
Definition: relation.h:1083
double clamp_row_est(double nrows)
Definition: costsize.c:188
Node * limitCount
Definition: relation.h:1732
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:86

◆ create_lockrows_path()

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

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

3254 {
3255  LockRowsPath *pathnode = makeNode(LockRowsPath);
3256 
3257  pathnode->path.pathtype = T_LockRows;
3258  pathnode->path.parent = rel;
3259  /* LockRows doesn't project, so use source path's pathtarget */
3260  pathnode->path.pathtarget = subpath->pathtarget;
3261  /* For now, assume we are above any joins, so no parameterization */
3262  pathnode->path.param_info = NULL;
3263  pathnode->path.parallel_aware = false;
3264  pathnode->path.parallel_safe = false;
3265  pathnode->path.parallel_workers = 0;
3266  pathnode->path.rows = subpath->rows;
3267 
3268  /*
3269  * The result cannot be assumed sorted, since locking might cause the sort
3270  * key columns to be replaced with new values.
3271  */
3272  pathnode->path.pathkeys = NIL;
3273 
3274  pathnode->subpath = subpath;
3275  pathnode->rowMarks = rowMarks;
3276  pathnode->epqParam = epqParam;
3277 
3278  /*
3279  * We should charge something extra for the costs of row locking and
3280  * possible refetches, but it's hard to say how much. For now, use
3281  * cpu_tuple_cost per row.
3282  */
3283  pathnode->path.startup_cost = subpath->startup_cost;
3284  pathnode->path.total_cost = subpath->total_cost +
3285  cpu_tuple_cost * subpath->rows;
3286 
3287  return pathnode;
3288 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * rowMarks
Definition: relation.h:1694
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Path * subpath
Definition: relation.h:1693
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_material_path()

MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1484 {
1485  MaterialPath *pathnode = makeNode(MaterialPath);
1486 
1487  Assert(subpath->parent == rel);
1488 
1489  pathnode->path.pathtype = T_Material;
1490  pathnode->path.parent = rel;
1491  pathnode->path.pathtarget = rel->reltarget;
1492  pathnode->path.param_info = subpath->param_info;
1493  pathnode->path.parallel_aware = false;
1494  pathnode->path.parallel_safe = rel->consider_parallel &&
1495  subpath->parallel_safe;
1496  pathnode->path.parallel_workers = subpath->parallel_workers;
1497  pathnode->path.pathkeys = subpath->pathkeys;
1498 
1499  pathnode->subpath = subpath;
1500 
1501  cost_material(&pathnode->path,
1502  subpath->startup_cost,
1503  subpath->total_cost,
1504  subpath->rows,
1505  subpath->pathtarget->width);
1506 
1507  return pathnode;
1508 }
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Path * subpath
Definition: relation.h:1356
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Cost total_cost
Definition: relation.h:1090
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:2006
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_merge_append_path()

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

Definition at line 1347 of file pathnode.c.

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

Referenced by generate_mergeappend_paths().

1353 {
1355  Cost input_startup_cost;
1356  Cost input_total_cost;
1357  ListCell *l;
1358 
1359  pathnode->path.pathtype = T_MergeAppend;
1360  pathnode->path.parent = rel;
1361  pathnode->path.pathtarget = rel->reltarget;
1363  required_outer);
1364  pathnode->path.parallel_aware = false;
1365  pathnode->path.parallel_safe = rel->consider_parallel;
1366  pathnode->path.parallel_workers = 0;
1367  pathnode->path.pathkeys = pathkeys;
1368  pathnode->partitioned_rels = list_copy(partitioned_rels);
1369  pathnode->subpaths = subpaths;
1370 
1371  /*
1372  * Apply query-wide LIMIT if known and path is for sole base relation.
1373  * (Handling this at this low level is a bit klugy.)
1374  */
1375  if (bms_equal(rel->relids, root->all_baserels))
1376  pathnode->limit_tuples = root->limit_tuples;
1377  else
1378  pathnode->limit_tuples = -1.0;
1379 
1380  /*
1381  * Add up the sizes and costs of the input paths.
1382  */
1383  pathnode->path.rows = 0;
1384  input_startup_cost = 0;
1385  input_total_cost = 0;
1386  foreach(l, subpaths)
1387  {
1388  Path *subpath = (Path *) lfirst(l);
1389 
1390  pathnode->path.rows += subpath->rows;
1391  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1392  subpath->parallel_safe;
1393 
1394  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1395  {
1396  /* Subpath is adequately ordered, we won't need to sort it */
1397  input_startup_cost += subpath->startup_cost;
1398  input_total_cost += subpath->total_cost;
1399  }
1400  else
1401  {
1402  /* We'll need to insert a Sort node, so include cost for that */
1403  Path sort_path; /* dummy for result of cost_sort */
1404 
1405  cost_sort(&sort_path,
1406  root,
1407  pathkeys,
1408  subpath->total_cost,
1409  subpath->parent->tuples,
1410  subpath->pathtarget->width,
1411  0.0,
1412  work_mem,
1413  pathnode->limit_tuples);
1414  input_startup_cost += sort_path.startup_cost;
1415  input_total_cost += sort_path.total_cost;
1416  }
1417 
1418  /* All child paths must have same parameterization */
1419  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1420  }
1421 
1422  /* Now we can compute total costs of the MergeAppend */
1423  cost_merge_append(&pathnode->path, root,
1424  pathkeys, list_length(subpaths),
1425  input_startup_cost, input_total_cost,
1426  pathnode->path.rows);
1427 
1428  return pathnode;
1429 }
PathTarget * pathtarget
Definition: relation.h:1079
double tuples
Definition: relation.h:652
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partitioned_rels
Definition: relation.h:1329
NodeTag pathtype
Definition: relation.h:1076
Relids all_baserels
Definition: relation.h:210
double limit_tuples
Definition: relation.h:307
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
bool pathkeys_contained_in(List *keys1, List *keys2)
Definition: pathkeys.c:317
void cost_sort(Path *path, PlannerInfo *root, List *pathkeys, Cost input_cost, double tuples, int width, Cost comparison_cost, int sort_mem, double limit_tuples)
Definition: costsize.c:1661
int work_mem
Definition: globals.c:122
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
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:1957
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
List * subpaths
Definition: relation.h:1330
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1552
struct PathTarget * reltarget
Definition: relation.h:623
double limit_tuples
Definition: relation.h:1331
double Cost
Definition: nodes.h:648
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:153

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

2265 {
2266  MergePath *pathnode = makeNode(MergePath);
2267 
2268  pathnode->jpath.path.pathtype = T_MergeJoin;
2269  pathnode->jpath.path.parent = joinrel;
2270  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2271  pathnode->jpath.path.param_info =
2273  joinrel,
2274  outer_path,
2275  inner_path,
2276  extra->sjinfo,
2277  required_outer,
2278  &restrict_clauses);
2279  pathnode->jpath.path.parallel_aware = false;
2280  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2281  outer_path->parallel_safe && inner_path->parallel_safe;
2282  /* This is a foolish way to estimate parallel_workers, but for now... */
2283  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2284  pathnode->jpath.path.pathkeys = pathkeys;
2285  pathnode->jpath.jointype = jointype;
2286  pathnode->jpath.inner_unique = extra->inner_unique;
2287  pathnode->jpath.outerjoinpath = outer_path;
2288  pathnode->jpath.innerjoinpath = inner_path;
2289  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2290  pathnode->path_mergeclauses = mergeclauses;
2291  pathnode->outersortkeys = outersortkeys;
2292  pathnode->innersortkeys = innersortkeys;
2293  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2294  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2295 
2296  final_cost_mergejoin(root, pathnode, workspace, extra);
2297 
2298  return pathnode;
2299 }
List * path_mergeclauses
Definition: relation.h:1482
List * outersortkeys
Definition: relation.h:1483
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
bool parallel_safe
Definition: relation.h:1084
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
List * innersortkeys
Definition: relation.h:1484
JoinType jointype
Definition: relation.h:1421
JoinPath jpath
Definition: relation.h:1481
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2830

◆ create_minmaxagg_path()

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

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

3014 {
3015  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
3016  Cost initplan_cost;
3017  ListCell *lc;
3018 
3019  /* The topmost generated Plan node will be a Result */
3020  pathnode->path.pathtype = T_Result;
3021  pathnode->path.parent = rel;
3022  pathnode->path.pathtarget = target;
3023  /* For now, assume we are above any joins, so no parameterization */
3024  pathnode->path.param_info = NULL;
3025  pathnode->path.parallel_aware = false;
3026  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
3027  pathnode->path.parallel_safe = false;
3028  pathnode->path.parallel_workers = 0;
3029  /* Result is one unordered row */
3030  pathnode->path.rows = 1;
3031  pathnode->path.pathkeys = NIL;
3032 
3033  pathnode->mmaggregates = mmaggregates;
3034  pathnode->quals = quals;
3035 
3036  /* Calculate cost of all the initplans ... */
3037  initplan_cost = 0;
3038  foreach(lc, mmaggregates)
3039  {
3040  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
3041 
3042  initplan_cost += mminfo->pathcost;
3043  }
3044 
3045  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
3046  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
3047  pathnode->path.total_cost = initplan_cost + target->cost.startup +
3048  target->cost.per_tuple + cpu_tuple_cost;
3049 
3050  /*
3051  * Add cost of qual, if any --- but we ignore its selectivity, since our
3052  * rowcount estimate should be 1 no matter what the qual is.
3053  */
3054  if (quals)
3055  {
3056  QualCost qual_cost;
3057 
3058  cost_qual_eval(&qual_cost, quals, root);
3059  pathnode->path.startup_cost += qual_cost.startup;
3060  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
3061  }
3062 
3063  return pathnode;
3064 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * quals
Definition: relation.h:1641
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3716
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * mmaggregates
Definition: relation.h:1640
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
double cpu_tuple_cost
Definition: costsize.c:113
bool parallel_aware
Definition: relation.h:1083
double Cost
Definition: nodes.h:648

◆ create_modifytable_path()

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

Definition at line 3313 of file pathnode.c.

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

Referenced by grouping_planner(), and inheritance_planner().

3322 {
3324  double total_size;
3325  ListCell *lc;
3326 
3327  Assert(list_length(resultRelations) == list_length(subpaths));
3328  Assert(list_length(resultRelations) == list_length(subroots));
3329  Assert(withCheckOptionLists == NIL ||
3330  list_length(resultRelations) == list_length(withCheckOptionLists));
3331  Assert(returningLists == NIL ||
3332  list_length(resultRelations) == list_length(returningLists));
3333 
3334  pathnode->path.pathtype = T_ModifyTable;
3335  pathnode->path.parent = rel;
3336  /* pathtarget is not interesting, just make it minimally valid */
3337  pathnode->path.pathtarget = rel->reltarget;
3338  /* For now, assume we are above any joins, so no parameterization */
3339  pathnode->path.param_info = NULL;
3340  pathnode->path.parallel_aware = false;
3341  pathnode->path.parallel_safe = false;
3342  pathnode->path.parallel_workers = 0;
3343  pathnode->path.pathkeys = NIL;
3344 
3345  /*
3346  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3347  *
3348  * Currently, we don't charge anything extra for the actual table
3349  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3350  * expressions if any. It would only be window dressing, since
3351  * ModifyTable is always a top-level node and there is no way for the
3352  * costs to change any higher-level planning choices. But we might want
3353  * to make it look better sometime.
3354  */
3355  pathnode->path.startup_cost = 0;
3356  pathnode->path.total_cost = 0;
3357  pathnode->path.rows = 0;
3358  total_size = 0;
3359  foreach(lc, subpaths)
3360  {
3361  Path *subpath = (Path *) lfirst(lc);
3362 
3363  if (lc == list_head(subpaths)) /* first node? */
3364  pathnode->path.startup_cost = subpath->startup_cost;
3365  pathnode->path.total_cost += subpath->total_cost;
3366  pathnode->path.rows += subpath->rows;
3367  total_size += subpath->pathtarget->width * subpath->rows;
3368  }
3369 
3370  /*
3371  * Set width to the average width of the subpath outputs. XXX this is
3372  * totally wrong: we should report zero if no RETURNING, else an average
3373  * of the RETURNING tlist widths. But it's what happened historically,
3374  * and improving it is a task for another day.
3375  */
3376  if (pathnode->path.rows > 0)
3377  total_size /= pathnode->path.rows;
3378  pathnode->path.pathtarget->width = rint(total_size);
3379 
3380  pathnode->operation = operation;
3381  pathnode->canSetTag = canSetTag;
3382  pathnode->nominalRelation = nominalRelation;
3383  pathnode->partitioned_rels = list_copy(partitioned_rels);
3384  pathnode->partColsUpdated = partColsUpdated;
3385  pathnode->resultRelations = resultRelations;
3386  pathnode->subpaths = subpaths;
3387  pathnode->subroots = subroots;
3388  pathnode->withCheckOptionLists = withCheckOptionLists;
3389  pathnode->returningLists = returningLists;
3390  pathnode->rowMarks = rowMarks;
3391  pathnode->onconflict = onconflict;
3392  pathnode->epqParam = epqParam;
3393 
3394  return pathnode;
3395 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
List * returningLists
Definition: relation.h:1718
OnConflictExpr * onconflict
Definition: relation.h:1720
Index nominalRelation
Definition: relation.h:1710
List * rowMarks
Definition: relation.h:1719
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:1076
Cost startup_cost
Definition: relation.h:1089
bool partColsUpdated
Definition: relation.h:1713
List * subroots
Definition: relation.h:1716
RelOptInfo * parent
Definition: relation.h:1078
List * subpaths
Definition: relation.h:1715
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
double rint(double x)
Definition: rint.c:22
List * partitioned_rels
Definition: relation.h:1712
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
#define Assert(condition)
Definition: c.h:699
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1717
CmdType operation
Definition: relation.h:1708
List * resultRelations
Definition: relation.h:1714
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_namedtuplestorescan_path()

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

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

2004 {
2005  Path *pathnode = makeNode(Path);
2006 
2007  pathnode->pathtype = T_NamedTuplestoreScan;
2008  pathnode->parent = rel;
2009  pathnode->pathtarget = rel->reltarget;
2010  pathnode->param_info = get_baserel_parampathinfo(root, rel,
2011  required_outer);
2012  pathnode->parallel_aware = false;
2013  pathnode->parallel_safe = rel->consider_parallel;
2014  pathnode->parallel_workers = 0;
2015  pathnode->pathkeys = NIL; /* result is always unordered */
2016 
2017  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
2018 
2019  return pathnode;
2020 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1261
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1541
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083
struct PathTarget * reltarget
Definition: relation.h:623

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

2174 {
2175  NestPath *pathnode = makeNode(NestPath);
2176  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2177 
2178  /*
2179  * If the inner path is parameterized by the outer, we must drop any
2180  * restrict_clauses that are due to be moved into the inner path. We have
2181  * to do this now, rather than postpone the work till createplan time,
2182  * because the restrict_clauses list can affect the size and cost
2183  * estimates for this path.
2184  */
2185  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2186  {
2187  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2188  inner_req_outer);
2189  List *jclauses = NIL;
2190  ListCell *lc;
2191 
2192  foreach(lc, restrict_clauses)
2193  {
2194  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2195 
2196  if (!join_clause_is_movable_into(rinfo,
2197  inner_path->parent->relids,
2198  inner_and_outer))
2199  jclauses = lappend(jclauses, rinfo);
2200  }
2201  restrict_clauses = jclauses;
2202  }
2203 
2204  pathnode->path.pathtype = T_NestLoop;
2205  pathnode->path.parent = joinrel;
2206  pathnode->path.pathtarget = joinrel->reltarget;
2207  pathnode->path.param_info =
2209  joinrel,
2210  outer_path,
2211  inner_path,
2212  extra->sjinfo,
2213  required_outer,
2214  &restrict_clauses);
2215  pathnode->path.parallel_aware = false;
2216  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2217  outer_path->parallel_safe && inner_path->parallel_safe;
2218  /* This is a foolish way to estimate parallel_workers, but for now... */
2219  pathnode->path.parallel_workers = outer_path->parallel_workers;
2220  pathnode->path.pathkeys = pathkeys;
2221  pathnode->jointype = jointype;
2222  pathnode->inner_unique = extra->inner_unique;
2223  pathnode->outerjoinpath = outer_path;
2224  pathnode->innerjoinpath = inner_path;
2225  pathnode->joinrestrictinfo = restrict_clauses;
2226 
2227  final_cost_nestloop(root, pathnode, workspace, extra);
2228 
2229  return pathnode;
2230 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
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:1348
Path * innerjoinpath
Definition: relation.h:1427
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2393
SpecialJoinInfo * sjinfo
Definition: relation.h:2313
List * joinrestrictinfo
Definition: relation.h:1429
RelOptInfo * parent
Definition: relation.h:1078
Relids relids
Definition: relation.h:612
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:511
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * outerjoinpath
Definition: relation.h:1426
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
Path path
Definition: relation.h:1419
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:1084
#define PATH_REQ_OUTER(path)
Definition: relation.h:1097
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:284
bool inner_unique
Definition: relation.h:1423
bool consider_parallel
Definition: relation.h:620
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:509
JoinType jointype
Definition: relation.h:1421
bool parallel_aware
Definition: relation.h:1083
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:623

◆ create_projection_path()

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

Definition at line 2384 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cpu_tuple_cost, ProjectionPath::dummypp, equal(), PathTarget::exprs, is_parallel_safe(), is_projection_capable_path(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ProjectionPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectionPath::subpath, T_Result, and Path::total_cost.

Referenced by adjust_paths_for_srfs(), apply_projection_to_path(), apply_scanjoin_target_to_paths(), and recurse_set_operations().

2388 {
2389  ProjectionPath *pathnode = makeNode(ProjectionPath);
2390  PathTarget *oldtarget = subpath->pathtarget;
2391 
2392  pathnode->path.pathtype = T_Result;
2393  pathnode->path.parent = rel;
2394  pathnode->path.pathtarget = target;
2395  /* For now, assume we are above any joins, so no parameterization */
2396  pathnode->path.param_info = NULL;
2397  pathnode->path.parallel_aware = false;
2398  pathnode->path.parallel_safe = rel->consider_parallel &&
2399  subpath->parallel_safe &&
2400  is_parallel_safe(root, (Node *) target->exprs);
2401  pathnode->path.parallel_workers = subpath->parallel_workers;
2402  /* Projection does not change the sort order */
2403  pathnode->path.pathkeys = subpath->pathkeys;
2404 
2405  pathnode->subpath = subpath;
2406 
2407  /*
2408  * We might not need a separate Result node. If the input plan node type
2409  * can project, we can just tell it to project something else. Or, if it
2410  * can't project but the desired target has the same expression list as
2411  * what the input will produce anyway, we can still give it the desired
2412  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2413  * Note: in the latter case, create_projection_plan has to recheck our
2414  * conclusion; see comments therein.
2415  */
2416  if (is_projection_capable_path(subpath) ||
2417  equal(oldtarget->exprs, target->exprs))
2418  {
2419  /* No separate Result node needed */
2420  pathnode->dummypp = true;
2421 
2422  /*
2423  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2424  */
2425  pathnode->path.rows = subpath->rows;
2426  pathnode->path.startup_cost = subpath->startup_cost +
2427  (target->cost.startup - oldtarget->cost.startup);
2428  pathnode->path.total_cost = subpath->total_cost +
2429  (target->cost.startup - oldtarget->cost.startup) +
2430  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2431  }
2432  else
2433  {
2434  /* We really do need the Result node */
2435  pathnode->dummypp = false;
2436 
2437  /*
2438  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2439  * evaluating the tlist. There is no qual to worry about.
2440  */
2441  pathnode->path.rows = subpath->rows;
2442  pathnode->path.startup_cost = subpath->startup_cost +
2443  target->cost.startup;
2444  pathnode->path.total_cost = subpath->total_cost +
2445  target->cost.startup +
2446  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2447  }
2448 
2449  return pathnode;
2450 }
PathTarget * pathtarget
Definition: relation.h:1079
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2986
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Definition: nodes.h:517
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1088
Cost per_tuple
Definition: relation.h:47
Definition: nodes.h:46
Cost startup_cost
Definition: relation.h:1089
RelOptInfo * parent
Definition: relation.h:1078
List * exprs
Definition: relation.h:1008
Cost total_cost
Definition: relation.h:1090
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
double rows
Definition: relation.h:1088
bool parallel_safe
Definition: relation.h:1084
QualCost cost
Definition: relation.h:1010
bool consider_parallel
Definition: relation.h:620
double cpu_tuple_cost
Definition: costsize.c:113
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6700
bool parallel_aware
Definition: relation.h:1083
Path * subpath
Definition: relation.h:1523
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234

◆ create_recursiveunion_path()

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

Definition at line 3207 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_recursive_union(), RecursiveUnionPath::distinctList, RecursiveUnionPath::leftpath, makeNode, NIL, RecursiveUnionPath::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, RecursiveUnionPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RecursiveUnionPath::rightpath, T_RecursiveUnion, and RecursiveUnionPath::wtParam.

Referenced by generate_recursion_path().

3215 {
3217 
3218  pathnode->path.pathtype = T_RecursiveUnion;
3219  pathnode->path.parent = rel;
3220  pathnode->path.pathtarget = target;
3221  /* For now, assume we are above any joins, so no parameterization */
3222  pathnode->path.param_info = NULL;
3223  pathnode->path.parallel_aware = false;
3224  pathnode->path.parallel_safe = rel->consider_parallel &&
3225  leftpath->parallel_safe && rightpath->parallel_safe;
3226  /* Foolish, but we'll do it like joins for now: */
3227  pathnode->path.parallel_workers = leftpath->parallel_workers;
3228  /* RecursiveUnion result is always unsorted */
3229  pathnode->path.pathkeys = NIL;
3230 
3231  pathnode->leftpath = leftpath;
3232  pathnode->rightpath = rightpath;
3233  pathnode->distinctList = distinctList;
3234  pathnode->wtParam = wtParam;
3235  pathnode->numGroups = numGroups;
3236 
3237  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3238 
3239  return pathnode;
3240 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
NodeTag pathtype
Definition: relation.h:1076
RelOptInfo * parent
Definition: relation.h:1078
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1581
List * pathkeys
Definition: relation.h:1092
#define makeNode(_type_)
Definition: nodes.h:565
bool parallel_safe
Definition: relation.h:1084
bool consider_parallel
Definition: relation.h:620
bool parallel_aware
Definition: relation.h:1083

◆ create_result_path()

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

Definition at line 1439 of file pathnode.c.

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

Referenced by create_degenerate_grouping_paths(), and query_planner().

1441 {
1442  ResultPath *pathnode = makeNode(ResultPath);
1443 
1444  pathnode->path.pathtype = T_Result;
1445  pathnode->path.parent = rel;
1446  pathnode->path.pathtarget = target;
1447  pathnode->path.param_info = NULL; /* there are no other rels... */
1448  pathnode->path.parallel_aware = false;
1449  pathnode->path.parallel_safe = rel->consider_parallel;
1450  pathnode->path.parallel_workers = 0;
1451  pathnode->path.pathkeys = NIL;
1452  pathnode->quals = resconstantqual;
1453 
1454  /* Hardly worth defining a cost_result() function ... just do it */
1455  pathnode->path.rows = 1;
1456  pathnode->path.startup_cost = target->cost.startup;
1457  pathnode->path.total_cost = target->cost.startup +
1458  cpu_tuple_cost + target->cost.per_tuple;
1459 
1460  /*
1461  * Add cost of qual, if any --- but we ignore its selectivity, since our
1462  * rowcount estimate should be 1 no matter what the qual is.
1463  */
1464  if (resconstantqual)
1465  {
1466  QualCost qual_cost;
1467 
1468  cost_qual_eval(&qual_cost, resconstantqual, root);
1469  /* resconstantqual is evaluated once at startup */
1470  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1471  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1472  }
1473 
1474  return pathnode;
1475 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:1079
int parallel_workers
Definition: relation.h:1085
ParamPathInfo * param_info
Definition: relation.h:1081
Cost startup
Definition: relation.h:46
NodeTag pathtype
Definition: relation.h:1076
Cost per_tuple
Definition: relation.h:47
Path path
Definition: relation.h:1343
Definition: nodes.h:46
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3716
Cost startup_cost
Definition: relation.h:1089