PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
pathnode.h File Reference
#include "nodes/relation.h"
Include dependency graph for pathnode.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int compare_path_costs (Path *path1, Path *path2, CostSelector criterion)
 
int compare_fractional_path_costs (Path *path1, Path *path2, double fraction)
 
void set_cheapest (RelOptInfo *parent_rel)
 
void add_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_path_precheck (RelOptInfo *parent_rel, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer)
 
void add_partial_path (RelOptInfo *parent_rel, Path *new_path)
 
bool add_partial_path_precheck (RelOptInfo *parent_rel, Cost total_cost, List *pathkeys)
 
Pathcreate_seqscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer, int parallel_workers)
 
Pathcreate_samplescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
IndexPathcreate_index_path (PlannerInfo *root, IndexOptInfo *index, List *indexclauses, List *indexclausecols, List *indexorderbys, List *indexorderbycols, List *pathkeys, ScanDirection indexscandir, bool indexonly, Relids required_outer, double loop_count, bool partial_path)
 
BitmapHeapPathcreate_bitmap_heap_path (PlannerInfo *root, RelOptInfo *rel, Path *bitmapqual, Relids required_outer, double loop_count, int parallel_degree)
 
BitmapAndPathcreate_bitmap_and_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
BitmapOrPathcreate_bitmap_or_path (PlannerInfo *root, RelOptInfo *rel, List *bitmapquals)
 
TidPathcreate_tidscan_path (PlannerInfo *root, RelOptInfo *rel, List *tidquals, Relids required_outer)
 
AppendPathcreate_append_path (RelOptInfo *rel, List *subpaths, Relids required_outer, int parallel_workers, List *partitioned_rels)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer, List *partitioned_rels)
 
ResultPathcreate_result_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *resconstantqual)
 
MaterialPathcreate_material_path (RelOptInfo *rel, Path *subpath)
 
UniquePathcreate_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SpecialJoinInfo *sjinfo)
 
GatherPathcreate_gather_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, Relids required_outer, double *rows)
 
GatherMergePathcreate_gather_merge_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *pathkeys, Relids required_outer, double *rows)
 
SubqueryScanPathcreate_subqueryscan_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
 
Pathcreate_functionscan_path (PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
 
Pathcreate_tablexprscan_path (PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
 
Pathcreate_valuesscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_tablefuncscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_ctescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_namedtuplestorescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_worktablescan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
ForeignPathcreate_foreignscan_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, double rows, Cost startup_cost, Cost total_cost, List *pathkeys, Relids required_outer, Path *fdw_outerpath, List *fdw_private)
 
Relids calc_nestloop_required_outer (Path *outer_path, Path *inner_path)
 
Relids calc_non_nestloop_required_outer (Path *outer_path, Path *inner_path)
 
NestPathcreate_nestloop_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer)
 
MergePathcreate_mergejoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, List *pathkeys, Relids required_outer, List *mergeclauses, List *outersortkeys, List *innersortkeys)
 
HashPathcreate_hashjoin_path (PlannerInfo *root, RelOptInfo *joinrel, JoinType jointype, JoinCostWorkspace *workspace, JoinPathExtraData *extra, Path *outer_path, Path *inner_path, List *restrict_clauses, Relids required_outer, List *hashclauses)
 
ProjectionPathcreate_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
Pathapply_projection_to_path (PlannerInfo *root, RelOptInfo *rel, Path *path, PathTarget *target)
 
ProjectSetPathcreate_set_projection_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
 
SortPathcreate_sort_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, double limit_tuples)
 
GroupPathcreate_group_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *groupClause, List *qual, double numGroups)
 
UpperUniquePathcreate_upper_unique_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, int numCols, double numGroups)
 
AggPathcreate_agg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, AggStrategy aggstrategy, AggSplit aggsplit, List *groupClause, List *qual, const AggClauseCosts *aggcosts, double numGroups)
 
GroupingSetsPathcreate_groupingsets_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *having_qual, AggStrategy aggstrategy, List *rollups, const AggClauseCosts *agg_costs, double numGroups)
 
MinMaxAggPathcreate_minmaxagg_path (PlannerInfo *root, RelOptInfo *rel, PathTarget *target, List *mmaggregates, List *quals)
 
WindowAggPathcreate_windowagg_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target, List *windowFuncs, WindowClause *winclause, List *winpathkeys)
 
SetOpPathcreate_setop_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, SetOpCmd cmd, SetOpStrategy strategy, List *distinctList, AttrNumber flagColIdx, int firstFlag, double numGroups, double outputRows)
 
RecursiveUnionPathcreate_recursiveunion_path (PlannerInfo *root, RelOptInfo *rel, Path *leftpath, Path *rightpath, PathTarget *target, List *distinctList, int wtParam, double numGroups)
 
LockRowsPathcreate_lockrows_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *rowMarks, int epqParam)
 
ModifyTablePathcreate_modifytable_path (PlannerInfo *root, RelOptInfo *rel, CmdType operation, bool canSetTag, Index nominalRelation, List *partitioned_rels, List *resultRelations, List *subpaths, List *subroots, List *withCheckOptionLists, List *returningLists, List *rowMarks, OnConflictExpr *onconflict, int epqParam)
 
LimitPathcreate_limit_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, Node *limitOffset, Node *limitCount, int64 offset_est, int64 count_est)
 
Pathreparameterize_path (PlannerInfo *root, Path *path, Relids required_outer, double loop_count)
 
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)
 

Function Documentation

void add_partial_path ( RelOptInfo parent_rel,
Path new_path 
)

Definition at line 752 of file pathnode.c.

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

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

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

Definition at line 876 of file pathnode.c.

References add_path_precheck(), compare_pathkeys(), lfirst, NULL, 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().

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

Definition at line 412 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, NULL, Path::parallel_safe, Path::param_info, PATH_REQ_OUTER, Path::pathkeys, PATHKEYS_BETTER1, PATHKEYS_BETTER2, PATHKEYS_DIFFERENT, RelOptInfo::pathlist, pfree(), Path::rows, STD_FUZZ_FACTOR, and Path::total_cost.

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

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

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

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

Definition at line 2369 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, and Path::total_cost.

Referenced by adjust_paths_for_srfs(), build_minmax_path(), create_ordered_paths(), grouping_planner(), and recurse_set_operations().

2373 {
2374  QualCost oldcost;
2375 
2376  /*
2377  * If given path can't project, we might need a Result node, so make a
2378  * separate ProjectionPath.
2379  */
2380  if (!is_projection_capable_path(path))
2381  return (Path *) create_projection_path(root, rel, path, target);
2382 
2383  /*
2384  * We can just jam the desired tlist into the existing path, being sure to
2385  * update its cost estimates appropriately.
2386  */
2387  oldcost = path->pathtarget->cost;
2388  path->pathtarget = target;
2389 
2390  path->startup_cost += target->cost.startup - oldcost.startup;
2391  path->total_cost += target->cost.startup - oldcost.startup +
2392  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2393 
2394  /*
2395  * If the path happens to be a Gather path, we'd like to arrange for the
2396  * subpath to return the required target list so that workers can help
2397  * project. But if there is something that is not parallel-safe in the
2398  * target expressions, then we can't.
2399  */
2400  if (IsA(path, GatherPath) &&
2401  is_parallel_safe(root, (Node *) target->exprs))
2402  {
2403  GatherPath *gpath = (GatherPath *) path;
2404 
2405  /*
2406  * We always use create_projection_path here, even if the subpath is
2407  * projection-capable, so as to avoid modifying the subpath in place.
2408  * It seems unlikely at present that there could be any other
2409  * references to the subpath, but better safe than sorry.
2410  *
2411  * Note that we don't change the GatherPath's cost estimates; it might
2412  * be appropriate to do so, to reflect the fact that the bulk of the
2413  * target evaluation will happen in workers.
2414  */
2415  gpath->subpath = (Path *)
2417  gpath->subpath->parent,
2418  gpath->subpath,
2419  target);
2420  }
2421  else if (path->parallel_safe &&
2422  !is_parallel_safe(root, (Node *) target->exprs))
2423  {
2424  /*
2425  * We're inserting a parallel-restricted target list into a path
2426  * currently marked parallel-safe, so we have to mark it as no longer
2427  * safe.
2428  */
2429  path->parallel_safe = false;
2430  }
2431 
2432  return path;
2433 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:560
PathTarget * pathtarget
Definition: relation.h:955
Definition: nodes.h:509
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2278
Cost startup
Definition: relation.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Path * subpath
Definition: relation.h:1265
List * exprs
Definition: relation.h:884
Cost total_cost
Definition: relation.h:966
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6540
Definition: relation.h:948
RelOptInfo* build_empty_join_rel ( PlannerInfo root)

Definition at line 885 of file relnode.c.

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

Referenced by query_planner().

886 {
887  RelOptInfo *joinrel;
888 
889  /* The dummy join relation should be the only one ... */
890  Assert(root->join_rel_list == NIL);
891 
892  joinrel = makeNode(RelOptInfo);
893  joinrel->reloptkind = RELOPT_JOINREL;
894  joinrel->relids = NULL; /* empty set */
895  joinrel->rows = 1; /* we produce one row for such cases */
896  joinrel->rtekind = RTE_JOIN;
897  joinrel->reltarget = create_empty_pathtarget();
898 
899  root->join_rel_list = lappend(root->join_rel_list, joinrel);
900 
901  return joinrel;
902 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:522
List * join_rel_list
Definition: relation.h:215
Relids relids
Definition: relation.h:525
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:555
double rows
Definition: relation.h:528
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
struct PathTarget * reltarget
Definition: relation.h:536
RelOptInfo* build_join_rel ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
SpecialJoinInfo sjinfo,
List **  restrictlist_ptr 
)

Definition at line 446 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(), build_joinrel_joinlist(), 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_parallel_safe(), PlannerInfo::join_cur_level, PlannerInfo::join_rel_level, RelOptInfo::joininfo, 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, NULL, RelOptInfo::pages, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RelOptInfo::relids, RELOPT_JOINREL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_JOIN, RelOptInfo::rtekind, RelOptInfo::serverid, set_foreign_rel_properties(), set_joinrel_size_estimates(), QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by make_join_rel().

452 {
453  RelOptInfo *joinrel;
454  List *restrictlist;
455 
456  /*
457  * See if we already have a joinrel for this set of base rels.
458  */
459  joinrel = find_join_rel(root, joinrelids);
460 
461  if (joinrel)
462  {
463  /*
464  * Yes, so we only need to figure the restrictlist for this particular
465  * pair of component relations.
466  */
467  if (restrictlist_ptr)
468  *restrictlist_ptr = build_joinrel_restrictlist(root,
469  joinrel,
470  outer_rel,
471  inner_rel);
472  return joinrel;
473  }
474 
475  /*
476  * Nope, so make one.
477  */
478  joinrel = makeNode(RelOptInfo);
479  joinrel->reloptkind = RELOPT_JOINREL;
480  joinrel->relids = bms_copy(joinrelids);
481  joinrel->rows = 0;
482  /* cheap startup cost is interesting iff not all tuples to be retrieved */
483  joinrel->consider_startup = (root->tuple_fraction > 0);
484  joinrel->consider_param_startup = false;
485  joinrel->consider_parallel = false;
486  joinrel->reltarget = create_empty_pathtarget();
487  joinrel->pathlist = NIL;
488  joinrel->ppilist = NIL;
489  joinrel->partial_pathlist = NIL;
490  joinrel->cheapest_startup_path = NULL;
491  joinrel->cheapest_total_path = NULL;
492  joinrel->cheapest_unique_path = NULL;
494  /* init direct_lateral_relids from children; we'll finish it up below */
495  joinrel->direct_lateral_relids =
496  bms_union(outer_rel->direct_lateral_relids,
497  inner_rel->direct_lateral_relids);
498  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
499  outer_rel, inner_rel);
500  joinrel->relid = 0; /* indicates not a baserel */
501  joinrel->rtekind = RTE_JOIN;
502  joinrel->min_attr = 0;
503  joinrel->max_attr = 0;
504  joinrel->attr_needed = NULL;
505  joinrel->attr_widths = NULL;
506  joinrel->lateral_vars = NIL;
507  joinrel->lateral_referencers = NULL;
508  joinrel->indexlist = NIL;
509  joinrel->statlist = NIL;
510  joinrel->pages = 0;
511  joinrel->tuples = 0;
512  joinrel->allvisfrac = 0;
513  joinrel->subroot = NULL;
514  joinrel->subplan_params = NIL;
515  joinrel->rel_parallel_workers = -1;
516  joinrel->serverid = InvalidOid;
517  joinrel->userid = InvalidOid;
518  joinrel->useridiscurrent = false;
519  joinrel->fdwroutine = NULL;
520  joinrel->fdw_private = NULL;
521  joinrel->unique_for_rels = NIL;
522  joinrel->non_unique_for_rels = NIL;
523  joinrel->baserestrictinfo = NIL;
524  joinrel->baserestrictcost.startup = 0;
525  joinrel->baserestrictcost.per_tuple = 0;
526  joinrel->baserestrict_min_security = UINT_MAX;
527  joinrel->joininfo = NIL;
528  joinrel->has_eclass_joins = false;
529  joinrel->top_parent_relids = NULL;
530 
531  /* Compute information relevant to the foreign relations. */
532  set_foreign_rel_properties(joinrel, outer_rel, inner_rel);
533 
534  /*
535  * Create a new tlist containing just the vars that need to be output from
536  * this join (ie, are needed for higher joinclauses or final output).
537  *
538  * NOTE: the tlist order for a join rel will depend on which pair of outer
539  * and inner rels we first try to build it from. But the contents should
540  * be the same regardless.
541  */
542  build_joinrel_tlist(root, joinrel, outer_rel);
543  build_joinrel_tlist(root, joinrel, inner_rel);
544  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
545 
546  /*
547  * add_placeholders_to_joinrel also took care of adding the ph_lateral
548  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
549  * now we can finish computing that. This is much like the computation of
550  * the transitively-closed lateral_relids in min_join_parameterization,
551  * except that here we *do* have to consider the added PHVs.
552  */
553  joinrel->direct_lateral_relids =
554  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
555  if (bms_is_empty(joinrel->direct_lateral_relids))
556  joinrel->direct_lateral_relids = NULL;
557 
558  /*
559  * Construct restrict and join clause lists for the new joinrel. (The
560  * caller might or might not need the restrictlist, but I need it anyway
561  * for set_joinrel_size_estimates().)
562  */
563  restrictlist = build_joinrel_restrictlist(root, joinrel,
564  outer_rel, inner_rel);
565  if (restrictlist_ptr)
566  *restrictlist_ptr = restrictlist;
567  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
568 
569  /*
570  * This is also the right place to check whether the joinrel has any
571  * pending EquivalenceClass joins.
572  */
573  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
574 
575  /*
576  * Set estimates of the joinrel's size.
577  */
578  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
579  sjinfo, restrictlist);
580 
581  /*
582  * Set the consider_parallel flag if this joinrel could potentially be
583  * scanned within a parallel worker. If this flag is false for either
584  * inner_rel or outer_rel, then it must be false for the joinrel also.
585  * Even if both are true, there might be parallel-restricted expressions
586  * in the targetlist or quals.
587  *
588  * Note that if there are more than two rels in this relation, they could
589  * be divided between inner_rel and outer_rel in any arbitrary way. We
590  * assume this doesn't matter, because we should hit all the same baserels
591  * and joinclauses while building up to this joinrel no matter which we
592  * take; therefore, we should make the same decision here however we get
593  * here.
594  */
595  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
596  is_parallel_safe(root, (Node *) restrictlist) &&
597  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
598  joinrel->consider_parallel = true;
599 
600  /* Add the joinrel to the PlannerInfo. */
601  add_join_rel(root, joinrel);
602 
603  /*
604  * Also, if dynamic-programming join search is active, add the new joinrel
605  * to the appropriate sublist. Note: you might think the Assert on number
606  * of members should be for equality, but some of the level 1 rels might
607  * have been joinrels already, so we can only assert <=.
608  */
609  if (root->join_rel_level)
610  {
611  Assert(root->join_cur_level > 0);
612  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
613  root->join_rel_level[root->join_cur_level] =
614  lappend(root->join_rel_level[root->join_cur_level], joinrel);
615  }
616 
617  return joinrel;
618 }
bool has_eclass_joins
Definition: relation.h:591
struct Path * cheapest_unique_path
Definition: relation.h:544
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:226
List * unique_for_rels
Definition: relation.h:580
List * statlist
Definition: relation.h:563
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:522
Relids * attr_needed
Definition: relation.h:558
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:308
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:4092
struct Path * cheapest_startup_path
Definition: relation.h:542
Oid userid
Definition: relation.h:573
double tuples
Definition: relation.h:565
List * baserestrictinfo
Definition: relation.h:585
bool consider_param_startup
Definition: relation.h:532
Definition: nodes.h:509
List * partial_pathlist
Definition: relation.h:541
List * cheapest_parameterized_paths
Definition: relation.h:545
Index baserestrict_min_security
Definition: relation.h:587
bool useridiscurrent
Definition: relation.h:574
void add_placeholders_to_joinrel(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: placeholder.c:411
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:566
PlannerInfo * subroot
Definition: relation.h:567
bool consider_startup
Definition: relation.h:531
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Relids lateral_relids
Definition: relation.h:550
Cost per_tuple
Definition: relation.h:46
static void set_foreign_rel_properties(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:371
double tuple_fraction
Definition: relation.h:291
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:672
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:629
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:605
struct Path * cheapest_total_path
Definition: relation.h:543
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:758
List * joininfo
Definition: relation.h:589
struct FdwRoutine * fdwroutine
Definition: relation.h:576
Relids relids
Definition: relation.h:525
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2358
List * non_unique_for_rels
Definition: relation.h:582
List * ppilist
Definition: relation.h:540
Index relid
Definition: relation.h:553
List * lappend(List *list, void *datum)
Definition: list.c:128
Relids lateral_referencers
Definition: relation.h:561
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
Oid serverid
Definition: relation.h:572
List * exprs
Definition: relation.h:884
Relids direct_lateral_relids
Definition: relation.h:549
int rel_parallel_workers
Definition: relation.h:569
RTEKind rtekind
Definition: relation.h:555
List * indexlist
Definition: relation.h:562
double rows
Definition: relation.h:528
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:577
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:564
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
List ** join_rel_level
Definition: relation.h:225
List * lateral_vars
Definition: relation.h:560
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool consider_parallel
Definition: relation.h:533
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
AttrNumber max_attr
Definition: relation.h:557
List * pathlist
Definition: relation.h:539
int32 * attr_widths
Definition: relation.h:559
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:536
QualCost baserestrictcost
Definition: relation.h:586
static void add_join_rel(PlannerInfo *root, RelOptInfo *joinrel)
Definition: relnode.c:409
List * subplan_params
Definition: relation.h:568
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:788
Relids top_parent_relids
Definition: relation.h:594
AttrNumber min_attr
Definition: relation.h:556
RelOptInfo* build_simple_rel ( PlannerInfo root,
int  relid,
RelOptInfo parent 
)

Definition at line 91 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(), 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, NULL, RelOptInfo::pages, palloc0(), AppendRelInfo::parent_relid, RelOptInfo::partial_pathlist, RelOptInfo::pathlist, QualCost::per_tuple, RelOptInfo::ppilist, PlannerInfo::qual_security_level, RelOptInfo::rel_parallel_workers, RelOptInfo::relid, RangeTblEntry::relid, RelOptInfo::relids, RELOPT_BASEREL, RELOPT_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, RelOptInfo::serverid, PlannerInfo::simple_rel_array, PlannerInfo::simple_rte_array, QualCost::startup, RelOptInfo::statlist, RelOptInfo::subplan_params, RelOptInfo::subroot, RelOptInfo::top_parent_relids, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::unique_for_rels, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

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

92 {
93  RelOptInfo *rel;
94  RangeTblEntry *rte;
95 
96  /* Rel should not exist already */
97  Assert(relid > 0 && relid < root->simple_rel_array_size);
98  if (root->simple_rel_array[relid] != NULL)
99  elog(ERROR, "rel %d already exists", relid);
100 
101  /* Fetch RTE for relation */
102  rte = root->simple_rte_array[relid];
103  Assert(rte != NULL);
104 
105  rel = makeNode(RelOptInfo);
107  rel->relids = bms_make_singleton(relid);
108  rel->rows = 0;
109  /* cheap startup cost is interesting iff not all tuples to be retrieved */
110  rel->consider_startup = (root->tuple_fraction > 0);
111  rel->consider_param_startup = false; /* might get changed later */
112  rel->consider_parallel = false; /* might get changed later */
114  rel->pathlist = NIL;
115  rel->ppilist = NIL;
116  rel->partial_pathlist = NIL;
118  rel->cheapest_total_path = NULL;
119  rel->cheapest_unique_path = NULL;
122  rel->lateral_relids = NULL;
123  rel->relid = relid;
124  rel->rtekind = rte->rtekind;
125  /* min_attr, max_attr, attr_needed, attr_widths are set below */
126  rel->lateral_vars = NIL;
127  rel->lateral_referencers = NULL;
128  rel->indexlist = NIL;
129  rel->statlist = NIL;
130  rel->pages = 0;
131  rel->tuples = 0;
132  rel->allvisfrac = 0;
133  rel->subroot = NULL;
134  rel->subplan_params = NIL;
135  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
136  rel->serverid = InvalidOid;
137  rel->userid = rte->checkAsUser;
138  rel->useridiscurrent = false;
139  rel->fdwroutine = NULL;
140  rel->fdw_private = NULL;
141  rel->unique_for_rels = NIL;
142  rel->non_unique_for_rels = NIL;
143  rel->baserestrictinfo = NIL;
144  rel->baserestrictcost.startup = 0;
145  rel->baserestrictcost.per_tuple = 0;
146  rel->baserestrict_min_security = UINT_MAX;
147  rel->joininfo = NIL;
148  rel->has_eclass_joins = false;
149 
150  /*
151  * Pass top parent's relids down the inheritance hierarchy. If the parent
152  * has top_parent_relids set, it's a direct or an indirect child of the
153  * top parent indicated by top_parent_relids. By extension this child is
154  * also an indirect child of that parent.
155  */
156  if (parent)
157  {
158  if (parent->top_parent_relids)
159  rel->top_parent_relids = parent->top_parent_relids;
160  else
161  rel->top_parent_relids = bms_copy(parent->relids);
162  }
163  else
164  rel->top_parent_relids = NULL;
165 
166  /* Check type of rtable entry */
167  switch (rte->rtekind)
168  {
169  case RTE_RELATION:
170  /* Table --- retrieve statistics from the system catalogs */
171  get_relation_info(root, rte->relid, rte->inh, rel);
172  break;
173  case RTE_SUBQUERY:
174  case RTE_FUNCTION:
175  case RTE_TABLEFUNC:
176  case RTE_VALUES:
177  case RTE_CTE:
178  case RTE_NAMEDTUPLESTORE:
179 
180  /*
181  * Subquery, function, tablefunc, or values list --- set up attr
182  * range and arrays
183  *
184  * Note: 0 is included in range to support whole-row Vars
185  */
186  rel->min_attr = 0;
187  rel->max_attr = list_length(rte->eref->colnames);
188  rel->attr_needed = (Relids *)
189  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
190  rel->attr_widths = (int32 *)
191  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
192  break;
193  default:
194  elog(ERROR, "unrecognized RTE kind: %d",
195  (int) rte->rtekind);
196  break;
197  }
198 
199  /* Save the finished struct in the query's simple_rel_array */
200  root->simple_rel_array[relid] = rel;
201 
202  /*
203  * This is a convenient spot at which to note whether rels participating
204  * in the query have any securityQuals attached. If so, increase
205  * root->qual_security_level to ensure it's larger than the maximum
206  * security level needed for securityQuals.
207  */
208  if (rte->securityQuals)
210  list_length(rte->securityQuals));
211 
212  /*
213  * If this rel is an appendrel parent, recurse to build "other rel"
214  * RelOptInfos for its children. They are "other rels" because they are
215  * not in the main join tree, but we will need RelOptInfos to plan access
216  * to them.
217  */
218  if (rte->inh)
219  {
220  ListCell *l;
221 
222  foreach(l, root->append_rel_list)
223  {
224  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
225 
226  /* append_rel_list contains all append rels; ignore others */
227  if (appinfo->parent_relid != relid)
228  continue;
229 
230  (void) build_simple_rel(root, appinfo->child_relid,
231  rel);
232  }
233  }
234 
235  return rel;
236 }
bool has_eclass_joins
Definition: relation.h:591
struct Path * cheapest_unique_path
Definition: relation.h:544
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
List * unique_for_rels
Definition: relation.h:580
List * statlist
Definition: relation.h:563
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptKind reloptkind
Definition: relation.h:522
Relids * attr_needed
Definition: relation.h:558
List * colnames
Definition: primnodes.h:43
struct Path * cheapest_startup_path
Definition: relation.h:542
Oid userid
Definition: relation.h:573
List * securityQuals
Definition: parsenodes.h:1052
double tuples
Definition: relation.h:565
List * baserestrictinfo
Definition: relation.h:585
bool consider_param_startup
Definition: relation.h:532
List * partial_pathlist
Definition: relation.h:541
List * cheapest_parameterized_paths
Definition: relation.h:545
Index baserestrict_min_security
Definition: relation.h:587
bool useridiscurrent
Definition: relation.h:574
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:566
signed int int32
Definition: c.h:256
struct RelOptInfo ** simple_rel_array
Definition: relation.h:179
PlannerInfo * subroot
Definition: relation.h:567
bool consider_startup
Definition: relation.h:531
Relids lateral_relids
Definition: relation.h:550
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:291
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:543
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:179
List * joininfo
Definition: relation.h:589
struct FdwRoutine * fdwroutine
Definition: relation.h:576
Relids relids
Definition: relation.h:525
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptInfo *parent)
Definition: relnode.c:91
List * non_unique_for_rels
Definition: relation.h:582
List * ppilist
Definition: relation.h:540
Index relid
Definition: relation.h:553
Bitmapset * Relids
Definition: relation.h:28
RangeTblEntry ** simple_rte_array
Definition: relation.h:188
Relids lateral_referencers
Definition: relation.h:561
Oid serverid
Definition: relation.h:572
Relids direct_lateral_relids
Definition: relation.h:549
void * palloc0(Size size)
Definition: mcxt.c:878
int rel_parallel_workers
Definition: relation.h:569
List * append_rel_list
Definition: relation.h:252
RTEKind rtekind
Definition: relation.h:555
List * indexlist
Definition: relation.h:562
double rows
Definition: relation.h:528
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:577
#define Max(x, y)
Definition: c.h:800
#define makeNode(_type_)
Definition: nodes.h:557
BlockNumber pages
Definition: relation.h:564
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
List * lateral_vars
Definition: relation.h:560
static int list_length(const List *l)
Definition: pg_list.h:89
Index qual_security_level
Definition: relation.h:294
bool consider_parallel
Definition: relation.h:533
RTEKind rtekind
Definition: parsenodes.h:944
AttrNumber max_attr
Definition: relation.h:557
List * pathlist
Definition: relation.h:539
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1976
Alias * eref
Definition: parsenodes.h:1043
Index parent_relid
Definition: relation.h:1975
int32 * attr_widths
Definition: relation.h:559
struct PathTarget * reltarget
Definition: relation.h:536
QualCost baserestrictcost
Definition: relation.h:586
List * subplan_params
Definition: relation.h:568
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:101
Relids top_parent_relids
Definition: relation.h:594
AttrNumber min_attr
Definition: relation.h:556
Relids calc_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

Definition at line 1996 of file pathnode.c.

References Assert, bms_copy(), bms_del_members(), bms_free(), bms_is_empty(), bms_overlap(), bms_union(), NULL, Path::parent, PATH_REQ_OUTER, and RelOptInfo::relids.

Referenced by try_nestloop_path().

1997 {
1998  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
1999  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2000  Relids required_outer;
2001 
2002  /* inner_path can require rels from outer path, but not vice versa */
2003  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2004  /* easy case if inner path is not parameterized */
2005  if (!inner_paramrels)
2006  return bms_copy(outer_paramrels);
2007  /* else, form the union ... */
2008  required_outer = bms_union(outer_paramrels, inner_paramrels);
2009  /* ... and remove any mention of now-satisfied outer rels */
2010  required_outer = bms_del_members(required_outer,
2011  outer_path->parent->relids);
2012  /* maintain invariant that required_outer is exactly NULL if empty */
2013  if (bms_is_empty(required_outer))
2014  {
2015  bms_free(required_outer);
2016  required_outer = NULL;
2017  }
2018  return required_outer;
2019 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:111
RelOptInfo * parent
Definition: relation.h:954
Relids relids
Definition: relation.h:525
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:663
void bms_free(Bitmapset *a)
Definition: bitmapset.c:201
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define PATH_REQ_OUTER(path)
Definition: relation.h:973
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:817
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

2029 {
2030  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
2031  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
2032  Relids required_outer;
2033 
2034  /* neither path can require rels from the other */
2035  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
2036  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
2037  /* form the union ... */
2038  required_outer = bms_union(outer_paramrels, inner_paramrels);
2039  /* we do not need an explicit test for empty; bms_union gets it right */
2040  return required_outer;
2041 }
RelOptInfo * parent
Definition: relation.h:954
Relids relids
Definition: relation.h:525
#define Assert(condition)
Definition: c.h:675
#define PATH_REQ_OUTER(path)
Definition: relation.h:973
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
int compare_fractional_path_costs ( Path path1,
Path path2,
double  fraction 
)

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

109 {
110  Cost cost1,
111  cost2;
112 
113  if (fraction <= 0.0 || fraction >= 1.0)
114  return compare_path_costs(path1, path2, TOTAL_COST);
115  cost1 = path1->startup_cost +
116  fraction * (path1->total_cost - path1->startup_cost);
117  cost2 = path2->startup_cost +
118  fraction * (path2->total_cost - path2->startup_cost);
119  if (cost1 < cost2)
120  return -1;
121  if (cost1 > cost2)
122  return +1;
123  return 0;
124 }
Cost startup_cost
Definition: relation.h:965
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:61
Cost total_cost
Definition: relation.h:966
double Cost
Definition: nodes.h:640
int compare_path_costs ( Path path1,
Path path2,
CostSelector  criterion 
)

Definition at line 61 of file pathnode.c.

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

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

62 {
63  if (criterion == STARTUP_COST)
64  {
65  if (path1->startup_cost < path2->startup_cost)
66  return -1;
67  if (path1->startup_cost > path2->startup_cost)
68  return +1;
69 
70  /*
71  * If paths have the same startup cost (not at all unlikely), order
72  * them by total cost.
73  */
74  if (path1->total_cost < path2->total_cost)
75  return -1;
76  if (path1->total_cost > path2->total_cost)
77  return +1;
78  }
79  else
80  {
81  if (path1->total_cost < path2->total_cost)
82  return -1;
83  if (path1->total_cost > path2->total_cost)
84  return +1;
85 
86  /*
87  * If paths have the same total cost, order them by startup cost.
88  */
89  if (path1->startup_cost < path2->startup_cost)
90  return -1;
91  if (path1->startup_cost > path2->startup_cost)
92  return +1;
93  }
94  return 0;
95 }
Cost startup_cost
Definition: relation.h:965
Cost total_cost
Definition: relation.h:966
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 2666 of file pathnode.c.

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

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

2676 {
2677  AggPath *pathnode = makeNode(AggPath);
2678 
2679  pathnode->path.pathtype = T_Agg;
2680  pathnode->path.parent = rel;
2681  pathnode->path.pathtarget = target;
2682  /* For now, assume we are above any joins, so no parameterization */
2683  pathnode->path.param_info = NULL;
2684  pathnode->path.parallel_aware = false;
2685  pathnode->path.parallel_safe = rel->consider_parallel &&
2686  subpath->parallel_safe;
2687  pathnode->path.parallel_workers = subpath->parallel_workers;
2688  if (aggstrategy == AGG_SORTED)
2689  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2690  else
2691  pathnode->path.pathkeys = NIL; /* output is unordered */
2692  pathnode->subpath = subpath;
2693 
2694  pathnode->aggstrategy = aggstrategy;
2695  pathnode->aggsplit = aggsplit;
2696  pathnode->numGroups = numGroups;
2697  pathnode->groupClause = groupClause;
2698  pathnode->qual = qual;
2699 
2700  cost_agg(&pathnode->path, root,
2701  aggstrategy, aggcosts,
2702  list_length(groupClause), numGroups,
2703  subpath->startup_cost, subpath->total_cost,
2704  subpath->rows);
2705 
2706  /* add tlist eval cost for each output row */
2707  pathnode->path.startup_cost += target->cost.startup;
2708  pathnode->path.total_cost += target->cost.startup +
2709  target->cost.per_tuple * pathnode->path.rows;
2710 
2711  return pathnode;
2712 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:955
AggStrategy aggstrategy
Definition: relation.h:1461
List * qual
Definition: relation.h:1465
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
AggSplit aggsplit
Definition: relation.h:1462
double numGroups
Definition: relation.h:1463
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1873
List * groupClause
Definition: relation.h:1464
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:533
Path * subpath
Definition: relation.h:1460
bool parallel_aware
Definition: relation.h:959
Path path
Definition: relation.h:1459
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
AppendPath* create_append_path ( RelOptInfo rel,
List subpaths,
Relids  required_outer,
int  parallel_workers,
List partitioned_rels 
)

Definition at line 1203 of file pathnode.c.

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

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

1205 {
1206  AppendPath *pathnode = makeNode(AppendPath);
1207  ListCell *l;
1208 
1209  pathnode->path.pathtype = T_Append;
1210  pathnode->path.parent = rel;
1211  pathnode->path.pathtarget = rel->reltarget;
1213  required_outer);
1214  pathnode->path.parallel_aware = false;
1215  pathnode->path.parallel_safe = rel->consider_parallel;
1216  pathnode->path.parallel_workers = parallel_workers;
1217  pathnode->path.pathkeys = NIL; /* result is always considered unsorted */
1218  pathnode->partitioned_rels = list_copy(partitioned_rels);
1219  pathnode->subpaths = subpaths;
1220 
1221  /*
1222  * We don't bother with inventing a cost_append(), but just do it here.
1223  *
1224  * Compute rows and costs as sums of subplan rows and costs. We charge
1225  * nothing extra for the Append itself, which perhaps is too optimistic,
1226  * but since it doesn't do any selection or projection, it is a pretty
1227  * cheap node.
1228  */
1229  pathnode->path.rows = 0;
1230  pathnode->path.startup_cost = 0;
1231  pathnode->path.total_cost = 0;
1232  foreach(l, subpaths)
1233  {
1234  Path *subpath = (Path *) lfirst(l);
1235 
1236  pathnode->path.rows += subpath->rows;
1237 
1238  if (l == list_head(subpaths)) /* first node? */
1239  pathnode->path.startup_cost = subpath->startup_cost;
1240  pathnode->path.total_cost += subpath->total_cost;
1241  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1242  subpath->parallel_safe;
1243 
1244  /* All child paths must have same parameterization */
1245  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1246  }
1247 
1248  return pathnode;
1249 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * list_copy(const List *oldlist)
Definition: list.c:1160
Definition: nodes.h:48
Path path
Definition: relation.h:1177
NodeTag pathtype
Definition: relation.h:952
List * subpaths
Definition: relation.h:1180
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
#define PATH_REQ_OUTER(path)
Definition: relation.h:973
bool consider_parallel
Definition: relation.h:533
List * partitioned_rels
Definition: relation.h:1179
bool parallel_aware
Definition: relation.h:959
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1334
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
BitmapAndPath* create_bitmap_and_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

Definition at line 1100 of file pathnode.c.

References BitmapAndPath::bitmapquals, RelOptInfo::consider_parallel, cost_bitmap_and_node(), makeNode, NIL, NULL, 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().

1103 {
1104  BitmapAndPath *pathnode = makeNode(BitmapAndPath);
1105 
1106  pathnode->path.pathtype = T_BitmapAnd;
1107  pathnode->path.parent = rel;
1108  pathnode->path.pathtarget = rel->reltarget;
1109  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1110 
1111  /*
1112  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1113  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1114  * set the flag for this path based only on the relation-level flag,
1115  * without actually iterating over the list of children.
1116  */
1117  pathnode->path.parallel_aware = false;
1118  pathnode->path.parallel_safe = rel->consider_parallel;
1119  pathnode->path.parallel_workers = 0;
1120 
1121  pathnode->path.pathkeys = NIL; /* always unordered */
1122 
1123  pathnode->bitmapquals = bitmapquals;
1124 
1125  /* this sets bitmapselectivity as well as the regular cost fields: */
1126  cost_bitmap_and_node(pathnode, root);
1127 
1128  return pathnode;
1129 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
void cost_bitmap_and_node(BitmapAndPath *path, PlannerInfo *root)
Definition: costsize.c:1072
ParamPathInfo * param_info
Definition: relation.h:957
List * bitmapquals
Definition: relation.h:1074
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
BitmapHeapPath* create_bitmap_heap_path ( PlannerInfo root,
RelOptInfo rel,
Path bitmapqual,
Relids  required_outer,
double  loop_count,
int  parallel_degree 
)

Definition at line 1067 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, and T_BitmapHeapScan.

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

1073 {
1074  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1075 
1076  pathnode->path.pathtype = T_BitmapHeapScan;
1077  pathnode->path.parent = rel;
1078  pathnode->path.pathtarget = rel->reltarget;
1079  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1080  required_outer);
1081  pathnode->path.parallel_aware = parallel_degree > 0 ? true : false;
1082  pathnode->path.parallel_safe = rel->consider_parallel;
1083  pathnode->path.parallel_workers = parallel_degree;
1084  pathnode->path.pathkeys = NIL; /* always unordered */
1085 
1086  pathnode->bitmapqual = bitmapqual;
1087 
1088  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1089  pathnode->path.param_info,
1090  bitmapqual, loop_count);
1091 
1092  return pathnode;
1093 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:928
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
Path * bitmapqual
Definition: relation.h:1062
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
BitmapOrPath* create_bitmap_or_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

Definition at line 1136 of file pathnode.c.

References BitmapOrPath::bitmapquals, RelOptInfo::consider_parallel, cost_bitmap_or_node(), makeNode, NIL, NULL, 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().

1139 {
1140  BitmapOrPath *pathnode = makeNode(BitmapOrPath);
1141 
1142  pathnode->path.pathtype = T_BitmapOr;
1143  pathnode->path.parent = rel;
1144  pathnode->path.pathtarget = rel->reltarget;
1145  pathnode->path.param_info = NULL; /* not used in bitmap trees */
1146 
1147  /*
1148  * Currently, a BitmapHeapPath, BitmapAndPath, or BitmapOrPath will be
1149  * parallel-safe if and only if rel->consider_parallel is set. So, we can
1150  * set the flag for this path based only on the relation-level flag,
1151  * without actually iterating over the list of children.
1152  */
1153  pathnode->path.parallel_aware = false;
1154  pathnode->path.parallel_safe = rel->consider_parallel;
1155  pathnode->path.parallel_workers = 0;
1156 
1157  pathnode->path.pathkeys = NIL; /* always unordered */
1158 
1159  pathnode->bitmapquals = bitmapquals;
1160 
1161  /* this sets bitmapselectivity as well as the regular cost fields: */
1162  cost_bitmap_or_node(pathnode, root);
1163 
1164  return pathnode;
1165 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * bitmapquals
Definition: relation.h:1087
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
void cost_bitmap_or_node(BitmapOrPath *path, PlannerInfo *root)
Definition: costsize.c:1116
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Path* create_ctescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

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

1876 {
1877  Path *pathnode = makeNode(Path);
1878 
1879  pathnode->pathtype = T_CteScan;
1880  pathnode->parent = rel;
1881  pathnode->pathtarget = rel->reltarget;
1882  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1883  required_outer);
1884  pathnode->parallel_aware = false;
1885  pathnode->parallel_safe = rel->consider_parallel;
1886  pathnode->parallel_workers = 0;
1887  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1888 
1889  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1890 
1891  return pathnode;
1892 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1483
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
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 1960 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().

1967 {
1968  ForeignPath *pathnode = makeNode(ForeignPath);
1969 
1970  pathnode->path.pathtype = T_ForeignScan;
1971  pathnode->path.parent = rel;
1972  pathnode->path.pathtarget = target ? target : rel->reltarget;
1973  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1974  required_outer);
1975  pathnode->path.parallel_aware = false;
1976  pathnode->path.parallel_safe = rel->consider_parallel;
1977  pathnode->path.parallel_workers = 0;
1978  pathnode->path.rows = rows;
1979  pathnode->path.startup_cost = startup_cost;
1980  pathnode->path.total_cost = total_cost;
1981  pathnode->path.pathkeys = pathkeys;
1982 
1983  pathnode->fdw_outerpath = fdw_outerpath;
1984  pathnode->fdw_private = fdw_private;
1985 
1986  return pathnode;
1987 }
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
Path * fdw_outerpath
Definition: relation.h:1131
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
List * fdw_private
Definition: relation.h:1132
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Path* create_functionscan_path ( PlannerInfo root,
RelOptInfo rel,
List pathkeys,
Relids  required_outer 
)

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

1799 {
1800  Path *pathnode = makeNode(Path);
1801 
1802  pathnode->pathtype = T_FunctionScan;
1803  pathnode->parent = rel;
1804  pathnode->pathtarget = rel->reltarget;
1805  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1806  required_outer);
1807  pathnode->parallel_aware = false;
1808  pathnode->parallel_safe = rel->consider_parallel;
1809  pathnode->parallel_workers = 0;
1810  pathnode->pathkeys = pathkeys;
1811 
1812  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1813 
1814  return pathnode;
1815 }
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1316
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
GatherMergePath* create_gather_merge_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List pathkeys,
Relids  required_outer,
double *  rows 
)

Definition at line 1639 of file pathnode.c.

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

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

1642 {
1644  Cost input_startup_cost = 0;
1645  Cost input_total_cost = 0;
1646 
1647  Assert(subpath->parallel_safe);
1648  Assert(pathkeys);
1649 
1650  pathnode->path.pathtype = T_GatherMerge;
1651  pathnode->path.parent = rel;
1652  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1653  required_outer);
1654  pathnode->path.parallel_aware = false;
1655 
1656  pathnode->subpath = subpath;
1657  pathnode->num_workers = subpath->parallel_workers;
1658  pathnode->path.pathkeys = pathkeys;
1659  pathnode->path.pathtarget = target ? target : rel->reltarget;
1660  pathnode->path.rows += subpath->rows;
1661 
1662  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1663  {
1664  /* Subpath is adequately ordered, we won't need to sort it */
1665  input_startup_cost += subpath->startup_cost;
1666  input_total_cost += subpath->total_cost;
1667  }
1668  else
1669  {
1670  /* We'll need to insert a Sort node, so include cost for that */
1671  Path sort_path; /* dummy for result of cost_sort */
1672 
1673  cost_sort(&sort_path,
1674  root,
1675  pathkeys,
1676  subpath->total_cost,
1677  subpath->rows,
1678  subpath->pathtarget->width,
1679  0.0,
1680  work_mem,
1681  -1);
1682  input_startup_cost += sort_path.startup_cost;
1683  input_total_cost += sort_path.total_cost;
1684  }
1685 
1686  cost_gather_merge(pathnode, root, rel, pathnode->path.param_info,
1687  input_startup_cost, input_total_cost, rows);
1688 
1689  return pathnode;
1690 }
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
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:387
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
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:1644
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
Path * subpath
Definition: relation.h:1278
int width
Definition: relation.h:887
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
double Cost
Definition: nodes.h:640
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GatherPath* create_gather_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
Relids  required_outer,
double *  rows 
)

Definition at line 1730 of file pathnode.c.

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

Referenced by create_grouping_paths(), and generate_gather_paths().

1732 {
1733  GatherPath *pathnode = makeNode(GatherPath);
1734 
1735  Assert(subpath->parallel_safe);
1736 
1737  pathnode->path.pathtype = T_Gather;
1738  pathnode->path.parent = rel;
1739  pathnode->path.pathtarget = target;
1740  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1741  required_outer);
1742  pathnode->path.parallel_aware = false;
1743  pathnode->path.parallel_safe = false;
1744  pathnode->path.parallel_workers = 0;
1745  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1746 
1747  pathnode->subpath = subpath;
1748  pathnode->num_workers = subpath->parallel_workers;
1749  pathnode->single_copy = false;
1750 
1751  if (pathnode->num_workers == 0)
1752  {
1753  pathnode->path.pathkeys = subpath->pathkeys;
1754  pathnode->num_workers = 1;
1755  pathnode->single_copy = true;
1756  }
1757 
1758  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1759 
1760  return pathnode;
1761 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
bool single_copy
Definition: relation.h:1266
int num_workers
Definition: relation.h:1267
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
Path * subpath
Definition: relation.h:1265
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
bool parallel_safe
Definition: relation.h:960
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:349
Definition: nodes.h:80
bool parallel_aware
Definition: relation.h:959
Path path
Definition: relation.h:1264
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GroupPath* create_group_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List groupClause,
List qual,
double  numGroups 
)

Definition at line 2556 of file pathnode.c.

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

Referenced by create_grouping_paths().

2563 {
2564  GroupPath *pathnode = makeNode(GroupPath);
2565 
2566  pathnode->path.pathtype = T_Group;
2567  pathnode->path.parent = rel;
2568  pathnode->path.pathtarget = target;
2569  /* For now, assume we are above any joins, so no parameterization */
2570  pathnode->path.param_info = NULL;
2571  pathnode->path.parallel_aware = false;
2572  pathnode->path.parallel_safe = rel->consider_parallel &&
2573  subpath->parallel_safe;
2574  pathnode->path.parallel_workers = subpath->parallel_workers;
2575  /* Group doesn't change sort ordering */
2576  pathnode->path.pathkeys = subpath->pathkeys;
2577 
2578  pathnode->subpath = subpath;
2579 
2580  pathnode->groupClause = groupClause;
2581  pathnode->qual = qual;
2582 
2583  cost_group(&pathnode->path, root,
2584  list_length(groupClause),
2585  numGroups,
2586  subpath->startup_cost, subpath->total_cost,
2587  subpath->rows);
2588 
2589  /* add tlist eval cost for each output row */
2590  pathnode->path.startup_cost += target->cost.startup;
2591  pathnode->path.total_cost += target->cost.startup +
2592  target->cost.per_tuple * pathnode->path.rows;
2593 
2594  return pathnode;
2595 }
void cost_group(Path *path, PlannerInfo *root, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:2040
List * qual
Definition: relation.h:1434
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Definition: nodes.h:76
Path path
Definition: relation.h:1431
List * groupClause
Definition: relation.h:1433
Path * subpath
Definition: relation.h:1432
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
GroupingSetsPath* create_groupingsets_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
List having_qual,
AggStrategy  aggstrategy,
List rollups,
const AggClauseCosts agg_costs,
double  numGroups 
)

Definition at line 2731 of file pathnode.c.

References AGG_HASHED, AGG_MIXED, AGG_PLAIN, AGG_SORTED, GroupingSetsPath::aggstrategy, Assert, RelOptInfo::consider_parallel, PathTarget::cost, cost_agg(), cost_sort(), PlannerInfo::group_pathkeys, RollupData::gsets, RollupData::is_hashed, lfirst, linitial, list_length(), makeNode, NIL, RollupData::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, GroupingSetsPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, GroupingSetsPath::qual, GroupingSetsPath::rollups, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupingSetsPath::subpath, T_Agg, Path::total_cost, PathTarget::width, and work_mem.

Referenced by consider_groupingsets_paths().

2740 {
2742  ListCell *lc;
2743  bool is_first = true;
2744  bool is_first_sort = true;
2745 
2746  /* The topmost generated Plan node will be an Agg */
2747  pathnode->path.pathtype = T_Agg;
2748  pathnode->path.parent = rel;
2749  pathnode->path.pathtarget = target;
2750  pathnode->path.param_info = subpath->param_info;
2751  pathnode->path.parallel_aware = false;
2752  pathnode->path.parallel_safe = rel->consider_parallel &&
2753  subpath->parallel_safe;
2754  pathnode->path.parallel_workers = subpath->parallel_workers;
2755  pathnode->subpath = subpath;
2756 
2757  /*
2758  * Simplify callers by downgrading AGG_SORTED to AGG_PLAIN, and AGG_MIXED
2759  * to AGG_HASHED, here if possible.
2760  */
2761  if (aggstrategy == AGG_SORTED &&
2762  list_length(rollups) == 1 &&
2763  ((RollupData *) linitial(rollups))->groupClause == NIL)
2764  aggstrategy = AGG_PLAIN;
2765 
2766  if (aggstrategy == AGG_MIXED &&
2767  list_length(rollups) == 1)
2768  aggstrategy = AGG_HASHED;
2769 
2770  /*
2771  * Output will be in sorted order by group_pathkeys if, and only if, there
2772  * is a single rollup operation on a non-empty list of grouping
2773  * expressions.
2774  */
2775  if (aggstrategy == AGG_SORTED && list_length(rollups) == 1)
2776  pathnode->path.pathkeys = root->group_pathkeys;
2777  else
2778  pathnode->path.pathkeys = NIL;
2779 
2780  pathnode->aggstrategy = aggstrategy;
2781  pathnode->rollups = rollups;
2782  pathnode->qual = having_qual;
2783 
2784  Assert(rollups != NIL);
2785  Assert(aggstrategy != AGG_PLAIN || list_length(rollups) == 1);
2786  Assert(aggstrategy != AGG_MIXED || list_length(rollups) > 1);
2787 
2788  foreach(lc, rollups)
2789  {
2790  RollupData *rollup = lfirst(lc);
2791  List *gsets = rollup->gsets;
2792  int numGroupCols = list_length(linitial(gsets));
2793 
2794  /*
2795  * In AGG_SORTED or AGG_PLAIN mode, the first rollup takes the
2796  * (already-sorted) input, and following ones do their own sort.
2797  *
2798  * In AGG_HASHED mode, there is one rollup for each grouping set.
2799  *
2800  * In AGG_MIXED mode, the first rollups are hashed, the first
2801  * non-hashed one takes the (already-sorted) input, and following ones
2802  * do their own sort.
2803  */
2804  if (is_first)
2805  {
2806  cost_agg(&pathnode->path, root,
2807  aggstrategy,
2808  agg_costs,
2809  numGroupCols,
2810  rollup->numGroups,
2811  subpath->startup_cost,
2812  subpath->total_cost,
2813  subpath->rows);
2814  is_first = false;
2815  if (!rollup->is_hashed)
2816  is_first_sort = false;
2817  }
2818  else
2819  {
2820  Path sort_path; /* dummy for result of cost_sort */
2821  Path agg_path; /* dummy for result of cost_agg */
2822 
2823  if (rollup->is_hashed || is_first_sort)
2824  {
2825  /*
2826  * Account for cost of aggregation, but don't charge input
2827  * cost again
2828  */
2829  cost_agg(&agg_path, root,
2830  rollup->is_hashed ? AGG_HASHED : AGG_SORTED,
2831  agg_costs,
2832  numGroupCols,
2833  rollup->numGroups,
2834  0.0, 0.0,
2835  subpath->rows);
2836  if (!rollup->is_hashed)
2837  is_first_sort = false;
2838  }
2839  else
2840  {
2841  /* Account for cost of sort, but don't charge input cost again */
2842  cost_sort(&sort_path, root, NIL,
2843  0.0,
2844  subpath->rows,
2845  subpath->pathtarget->width,
2846  0.0,
2847  work_mem,
2848  -1.0);
2849 
2850  /* Account for cost of aggregation */
2851 
2852  cost_agg(&agg_path, root,
2853  AGG_SORTED,
2854  agg_costs,
2855  numGroupCols,
2856  rollup->numGroups,
2857  sort_path.startup_cost,
2858  sort_path.total_cost,
2859  sort_path.rows);
2860  }
2861 
2862  pathnode->path.total_cost += agg_path.total_cost;
2863  pathnode->path.rows += agg_path.rows;
2864  }
2865  }
2866 
2867  /* add tlist eval cost for each output row */
2868  pathnode->path.startup_cost += target->cost.startup;
2869  pathnode->path.total_cost += target->cost.startup +
2870  target->cost.per_tuple * pathnode->path.rows;
2871 
2872  return pathnode;
2873 }
List * group_pathkeys
Definition: relation.h:264
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:77
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
bool is_hashed
Definition: relation.h:1487
ParamPathInfo * param_info
Definition: relation.h:957
double numGroups
Definition: relation.h:1485
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
Cost per_tuple
Definition: relation.h:46
#define linitial(l)
Definition: pg_list.h:111
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
void cost_agg(Path *path, PlannerInfo *root, AggStrategy aggstrategy, const AggClauseCosts *aggcosts, int numGroupCols, double numGroups, Cost input_startup_cost, Cost input_total_cost, double input_tuples)
Definition: costsize.c:1873
AggStrategy aggstrategy
Definition: relation.h:1498
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:1644
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:533
int width
Definition: relation.h:887
bool parallel_aware
Definition: relation.h:959
Definition: pg_list.h:45
Definition: relation.h:948
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
List * gsets
Definition: relation.h:1483
HashPath* create_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
JoinPathExtraData extra,
Path outer_path,
Path inner_path,
List restrict_clauses,
Relids  required_outer,
List hashclauses 
)

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

2224 {
2225  HashPath *pathnode = makeNode(HashPath);
2226 
2227  pathnode->jpath.path.pathtype = T_HashJoin;
2228  pathnode->jpath.path.parent = joinrel;
2229  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2230  pathnode->jpath.path.param_info =
2232  joinrel,
2233  outer_path,
2234  inner_path,
2235  extra->sjinfo,
2236  required_outer,
2237  &restrict_clauses);
2238  pathnode->jpath.path.parallel_aware = false;
2239  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2240  outer_path->parallel_safe && inner_path->parallel_safe;
2241  /* This is a foolish way to estimate parallel_workers, but for now... */
2242  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2243 
2244  /*
2245  * A hashjoin never has pathkeys, since its output ordering is
2246  * unpredictable due to possible batching. XXX If the inner relation is
2247  * small enough, we could instruct the executor that it must not batch,
2248  * and then we could assume that the output inherits the outer relation's
2249  * ordering, which might save a sort step. However there is considerable
2250  * downside if our estimate of the inner relation size is badly off. For
2251  * the moment we don't risk it. (Note also that if we wanted to take this
2252  * seriously, joinpath.c would have to consider many more paths for the
2253  * outer rel than it does now.)
2254  */
2255  pathnode->jpath.path.pathkeys = NIL;
2256  pathnode->jpath.jointype = jointype;
2257  pathnode->jpath.inner_unique = extra->inner_unique;
2258  pathnode->jpath.outerjoinpath = outer_path;
2259  pathnode->jpath.innerjoinpath = inner_path;
2260  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2261  pathnode->path_hashclauses = hashclauses;
2262  /* final_cost_hashjoin will fill in pathnode->num_batches */
2263 
2264  final_cost_hashjoin(root, pathnode, workspace, extra);
2265 
2266  return pathnode;
2267 }
#define NIL
Definition: pg_list.h:69
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:3012
JoinPath jpath
Definition: relation.h:1370
PathTarget * pathtarget
Definition: relation.h:955
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:1126
Path * innerjoinpath
Definition: relation.h:1297
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
SpecialJoinInfo * sjinfo
Definition: relation.h:2183
List * joinrestrictinfo
Definition: relation.h:1299
RelOptInfo * parent
Definition: relation.h:954
Path * outerjoinpath
Definition: relation.h:1296
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
Path path
Definition: relation.h:1289
bool parallel_safe
Definition: relation.h:960
bool inner_unique
Definition: relation.h:1293
bool consider_parallel
Definition: relation.h:533
JoinType jointype
Definition: relation.h:1291
bool parallel_aware
Definition: relation.h:959
List * path_hashclauses
Definition: relation.h:1371
struct PathTarget * reltarget
Definition: relation.h:536
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 1008 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().

1020 {
1021  IndexPath *pathnode = makeNode(IndexPath);
1022  RelOptInfo *rel = index->rel;
1023  List *indexquals,
1024  *indexqualcols;
1025 
1026  pathnode->path.pathtype = indexonly ? T_IndexOnlyScan : T_IndexScan;
1027  pathnode->path.parent = rel;
1028  pathnode->path.pathtarget = rel->reltarget;
1029  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1030  required_outer);
1031  pathnode->path.parallel_aware = false;
1032  pathnode->path.parallel_safe = rel->consider_parallel;
1033  pathnode->path.parallel_workers = 0;
1034  pathnode->path.pathkeys = pathkeys;
1035 
1036  /* Convert clauses to indexquals the executor can handle */
1037  expand_indexqual_conditions(index, indexclauses, indexclausecols,
1038  &indexquals, &indexqualcols);
1039 
1040  /* Fill in the pathnode */
1041  pathnode->indexinfo = index;
1042  pathnode->indexclauses = indexclauses;
1043  pathnode->indexquals = indexquals;
1044  pathnode->indexqualcols = indexqualcols;
1045  pathnode->indexorderbys = indexorderbys;
1046  pathnode->indexorderbycols = indexorderbycols;
1047  pathnode->indexscandir = indexscandir;
1048 
1049  cost_index(pathnode, root, loop_count, partial_path);
1050 
1051  return pathnode;
1052 }
List * indexorderbycols
Definition: relation.h:1036
PathTarget * pathtarget
Definition: relation.h:955
Path path
Definition: relation.h:1030
IndexOptInfo * indexinfo
Definition: relation.h:1031
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * indexclauses
Definition: relation.h:1032
NodeTag pathtype
Definition: relation.h:952
List * indexquals
Definition: relation.h:1033
RelOptInfo * rel
Definition: relation.h:633
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3526
RelOptInfo * parent
Definition: relation.h:954
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:462
List * indexorderbys
Definition: relation.h:1035
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
List * indexqualcols
Definition: relation.h:1034
ScanDirection indexscandir
Definition: relation.h:1037
bool parallel_aware
Definition: relation.h:959
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:536
LimitPath* create_limit_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
Node limitOffset,
Node limitCount,
int64  offset_est,
int64  count_est 
)

Definition at line 3274 of file pathnode.c.

References clamp_row_est(), RelOptInfo::consider_parallel, LimitPath::limitCount, LimitPath::limitOffset, makeNode, NULL, 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().

3278 {
3279  LimitPath *pathnode = makeNode(LimitPath);
3280 
3281  pathnode->path.pathtype = T_Limit;
3282  pathnode->path.parent = rel;
3283  /* Limit doesn't project, so use source path's pathtarget */
3284  pathnode->path.pathtarget = subpath->pathtarget;
3285  /* For now, assume we are above any joins, so no parameterization */
3286  pathnode->path.param_info = NULL;
3287  pathnode->path.parallel_aware = false;
3288  pathnode->path.parallel_safe = rel->consider_parallel &&
3289  subpath->parallel_safe;
3290  pathnode->path.parallel_workers = subpath->parallel_workers;
3291  pathnode->path.rows = subpath->rows;
3292  pathnode->path.startup_cost = subpath->startup_cost;
3293  pathnode->path.total_cost = subpath->total_cost;
3294  pathnode->path.pathkeys = subpath->pathkeys;
3295  pathnode->subpath = subpath;
3296  pathnode->limitOffset = limitOffset;
3297  pathnode->limitCount = limitCount;
3298 
3299  /*
3300  * Adjust the output rows count and costs according to the offset/limit.
3301  * This is only a cosmetic issue if we are at top level, but if we are
3302  * building a subquery then it's important to report correct info to the
3303  * outer planner.
3304  *
3305  * When the offset or count couldn't be estimated, use 10% of the
3306  * estimated number of rows emitted from the subpath.
3307  *
3308  * XXX we don't bother to add eval costs of the offset/limit expressions
3309  * themselves to the path costs. In theory we should, but in most cases
3310  * those expressions are trivial and it's just not worth the trouble.
3311  */
3312  if (offset_est != 0)
3313  {
3314  double offset_rows;
3315 
3316  if (offset_est > 0)
3317  offset_rows = (double) offset_est;
3318  else
3319  offset_rows = clamp_row_est(subpath->rows * 0.10);
3320  if (offset_rows > pathnode->path.rows)
3321  offset_rows = pathnode->path.rows;
3322  if (subpath->rows > 0)
3323  pathnode->path.startup_cost +=
3324  (subpath->total_cost - subpath->startup_cost)
3325  * offset_rows / subpath->rows;
3326  pathnode->path.rows -= offset_rows;
3327  if (pathnode->path.rows < 1)
3328  pathnode->path.rows = 1;
3329  }
3330 
3331  if (count_est != 0)
3332  {
3333  double count_rows;
3334 
3335  if (count_est > 0)
3336  count_rows = (double) count_est;
3337  else
3338  count_rows = clamp_row_est(subpath->rows * 0.10);
3339  if (count_rows > pathnode->path.rows)
3340  count_rows = pathnode->path.rows;
3341  if (subpath->rows > 0)
3342  pathnode->path.total_cost = pathnode->path.startup_cost +
3343  (subpath->total_cost - subpath->startup_cost)
3344  * count_rows / subpath->rows;
3345  pathnode->path.rows = count_rows;
3346  if (pathnode->path.rows < 1)
3347  pathnode->path.rows = 1;
3348  }
3349 
3350  return pathnode;
3351 }
PathTarget * pathtarget
Definition: relation.h:955
Node * limitOffset
Definition: relation.h:1599
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
Path * subpath
Definition: relation.h:1598
RelOptInfo * parent
Definition: relation.h:954
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
Path path
Definition: relation.h:1597
bool parallel_aware
Definition: relation.h:959
double clamp_row_est(double nrows)
Definition: costsize.c:173
Node * limitCount
Definition: relation.h:1600
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:85
LockRowsPath* create_lockrows_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List rowMarks,
int  epqParam 
)

Definition at line 3115 of file pathnode.c.

References cpu_tuple_cost, LockRowsPath::epqParam, makeNode, NIL, NULL, 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().

3117 {
3118  LockRowsPath *pathnode = makeNode(LockRowsPath);
3119 
3120  pathnode->path.pathtype = T_LockRows;
3121  pathnode->path.parent = rel;
3122  /* LockRows doesn't project, so use source path's pathtarget */
3123  pathnode->path.pathtarget = subpath->pathtarget;
3124  /* For now, assume we are above any joins, so no parameterization */
3125  pathnode->path.param_info = NULL;
3126  pathnode->path.parallel_aware = false;
3127  pathnode->path.parallel_safe = false;
3128  pathnode->path.parallel_workers = 0;
3129  pathnode->path.rows = subpath->rows;
3130 
3131  /*
3132  * The result cannot be assumed sorted, since locking might cause the sort
3133  * key columns to be replaced with new values.
3134  */
3135  pathnode->path.pathkeys = NIL;
3136 
3137  pathnode->subpath = subpath;
3138  pathnode->rowMarks = rowMarks;
3139  pathnode->epqParam = epqParam;
3140 
3141  /*
3142  * We should charge something extra for the costs of row locking and
3143  * possible refetches, but it's hard to say how much. For now, use
3144  * cpu_tuple_cost per row.
3145  */
3146  pathnode->path.startup_cost = subpath->startup_cost;
3147  pathnode->path.total_cost = subpath->total_cost +
3148  cpu_tuple_cost * subpath->rows;
3149 
3150  return pathnode;
3151 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * rowMarks
Definition: relation.h:1563
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Path * subpath
Definition: relation.h:1562
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:959
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1389 {
1390  MaterialPath *pathnode = makeNode(MaterialPath);
1391 
1392  Assert(subpath->parent == rel);
1393 
1394  pathnode->path.pathtype = T_Material;
1395  pathnode->path.parent = rel;
1396  pathnode->path.pathtarget = rel->reltarget;
1397  pathnode->path.param_info = subpath->param_info;
1398  pathnode->path.parallel_aware = false;
1399  pathnode->path.parallel_safe = rel->consider_parallel &&
1400  subpath->parallel_safe;
1401  pathnode->path.parallel_workers = subpath->parallel_workers;
1402  pathnode->path.pathkeys = subpath->pathkeys;
1403 
1404  pathnode->subpath = subpath;
1405 
1406  cost_material(&pathnode->path,
1407  subpath->startup_cost,
1408  subpath->total_cost,
1409  subpath->rows,
1410  subpath->pathtarget->width);
1411 
1412  return pathnode;
1413 }
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Path * subpath
Definition: relation.h:1226
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Cost total_cost
Definition: relation.h:966
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1819
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define Assert(condition)
Definition: c.h:675
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
int width
Definition: relation.h:887
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
MergeAppendPath* create_merge_append_path ( PlannerInfo root,
RelOptInfo rel,
List subpaths,
List pathkeys,
Relids  required_outer,
List partitioned_rels 
)

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

1263 {
1265  Cost input_startup_cost;
1266  Cost input_total_cost;
1267  ListCell *l;
1268 
1269  pathnode->path.pathtype = T_MergeAppend;
1270  pathnode->path.parent = rel;
1271  pathnode->path.pathtarget = rel->reltarget;
1273  required_outer);
1274  pathnode->path.parallel_aware = false;
1275  pathnode->path.parallel_safe = rel->consider_parallel;
1276  pathnode->path.parallel_workers = 0;
1277  pathnode->path.pathkeys = pathkeys;
1278  pathnode->partitioned_rels = list_copy(partitioned_rels);
1279  pathnode->subpaths = subpaths;
1280 
1281  /*
1282  * Apply query-wide LIMIT if known and path is for sole base relation.
1283  * (Handling this at this low level is a bit klugy.)
1284  */
1285  if (bms_equal(rel->relids, root->all_baserels))
1286  pathnode->limit_tuples = root->limit_tuples;
1287  else
1288  pathnode->limit_tuples = -1.0;
1289 
1290  /*
1291  * Add up the sizes and costs of the input paths.
1292  */
1293  pathnode->path.rows = 0;
1294  input_startup_cost = 0;
1295  input_total_cost = 0;
1296  foreach(l, subpaths)
1297  {
1298  Path *subpath = (Path *) lfirst(l);
1299 
1300  pathnode->path.rows += subpath->rows;
1301  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1302  subpath->parallel_safe;
1303 
1304  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1305  {
1306  /* Subpath is adequately ordered, we won't need to sort it */
1307  input_startup_cost += subpath->startup_cost;
1308  input_total_cost += subpath->total_cost;
1309  }
1310  else
1311  {
1312  /* We'll need to insert a Sort node, so include cost for that */
1313  Path sort_path; /* dummy for result of cost_sort */
1314 
1315  cost_sort(&sort_path,
1316  root,
1317  pathkeys,
1318  subpath->total_cost,
1319  subpath->parent->tuples,
1320  subpath->pathtarget->width,
1321  0.0,
1322  work_mem,
1323  pathnode->limit_tuples);
1324  input_startup_cost += sort_path.startup_cost;
1325  input_total_cost += sort_path.total_cost;
1326  }
1327 
1328  /* All child paths must have same parameterization */
1329  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1330  }
1331 
1332  /* Now we can compute total costs of the MergeAppend */
1333  cost_merge_append(&pathnode->path, root,
1334  pathkeys, list_length(subpaths),
1335  input_startup_cost, input_total_cost,
1336  pathnode->path.rows);
1337 
1338  return pathnode;
1339 }
PathTarget * pathtarget
Definition: relation.h:955
double tuples
Definition: relation.h:565
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * list_copy(const List *oldlist)
Definition: list.c:1160
List * partitioned_rels
Definition: relation.h:1199
NodeTag pathtype
Definition: relation.h:952
Relids all_baserels
Definition: relation.h:196
double limit_tuples
Definition: relation.h:292
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Relids relids
Definition: relation.h:525
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:1644
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
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:1768
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
#define PATH_REQ_OUTER(path)
Definition: relation.h:973
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:533
int width
Definition: relation.h:887
bool parallel_aware
Definition: relation.h:959
List * subpaths
Definition: relation.h:1200
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1334
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
double limit_tuples
Definition: relation.h:1201
double Cost
Definition: nodes.h:640
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:131
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 2149 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().

2162 {
2163  MergePath *pathnode = makeNode(MergePath);
2164 
2165  pathnode->jpath.path.pathtype = T_MergeJoin;
2166  pathnode->jpath.path.parent = joinrel;
2167  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2168  pathnode->jpath.path.param_info =
2170  joinrel,
2171  outer_path,
2172  inner_path,
2173  extra->sjinfo,
2174  required_outer,
2175  &restrict_clauses);
2176  pathnode->jpath.path.parallel_aware = false;
2177  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2178  outer_path->parallel_safe && inner_path->parallel_safe;
2179  /* This is a foolish way to estimate parallel_workers, but for now... */
2180  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2181  pathnode->jpath.path.pathkeys = pathkeys;
2182  pathnode->jpath.jointype = jointype;
2183  pathnode->jpath.inner_unique = extra->inner_unique;
2184  pathnode->jpath.outerjoinpath = outer_path;
2185  pathnode->jpath.innerjoinpath = inner_path;
2186  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2187  pathnode->path_mergeclauses = mergeclauses;
2188  pathnode->outersortkeys = outersortkeys;
2189  pathnode->innersortkeys = innersortkeys;
2190  /* pathnode->skip_mark_restore will be set by final_cost_mergejoin */
2191  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2192 
2193  final_cost_mergejoin(root, pathnode, workspace, extra);
2194 
2195  return pathnode;
2196 }
List * path_mergeclauses
Definition: relation.h:1352
List * outersortkeys
Definition: relation.h:1353
PathTarget * pathtarget
Definition: relation.h:955
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:1126
Path * innerjoinpath
Definition: relation.h:1297
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
SpecialJoinInfo * sjinfo
Definition: relation.h:2183
List * joinrestrictinfo
Definition: relation.h:1299
RelOptInfo * parent
Definition: relation.h:954
Path * outerjoinpath
Definition: relation.h:1296
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
Path path
Definition: relation.h:1289
bool parallel_safe
Definition: relation.h:960
bool inner_unique
Definition: relation.h:1293
bool consider_parallel
Definition: relation.h:533
List * innersortkeys
Definition: relation.h:1354
JoinType jointype
Definition: relation.h:1291
JoinPath jpath
Definition: relation.h:1351
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2599
MinMaxAggPath* create_minmaxagg_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List mmaggregates,
List quals 
)

Definition at line 2885 of file pathnode.c.

References PathTarget::cost, cpu_tuple_cost, lfirst, makeNode, MinMaxAggPath::mmaggregates, NIL, NULL, 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().

2890 {
2891  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2892  Cost initplan_cost;
2893  ListCell *lc;
2894 
2895  /* The topmost generated Plan node will be a Result */
2896  pathnode->path.pathtype = T_Result;
2897  pathnode->path.parent = rel;
2898  pathnode->path.pathtarget = target;
2899  /* For now, assume we are above any joins, so no parameterization */
2900  pathnode->path.param_info = NULL;
2901  pathnode->path.parallel_aware = false;
2902  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2903  pathnode->path.parallel_safe = false;
2904  pathnode->path.parallel_workers = 0;
2905  /* Result is one unordered row */
2906  pathnode->path.rows = 1;
2907  pathnode->path.pathkeys = NIL;
2908 
2909  pathnode->mmaggregates = mmaggregates;
2910  pathnode->quals = quals;
2911 
2912  /* Calculate cost of all the initplans ... */
2913  initplan_cost = 0;
2914  foreach(lc, mmaggregates)
2915  {
2916  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2917 
2918  initplan_cost += mminfo->pathcost;
2919  }
2920 
2921  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
2922  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
2923  pathnode->path.total_cost = initplan_cost + target->cost.startup +
2924  target->cost.per_tuple + cpu_tuple_cost;
2925 
2926  return pathnode;
2927 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * quals
Definition: relation.h:1510
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
List * mmaggregates
Definition: relation.h:1509
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:959
double Cost
Definition: nodes.h:640
ModifyTablePath* create_modifytable_path ( PlannerInfo root,
RelOptInfo rel,
CmdType  operation,
bool  canSetTag,
Index  nominalRelation,
List partitioned_rels,
List resultRelations,
List subpaths,
List subroots,
List withCheckOptionLists,
List returningLists,
List rowMarks,
OnConflictExpr onconflict,
int  epqParam 
)

Definition at line 3174 of file pathnode.c.

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

Referenced by grouping_planner(), and inheritance_planner().

3182 {
3184  double total_size;
3185  ListCell *lc;
3186 
3187  Assert(list_length(resultRelations) == list_length(subpaths));
3188  Assert(list_length(resultRelations) == list_length(subroots));
3189  Assert(withCheckOptionLists == NIL ||
3190  list_length(resultRelations) == list_length(withCheckOptionLists));
3191  Assert(returningLists == NIL ||
3192  list_length(resultRelations) == list_length(returningLists));
3193 
3194  pathnode->path.pathtype = T_ModifyTable;
3195  pathnode->path.parent = rel;
3196  /* pathtarget is not interesting, just make it minimally valid */
3197  pathnode->path.pathtarget = rel->reltarget;
3198  /* For now, assume we are above any joins, so no parameterization */
3199  pathnode->path.param_info = NULL;
3200  pathnode->path.parallel_aware = false;
3201  pathnode->path.parallel_safe = false;
3202  pathnode->path.parallel_workers = 0;
3203  pathnode->path.pathkeys = NIL;
3204 
3205  /*
3206  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3207  *
3208  * Currently, we don't charge anything extra for the actual table
3209  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3210  * expressions if any. It would only be window dressing, since
3211  * ModifyTable is always a top-level node and there is no way for the
3212  * costs to change any higher-level planning choices. But we might want
3213  * to make it look better sometime.
3214  */
3215  pathnode->path.startup_cost = 0;
3216  pathnode->path.total_cost = 0;
3217  pathnode->path.rows = 0;
3218  total_size = 0;
3219  foreach(lc, subpaths)
3220  {
3221  Path *subpath = (Path *) lfirst(lc);
3222 
3223  if (lc == list_head(subpaths)) /* first node? */
3224  pathnode->path.startup_cost = subpath->startup_cost;
3225  pathnode->path.total_cost += subpath->total_cost;
3226  pathnode->path.rows += subpath->rows;
3227  total_size += subpath->pathtarget->width * subpath->rows;
3228  }
3229 
3230  /*
3231  * Set width to the average width of the subpath outputs. XXX this is
3232  * totally wrong: we should report zero if no RETURNING, else an average
3233  * of the RETURNING tlist widths. But it's what happened historically,
3234  * and improving it is a task for another day.
3235  */
3236  if (pathnode->path.rows > 0)
3237  total_size /= pathnode->path.rows;
3238  pathnode->path.pathtarget->width = rint(total_size);
3239 
3240  pathnode->operation = operation;
3241  pathnode->canSetTag = canSetTag;
3242  pathnode->nominalRelation = nominalRelation;
3243  pathnode->partitioned_rels = list_copy(partitioned_rels);
3244  pathnode->resultRelations = resultRelations;
3245  pathnode->subpaths = subpaths;
3246  pathnode->subroots = subroots;
3247  pathnode->withCheckOptionLists = withCheckOptionLists;
3248  pathnode->returningLists = returningLists;
3249  pathnode->rowMarks = rowMarks;
3250  pathnode->onconflict = onconflict;
3251  pathnode->epqParam = epqParam;
3252 
3253  return pathnode;
3254 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
List * returningLists
Definition: relation.h:1586
OnConflictExpr * onconflict
Definition: relation.h:1588
Index nominalRelation
Definition: relation.h:1579
List * rowMarks
Definition: relation.h:1587
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
List * list_copy(const List *oldlist)
Definition: list.c:1160
NodeTag pathtype
Definition: relation.h:952
Cost startup_cost
Definition: relation.h:965
List * subroots
Definition: relation.h:1584
RelOptInfo * parent
Definition: relation.h:954
List * subpaths
Definition: relation.h:1583
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:1581
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1585
int width
Definition: relation.h:887
CmdType operation
Definition: relation.h:1577
List * resultRelations
Definition: relation.h:1582
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Path* create_namedtuplestorescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

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

1902 {
1903  Path *pathnode = makeNode(Path);
1904 
1905  pathnode->pathtype = T_NamedTuplestoreScan;
1906  pathnode->parent = rel;
1907  pathnode->pathtarget = rel->reltarget;
1908  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1909  required_outer);
1910  pathnode->parallel_aware = false;
1911  pathnode->parallel_safe = rel->consider_parallel;
1912  pathnode->parallel_workers = 0;
1913  pathnode->pathkeys = NIL; /* result is always unordered */
1914 
1915  cost_namedtuplestorescan(pathnode, root, rel, pathnode->param_info);
1916 
1917  return pathnode;
1918 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
void cost_namedtuplestorescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1524
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
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 2061 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().

2071 {
2072  NestPath *pathnode = makeNode(NestPath);
2073  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
2074 
2075  /*
2076  * If the inner path is parameterized by the outer, we must drop any
2077  * restrict_clauses that are due to be moved into the inner path. We have
2078  * to do this now, rather than postpone the work till createplan time,
2079  * because the restrict_clauses list can affect the size and cost
2080  * estimates for this path.
2081  */
2082  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
2083  {
2084  Relids inner_and_outer = bms_union(inner_path->parent->relids,
2085  inner_req_outer);
2086  List *jclauses = NIL;
2087  ListCell *lc;
2088 
2089  foreach(lc, restrict_clauses)
2090  {
2091  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
2092 
2093  if (!join_clause_is_movable_into(rinfo,
2094  inner_path->parent->relids,
2095  inner_and_outer))
2096  jclauses = lappend(jclauses, rinfo);
2097  }
2098  restrict_clauses = jclauses;
2099  }
2100 
2101  pathnode->path.pathtype = T_NestLoop;
2102  pathnode->path.parent = joinrel;
2103  pathnode->path.pathtarget = joinrel->reltarget;
2104  pathnode->path.param_info =
2106  joinrel,
2107  outer_path,
2108  inner_path,
2109  extra->sjinfo,
2110  required_outer,
2111  &restrict_clauses);
2112  pathnode->path.parallel_aware = false;
2113  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2114  outer_path->parallel_safe && inner_path->parallel_safe;
2115  /* This is a foolish way to estimate parallel_workers, but for now... */
2116  pathnode->path.parallel_workers = outer_path->parallel_workers;
2117  pathnode->path.pathkeys = pathkeys;
2118  pathnode->jointype = jointype;
2119  pathnode->inner_unique = extra->inner_unique;
2120  pathnode->outerjoinpath = outer_path;
2121  pathnode->innerjoinpath = inner_path;
2122  pathnode->joinrestrictinfo = restrict_clauses;
2123 
2124  final_cost_nestloop(root, pathnode, workspace, extra);
2125 
2126  return pathnode;
2127 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
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:1126
Path * innerjoinpath
Definition: relation.h:1297
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, JoinPathExtraData *extra)
Definition: costsize.c:2162
SpecialJoinInfo * sjinfo
Definition: relation.h:2183
List * joinrestrictinfo
Definition: relation.h:1299
RelOptInfo * parent
Definition: relation.h:954
Relids relids
Definition: relation.h:525
bool join_clause_is_movable_into(RestrictInfo *rinfo, Relids currentrelids, Relids current_and_outer)
Definition: restrictinfo.c:508
List * lappend(List *list, void *datum)
Definition: list.c:128
Path * outerjoinpath
Definition: relation.h:1296
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
Path path
Definition: relation.h:1289
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:960
#define PATH_REQ_OUTER(path)
Definition: relation.h:973
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:218
bool inner_unique
Definition: relation.h:1293
bool consider_parallel
Definition: relation.h:533
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:443
JoinType jointype
Definition: relation.h:1291
bool parallel_aware
Definition: relation.h:959
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:536
ProjectionPath* create_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

Definition at line 2278 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, NULL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ProjectionPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectionPath::subpath, T_Result, and Path::total_cost.

Referenced by adjust_paths_for_srfs(), apply_projection_to_path(), and grouping_planner().

2282 {
2283  ProjectionPath *pathnode = makeNode(ProjectionPath);
2284  PathTarget *oldtarget = subpath->pathtarget;
2285 
2286  pathnode->path.pathtype = T_Result;
2287  pathnode->path.parent = rel;
2288  pathnode->path.pathtarget = target;
2289  /* For now, assume we are above any joins, so no parameterization */
2290  pathnode->path.param_info = NULL;
2291  pathnode->path.parallel_aware = false;
2292  pathnode->path.parallel_safe = rel->consider_parallel &&
2293  subpath->parallel_safe &&
2294  is_parallel_safe(root, (Node *) target->exprs);
2295  pathnode->path.parallel_workers = subpath->parallel_workers;
2296  /* Projection does not change the sort order */
2297  pathnode->path.pathkeys = subpath->pathkeys;
2298 
2299  pathnode->subpath = subpath;
2300 
2301  /*
2302  * We might not need a separate Result node. If the input plan node type
2303  * can project, we can just tell it to project something else. Or, if it
2304  * can't project but the desired target has the same expression list as
2305  * what the input will produce anyway, we can still give it the desired
2306  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2307  * Note: in the latter case, create_projection_plan has to recheck our
2308  * conclusion; see comments therein.
2309  */
2310  if (is_projection_capable_path(subpath) ||
2311  equal(oldtarget->exprs, target->exprs))
2312  {
2313  /* No separate Result node needed */
2314  pathnode->dummypp = true;
2315 
2316  /*
2317  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2318  */
2319  pathnode->path.rows = subpath->rows;
2320  pathnode->path.startup_cost = subpath->startup_cost +
2321  (target->cost.startup - oldtarget->cost.startup);
2322  pathnode->path.total_cost = subpath->total_cost +
2323  (target->cost.startup - oldtarget->cost.startup) +
2324  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2325  }
2326  else
2327  {
2328  /* We really do need the Result node */
2329  pathnode->dummypp = false;
2330 
2331  /*
2332  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2333  * evaluating the tlist. There is no qual to worry about.
2334  */
2335  pathnode->path.rows = subpath->rows;
2336  pathnode->path.startup_cost = subpath->startup_cost +
2337  target->cost.startup;
2338  pathnode->path.total_cost = subpath->total_cost +
2339  target->cost.startup +
2340  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2341  }
2342 
2343  return pathnode;
2344 }
PathTarget * pathtarget
Definition: relation.h:955
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2962
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Definition: nodes.h:509
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
List * exprs
Definition: relation.h:884
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
bool consider_parallel
Definition: relation.h:533
double cpu_tuple_cost
Definition: costsize.c:106
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6540
bool parallel_aware
Definition: relation.h:959
Path * subpath
Definition: relation.h:1392
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
RecursiveUnionPath* create_recursiveunion_path ( PlannerInfo root,
RelOptInfo rel,
Path leftpath,
Path rightpath,
PathTarget target,
List distinctList,
int  wtParam,
double  numGroups 
)

Definition at line 3070 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_recursive_union(), RecursiveUnionPath::distinctList, RecursiveUnionPath::leftpath, makeNode, NIL, NULL, 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().

3078 {
3080 
3081  pathnode->path.pathtype = T_RecursiveUnion;
3082  pathnode->path.parent = rel;
3083  pathnode->path.pathtarget = target;
3084  /* For now, assume we are above any joins, so no parameterization */
3085  pathnode->path.param_info = NULL;
3086  pathnode->path.parallel_aware = false;
3087  pathnode->path.parallel_safe = rel->consider_parallel &&
3088  leftpath->parallel_safe && rightpath->parallel_safe;
3089  /* Foolish, but we'll do it like joins for now: */
3090  pathnode->path.parallel_workers = leftpath->parallel_workers;
3091  /* RecursiveUnion result is always unsorted */
3092  pathnode->path.pathkeys = NIL;
3093 
3094  pathnode->leftpath = leftpath;
3095  pathnode->rightpath = rightpath;
3096  pathnode->distinctList = distinctList;
3097  pathnode->wtParam = wtParam;
3098  pathnode->numGroups = numGroups;
3099 
3100  cost_recursive_union(&pathnode->path, leftpath, rightpath);
3101 
3102  return pathnode;
3103 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1564
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
ResultPath* create_result_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List resconstantqual 
)

Definition at line 1349 of file pathnode.c.

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

Referenced by create_grouping_paths(), and query_planner().

1351 {
1352  ResultPath *pathnode = makeNode(ResultPath);
1353 
1354  pathnode->path.pathtype = T_Result;
1355  pathnode->path.parent = rel;
1356  pathnode->path.pathtarget = target;
1357  pathnode->path.param_info = NULL; /* there are no other rels... */
1358  pathnode->path.parallel_aware = false;
1359  pathnode->path.parallel_safe = rel->consider_parallel;
1360  pathnode->path.parallel_workers = 0;
1361  pathnode->path.pathkeys = NIL;
1362  pathnode->quals = resconstantqual;
1363 
1364  /* Hardly worth defining a cost_result() function ... just do it */
1365  pathnode->path.rows = 1;
1366  pathnode->path.startup_cost = target->cost.startup;
1367  pathnode->path.total_cost = target->cost.startup +
1368  cpu_tuple_cost + target->cost.per_tuple;
1369  if (resconstantqual)
1370  {
1371  QualCost qual_cost;
1372 
1373  cost_qual_eval(&qual_cost, resconstantqual, root);
1374  /* resconstantqual is evaluated once at startup */
1375  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1376  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1377  }
1378 
1379  return pathnode;
1380 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
Cost per_tuple
Definition: relation.h:46
Path path
Definition: relation.h:1213
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3438
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
List * quals
Definition: relation.h:1214
QualCost cost
Definition: relation.h:886
bool consider_parallel
Definition: relation.h:533
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:959
Path* create_samplescan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer 
)

Definition at line 963 of file pathnode.c.

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

Referenced by reparameterize_path(), and set_tablesample_rel_pathlist().

964 {
965  Path *pathnode = makeNode(Path);
966 
967  pathnode->pathtype = T_SampleScan;
968  pathnode->parent = rel;
969  pathnode->pathtarget = rel->reltarget;
970  pathnode->param_info = get_baserel_parampathinfo(root, rel,
971  required_outer);
972  pathnode->parallel_aware = false;
973  pathnode->parallel_safe = rel->consider_parallel;
974  pathnode->parallel_workers = 0;
975  pathnode->pathkeys = NIL; /* samplescan has unordered result */
976 
977  cost_samplescan(pathnode, root, rel, pathnode->param_info);
978 
979  return pathnode;
980 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:274
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
Path* create_seqscan_path ( PlannerInfo root,
RelOptInfo rel,
Relids  required_outer,
int  parallel_workers 
)

Definition at line 938 of file pathnode.c.

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

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

940 {
941  Path *pathnode = makeNode(Path);
942 
943  pathnode->pathtype = T_SeqScan;
944  pathnode->parent = rel;
945  pathnode->pathtarget = rel->reltarget;
946  pathnode->param_info = get_baserel_parampathinfo(root, rel,
947  required_outer);
948  pathnode->parallel_aware = parallel_workers > 0 ? true : false;
949  pathnode->parallel_safe = rel->consider_parallel;
950  pathnode->parallel_workers = parallel_workers;
951  pathnode->pathkeys = NIL; /* seqscan has unordered result */
952 
953  cost_seqscan(pathnode, root, rel, pathnode->param_info);
954 
955  return pathnode;
956 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:955
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1035
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
NodeTag pathtype
Definition: relation.h:952
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:197
RelOptInfo * parent
Definition: relation.h:954
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
bool parallel_aware
Definition: relation.h:959
struct PathTarget * reltarget
Definition: relation.h:536
Definition: relation.h:948
ProjectSetPath* create_set_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

Definition at line 2445 of file pathnode.c.

References RelOptInfo::consider_parallel, PathTarget::cost, cpu_tuple_cost, expression_returns_set_rows(), PathTarget::exprs, is_parallel_safe(), lfirst, makeNode, NULL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, ProjectSetPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, QualCost::per_tuple, Path::rows, QualCost::startup, Path::startup_cost, subpath(), ProjectSetPath::subpath, T_ProjectSet, and Path::total_cost.

Referenced by adjust_paths_for_srfs().

2449 {
2450  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2451  double tlist_rows;
2452  ListCell *lc;
2453 
2454  pathnode->path.pathtype = T_ProjectSet;
2455  pathnode->path.parent = rel;
2456  pathnode->path.pathtarget = target;
2457  /* For now, assume we are above any joins, so no parameterization */
2458  pathnode->path.param_info = NULL;
2459  pathnode->path.parallel_aware = false;
2460  pathnode->path.parallel_safe = rel->consider_parallel &&
2461  subpath->parallel_safe &&
2462  is_parallel_safe(root, (Node *) target->exprs);
2463  pathnode->path.parallel_workers = subpath->parallel_workers;
2464  /* Projection does not change the sort order XXX? */
2465  pathnode->path.pathkeys = subpath->pathkeys;
2466 
2467  pathnode->subpath = subpath;
2468 
2469  /*
2470  * Estimate number of rows produced by SRFs for each row of input; if
2471  * there's more than one in this node, use the maximum.
2472  */
2473  tlist_rows = 1;
2474  foreach(lc, target->exprs)
2475  {
2476  Node *node = (Node *) lfirst(lc);
2477  double itemrows;
2478 
2479  itemrows = expression_returns_set_rows(node);
2480  if (tlist_rows < itemrows)
2481  tlist_rows = itemrows;
2482  }
2483 
2484  /*
2485  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2486  * per input row, and half of cpu_tuple_cost for each added output row.
2487  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2488  * this estimate later.
2489  */
2490  pathnode->path.rows = subpath->rows * tlist_rows;
2491  pathnode->path.startup_cost = subpath->startup_cost +
2492  target->cost.startup;
2493  pathnode->path.total_cost = subpath->total_cost +
2494  target->cost.startup +
2495  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2496  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2497 
2498  return pathnode;
2499 }
PathTarget * pathtarget
Definition: relation.h:955
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:802
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Definition: nodes.h:509
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:952
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1087
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
List * exprs
Definition: relation.h:884
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1404
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
QualCost cost
Definition: relation.h:886
bool consider_parallel
Definition: relation.h:533
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:959
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
SetOpPath* create_setop_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
SetOpCmd  cmd,
SetOpStrategy  strategy,
List distinctList,
AttrNumber  flagColIdx,
int  firstFlag,
double  numGroups,
double  outputRows 
)

Definition at line 3008 of file pathnode.c.

References SetOpPath::cmd, RelOptInfo::consider_parallel, cpu_operator_cost, SetOpPath::distinctList, SetOpPath::firstFlag, SetOpPath::flagColIdx, list_length(), makeNode, NIL, NULL, SetOpPath::numGroups, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SetOpPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, SETOP_SORTED, Path::startup_cost, SetOpPath::strategy, SetOpPath::subpath, T_SetOp, and Path::total_cost.

Referenced by generate_nonunion_path().

3018 {
3019  SetOpPath *pathnode = makeNode(SetOpPath);
3020 
3021  pathnode->path.pathtype = T_SetOp;
3022  pathnode->path.parent = rel;
3023  /* SetOp doesn't project, so use source path's pathtarget */
3024  pathnode->path.pathtarget = subpath->pathtarget;
3025  /* For now, assume we are above any joins, so no parameterization */
3026  pathnode->path.param_info = NULL;
3027  pathnode->path.parallel_aware = false;
3028  pathnode->path.parallel_safe = rel->consider_parallel &&
3029  subpath->parallel_safe;
3030  pathnode->path.parallel_workers = subpath->parallel_workers;
3031  /* SetOp preserves the input sort order if in sort mode */
3032  pathnode->path.pathkeys =
3033  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
3034 
3035  pathnode->subpath = subpath;
3036  pathnode->cmd = cmd;
3037  pathnode->strategy = strategy;
3038  pathnode->distinctList = distinctList;
3039  pathnode->flagColIdx = flagColIdx;
3040  pathnode->firstFlag = firstFlag;
3041  pathnode->numGroups = numGroups;
3042 
3043  /*
3044  * Charge one cpu_operator_cost per comparison per input tuple. We assume
3045  * all columns get compared at most of the tuples.
3046  */
3047  pathnode->path.startup_cost = subpath->startup_cost;
3048  pathnode->path.total_cost = subpath->total_cost +
3049  cpu_operator_cost * subpath->rows * list_length(distinctList);
3050  pathnode->path.rows = outputRows;
3051 
3052  return pathnode;
3053 }
#define NIL
Definition: pg_list.h:69
List * distinctList
Definition: relation.h:1537
PathTarget * pathtarget
Definition: relation.h:955
SetOpStrategy strategy
Definition: relation.h:1536
Path * subpath
Definition: relation.h:1534
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
double numGroups
Definition: relation.h:1540
NodeTag pathtype
Definition: relation.h:952
SetOpCmd cmd
Definition: relation.h:1535
Cost startup_cost
Definition: relation.h:965
RelOptInfo * parent
Definition: relation.h:954
AttrNumber flagColIdx
Definition: relation.h:1538
double cpu_operator_cost
Definition: costsize.c:108
Cost total_cost
Definition: relation.h:966
int firstFlag
Definition: relation.h:1539
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:533
Definition: nodes.h:83
bool parallel_aware
Definition: relation.h:959
Path path
Definition: relation.h:1533
SortPath* create_sort_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
double  limit_tuples 
)

Definition at line 2512 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_sort(), makeNode, NULL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SortPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, Path::rows, subpath(), SortPath::subpath, T_Sort, Path::total_cost, PathTarget::width, and work_mem.

Referenced by create_distinct_paths(), create_grouping_paths(), create_one_window_path(), create_ordered_paths(), generate_nonunion_path(), and make_union_unique().

2517 {
2518  SortPath *pathnode = makeNode(SortPath);
2519 
2520  pathnode->path.pathtype = T_Sort;
2521  pathnode->path.parent = rel;
2522  /* Sort doesn't project, so use source path's pathtarget */
2523  pathnode->path.pathtarget = subpath->pathtarget;
2524  /* For now, assume we are above any joins, so no parameterization */
2525  pathnode->path.param_info = NULL;
2526  pathnode->path.parallel_aware = false;
2527  pathnode->path.parallel_safe = rel->consider_parallel &&
2528  subpath->parallel_safe;
2529  pathnode->path.parallel_workers = subpath->parallel_workers;
2530  pathnode->path.pathkeys = pathkeys;
2531 
2532  pathnode->subpath = subpath;
2533 
2534  cost_sort(&pathnode->path, root, pathkeys,
2535  subpath->total_cost,
2536  subpath->rows,
2537  subpath->pathtarget->width,
2538  0.0, /* XXX comparison_cost shouldn't be 0? */
2539  work_mem, limit_tuples);
2540 
2541  return pathnode;
2542 }
PathTarget * pathtarget
Definition: relation.h:955
Path * subpath
Definition: relation.h:1418
int parallel_workers
Definition: relation.h:961
ParamPathInfo * param_info
Definition: relation.h:957
Definition: nodes.h:75
NodeTag pathtype
Definition: relation.h:952
RelOptInfo * parent
Definition: relation.h:954
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:1644
int work_mem
Definition: globals.c:113
Cost total_cost
Definition: relation.h:966
List * pathkeys
Definition: relation.h:968
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
double rows
Definition: relation.h:964
bool parallel_safe
Definition: relation.h:960
bool consider_parallel
Definition: relation.h:533
int width
Definition: relation.h:887
bool parallel_aware
Definition: relation.h:959
Path path
Definition: relation.h:1417
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234