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)
 
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)
 
MergeAppendPathcreate_merge_append_path (PlannerInfo *root, RelOptInfo *rel, List *subpaths, List *pathkeys, Relids required_outer)
 
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)
 
SubqueryScanPathcreate_subqueryscan_path (PlannerInfo *root, RelOptInfo *rel, Path *subpath, List *pathkeys, Relids required_outer)
 
Pathcreate_functionscan_path (PlannerInfo *root, RelOptInfo *rel, List *pathkeys, Relids required_outer)
 
Pathcreate_valuesscan_path (PlannerInfo *root, RelOptInfo *rel, Relids required_outer)
 
Pathcreate_ctescan_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, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors, 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, SpecialJoinInfo *sjinfo, 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, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors, 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, List *rollup_lists, List *rollup_groupclauses, 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 *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, RelOptKind reloptkind)
 
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)
 
RelOptInfofind_childrel_top_parent (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 build_index_paths(), create_grouping_paths(), create_plain_partial_paths(), set_append_rel_pathlist(), try_partial_hashjoin_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:506
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:992
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:907
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:909
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
#define STD_FUZZ_FACTOR
Definition: pathnode.c:46
PathKeysComparison
Definition: paths.h:173
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
Definition: relation.h:888
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(), 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:506
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
#define STD_FUZZ_FACTOR
Definition: pathnode.c:46
PathKeysComparison
Definition: paths.h:173
Definition: relation.h:888
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_with_pathkeys_for_rel(), 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_append_rel_pathlist(), set_cte_pathlist(), set_dummy_rel_pathlist(), set_function_pathlist(), set_plain_rel_pathlist(), set_subquery_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:559
ParamPathInfo * param_info
Definition: relation.h:897
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:992
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:344
Cost total_cost
Definition: relation.h:907
List * lcons(void *datum, List *list)
Definition: list.c:259
List * pathkeys
Definition: relation.h:909
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
#define STD_FUZZ_FACTOR
Definition: pathnode.c:46
PathKeysComparison
Definition: paths.h:173
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:97
List * pathlist
Definition: relation.h:504
Definition: pg_list.h:45
Definition: relation.h:888
BMS_Comparison
Definition: bitmapset.h:40
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:497
ParamPathInfo * param_info
Definition: relation.h:897
PathKeysComparison compare_pathkeys(List *keys1, List *keys2)
Definition: pathkeys.c:278
bool consider_startup
Definition: relation.h:496
Cost startup_cost
Definition: relation.h:906
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define lfirst(lc)
Definition: pg_list.h:106
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
#define STD_FUZZ_FACTOR
Definition: pathnode.c:46
PathKeysComparison
Definition: paths.h:173
List * pathlist
Definition: relation.h:504
Definition: pg_list.h:45
Definition: relation.h:888
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
Path* apply_projection_to_path ( PlannerInfo root,
RelOptInfo rel,
Path path,
PathTarget target 
)

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

2257 {
2258  QualCost oldcost;
2259 
2260  /*
2261  * If given path can't project, we might need a Result node, so make a
2262  * separate ProjectionPath.
2263  */
2264  if (!is_projection_capable_path(path))
2265  return (Path *) create_projection_path(root, rel, path, target);
2266 
2267  /*
2268  * We can just jam the desired tlist into the existing path, being sure to
2269  * update its cost estimates appropriately.
2270  */
2271  oldcost = path->pathtarget->cost;
2272  path->pathtarget = target;
2273 
2274  path->startup_cost += target->cost.startup - oldcost.startup;
2275  path->total_cost += target->cost.startup - oldcost.startup +
2276  (target->cost.per_tuple - oldcost.per_tuple) * path->rows;
2277 
2278  /*
2279  * If the path happens to be a Gather path, we'd like to arrange for the
2280  * subpath to return the required target list so that workers can help
2281  * project. But if there is something that is not parallel-safe in the
2282  * target expressions, then we can't.
2283  */
2284  if (IsA(path, GatherPath) &&
2285  is_parallel_safe(root, (Node *) target->exprs))
2286  {
2287  GatherPath *gpath = (GatherPath *) path;
2288 
2289  /*
2290  * We always use create_projection_path here, even if the subpath is
2291  * projection-capable, so as to avoid modifying the subpath in place.
2292  * It seems unlikely at present that there could be any other
2293  * references to the subpath, but better safe than sorry.
2294  *
2295  * Note that we don't change the GatherPath's cost estimates; it might
2296  * be appropriate to do so, to reflect the fact that the bulk of the
2297  * target evaluation will happen in workers.
2298  */
2299  gpath->subpath = (Path *)
2301  gpath->subpath->parent,
2302  gpath->subpath,
2303  target);
2304  }
2305  else if (path->parallel_safe &&
2306  !is_parallel_safe(root, (Node *) target->exprs))
2307  {
2308  /*
2309  * We're inserting a parallel-restricted target list into a path
2310  * currently marked parallel-safe, so we have to mark it as no longer
2311  * safe.
2312  */
2313  path->parallel_safe = false;
2314  }
2315 
2316  return path;
2317 }
#define IsA(nodeptr, _type_)
Definition: nodes.h:559
PathTarget * pathtarget
Definition: relation.h:895
Definition: nodes.h:508
ProjectionPath * create_projection_path(PlannerInfo *root, RelOptInfo *rel, Path *subpath, PathTarget *target)
Definition: pathnode.c:2162
Cost startup
Definition: relation.h:45
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Path * subpath
Definition: relation.h:1202
List * exprs
Definition: relation.h:824
Cost total_cost
Definition: relation.h:907
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6261
Definition: relation.h:888
RelOptInfo* build_empty_join_rel ( PlannerInfo root)

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

837 {
838  RelOptInfo *joinrel;
839 
840  /* The dummy join relation should be the only one ... */
841  Assert(root->join_rel_list == NIL);
842 
843  joinrel = makeNode(RelOptInfo);
844  joinrel->reloptkind = RELOPT_JOINREL;
845  joinrel->relids = NULL; /* empty set */
846  joinrel->rows = 1; /* we produce one row for such cases */
847  joinrel->rtekind = RTE_JOIN;
848  joinrel->reltarget = create_empty_pathtarget();
849 
850  root->join_rel_list = lappend(root->join_rel_list, joinrel);
851 
852  return joinrel;
853 }
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:487
List * join_rel_list
Definition: relation.h:212
Relids relids
Definition: relation.h:490
List * lappend(List *list, void *datum)
Definition: list.c:128
RTEKind rtekind
Definition: relation.h:520
double rows
Definition: relation.h:493
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
struct PathTarget * reltarget
Definition: relation.h:501
RelOptInfo* build_join_rel ( PlannerInfo root,
Relids  joinrelids,
RelOptInfo outer_rel,
RelOptInfo inner_rel,
SpecialJoinInfo sjinfo,
List **  restrictlist_ptr 
)

Definition at line 346 of file relnode.c.

References 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(), GetUserId(), RelOptInfo::has_eclass_joins, has_relevant_eclass_joinclause(), HASH_ENTER, hash_search(), RelOptInfo::indexlist, InvalidOid, is_parallel_safe(), PlannerInfo::join_cur_level, JoinHashEntry::join_rel, PlannerInfo::join_rel_hash, PlannerInfo::join_rel_level, PlannerInfo::join_rel_list, RelOptInfo::joininfo, lappend(), RelOptInfo::lateral_referencers, RelOptInfo::lateral_relids, RelOptInfo::lateral_vars, makeNode, RelOptInfo::max_attr, RelOptInfo::min_attr, min_join_parameterization(), NIL, NULL, OidIsValid, 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_joinrel_size_estimates(), QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

Referenced by make_join_rel().

352 {
353  RelOptInfo *joinrel;
354  List *restrictlist;
355 
356  /*
357  * See if we already have a joinrel for this set of base rels.
358  */
359  joinrel = find_join_rel(root, joinrelids);
360 
361  if (joinrel)
362  {
363  /*
364  * Yes, so we only need to figure the restrictlist for this particular
365  * pair of component relations.
366  */
367  if (restrictlist_ptr)
368  *restrictlist_ptr = build_joinrel_restrictlist(root,
369  joinrel,
370  outer_rel,
371  inner_rel);
372  return joinrel;
373  }
374 
375  /*
376  * Nope, so make one.
377  */
378  joinrel = makeNode(RelOptInfo);
379  joinrel->reloptkind = RELOPT_JOINREL;
380  joinrel->relids = bms_copy(joinrelids);
381  joinrel->rows = 0;
382  /* cheap startup cost is interesting iff not all tuples to be retrieved */
383  joinrel->consider_startup = (root->tuple_fraction > 0);
384  joinrel->consider_param_startup = false;
385  joinrel->consider_parallel = false;
386  joinrel->reltarget = create_empty_pathtarget();
387  joinrel->pathlist = NIL;
388  joinrel->ppilist = NIL;
389  joinrel->partial_pathlist = NIL;
390  joinrel->cheapest_startup_path = NULL;
391  joinrel->cheapest_total_path = NULL;
392  joinrel->cheapest_unique_path = NULL;
394  /* init direct_lateral_relids from children; we'll finish it up below */
395  joinrel->direct_lateral_relids =
396  bms_union(outer_rel->direct_lateral_relids,
397  inner_rel->direct_lateral_relids);
398  joinrel->lateral_relids = min_join_parameterization(root, joinrel->relids,
399  outer_rel, inner_rel);
400  joinrel->relid = 0; /* indicates not a baserel */
401  joinrel->rtekind = RTE_JOIN;
402  joinrel->min_attr = 0;
403  joinrel->max_attr = 0;
404  joinrel->attr_needed = NULL;
405  joinrel->attr_widths = NULL;
406  joinrel->lateral_vars = NIL;
407  joinrel->lateral_referencers = NULL;
408  joinrel->indexlist = NIL;
409  joinrel->pages = 0;
410  joinrel->tuples = 0;
411  joinrel->allvisfrac = 0;
412  joinrel->subroot = NULL;
413  joinrel->subplan_params = NIL;
414  joinrel->rel_parallel_workers = -1;
415  joinrel->serverid = InvalidOid;
416  joinrel->userid = InvalidOid;
417  joinrel->useridiscurrent = false;
418  joinrel->fdwroutine = NULL;
419  joinrel->fdw_private = NULL;
420  joinrel->baserestrictinfo = NIL;
421  joinrel->baserestrictcost.startup = 0;
422  joinrel->baserestrictcost.per_tuple = 0;
423  joinrel->baserestrict_min_security = UINT_MAX;
424  joinrel->joininfo = NIL;
425  joinrel->has_eclass_joins = false;
426 
427  /*
428  * Set up foreign-join fields if outer and inner relation are foreign
429  * tables (or joins) belonging to the same server and assigned to the same
430  * user to check access permissions as. In addition to an exact match of
431  * userid, we allow the case where one side has zero userid (implying
432  * current user) and the other side has explicit userid that happens to
433  * equal the current user; but in that case, pushdown of the join is only
434  * valid for the current user. The useridiscurrent field records whether
435  * we had to make such an assumption for this join or any sub-join.
436  *
437  * Otherwise these fields are left invalid, so GetForeignJoinPaths will
438  * not be called for the join relation.
439  */
440  if (OidIsValid(outer_rel->serverid) &&
441  inner_rel->serverid == outer_rel->serverid)
442  {
443  if (inner_rel->userid == outer_rel->userid)
444  {
445  joinrel->serverid = outer_rel->serverid;
446  joinrel->userid = outer_rel->userid;
447  joinrel->useridiscurrent = outer_rel->useridiscurrent || inner_rel->useridiscurrent;
448  joinrel->fdwroutine = outer_rel->fdwroutine;
449  }
450  else if (!OidIsValid(inner_rel->userid) &&
451  outer_rel->userid == GetUserId())
452  {
453  joinrel->serverid = outer_rel->serverid;
454  joinrel->userid = outer_rel->userid;
455  joinrel->useridiscurrent = true;
456  joinrel->fdwroutine = outer_rel->fdwroutine;
457  }
458  else if (!OidIsValid(outer_rel->userid) &&
459  inner_rel->userid == GetUserId())
460  {
461  joinrel->serverid = outer_rel->serverid;
462  joinrel->userid = inner_rel->userid;
463  joinrel->useridiscurrent = true;
464  joinrel->fdwroutine = outer_rel->fdwroutine;
465  }
466  }
467 
468  /*
469  * Create a new tlist containing just the vars that need to be output from
470  * this join (ie, are needed for higher joinclauses or final output).
471  *
472  * NOTE: the tlist order for a join rel will depend on which pair of outer
473  * and inner rels we first try to build it from. But the contents should
474  * be the same regardless.
475  */
476  build_joinrel_tlist(root, joinrel, outer_rel);
477  build_joinrel_tlist(root, joinrel, inner_rel);
478  add_placeholders_to_joinrel(root, joinrel, outer_rel, inner_rel);
479 
480  /*
481  * add_placeholders_to_joinrel also took care of adding the ph_lateral
482  * sets of any PlaceHolderVars computed here to direct_lateral_relids, so
483  * now we can finish computing that. This is much like the computation of
484  * the transitively-closed lateral_relids in min_join_parameterization,
485  * except that here we *do* have to consider the added PHVs.
486  */
487  joinrel->direct_lateral_relids =
488  bms_del_members(joinrel->direct_lateral_relids, joinrel->relids);
489  if (bms_is_empty(joinrel->direct_lateral_relids))
490  joinrel->direct_lateral_relids = NULL;
491 
492  /*
493  * Construct restrict and join clause lists for the new joinrel. (The
494  * caller might or might not need the restrictlist, but I need it anyway
495  * for set_joinrel_size_estimates().)
496  */
497  restrictlist = build_joinrel_restrictlist(root, joinrel,
498  outer_rel, inner_rel);
499  if (restrictlist_ptr)
500  *restrictlist_ptr = restrictlist;
501  build_joinrel_joinlist(joinrel, outer_rel, inner_rel);
502 
503  /*
504  * This is also the right place to check whether the joinrel has any
505  * pending EquivalenceClass joins.
506  */
507  joinrel->has_eclass_joins = has_relevant_eclass_joinclause(root, joinrel);
508 
509  /*
510  * Set estimates of the joinrel's size.
511  */
512  set_joinrel_size_estimates(root, joinrel, outer_rel, inner_rel,
513  sjinfo, restrictlist);
514 
515  /*
516  * Set the consider_parallel flag if this joinrel could potentially be
517  * scanned within a parallel worker. If this flag is false for either
518  * inner_rel or outer_rel, then it must be false for the joinrel also.
519  * Even if both are true, there might be parallel-restricted expressions
520  * in the targetlist or quals.
521  *
522  * Note that if there are more than two rels in this relation, they could
523  * be divided between inner_rel and outer_rel in any arbitrary way. We
524  * assume this doesn't matter, because we should hit all the same baserels
525  * and joinclauses while building up to this joinrel no matter which we
526  * take; therefore, we should make the same decision here however we get
527  * here.
528  */
529  if (inner_rel->consider_parallel && outer_rel->consider_parallel &&
530  is_parallel_safe(root, (Node *) restrictlist) &&
531  is_parallel_safe(root, (Node *) joinrel->reltarget->exprs))
532  joinrel->consider_parallel = true;
533 
534  /*
535  * Add the joinrel to the query's joinrel list, and store it into the
536  * auxiliary hashtable if there is one. NB: GEQO requires us to append
537  * the new joinrel to the end of the list!
538  */
539  root->join_rel_list = lappend(root->join_rel_list, joinrel);
540 
541  if (root->join_rel_hash)
542  {
543  JoinHashEntry *hentry;
544  bool found;
545 
546  hentry = (JoinHashEntry *) hash_search(root->join_rel_hash,
547  &(joinrel->relids),
548  HASH_ENTER,
549  &found);
550  Assert(!found);
551  hentry->join_rel = joinrel;
552  }
553 
554  /*
555  * Also, if dynamic-programming join search is active, add the new joinrel
556  * to the appropriate sublist. Note: you might think the Assert on number
557  * of members should be for equality, but some of the level 1 rels might
558  * have been joinrels already, so we can only assert <=.
559  */
560  if (root->join_rel_level)
561  {
562  Assert(root->join_cur_level > 0);
563  Assert(root->join_cur_level <= bms_num_members(joinrel->relids));
564  root->join_rel_level[root->join_cur_level] =
565  lappend(root->join_rel_level[root->join_cur_level], joinrel);
566  }
567 
568  return joinrel;
569 }
bool has_eclass_joins
Definition: relation.h:551
struct Path * cheapest_unique_path
Definition: relation.h:509
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
int join_cur_level
Definition: relation.h:223
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:110
RelOptKind reloptkind
Definition: relation.h:487
Relids * attr_needed
Definition: relation.h:523
RelOptInfo * find_join_rel(PlannerInfo *root, Relids relids)
Definition: relnode.c:284
Oid GetUserId(void)
Definition: miscinit.c:282
void set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *outer_rel, RelOptInfo *inner_rel, SpecialJoinInfo *sjinfo, List *restrictlist)
Definition: costsize.c:3845
struct Path * cheapest_startup_path
Definition: relation.h:507
Oid userid
Definition: relation.h:537
double tuples
Definition: relation.h:529
List * baserestrictinfo
Definition: relation.h:544
bool consider_param_startup
Definition: relation.h:497
Definition: nodes.h:508
List * partial_pathlist
Definition: relation.h:506
List * join_rel_list
Definition: relation.h:212
List * cheapest_parameterized_paths
Definition: relation.h:510
Index baserestrict_min_security
Definition: relation.h:547
void * hash_search(HTAB *hashp, const void *keyPtr, HASHACTION action, bool *foundPtr)
Definition: dynahash.c:885
bool useridiscurrent
Definition: relation.h:538
#define OidIsValid(objectId)
Definition: c.h:534
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:530
PlannerInfo * subroot
Definition: relation.h:531
bool consider_startup
Definition: relation.h:496
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
Relids lateral_relids
Definition: relation.h:515
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:286
static void build_joinrel_tlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *input_rel)
Definition: relnode.c:623
Relids min_join_parameterization(PlannerInfo *root, Relids joinrelids, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:580
RelOptInfo * join_rel
Definition: relnode.c:34
int bms_num_members(const Bitmapset *a)
Definition: bitmapset.c:575
struct Path * cheapest_total_path
Definition: relation.h:508
static List * build_joinrel_restrictlist(PlannerInfo *root, RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:709
List * joininfo
Definition: relation.h:549
struct FdwRoutine * fdwroutine
Definition: relation.h:540
Relids relids
Definition: relation.h:490
bool has_relevant_eclass_joinclause(PlannerInfo *root, RelOptInfo *rel1)
Definition: equivclass.c:2354
List * ppilist
Definition: relation.h:505
Index relid
Definition: relation.h:518
List * lappend(List *list, void *datum)
Definition: list.c:128
Relids lateral_referencers
Definition: relation.h:526
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
Oid serverid
Definition: relation.h:536
List * exprs
Definition: relation.h:824
Relids direct_lateral_relids
Definition: relation.h:514
int rel_parallel_workers
Definition: relation.h:533
RTEKind rtekind
Definition: relation.h:520
List * indexlist
Definition: relation.h:527
double rows
Definition: relation.h:493
#define InvalidOid
Definition: postgres_ext.h:36
void * fdw_private
Definition: relation.h:541
#define makeNode(_type_)
Definition: nodes.h:556
BlockNumber pages
Definition: relation.h:528
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
List ** join_rel_level
Definition: relation.h:222
List * lateral_vars
Definition: relation.h:525
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
struct HTAB * join_rel_hash
Definition: relation.h:213
bool consider_parallel
Definition: relation.h:498
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:787
AttrNumber max_attr
Definition: relation.h:522
List * pathlist
Definition: relation.h:504
int32 * attr_widths
Definition: relation.h:524
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:501
QualCost baserestrictcost
Definition: relation.h:546
List * subplan_params
Definition: relation.h:532
static void build_joinrel_joinlist(RelOptInfo *joinrel, RelOptInfo *outer_rel, RelOptInfo *inner_rel)
Definition: relnode.c:739
AttrNumber min_attr
Definition: relation.h:521
RelOptInfo* build_simple_rel ( PlannerInfo root,
int  relid,
RelOptKind  reloptkind 
)

Definition at line 88 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_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, 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_OTHER_MEMBER_REL, RelOptInfo::reloptkind, RelOptInfo::reltarget, RelOptInfo::rows, RTE_CTE, RTE_FUNCTION, RTE_RELATION, RTE_SUBQUERY, RTE_VALUES, RelOptInfo::rtekind, RangeTblEntry::rtekind, RangeTblEntry::securityQuals, RelOptInfo::serverid, PlannerInfo::simple_rel_array, PlannerInfo::simple_rte_array, QualCost::startup, RelOptInfo::subplan_params, RelOptInfo::subroot, PlannerInfo::tuple_fraction, RelOptInfo::tuples, RelOptInfo::userid, and RelOptInfo::useridiscurrent.

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

89 {
90  RelOptInfo *rel;
91  RangeTblEntry *rte;
92 
93  /* Rel should not exist already */
94  Assert(relid > 0 && relid < root->simple_rel_array_size);
95  if (root->simple_rel_array[relid] != NULL)
96  elog(ERROR, "rel %d already exists", relid);
97 
98  /* Fetch RTE for relation */
99  rte = root->simple_rte_array[relid];
100  Assert(rte != NULL);
101 
102  rel = makeNode(RelOptInfo);
103  rel->reloptkind = reloptkind;
104  rel->relids = bms_make_singleton(relid);
105  rel->rows = 0;
106  /* cheap startup cost is interesting iff not all tuples to be retrieved */
107  rel->consider_startup = (root->tuple_fraction > 0);
108  rel->consider_param_startup = false; /* might get changed later */
109  rel->consider_parallel = false; /* might get changed later */
111  rel->pathlist = NIL;
112  rel->ppilist = NIL;
113  rel->partial_pathlist = NIL;
115  rel->cheapest_total_path = NULL;
116  rel->cheapest_unique_path = NULL;
119  rel->lateral_relids = NULL;
120  rel->relid = relid;
121  rel->rtekind = rte->rtekind;
122  /* min_attr, max_attr, attr_needed, attr_widths are set below */
123  rel->lateral_vars = NIL;
124  rel->lateral_referencers = NULL;
125  rel->indexlist = NIL;
126  rel->pages = 0;
127  rel->tuples = 0;
128  rel->allvisfrac = 0;
129  rel->subroot = NULL;
130  rel->subplan_params = NIL;
131  rel->rel_parallel_workers = -1; /* set up in get_relation_info */
132  rel->serverid = InvalidOid;
133  rel->userid = rte->checkAsUser;
134  rel->useridiscurrent = false;
135  rel->fdwroutine = NULL;
136  rel->fdw_private = NULL;
137  rel->baserestrictinfo = NIL;
138  rel->baserestrictcost.startup = 0;
139  rel->baserestrictcost.per_tuple = 0;
140  rel->baserestrict_min_security = UINT_MAX;
141  rel->joininfo = NIL;
142  rel->has_eclass_joins = false;
143 
144  /* Check type of rtable entry */
145  switch (rte->rtekind)
146  {
147  case RTE_RELATION:
148  /* Table --- retrieve statistics from the system catalogs */
149  get_relation_info(root, rte->relid, rte->inh, rel);
150  break;
151  case RTE_SUBQUERY:
152  case RTE_FUNCTION:
153  case RTE_VALUES:
154  case RTE_CTE:
155 
156  /*
157  * Subquery, function, or values list --- set up attr range and
158  * arrays
159  *
160  * Note: 0 is included in range to support whole-row Vars
161  */
162  rel->min_attr = 0;
163  rel->max_attr = list_length(rte->eref->colnames);
164  rel->attr_needed = (Relids *)
165  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(Relids));
166  rel->attr_widths = (int32 *)
167  palloc0((rel->max_attr - rel->min_attr + 1) * sizeof(int32));
168  break;
169  default:
170  elog(ERROR, "unrecognized RTE kind: %d",
171  (int) rte->rtekind);
172  break;
173  }
174 
175  /* Save the finished struct in the query's simple_rel_array */
176  root->simple_rel_array[relid] = rel;
177 
178  /*
179  * This is a convenient spot at which to note whether rels participating
180  * in the query have any securityQuals attached. If so, increase
181  * root->qual_security_level to ensure it's larger than the maximum
182  * security level needed for securityQuals.
183  */
184  if (rte->securityQuals)
186  list_length(rte->securityQuals));
187 
188  /*
189  * If this rel is an appendrel parent, recurse to build "other rel"
190  * RelOptInfos for its children. They are "other rels" because they are
191  * not in the main join tree, but we will need RelOptInfos to plan access
192  * to them.
193  */
194  if (rte->inh)
195  {
196  ListCell *l;
197 
198  foreach(l, root->append_rel_list)
199  {
200  AppendRelInfo *appinfo = (AppendRelInfo *) lfirst(l);
201 
202  /* append_rel_list contains all append rels; ignore others */
203  if (appinfo->parent_relid != relid)
204  continue;
205 
206  (void) build_simple_rel(root, appinfo->child_relid,
208  }
209  }
210 
211  return rel;
212 }
bool has_eclass_joins
Definition: relation.h:551
struct Path * cheapest_unique_path
Definition: relation.h:509
PathTarget * create_empty_pathtarget(void)
Definition: tlist.c:653
#define NIL
Definition: pg_list.h:69
RelOptKind reloptkind
Definition: relation.h:487
Relids * attr_needed
Definition: relation.h:523
List * colnames
Definition: primnodes.h:42
struct Path * cheapest_startup_path
Definition: relation.h:507
Oid userid
Definition: relation.h:537
List * securityQuals
Definition: parsenodes.h:970
double tuples
Definition: relation.h:529
List * baserestrictinfo
Definition: relation.h:544
bool consider_param_startup
Definition: relation.h:497
List * partial_pathlist
Definition: relation.h:506
List * cheapest_parameterized_paths
Definition: relation.h:510
Index baserestrict_min_security
Definition: relation.h:547
bool useridiscurrent
Definition: relation.h:538
Cost startup
Definition: relation.h:45
double allvisfrac
Definition: relation.h:530
signed int int32
Definition: c.h:253
struct RelOptInfo ** simple_rel_array
Definition: relation.h:176
PlannerInfo * subroot
Definition: relation.h:531
bool consider_startup
Definition: relation.h:496
Relids lateral_relids
Definition: relation.h:515
Cost per_tuple
Definition: relation.h:46
double tuple_fraction
Definition: relation.h:286
#define ERROR
Definition: elog.h:43
struct Path * cheapest_total_path
Definition: relation.h:508
Bitmapset * bms_make_singleton(int x)
Definition: bitmapset.c:178
List * joininfo
Definition: relation.h:549
struct FdwRoutine * fdwroutine
Definition: relation.h:540
Relids relids
Definition: relation.h:490
List * ppilist
Definition: relation.h:505
Index relid
Definition: relation.h:518
Bitmapset * Relids
Definition: relation.h:28
RangeTblEntry ** simple_rte_array
Definition: relation.h:185
Relids lateral_referencers
Definition: relation.h:526
Oid serverid
Definition: relation.h:536
Relids direct_lateral_relids
Definition: relation.h:514
void * palloc0(Size size)
Definition: mcxt.c:920
int rel_parallel_workers
Definition: relation.h:533
List * append_rel_list
Definition: relation.h:249
RTEKind rtekind
Definition: relation.h:520
List * indexlist
Definition: relation.h:527
double rows
Definition: relation.h:493
#define InvalidOid
Definition: postgres_ext.h:36
RelOptInfo * build_simple_rel(PlannerInfo *root, int relid, RelOptKind reloptkind)
Definition: relnode.c:88
void * fdw_private
Definition: relation.h:541
#define Max(x, y)
Definition: c.h:796
#define makeNode(_type_)
Definition: nodes.h:556
BlockNumber pages
Definition: relation.h:528
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
List * lateral_vars
Definition: relation.h:525
static int list_length(const List *l)
Definition: pg_list.h:89
Index qual_security_level
Definition: relation.h:289
bool consider_parallel
Definition: relation.h:498
RTEKind rtekind
Definition: parsenodes.h:882
AttrNumber max_attr
Definition: relation.h:522
List * pathlist
Definition: relation.h:504
#define elog
Definition: elog.h:219
Index child_relid
Definition: relation.h:1866
Alias * eref
Definition: parsenodes.h:961
Index parent_relid
Definition: relation.h:1865
int32 * attr_widths
Definition: relation.h:524
struct PathTarget * reltarget
Definition: relation.h:501
QualCost baserestrictcost
Definition: relation.h:546
List * subplan_params
Definition: relation.h:532
void get_relation_info(PlannerInfo *root, Oid relationObjectId, bool inhparent, RelOptInfo *rel)
Definition: plancat.c:96
AttrNumber min_attr
Definition: relation.h:521
Relids calc_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

1881 {
1882  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
1883  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
1884  Relids required_outer;
1885 
1886  /* inner_path can require rels from outer path, but not vice versa */
1887  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
1888  /* easy case if inner path is not parameterized */
1889  if (!inner_paramrels)
1890  return bms_copy(outer_paramrels);
1891  /* else, form the union ... */
1892  required_outer = bms_union(outer_paramrels, inner_paramrels);
1893  /* ... and remove any mention of now-satisfied outer rels */
1894  required_outer = bms_del_members(required_outer,
1895  outer_path->parent->relids);
1896  /* maintain invariant that required_outer is exactly NULL if empty */
1897  if (bms_is_empty(required_outer))
1898  {
1899  bms_free(required_outer);
1900  required_outer = NULL;
1901  }
1902  return required_outer;
1903 }
Bitmapset * bms_copy(const Bitmapset *a)
Definition: bitmapset.c:110
RelOptInfo * parent
Definition: relation.h:894
Relids relids
Definition: relation.h:490
bool bms_is_empty(const Bitmapset *a)
Definition: bitmapset.c:633
void bms_free(Bitmapset *a)
Definition: bitmapset.c:200
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:787
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
Relids calc_non_nestloop_required_outer ( Path outer_path,
Path inner_path 
)

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

1913 {
1914  Relids outer_paramrels = PATH_REQ_OUTER(outer_path);
1915  Relids inner_paramrels = PATH_REQ_OUTER(inner_path);
1916  Relids required_outer;
1917 
1918  /* neither path can require rels from the other */
1919  Assert(!bms_overlap(outer_paramrels, inner_path->parent->relids));
1920  Assert(!bms_overlap(inner_paramrels, outer_path->parent->relids));
1921  /* form the union ... */
1922  required_outer = bms_union(outer_paramrels, inner_paramrels);
1923  /* we do not need an explicit test for empty; bms_union gets it right */
1924  return required_outer;
1925 }
RelOptInfo * parent
Definition: relation.h:894
Relids relids
Definition: relation.h:490
#define Assert(condition)
Definition: c.h:671
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
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:906
int compare_path_costs(Path *path1, Path *path2, CostSelector criterion)
Definition: pathnode.c:61
Cost total_cost
Definition: relation.h:907
double Cost
Definition: nodes.h:632
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:906
Cost total_cost
Definition: relation.h:907
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 2550 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().

2560 {
2561  AggPath *pathnode = makeNode(AggPath);
2562 
2563  pathnode->path.pathtype = T_Agg;
2564  pathnode->path.parent = rel;
2565  pathnode->path.pathtarget = target;
2566  /* For now, assume we are above any joins, so no parameterization */
2567  pathnode->path.param_info = NULL;
2568  pathnode->path.parallel_aware = false;
2569  pathnode->path.parallel_safe = rel->consider_parallel &&
2570  subpath->parallel_safe;
2571  pathnode->path.parallel_workers = subpath->parallel_workers;
2572  if (aggstrategy == AGG_SORTED)
2573  pathnode->path.pathkeys = subpath->pathkeys; /* preserves order */
2574  else
2575  pathnode->path.pathkeys = NIL; /* output is unordered */
2576  pathnode->subpath = subpath;
2577 
2578  pathnode->aggstrategy = aggstrategy;
2579  pathnode->aggsplit = aggsplit;
2580  pathnode->numGroups = numGroups;
2581  pathnode->groupClause = groupClause;
2582  pathnode->qual = qual;
2583 
2584  cost_agg(&pathnode->path, root,
2585  aggstrategy, aggcosts,
2586  list_length(groupClause), numGroups,
2587  subpath->startup_cost, subpath->total_cost,
2588  subpath->rows);
2589 
2590  /* add tlist eval cost for each output row */
2591  pathnode->path.startup_cost += target->cost.startup;
2592  pathnode->path.total_cost += target->cost.startup +
2593  target->cost.per_tuple * pathnode->path.rows;
2594 
2595  return pathnode;
2596 }
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:75
PathTarget * pathtarget
Definition: relation.h:895
AggStrategy aggstrategy
Definition: relation.h:1373
List * qual
Definition: relation.h:1377
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
AggSplit aggsplit
Definition: relation.h:1374
double numGroups
Definition: relation.h:1375
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
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:1691
List * groupClause
Definition: relation.h:1376
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:498
Path * subpath
Definition: relation.h:1372
bool parallel_aware
Definition: relation.h:899
Path path
Definition: relation.h:1371
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
AppendPath* create_append_path ( RelOptInfo rel,
List subpaths,
Relids  required_outer,
int  parallel_workers 
)

Definition at line 1202 of file pathnode.c.

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

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

1204 {
1205  AppendPath *pathnode = makeNode(AppendPath);
1206  ListCell *l;
1207 
1208  pathnode->path.pathtype = T_Append;
1209  pathnode->path.parent = rel;
1210  pathnode->path.pathtarget = rel->reltarget;
1212  required_outer);
1213  pathnode->path.parallel_aware = false;
1214  pathnode->path.parallel_safe = rel->consider_parallel;
1215  pathnode->path.parallel_workers = parallel_workers;
1216  pathnode->path.pathkeys = NIL; /* result is always considered
1217  * unsorted */
1218  pathnode->subpaths = subpaths;
1219 
1220  /*
1221  * We don't bother with inventing a cost_append(), but just do it here.
1222  *
1223  * Compute rows and costs as sums of subplan rows and costs. We charge
1224  * nothing extra for the Append itself, which perhaps is too optimistic,
1225  * but since it doesn't do any selection or projection, it is a pretty
1226  * cheap node.
1227  */
1228  pathnode->path.rows = 0;
1229  pathnode->path.startup_cost = 0;
1230  pathnode->path.total_cost = 0;
1231  foreach(l, subpaths)
1232  {
1233  Path *subpath = (Path *) lfirst(l);
1234 
1235  pathnode->path.rows += subpath->rows;
1236 
1237  if (l == list_head(subpaths)) /* first node? */
1238  pathnode->path.startup_cost = subpath->startup_cost;
1239  pathnode->path.total_cost += subpath->total_cost;
1240  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1241  subpath->parallel_safe;
1242 
1243  /* All child paths must have same parameterization */
1244  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1245  }
1246 
1247  return pathnode;
1248 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Definition: nodes.h:48
Path path
Definition: relation.h:1118
NodeTag pathtype
Definition: relation.h:892
List * subpaths
Definition: relation.h:1119
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1309
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
BitmapAndPath* create_bitmap_and_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

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

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

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(), and reparameterize_path().

1072 {
1073  BitmapHeapPath *pathnode = makeNode(BitmapHeapPath);
1074 
1075  pathnode->path.pathtype = T_BitmapHeapScan;
1076  pathnode->path.parent = rel;
1077  pathnode->path.pathtarget = rel->reltarget;
1078  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1079  required_outer);
1080  pathnode->path.parallel_aware = false;
1081  pathnode->path.parallel_safe = rel->consider_parallel;
1082  pathnode->path.parallel_workers = 0;
1083  pathnode->path.pathkeys = NIL; /* always unordered */
1084 
1085  pathnode->bitmapqual = bitmapqual;
1086 
1087  cost_bitmap_heap_scan(&pathnode->path, root, rel,
1088  pathnode->path.param_info,
1089  bitmapqual, loop_count);
1090 
1091  return pathnode;
1092 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
void cost_bitmap_heap_scan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info, Path *bitmapqual, double loop_count)
Definition: costsize.c:853
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
Path * bitmapqual
Definition: relation.h:1003
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
BitmapOrPath* create_bitmap_or_path ( PlannerInfo root,
RelOptInfo rel,
List bitmapquals 
)

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

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

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

1786 {
1787  Path *pathnode = makeNode(Path);
1788 
1789  pathnode->pathtype = T_CteScan;
1790  pathnode->parent = rel;
1791  pathnode->pathtarget = rel->reltarget;
1792  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1793  required_outer);
1794  pathnode->parallel_aware = false;
1795  pathnode->parallel_safe = rel->consider_parallel;
1796  pathnode->parallel_workers = 0;
1797  pathnode->pathkeys = NIL; /* XXX for now, result is always unordered */
1798 
1799  cost_ctescan(pathnode, root, rel, pathnode->param_info);
1800 
1801  return pathnode;
1802 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
void cost_ctescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1338
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
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 1844 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().

1851 {
1852  ForeignPath *pathnode = makeNode(ForeignPath);
1853 
1854  pathnode->path.pathtype = T_ForeignScan;
1855  pathnode->path.parent = rel;
1856  pathnode->path.pathtarget = target ? target : rel->reltarget;
1857  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1858  required_outer);
1859  pathnode->path.parallel_aware = false;
1860  pathnode->path.parallel_safe = rel->consider_parallel;
1861  pathnode->path.parallel_workers = 0;
1862  pathnode->path.rows = rows;
1863  pathnode->path.startup_cost = startup_cost;
1864  pathnode->path.total_cost = total_cost;
1865  pathnode->path.pathkeys = pathkeys;
1866 
1867  pathnode->fdw_outerpath = fdw_outerpath;
1868  pathnode->fdw_private = fdw_private;
1869 
1870  return pathnode;
1871 }
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
Path * fdw_outerpath
Definition: relation.h:1072
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
List * fdw_private
Definition: relation.h:1073
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Path* create_functionscan_path ( PlannerInfo root,
RelOptInfo rel,
List pathkeys,
Relids  required_outer 
)

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

1735 {
1736  Path *pathnode = makeNode(Path);
1737 
1738  pathnode->pathtype = T_FunctionScan;
1739  pathnode->parent = rel;
1740  pathnode->pathtarget = rel->reltarget;
1741  pathnode->param_info = get_baserel_parampathinfo(root, rel,
1742  required_outer);
1743  pathnode->parallel_aware = false;
1744  pathnode->parallel_safe = rel->consider_parallel;
1745  pathnode->parallel_workers = 0;
1746  pathnode->pathkeys = pathkeys;
1747 
1748  cost_functionscan(pathnode, root, rel, pathnode->param_info);
1749 
1750  return pathnode;
1751 }
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
void cost_functionscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1227
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
GatherPath* create_gather_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target,
Relids  required_outer,
double *  rows 
)

Definition at line 1667 of file pathnode.c.

References Assert, cost_gather(), get_baserel_parampathinfo(), makeNode, NIL, 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().

1669 {
1670  GatherPath *pathnode = makeNode(GatherPath);
1671 
1672  Assert(subpath->parallel_safe);
1673 
1674  pathnode->path.pathtype = T_Gather;
1675  pathnode->path.parent = rel;
1676  pathnode->path.pathtarget = target;
1677  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1678  required_outer);
1679  pathnode->path.parallel_aware = false;
1680  pathnode->path.parallel_safe = false;
1681  pathnode->path.parallel_workers = subpath->parallel_workers;
1682  pathnode->path.pathkeys = NIL; /* Gather has unordered result */
1683 
1684  pathnode->subpath = subpath;
1685  pathnode->single_copy = false;
1686 
1687  if (pathnode->path.parallel_workers == 0)
1688  {
1689  pathnode->path.parallel_workers = 1;
1690  pathnode->path.pathkeys = subpath->pathkeys;
1691  pathnode->single_copy = true;
1692  }
1693 
1694  cost_gather(pathnode, root, rel, pathnode->path.param_info, rows);
1695 
1696  return pathnode;
1697 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
bool single_copy
Definition: relation.h:1203
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
Path * subpath
Definition: relation.h:1202
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define Assert(condition)
Definition: c.h:671
bool parallel_safe
Definition: relation.h:900
void cost_gather(GatherPath *path, PlannerInfo *root, RelOptInfo *rel, ParamPathInfo *param_info, double *rows)
Definition: costsize.c:348
Definition: nodes.h:78
bool parallel_aware
Definition: relation.h:899
Path path
Definition: relation.h:1201
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 2440 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().

2447 {
2448  GroupPath *pathnode = makeNode(GroupPath);
2449 
2450  pathnode->path.pathtype = T_Group;
2451  pathnode->path.parent = rel;
2452  pathnode->path.pathtarget = target;
2453  /* For now, assume we are above any joins, so no parameterization */
2454  pathnode->path.param_info = NULL;
2455  pathnode->path.parallel_aware = false;
2456  pathnode->path.parallel_safe = rel->consider_parallel &&
2457  subpath->parallel_safe;
2458  pathnode->path.parallel_workers = subpath->parallel_workers;
2459  /* Group doesn't change sort ordering */
2460  pathnode->path.pathkeys = subpath->pathkeys;
2461 
2462  pathnode->subpath = subpath;
2463 
2464  pathnode->groupClause = groupClause;
2465  pathnode->qual = qual;
2466 
2467  cost_group(&pathnode->path, root,
2468  list_length(groupClause),
2469  numGroups,
2470  subpath->startup_cost, subpath->total_cost,
2471  subpath->rows);
2472 
2473  /* add tlist eval cost for each output row */
2474  pathnode->path.startup_cost += target->cost.startup;
2475  pathnode->path.total_cost += target->cost.startup +
2476  target->cost.per_tuple * pathnode->path.rows;
2477 
2478  return pathnode;
2479 }
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:1853
List * qual
Definition: relation.h:1346
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Definition: nodes.h:74
Path path
Definition: relation.h:1343
List * groupClause
Definition: relation.h:1345
Path * subpath
Definition: relation.h:1344
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
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,
List rollup_lists,
List rollup_groupclauses,
const AggClauseCosts agg_costs,
double  numGroups 
)

Definition at line 2616 of file pathnode.c.

References AGG_PLAIN, AGG_SORTED, Assert, RelOptInfo::consider_parallel, PathTarget::cost, cost_agg(), cost_sort(), PlannerInfo::group_pathkeys, lfirst, linitial, list_length(), llast, lnext, makeNode, NIL, NULL, 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::rollup_groupclauses, GroupingSetsPath::rollup_lists, Path::rows, QualCost::startup, Path::startup_cost, subpath(), GroupingSetsPath::subpath, T_Agg, Path::total_cost, PathTarget::width, and work_mem.

Referenced by create_grouping_paths().

2625 {
2627  int numGroupCols;
2628 
2629  /* The topmost generated Plan node will be an Agg */
2630  pathnode->path.pathtype = T_Agg;
2631  pathnode->path.parent = rel;
2632  pathnode->path.pathtarget = target;
2633  pathnode->path.param_info = subpath->param_info;
2634  pathnode->path.parallel_aware = false;
2635  pathnode->path.parallel_safe = rel->consider_parallel &&
2636  subpath->parallel_safe;
2637  pathnode->path.parallel_workers = subpath->parallel_workers;
2638  pathnode->subpath = subpath;
2639 
2640  /*
2641  * Output will be in sorted order by group_pathkeys if, and only if, there
2642  * is a single rollup operation on a non-empty list of grouping
2643  * expressions.
2644  */
2645  if (list_length(rollup_groupclauses) == 1 &&
2646  ((List *) linitial(rollup_groupclauses)) != NIL)
2647  pathnode->path.pathkeys = root->group_pathkeys;
2648  else
2649  pathnode->path.pathkeys = NIL;
2650 
2651  pathnode->rollup_groupclauses = rollup_groupclauses;
2652  pathnode->rollup_lists = rollup_lists;
2653  pathnode->qual = having_qual;
2654 
2655  Assert(rollup_lists != NIL);
2656  Assert(list_length(rollup_lists) == list_length(rollup_groupclauses));
2657 
2658  /* Account for cost of the topmost Agg node */
2659  numGroupCols = list_length((List *) linitial((List *) llast(rollup_lists)));
2660 
2661  cost_agg(&pathnode->path, root,
2662  (numGroupCols > 0) ? AGG_SORTED : AGG_PLAIN,
2663  agg_costs,
2664  numGroupCols,
2665  numGroups,
2666  subpath->startup_cost,
2667  subpath->total_cost,
2668  subpath->rows);
2669 
2670  /*
2671  * Add in the costs and output rows of the additional sorting/aggregation
2672  * steps, if any. Only total costs count, since the extra sorts aren't
2673  * run on startup.
2674  */
2675  if (list_length(rollup_lists) > 1)
2676  {
2677  ListCell *lc;
2678 
2679  foreach(lc, rollup_lists)
2680  {
2681  List *gsets = (List *) lfirst(lc);
2682  Path sort_path; /* dummy for result of cost_sort */
2683  Path agg_path; /* dummy for result of cost_agg */
2684 
2685  /* We must iterate over all but the last rollup_lists element */
2686  if (lnext(lc) == NULL)
2687  break;
2688 
2689  /* Account for cost of sort, but don't charge input cost again */
2690  cost_sort(&sort_path, root, NIL,
2691  0.0,
2692  subpath->rows,
2693  subpath->pathtarget->width,
2694  0.0,
2695  work_mem,
2696  -1.0);
2697 
2698  /* Account for cost of aggregation */
2699  numGroupCols = list_length((List *) linitial(gsets));
2700 
2701  cost_agg(&agg_path, root,
2702  AGG_SORTED,
2703  agg_costs,
2704  numGroupCols,
2705  numGroups, /* XXX surely not right for all steps? */
2706  sort_path.startup_cost,
2707  sort_path.total_cost,
2708  sort_path.rows);
2709 
2710  pathnode->path.total_cost += agg_path.total_cost;
2711  pathnode->path.rows += agg_path.rows;
2712  }
2713  }
2714 
2715  /* add tlist eval cost for each output row */
2716  pathnode->path.startup_cost += target->cost.startup;
2717  pathnode->path.total_cost += target->cost.startup +
2718  target->cost.per_tuple * pathnode->path.rows;
2719 
2720  return pathnode;
2721 }
List * group_pathkeys
Definition: relation.h:259
#define NIL
Definition: pg_list.h:69
Definition: nodes.h:75
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
#define llast(l)
Definition: pg_list.h:126
ParamPathInfo * param_info
Definition: relation.h:897
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
Cost per_tuple
Definition: relation.h:46
#define linitial(l)
Definition: pg_list.h:110
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
List * rollup_lists
Definition: relation.h:1391
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:1691
#define lnext(lc)
Definition: pg_list.h:105
List * rollup_groupclauses
Definition: relation.h:1390
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:1462
int work_mem
Definition: globals.c:112
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:498
int width
Definition: relation.h:827
bool parallel_aware
Definition: relation.h:899
Definition: pg_list.h:45
Definition: relation.h:888
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
HashPath* create_hashjoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
SpecialJoinInfo sjinfo,
SemiAntiJoinFactors semifactors,
Path outer_path,
Path inner_path,
List restrict_clauses,
Relids  required_outer,
List hashclauses 
)

Definition at line 2098 of file pathnode.c.

References RelOptInfo::consider_parallel, final_cost_hashjoin(), get_joinrel_parampathinfo(), 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, and T_HashJoin.

Referenced by try_hashjoin_path(), and try_partial_hashjoin_path().

2109 {
2110  HashPath *pathnode = makeNode(HashPath);
2111 
2112  pathnode->jpath.path.pathtype = T_HashJoin;
2113  pathnode->jpath.path.parent = joinrel;
2114  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2115  pathnode->jpath.path.param_info =
2117  joinrel,
2118  outer_path,
2119  inner_path,
2120  sjinfo,
2121  required_outer,
2122  &restrict_clauses);
2123  pathnode->jpath.path.parallel_aware = false;
2124  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2125  outer_path->parallel_safe && inner_path->parallel_safe;
2126  /* This is a foolish way to estimate parallel_workers, but for now... */
2127  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2128 
2129  /*
2130  * A hashjoin never has pathkeys, since its output ordering is
2131  * unpredictable due to possible batching. XXX If the inner relation is
2132  * small enough, we could instruct the executor that it must not batch,
2133  * and then we could assume that the output inherits the outer relation's
2134  * ordering, which might save a sort step. However there is considerable
2135  * downside if our estimate of the inner relation size is badly off. For
2136  * the moment we don't risk it. (Note also that if we wanted to take this
2137  * seriously, joinpath.c would have to consider many more paths for the
2138  * outer rel than it does now.)
2139  */
2140  pathnode->jpath.path.pathkeys = NIL;
2141  pathnode->jpath.jointype = jointype;
2142  pathnode->jpath.outerjoinpath = outer_path;
2143  pathnode->jpath.innerjoinpath = inner_path;
2144  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2145  pathnode->path_hashclauses = hashclauses;
2146  /* final_cost_hashjoin will fill in pathnode->num_batches */
2147 
2148  final_cost_hashjoin(root, pathnode, workspace, sjinfo, semifactors);
2149 
2150  return pathnode;
2151 }
#define NIL
Definition: pg_list.h:69
JoinPath jpath
Definition: relation.h:1282
PathTarget * pathtarget
Definition: relation.h:895
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:1101
Path * innerjoinpath
Definition: relation.h:1217
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
List * joinrestrictinfo
Definition: relation.h:1219
RelOptInfo * parent
Definition: relation.h:894
Path * outerjoinpath
Definition: relation.h:1216
void final_cost_hashjoin(PlannerInfo *root, HashPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:2780
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
Path path
Definition: relation.h:1212
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
JoinType jointype
Definition: relation.h:1214
bool parallel_aware
Definition: relation.h:899
List * path_hashclauses
Definition: relation.h:1283
struct PathTarget * reltarget
Definition: relation.h:501
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:977
PathTarget * pathtarget
Definition: relation.h:895
Path path
Definition: relation.h:971
IndexOptInfo * indexinfo
Definition: relation.h:972
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
List * indexclauses
Definition: relation.h:973
NodeTag pathtype
Definition: relation.h:892
List * indexquals
Definition: relation.h:974
RelOptInfo * rel
Definition: relation.h:590
void expand_indexqual_conditions(IndexOptInfo *index, List *indexclauses, List *indexclausecols, List **indexquals_p, List **indexqualcols_p)
Definition: indxpath.c:3507
RelOptInfo * parent
Definition: relation.h:894
void cost_index(IndexPath *path, PlannerInfo *root, double loop_count, bool partial_path)
Definition: costsize.c:394
List * indexorderbys
Definition: relation.h:976
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
List * indexqualcols
Definition: relation.h:975
ScanDirection indexscandir
Definition: relation.h:978
bool parallel_aware
Definition: relation.h:899
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:501
LimitPath* create_limit_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
Node limitOffset,
Node limitCount,
int64  offset_est,
int64  count_est 
)

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

3122 {
3123  LimitPath *pathnode = makeNode(LimitPath);
3124 
3125  pathnode->path.pathtype = T_Limit;
3126  pathnode->path.parent = rel;
3127  /* Limit doesn't project, so use source path's pathtarget */
3128  pathnode->path.pathtarget = subpath->pathtarget;
3129  /* For now, assume we are above any joins, so no parameterization */
3130  pathnode->path.param_info = NULL;
3131  pathnode->path.parallel_aware = false;
3132  pathnode->path.parallel_safe = rel->consider_parallel &&
3133  subpath->parallel_safe;
3134  pathnode->path.parallel_workers = subpath->parallel_workers;
3135  pathnode->path.rows = subpath->rows;
3136  pathnode->path.startup_cost = subpath->startup_cost;
3137  pathnode->path.total_cost = subpath->total_cost;
3138  pathnode->path.pathkeys = subpath->pathkeys;
3139  pathnode->subpath = subpath;
3140  pathnode->limitOffset = limitOffset;
3141  pathnode->limitCount = limitCount;
3142 
3143  /*
3144  * Adjust the output rows count and costs according to the offset/limit.
3145  * This is only a cosmetic issue if we are at top level, but if we are
3146  * building a subquery then it's important to report correct info to the
3147  * outer planner.
3148  *
3149  * When the offset or count couldn't be estimated, use 10% of the
3150  * estimated number of rows emitted from the subpath.
3151  *
3152  * XXX we don't bother to add eval costs of the offset/limit expressions
3153  * themselves to the path costs. In theory we should, but in most cases
3154  * those expressions are trivial and it's just not worth the trouble.
3155  */
3156  if (offset_est != 0)
3157  {
3158  double offset_rows;
3159 
3160  if (offset_est > 0)
3161  offset_rows = (double) offset_est;
3162  else
3163  offset_rows = clamp_row_est(subpath->rows * 0.10);
3164  if (offset_rows > pathnode->path.rows)
3165  offset_rows = pathnode->path.rows;
3166  if (subpath->rows > 0)
3167  pathnode->path.startup_cost +=
3168  (subpath->total_cost - subpath->startup_cost)
3169  * offset_rows / subpath->rows;
3170  pathnode->path.rows -= offset_rows;
3171  if (pathnode->path.rows < 1)
3172  pathnode->path.rows = 1;
3173  }
3174 
3175  if (count_est != 0)
3176  {
3177  double count_rows;
3178 
3179  if (count_est > 0)
3180  count_rows = (double) count_est;
3181  else
3182  count_rows = clamp_row_est(subpath->rows * 0.10);
3183  if (count_rows > pathnode->path.rows)
3184  count_rows = pathnode->path.rows;
3185  if (subpath->rows > 0)
3186  pathnode->path.total_cost = pathnode->path.startup_cost +
3187  (subpath->total_cost - subpath->startup_cost)
3188  * count_rows / subpath->rows;
3189  pathnode->path.rows = count_rows;
3190  if (pathnode->path.rows < 1)
3191  pathnode->path.rows = 1;
3192  }
3193 
3194  return pathnode;
3195 }
PathTarget * pathtarget
Definition: relation.h:895
Node * limitOffset
Definition: relation.h:1489
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
Cost startup_cost
Definition: relation.h:906
Path * subpath
Definition: relation.h:1488
RelOptInfo * parent
Definition: relation.h:894
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
Path path
Definition: relation.h:1487
bool parallel_aware
Definition: relation.h:899
double clamp_row_est(double nrows)
Definition: costsize.c:172
Node * limitCount
Definition: relation.h:1490
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
Definition: nodes.h:82
LockRowsPath* create_lockrows_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List rowMarks,
int  epqParam 
)

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

2965 {
2966  LockRowsPath *pathnode = makeNode(LockRowsPath);
2967 
2968  pathnode->path.pathtype = T_LockRows;
2969  pathnode->path.parent = rel;
2970  /* LockRows doesn't project, so use source path's pathtarget */
2971  pathnode->path.pathtarget = subpath->pathtarget;
2972  /* For now, assume we are above any joins, so no parameterization */
2973  pathnode->path.param_info = NULL;
2974  pathnode->path.parallel_aware = false;
2975  pathnode->path.parallel_safe = false;
2976  pathnode->path.parallel_workers = 0;
2977  pathnode->path.rows = subpath->rows;
2978 
2979  /*
2980  * The result cannot be assumed sorted, since locking might cause the sort
2981  * key columns to be replaced with new values.
2982  */
2983  pathnode->path.pathkeys = NIL;
2984 
2985  pathnode->subpath = subpath;
2986  pathnode->rowMarks = rowMarks;
2987  pathnode->epqParam = epqParam;
2988 
2989  /*
2990  * We should charge something extra for the costs of row locking and
2991  * possible refetches, but it's hard to say how much. For now, use
2992  * cpu_tuple_cost per row.
2993  */
2994  pathnode->path.startup_cost = subpath->startup_cost;
2995  pathnode->path.total_cost = subpath->total_cost +
2996  cpu_tuple_cost * subpath->rows;
2997 
2998  return pathnode;
2999 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
List * rowMarks
Definition: relation.h:1455
NodeTag pathtype
Definition: relation.h:892
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Path * subpath
Definition: relation.h:1454
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:899
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
MaterialPath* create_material_path ( RelOptInfo rel,
Path subpath 
)

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

1386 {
1387  MaterialPath *pathnode = makeNode(MaterialPath);
1388 
1389  Assert(subpath->parent == rel);
1390 
1391  pathnode->path.pathtype = T_Material;
1392  pathnode->path.parent = rel;
1393  pathnode->path.pathtarget = rel->reltarget;
1394  pathnode->path.param_info = subpath->param_info;
1395  pathnode->path.parallel_aware = false;
1396  pathnode->path.parallel_safe = rel->consider_parallel &&
1397  subpath->parallel_safe;
1398  pathnode->path.parallel_workers = subpath->parallel_workers;
1399  pathnode->path.pathkeys = subpath->pathkeys;
1400 
1401  pathnode->subpath = subpath;
1402 
1403  cost_material(&pathnode->path,
1404  subpath->startup_cost,
1405  subpath->total_cost,
1406  subpath->rows,
1407  subpath->pathtarget->width);
1408 
1409  return pathnode;
1410 }
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Path * subpath
Definition: relation.h:1163
NodeTag pathtype
Definition: relation.h:892
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Cost total_cost
Definition: relation.h:907
void cost_material(Path *path, Cost input_startup_cost, Cost input_total_cost, double tuples, int width)
Definition: costsize.c:1637
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define Assert(condition)
Definition: c.h:671
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
int width
Definition: relation.h:827
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
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 
)

Definition at line 1256 of file pathnode.c.

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

Referenced by generate_mergeappend_paths().

1261 {
1263  Cost input_startup_cost;
1264  Cost input_total_cost;
1265  ListCell *l;
1266 
1267  pathnode->path.pathtype = T_MergeAppend;
1268  pathnode->path.parent = rel;
1269  pathnode->path.pathtarget = rel->reltarget;
1271  required_outer);
1272  pathnode->path.parallel_aware = false;
1273  pathnode->path.parallel_safe = rel->consider_parallel;
1274  pathnode->path.parallel_workers = 0;
1275  pathnode->path.pathkeys = pathkeys;
1276  pathnode->subpaths = subpaths;
1277 
1278  /*
1279  * Apply query-wide LIMIT if known and path is for sole base relation.
1280  * (Handling this at this low level is a bit klugy.)
1281  */
1282  if (bms_equal(rel->relids, root->all_baserels))
1283  pathnode->limit_tuples = root->limit_tuples;
1284  else
1285  pathnode->limit_tuples = -1.0;
1286 
1287  /*
1288  * Add up the sizes and costs of the input paths.
1289  */
1290  pathnode->path.rows = 0;
1291  input_startup_cost = 0;
1292  input_total_cost = 0;
1293  foreach(l, subpaths)
1294  {
1295  Path *subpath = (Path *) lfirst(l);
1296 
1297  pathnode->path.rows += subpath->rows;
1298  pathnode->path.parallel_safe = pathnode->path.parallel_safe &&
1299  subpath->parallel_safe;
1300 
1301  if (pathkeys_contained_in(pathkeys, subpath->pathkeys))
1302  {
1303  /* Subpath is adequately ordered, we won't need to sort it */
1304  input_startup_cost += subpath->startup_cost;
1305  input_total_cost += subpath->total_cost;
1306  }
1307  else
1308  {
1309  /* We'll need to insert a Sort node, so include cost for that */
1310  Path sort_path; /* dummy for result of cost_sort */
1311 
1312  cost_sort(&sort_path,
1313  root,
1314  pathkeys,
1315  subpath->total_cost,
1316  subpath->parent->tuples,
1317  subpath->pathtarget->width,
1318  0.0,
1319  work_mem,
1320  pathnode->limit_tuples);
1321  input_startup_cost += sort_path.startup_cost;
1322  input_total_cost += sort_path.total_cost;
1323  }
1324 
1325  /* All child paths must have same parameterization */
1326  Assert(bms_equal(PATH_REQ_OUTER(subpath), required_outer));
1327  }
1328 
1329  /* Now we can compute total costs of the MergeAppend */
1330  cost_merge_append(&pathnode->path, root,
1331  pathkeys, list_length(subpaths),
1332  input_startup_cost, input_total_cost,
1333  pathnode->path.rows);
1334 
1335  return pathnode;
1336 }
PathTarget * pathtarget
Definition: relation.h:895
double tuples
Definition: relation.h:529
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
Relids all_baserels
Definition: relation.h:193
double limit_tuples
Definition: relation.h:287
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Relids relids
Definition: relation.h:490
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:1462
int work_mem
Definition: globals.c:112
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
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:1586
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:498
int width
Definition: relation.h:827
bool parallel_aware
Definition: relation.h:899
List * subpaths
Definition: relation.h:1137
ParamPathInfo * get_appendrel_parampathinfo(RelOptInfo *appendrel, Relids required_outer)
Definition: relnode.c:1309
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
double limit_tuples
Definition: relation.h:1138
double Cost
Definition: nodes.h:632
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:130
MergePath* create_mergejoin_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
SpecialJoinInfo sjinfo,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer,
List mergeclauses,
List outersortkeys,
List innersortkeys 
)

Definition at line 2034 of file pathnode.c.

References RelOptInfo::consider_parallel, final_cost_mergejoin(), get_joinrel_parampathinfo(), 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, and T_MergeJoin.

Referenced by try_mergejoin_path().

2047 {
2048  MergePath *pathnode = makeNode(MergePath);
2049 
2050  pathnode->jpath.path.pathtype = T_MergeJoin;
2051  pathnode->jpath.path.parent = joinrel;
2052  pathnode->jpath.path.pathtarget = joinrel->reltarget;
2053  pathnode->jpath.path.param_info =
2055  joinrel,
2056  outer_path,
2057  inner_path,
2058  sjinfo,
2059  required_outer,
2060  &restrict_clauses);
2061  pathnode->jpath.path.parallel_aware = false;
2062  pathnode->jpath.path.parallel_safe = joinrel->consider_parallel &&
2063  outer_path->parallel_safe && inner_path->parallel_safe;
2064  /* This is a foolish way to estimate parallel_workers, but for now... */
2065  pathnode->jpath.path.parallel_workers = outer_path->parallel_workers;
2066  pathnode->jpath.path.pathkeys = pathkeys;
2067  pathnode->jpath.jointype = jointype;
2068  pathnode->jpath.outerjoinpath = outer_path;
2069  pathnode->jpath.innerjoinpath = inner_path;
2070  pathnode->jpath.joinrestrictinfo = restrict_clauses;
2071  pathnode->path_mergeclauses = mergeclauses;
2072  pathnode->outersortkeys = outersortkeys;
2073  pathnode->innersortkeys = innersortkeys;
2074  /* pathnode->materialize_inner will be set by final_cost_mergejoin */
2075 
2076  final_cost_mergejoin(root, pathnode, workspace, sjinfo);
2077 
2078  return pathnode;
2079 }
List * path_mergeclauses
Definition: relation.h:1265
List * outersortkeys
Definition: relation.h:1266
PathTarget * pathtarget
Definition: relation.h:895
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:1101
Path * innerjoinpath
Definition: relation.h:1217
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
void final_cost_mergejoin(PlannerInfo *root, MergePath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo)
Definition: costsize.c:2390
List * joinrestrictinfo
Definition: relation.h:1219
RelOptInfo * parent
Definition: relation.h:894
Path * outerjoinpath
Definition: relation.h:1216
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
Path path
Definition: relation.h:1212
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
List * innersortkeys
Definition: relation.h:1267
JoinType jointype
Definition: relation.h:1214
JoinPath jpath
Definition: relation.h:1264
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
MinMaxAggPath* create_minmaxagg_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List mmaggregates,
List quals 
)

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

2738 {
2739  MinMaxAggPath *pathnode = makeNode(MinMaxAggPath);
2740  Cost initplan_cost;
2741  ListCell *lc;
2742 
2743  /* The topmost generated Plan node will be a Result */
2744  pathnode->path.pathtype = T_Result;
2745  pathnode->path.parent = rel;
2746  pathnode->path.pathtarget = target;
2747  /* For now, assume we are above any joins, so no parameterization */
2748  pathnode->path.param_info = NULL;
2749  pathnode->path.parallel_aware = false;
2750  /* A MinMaxAggPath implies use of subplans, so cannot be parallel-safe */
2751  pathnode->path.parallel_safe = false;
2752  pathnode->path.parallel_workers = 0;
2753  /* Result is one unordered row */
2754  pathnode->path.rows = 1;
2755  pathnode->path.pathkeys = NIL;
2756 
2757  pathnode->mmaggregates = mmaggregates;
2758  pathnode->quals = quals;
2759 
2760  /* Calculate cost of all the initplans ... */
2761  initplan_cost = 0;
2762  foreach(lc, mmaggregates)
2763  {
2764  MinMaxAggInfo *mminfo = (MinMaxAggInfo *) lfirst(lc);
2765 
2766  initplan_cost += mminfo->pathcost;
2767  }
2768 
2769  /* add tlist eval cost for each output row, plus cpu_tuple_cost */
2770  pathnode->path.startup_cost = initplan_cost + target->cost.startup;
2771  pathnode->path.total_cost = initplan_cost + target->cost.startup +
2772  target->cost.per_tuple + cpu_tuple_cost;
2773 
2774  return pathnode;
2775 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
List * quals
Definition: relation.h:1402
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
List * mmaggregates
Definition: relation.h:1401
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:899
double Cost
Definition: nodes.h:632
ModifyTablePath* create_modifytable_path ( PlannerInfo root,
RelOptInfo rel,
CmdType  operation,
bool  canSetTag,
Index  nominalRelation,
List resultRelations,
List subpaths,
List subroots,
List withCheckOptionLists,
List returningLists,
List rowMarks,
OnConflictExpr onconflict,
int  epqParam 
)

Definition at line 3019 of file pathnode.c.

References Assert, ModifyTablePath::canSetTag, ModifyTablePath::epqParam, lfirst, 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::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().

3027 {
3029  double total_size;
3030  ListCell *lc;
3031 
3032  Assert(list_length(resultRelations) == list_length(subpaths));
3033  Assert(list_length(resultRelations) == list_length(subroots));
3034  Assert(withCheckOptionLists == NIL ||
3035  list_length(resultRelations) == list_length(withCheckOptionLists));
3036  Assert(returningLists == NIL ||
3037  list_length(resultRelations) == list_length(returningLists));
3038 
3039  pathnode->path.pathtype = T_ModifyTable;
3040  pathnode->path.parent = rel;
3041  /* pathtarget is not interesting, just make it minimally valid */
3042  pathnode->path.pathtarget = rel->reltarget;
3043  /* For now, assume we are above any joins, so no parameterization */
3044  pathnode->path.param_info = NULL;
3045  pathnode->path.parallel_aware = false;
3046  pathnode->path.parallel_safe = false;
3047  pathnode->path.parallel_workers = 0;
3048  pathnode->path.pathkeys = NIL;
3049 
3050  /*
3051  * Compute cost & rowcount as sum of subpath costs & rowcounts.
3052  *
3053  * Currently, we don't charge anything extra for the actual table
3054  * modification work, nor for the WITH CHECK OPTIONS or RETURNING
3055  * expressions if any. It would only be window dressing, since
3056  * ModifyTable is always a top-level node and there is no way for the
3057  * costs to change any higher-level planning choices. But we might want
3058  * to make it look better sometime.
3059  */
3060  pathnode->path.startup_cost = 0;
3061  pathnode->path.total_cost = 0;
3062  pathnode->path.rows = 0;
3063  total_size = 0;
3064  foreach(lc, subpaths)
3065  {
3066  Path *subpath = (Path *) lfirst(lc);
3067 
3068  if (lc == list_head(subpaths)) /* first node? */
3069  pathnode->path.startup_cost = subpath->startup_cost;
3070  pathnode->path.total_cost += subpath->total_cost;
3071  pathnode->path.rows += subpath->rows;
3072  total_size += subpath->pathtarget->width * subpath->rows;
3073  }
3074 
3075  /*
3076  * Set width to the average width of the subpath outputs. XXX this is
3077  * totally wrong: we should report zero if no RETURNING, else an average
3078  * of the RETURNING tlist widths. But it's what happened historically,
3079  * and improving it is a task for another day.
3080  */
3081  if (pathnode->path.rows > 0)
3082  total_size /= pathnode->path.rows;
3083  pathnode->path.pathtarget->width = rint(total_size);
3084 
3085  pathnode->operation = operation;
3086  pathnode->canSetTag = canSetTag;
3087  pathnode->nominalRelation = nominalRelation;
3088  pathnode->resultRelations = resultRelations;
3089  pathnode->subpaths = subpaths;
3090  pathnode->subroots = subroots;
3091  pathnode->withCheckOptionLists = withCheckOptionLists;
3092  pathnode->returningLists = returningLists;
3093  pathnode->rowMarks = rowMarks;
3094  pathnode->onconflict = onconflict;
3095  pathnode->epqParam = epqParam;
3096 
3097  return pathnode;
3098 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
List * returningLists
Definition: relation.h:1476
OnConflictExpr * onconflict
Definition: relation.h:1478
Index nominalRelation
Definition: relation.h:1471
List * rowMarks
Definition: relation.h:1477
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
Cost startup_cost
Definition: relation.h:906
List * subroots
Definition: relation.h:1474
RelOptInfo * parent
Definition: relation.h:894
List * subpaths
Definition: relation.h:1473
static ListCell * list_head(const List *l)
Definition: pg_list.h:77
double rint(double x)
Definition: rint.c:22
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define Assert(condition)
Definition: c.h:671
#define lfirst(lc)
Definition: pg_list.h:106
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
static int list_length(const List *l)
Definition: pg_list.h:89
List * withCheckOptionLists
Definition: relation.h:1475
int width
Definition: relation.h:827
CmdType operation
Definition: relation.h:1469
List * resultRelations
Definition: relation.h:1472
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
NestPath* create_nestloop_path ( PlannerInfo root,
RelOptInfo joinrel,
JoinType  jointype,
JoinCostWorkspace workspace,
SpecialJoinInfo sjinfo,
SemiAntiJoinFactors semifactors,
Path outer_path,
Path inner_path,
List restrict_clauses,
List pathkeys,
Relids  required_outer 
)

Definition at line 1946 of file pathnode.c.

References bms_overlap(), bms_union(), RelOptInfo::consider_parallel, final_cost_nestloop(), get_joinrel_parampathinfo(), 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, and T_NestLoop.

Referenced by try_nestloop_path(), and try_partial_nestloop_path().

1957 {
1958  NestPath *pathnode = makeNode(NestPath);
1959  Relids inner_req_outer = PATH_REQ_OUTER(inner_path);
1960 
1961  /*
1962  * If the inner path is parameterized by the outer, we must drop any
1963  * restrict_clauses that are due to be moved into the inner path. We have
1964  * to do this now, rather than postpone the work till createplan time,
1965  * because the restrict_clauses list can affect the size and cost
1966  * estimates for this path.
1967  */
1968  if (bms_overlap(inner_req_outer, outer_path->parent->relids))
1969  {
1970  Relids inner_and_outer = bms_union(inner_path->parent->relids,
1971  inner_req_outer);
1972  List *jclauses = NIL;
1973  ListCell *lc;
1974 
1975  foreach(lc, restrict_clauses)
1976  {
1977  RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc);
1978 
1979  if (!join_clause_is_movable_into(rinfo,
1980  inner_path->parent->relids,
1981  inner_and_outer))
1982  jclauses = lappend(jclauses, rinfo);
1983  }
1984  restrict_clauses = jclauses;
1985  }
1986 
1987  pathnode->path.pathtype = T_NestLoop;
1988  pathnode->path.parent = joinrel;
1989  pathnode->path.pathtarget = joinrel->reltarget;
1990  pathnode->path.param_info =
1992  joinrel,
1993  outer_path,
1994  inner_path,
1995  sjinfo,
1996  required_outer,
1997  &restrict_clauses);
1998  pathnode->path.parallel_aware = false;
1999  pathnode->path.parallel_safe = joinrel->consider_parallel &&
2000  outer_path->parallel_safe && inner_path->parallel_safe;
2001  /* This is a foolish way to estimate parallel_workers, but for now... */
2002  pathnode->path.parallel_workers = outer_path->parallel_workers;
2003  pathnode->path.pathkeys = pathkeys;
2004  pathnode->jointype = jointype;
2005  pathnode->outerjoinpath = outer_path;
2006  pathnode->innerjoinpath = inner_path;
2007  pathnode->joinrestrictinfo = restrict_clauses;
2008 
2009  final_cost_nestloop(root, pathnode, workspace, sjinfo, semifactors);
2010 
2011  return pathnode;
2012 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
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:1101
Path * innerjoinpath
Definition: relation.h:1217
void final_cost_nestloop(PlannerInfo *root, NestPath *path, JoinCostWorkspace *workspace, SpecialJoinInfo *sjinfo, SemiAntiJoinFactors *semifactors)
Definition: costsize.c:1976
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
List * joinrestrictinfo
Definition: relation.h:1219
RelOptInfo * parent
Definition: relation.h:894
Relids relids
Definition: relation.h:490
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:1216
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
Path path
Definition: relation.h:1212
#define lfirst(lc)
Definition: pg_list.h:106
bool parallel_safe
Definition: relation.h:900
#define PATH_REQ_OUTER(path)
Definition: relation.h:914
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:217
bool consider_parallel
Definition: relation.h:498
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:442
JoinType jointype
Definition: relation.h:1214
bool parallel_aware
Definition: relation.h:899
Definition: pg_list.h:45
struct PathTarget * reltarget
Definition: relation.h:501
ProjectionPath* create_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

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

2166 {
2167  ProjectionPath *pathnode = makeNode(ProjectionPath);
2168  PathTarget *oldtarget = subpath->pathtarget;
2169 
2170  pathnode->path.pathtype = T_Result;
2171  pathnode->path.parent = rel;
2172  pathnode->path.pathtarget = target;
2173  /* For now, assume we are above any joins, so no parameterization */
2174  pathnode->path.param_info = NULL;
2175  pathnode->path.parallel_aware = false;
2176  pathnode->path.parallel_safe = rel->consider_parallel &&
2177  subpath->parallel_safe &&
2178  is_parallel_safe(root, (Node *) target->exprs);
2179  pathnode->path.parallel_workers = subpath->parallel_workers;
2180  /* Projection does not change the sort order */
2181  pathnode->path.pathkeys = subpath->pathkeys;
2182 
2183  pathnode->subpath = subpath;
2184 
2185  /*
2186  * We might not need a separate Result node. If the input plan node type
2187  * can project, we can just tell it to project something else. Or, if it
2188  * can't project but the desired target has the same expression list as
2189  * what the input will produce anyway, we can still give it the desired
2190  * tlist (possibly changing its ressortgroupref labels, but nothing else).
2191  * Note: in the latter case, create_projection_plan has to recheck our
2192  * conclusion; see comments therein.
2193  */
2194  if (is_projection_capable_path(subpath) ||
2195  equal(oldtarget->exprs, target->exprs))
2196  {
2197  /* No separate Result node needed */
2198  pathnode->dummypp = true;
2199 
2200  /*
2201  * Set cost of plan as subpath's cost, adjusted for tlist replacement.
2202  */
2203  pathnode->path.rows = subpath->rows;
2204  pathnode->path.startup_cost = subpath->startup_cost +
2205  (target->cost.startup - oldtarget->cost.startup);
2206  pathnode->path.total_cost = subpath->total_cost +
2207  (target->cost.startup - oldtarget->cost.startup) +
2208  (target->cost.per_tuple - oldtarget->cost.per_tuple) * subpath->rows;
2209  }
2210  else
2211  {
2212  /* We really do need the Result node */
2213  pathnode->dummypp = false;
2214 
2215  /*
2216  * The Result node's cost is cpu_tuple_cost per row, plus the cost of
2217  * evaluating the tlist. There is no qual to worry about.
2218  */
2219  pathnode->path.rows = subpath->rows;
2220  pathnode->path.startup_cost = subpath->startup_cost +
2221  target->cost.startup;
2222  pathnode->path.total_cost = subpath->total_cost +
2223  target->cost.startup +
2224  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows;
2225  }
2226 
2227  return pathnode;
2228 }
PathTarget * pathtarget
Definition: relation.h:895
bool equal(const void *a, const void *b)
Definition: equalfuncs.c:2870
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Definition: nodes.h:508
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
Cost per_tuple
Definition: relation.h:46
Definition: nodes.h:45
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
List * exprs
Definition: relation.h:824
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
bool consider_parallel
Definition: relation.h:498
double cpu_tuple_cost
Definition: costsize.c:106
bool is_projection_capable_path(Path *path)
Definition: createplan.c:6261
bool parallel_aware
Definition: relation.h:899
Path * subpath
Definition: relation.h:1304
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 2918 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().

2926 {
2928 
2929  pathnode->path.pathtype = T_RecursiveUnion;
2930  pathnode->path.parent = rel;
2931  pathnode->path.pathtarget = target;
2932  /* For now, assume we are above any joins, so no parameterization */
2933  pathnode->path.param_info = NULL;
2934  pathnode->path.parallel_aware = false;
2935  pathnode->path.parallel_safe = rel->consider_parallel &&
2936  leftpath->parallel_safe && rightpath->parallel_safe;
2937  /* Foolish, but we'll do it like joins for now: */
2938  pathnode->path.parallel_workers = leftpath->parallel_workers;
2939  /* RecursiveUnion result is always unsorted */
2940  pathnode->path.pathkeys = NIL;
2941 
2942  pathnode->leftpath = leftpath;
2943  pathnode->rightpath = rightpath;
2944  pathnode->distinctList = distinctList;
2945  pathnode->wtParam = wtParam;
2946  pathnode->numGroups = numGroups;
2947 
2948  cost_recursive_union(&pathnode->path, leftpath, rightpath);
2949 
2950  return pathnode;
2951 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
void cost_recursive_union(Path *runion, Path *nrterm, Path *rterm)
Definition: costsize.c:1382
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
ResultPath* create_result_path ( PlannerInfo root,
RelOptInfo rel,
PathTarget target,
List resconstantqual 
)

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

1348 {
1349  ResultPath *pathnode = makeNode(ResultPath);
1350 
1351  pathnode->path.pathtype = T_Result;
1352  pathnode->path.parent = rel;
1353  pathnode->path.pathtarget = target;
1354  pathnode->path.param_info = NULL; /* there are no other rels... */
1355  pathnode->path.parallel_aware = false;
1356  pathnode->path.parallel_safe = rel->consider_parallel;
1357  pathnode->path.parallel_workers = 0;
1358  pathnode->path.pathkeys = NIL;
1359  pathnode->quals = resconstantqual;
1360 
1361  /* Hardly worth defining a cost_result() function ... just do it */
1362  pathnode->path.rows = 1;
1363  pathnode->path.startup_cost = target->cost.startup;
1364  pathnode->path.total_cost = target->cost.startup +
1365  cpu_tuple_cost + target->cost.per_tuple;
1366  if (resconstantqual)
1367  {
1368  QualCost qual_cost;
1369 
1370  cost_qual_eval(&qual_cost, resconstantqual, root);
1371  /* resconstantqual is evaluated once at startup */
1372  pathnode->path.startup_cost += qual_cost.startup + qual_cost.per_tuple;
1373  pathnode->path.total_cost += qual_cost.startup + qual_cost.per_tuple;
1374  }
1375 
1376  return pathnode;
1377 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
Cost per_tuple
Definition: relation.h:46
Path path
Definition: relation.h:1150
Definition: nodes.h:45
void cost_qual_eval(QualCost *cost, List *quals, PlannerInfo *root)
Definition: costsize.c:3199
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
List * quals
Definition: relation.h:1151
QualCost cost
Definition: relation.h:826
bool consider_parallel
Definition: relation.h:498
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:899
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:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
void cost_samplescan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:273
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
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:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
void cost_seqscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:196
RelOptInfo * parent
Definition: relation.h:894
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Definition: relation.h:888
ProjectSetPath* create_set_projection_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
PathTarget target 
)

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

2333 {
2334  ProjectSetPath *pathnode = makeNode(ProjectSetPath);
2335  double tlist_rows;
2336  ListCell *lc;
2337 
2338  pathnode->path.pathtype = T_ProjectSet;
2339  pathnode->path.parent = rel;
2340  pathnode->path.pathtarget = target;
2341  /* For now, assume we are above any joins, so no parameterization */
2342  pathnode->path.param_info = NULL;
2343  pathnode->path.parallel_aware = false;
2344  pathnode->path.parallel_safe = rel->consider_parallel &&
2345  subpath->parallel_safe &&
2346  is_parallel_safe(root, (Node *) target->exprs);
2347  pathnode->path.parallel_workers = subpath->parallel_workers;
2348  /* Projection does not change the sort order XXX? */
2349  pathnode->path.pathkeys = subpath->pathkeys;
2350 
2351  pathnode->subpath = subpath;
2352 
2353  /*
2354  * Estimate number of rows produced by SRFs for each row of input; if
2355  * there's more than one in this node, use the maximum.
2356  */
2357  tlist_rows = 1;
2358  foreach(lc, target->exprs)
2359  {
2360  Node *node = (Node *) lfirst(lc);
2361  double itemrows;
2362 
2363  itemrows = expression_returns_set_rows(node);
2364  if (tlist_rows < itemrows)
2365  tlist_rows = itemrows;
2366  }
2367 
2368  /*
2369  * In addition to the cost of evaluating the tlist, charge cpu_tuple_cost
2370  * per input row, and half of cpu_tuple_cost for each added output row.
2371  * This is slightly bizarre maybe, but it's what 9.6 did; we may revisit
2372  * this estimate later.
2373  */
2374  pathnode->path.rows = subpath->rows * tlist_rows;
2375  pathnode->path.startup_cost = subpath->startup_cost +
2376  target->cost.startup;
2377  pathnode->path.total_cost = subpath->total_cost +
2378  target->cost.startup +
2379  (cpu_tuple_cost + target->cost.per_tuple) * subpath->rows +
2380  (pathnode->path.rows - subpath->rows) * cpu_tuple_cost / 2;
2381 
2382  return pathnode;
2383 }
PathTarget * pathtarget
Definition: relation.h:895
double expression_returns_set_rows(Node *clause)
Definition: clauses.c:801
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Definition: nodes.h:508
Cost startup
Definition: relation.h:45
NodeTag pathtype
Definition: relation.h:892
bool is_parallel_safe(PlannerInfo *root, Node *node)
Definition: clauses.c:1071
Cost per_tuple
Definition: relation.h:46
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
List * exprs
Definition: relation.h:824
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
#define lfirst(lc)
Definition: pg_list.h:106
Path * subpath
Definition: relation.h:1316
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
QualCost cost
Definition: relation.h:826
bool consider_parallel
Definition: relation.h:498
double cpu_tuple_cost
Definition: costsize.c:106
bool parallel_aware
Definition: relation.h:899
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 2856 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().

2866 {
2867  SetOpPath *pathnode = makeNode(SetOpPath);
2868 
2869  pathnode->path.pathtype = T_SetOp;
2870  pathnode->path.parent = rel;
2871  /* SetOp doesn't project, so use source path's pathtarget */
2872  pathnode->path.pathtarget = subpath->pathtarget;
2873  /* For now, assume we are above any joins, so no parameterization */
2874  pathnode->path.param_info = NULL;
2875  pathnode->path.parallel_aware = false;
2876  pathnode->path.parallel_safe = rel->consider_parallel &&
2877  subpath->parallel_safe;
2878  pathnode->path.parallel_workers = subpath->parallel_workers;
2879  /* SetOp preserves the input sort order if in sort mode */
2880  pathnode->path.pathkeys =
2881  (strategy == SETOP_SORTED) ? subpath->pathkeys : NIL;
2882 
2883  pathnode->subpath = subpath;
2884  pathnode->cmd = cmd;
2885  pathnode->strategy = strategy;
2886  pathnode->distinctList = distinctList;
2887  pathnode->flagColIdx = flagColIdx;
2888  pathnode->firstFlag = firstFlag;
2889  pathnode->numGroups = numGroups;
2890 
2891  /*
2892  * Charge one cpu_operator_cost per comparison per input tuple. We assume
2893  * all columns get compared at most of the tuples.
2894  */
2895  pathnode->path.startup_cost = subpath->startup_cost;
2896  pathnode->path.total_cost = subpath->total_cost +
2897  cpu_operator_cost * subpath->rows * list_length(distinctList);
2898  pathnode->path.rows = outputRows;
2899 
2900  return pathnode;
2901 }
#define NIL
Definition: pg_list.h:69
List * distinctList
Definition: relation.h:1429
PathTarget * pathtarget
Definition: relation.h:895
SetOpStrategy strategy
Definition: relation.h:1428
Path * subpath
Definition: relation.h:1426
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
double numGroups
Definition: relation.h:1432
NodeTag pathtype
Definition: relation.h:892
SetOpCmd cmd
Definition: relation.h:1427
Cost startup_cost
Definition: relation.h:906
RelOptInfo * parent
Definition: relation.h:894
AttrNumber flagColIdx
Definition: relation.h:1430
double cpu_operator_cost
Definition: costsize.c:108
Cost total_cost
Definition: relation.h:907
int firstFlag
Definition: relation.h:1431
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
static int list_length(const List *l)
Definition: pg_list.h:89
bool consider_parallel
Definition: relation.h:498
Definition: nodes.h:80
bool parallel_aware
Definition: relation.h:899
Path path
Definition: relation.h:1425
SortPath* create_sort_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
double  limit_tuples 
)

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

2401 {
2402  SortPath *pathnode = makeNode(SortPath);
2403 
2404  pathnode->path.pathtype = T_Sort;
2405  pathnode->path.parent = rel;
2406  /* Sort doesn't project, so use source path's pathtarget */
2407  pathnode->path.pathtarget = subpath->pathtarget;
2408  /* For now, assume we are above any joins, so no parameterization */
2409  pathnode->path.param_info = NULL;
2410  pathnode->path.parallel_aware = false;
2411  pathnode->path.parallel_safe = rel->consider_parallel &&
2412  subpath->parallel_safe;
2413  pathnode->path.parallel_workers = subpath->parallel_workers;
2414  pathnode->path.pathkeys = pathkeys;
2415 
2416  pathnode->subpath = subpath;
2417 
2418  cost_sort(&pathnode->path, root, pathkeys,
2419  subpath->total_cost,
2420  subpath->rows,
2421  subpath->pathtarget->width,
2422  0.0, /* XXX comparison_cost shouldn't be 0? */
2423  work_mem, limit_tuples);
2424 
2425  return pathnode;
2426 }
PathTarget * pathtarget
Definition: relation.h:895
Path * subpath
Definition: relation.h:1330
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
Definition: nodes.h:73
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
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:1462
int work_mem
Definition: globals.c:112
Cost total_cost
Definition: relation.h:907
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
#define NULL
Definition: c.h:226
double rows
Definition: relation.h:905
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
int width
Definition: relation.h:827
bool parallel_aware
Definition: relation.h:899
Path path
Definition: relation.h:1329
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
SubqueryScanPath* create_subqueryscan_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
List pathkeys,
Relids  required_outer 
)

Definition at line 1705 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_subqueryscan(), get_baserel_parampathinfo(), makeNode, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, SubqueryScanPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, subpath(), SubqueryScanPath::subpath, and T_SubqueryScan.

Referenced by recurse_set_operations(), reparameterize_path(), and set_subquery_pathlist().

1707 {
1709 
1710  pathnode->path.pathtype = T_SubqueryScan;
1711  pathnode->path.parent = rel;
1712  pathnode->path.pathtarget = rel->reltarget;
1713  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1714  required_outer);
1715  pathnode->path.parallel_aware = false;
1716  pathnode->path.parallel_safe = rel->consider_parallel &&
1717  subpath->parallel_safe;
1718  pathnode->path.parallel_workers = subpath->parallel_workers;
1719  pathnode->path.pathkeys = pathkeys;
1720  pathnode->subpath = subpath;
1721 
1722  cost_subqueryscan(pathnode, root, rel, pathnode->path.param_info);
1723 
1724  return pathnode;
1725 }
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
void cost_subqueryscan(SubqueryScanPath *path, PlannerInfo *root, RelOptInfo *baserel, ParamPathInfo *param_info)
Definition: costsize.c:1178
RelOptInfo * parent
Definition: relation.h:894
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
Datum subpath(PG_FUNCTION_ARGS)
Definition: ltree_op.c:234
TidPath* create_tidscan_path ( PlannerInfo root,
RelOptInfo rel,
List tidquals,
Relids  required_outer 
)

Definition at line 1171 of file pathnode.c.

References RelOptInfo::consider_parallel, cost_tidscan(), get_baserel_parampathinfo(), makeNode, NIL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, TidPath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, RelOptInfo::reltarget, T_TidScan, and TidPath::tidquals.

Referenced by create_tidscan_paths().

1173 {
1174  TidPath *pathnode = makeNode(TidPath);
1175 
1176  pathnode->path.pathtype = T_TidScan;
1177  pathnode->path.parent = rel;
1178  pathnode->path.pathtarget = rel->reltarget;
1179  pathnode->path.param_info = get_baserel_parampathinfo(root, rel,
1180  required_outer);
1181  pathnode->path.parallel_aware = false;
1182  pathnode->path.parallel_safe = rel->consider_parallel;
1183  pathnode->path.parallel_workers = 0;
1184  pathnode->path.pathkeys = NIL; /* always unordered */
1185 
1186  pathnode->tidquals = tidquals;
1187 
1188  cost_tidscan(&pathnode->path, root, rel, tidquals,
1189  pathnode->path.param_info);
1190 
1191  return pathnode;
1192 }
#define NIL
Definition: pg_list.h:69
PathTarget * pathtarget
Definition: relation.h:895
ParamPathInfo * get_baserel_parampathinfo(PlannerInfo *root, RelOptInfo *baserel, Relids required_outer)
Definition: relnode.c:1010
void cost_tidscan(Path *path, PlannerInfo *root, RelOptInfo *baserel, List *tidquals, ParamPathInfo *param_info)
Definition: costsize.c:1075
int parallel_workers
Definition: relation.h:901
ParamPathInfo * param_info
Definition: relation.h:897
NodeTag pathtype
Definition: relation.h:892
RelOptInfo * parent
Definition: relation.h:894
List * tidquals
Definition: relation.h:1042
List * pathkeys
Definition: relation.h:909
#define makeNode(_type_)
Definition: nodes.h:556
bool parallel_safe
Definition: relation.h:900
bool consider_parallel
Definition: relation.h:498
Path path
Definition: relation.h:1041
bool parallel_aware
Definition: relation.h:899
struct PathTarget * reltarget
Definition: relation.h:501
UniquePath* create_unique_path ( PlannerInfo root,
RelOptInfo rel,
Path subpath,
SpecialJoinInfo sjinfo 
)

Definition at line 1424 of file pathnode.c.

References AGG_HASHED, Assert, bms_equal(), RelOptInfo::cheapest_total_path, RelOptInfo::cheapest_unique_path, RelOptInfo::consider_parallel, cost_agg(), cost_sort(), cpu_operator_cost, estimate_num_groups(), UniquePath::in_operators, JOIN_SEMI, SpecialJoinInfo::jointype, list_length(), makeNode, MemoryContextSwitchTo(), NIL, NULL, Path::parallel_aware, Path::parallel_safe, Path::parallel_workers, Path::param_info, Path::parent, UniquePath::path, Path::pathkeys, Path::pathtarget, Path::pathtype, PlannerInfo::planner_cxt, planner_rt_fetch, query_is_distinct_for(), query_supports_distinctness(), relation_has_unique_index_for(), RelOptInfo::relid, RelOptInfo::relids, RelOptInfo::reltarget, RelOptInfo::rows, Path::rows, RTE_RELATION, RTE_SUBQUERY, RelOptInfo::rtekind, SpecialJoinInfo::semi_can_btree, SpecialJoinInfo::semi_can_hash, SpecialJoinInfo::semi_operators, SpecialJoinInfo::semi_rhs_exprs, Path::startup_cost, subpath(), UniquePath::subpath, RangeTblEntry::subquery, SpecialJoinInfo::syn_righthand, T_Unique, Path::total_cost, translate_sub_tlist(), UniquePath::umethod, UniquePath::uniq_exprs, UNIQUE_PATH_HASH, UNIQUE_PATH_NOOP, UNIQUE_PATH_SORT, PathTarget::width, and work_mem.

Referenced by consider_parallel_nestloop(), hash_inner_and_outer(), join_is_legal(), make_join_rel(), match_unsorted_outer(), and sort_inner_and_outer().

1426 {
1427  UniquePath *pathnode;
1428  Path sort_path; /* dummy for result of cost_sort */
1429  Path agg_path; /* dummy for result of cost_agg */
1430  MemoryContext oldcontext;
1431  int numCols;
1432 
1433  /* Caller made a mistake if subpath isn't cheapest_total ... */
1434  Assert(subpath == rel->cheapest_total_path);
1435  Assert(subpath->parent == rel);
1436  /* ... or if SpecialJoinInfo is the wrong one */
1437  Assert(sjinfo->jointype == JOIN_SEMI);
1438  Assert(bms_equal(rel->relids, sjinfo->syn_righthand));
1439 
1440  /* If result already cached, return it */
1441  if (rel->cheapest_unique_path)
1442  return (UniquePath *) rel->cheapest_unique_path;
1443 
1444  /* If it's not possible to unique-ify, return NULL */
1445  if (!(sjinfo->semi_can_btree || sjinfo->semi_can_hash))
1446  return NULL;
1447 
1448  /*
1449  * We must ensure path struct and subsidiary data are allocated in main
1450  * planning context; otherwise GEQO memory management causes trouble.
1451  */
1452  oldcontext = MemoryContextSwitchTo(root->planner_cxt);
1453 
1454  pathnode = makeNode(UniquePath);
1455 
1456  pathnode->path.pathtype = T_Unique;
1457  pathnode->path.parent = rel;
1458  pathnode->path.pathtarget = rel->reltarget;
1459  pathnode->path.param_info = subpath->param_info;
1460  pathnode->path.parallel_aware = false;
1461  pathnode->path.parallel_safe = rel->consider_parallel &&
1462  subpath->parallel_safe;
1463  pathnode->path.parallel_workers = subpath->parallel_workers;
1464 
1465  /*
1466  * Assume the output is unsorted, since we don't necessarily have pathkeys
1467  * to represent it. (This might get overridden below.)
1468  */
1469  pathnode->path.pathkeys = NIL;
1470 
1471  pathnode->subpath = subpath;
1472  pathnode->in_operators = sjinfo->semi_operators;
1473  pathnode->uniq_exprs = sjinfo->semi_rhs_exprs;
1474 
1475  /*
1476  * If the input is a relation and it has a unique index that proves the
1477  * semi_rhs_exprs are unique, then we don't need to do anything. Note
1478  * that relation_has_unique_index_for automatically considers restriction
1479  * clauses for the rel, as well.
1480  */
1481  if (rel->rtekind == RTE_RELATION && sjinfo->semi_can_btree &&
1483  sjinfo->semi_rhs_exprs,
1484  sjinfo->semi_operators))
1485  {
1486  pathnode->umethod = UNIQUE_PATH_NOOP;
1487  pathnode->path.rows = rel->rows;
1488  pathnode->path.startup_cost = subpath->startup_cost;
1489  pathnode->path.total_cost = subpath->total_cost;
1490  pathnode->path.pathkeys = subpath->pathkeys;
1491 
1492  rel->cheapest_unique_path = (Path *) pathnode;
1493 
1494  MemoryContextSwitchTo(oldcontext);
1495 
1496  return pathnode;
1497  }
1498 
1499  /*
1500  * If the input is a subquery whose output must be unique already, then we
1501  * don't need to do anything. The test for uniqueness has to consider
1502  * exactly which columns we are extracting; for example "SELECT DISTINCT
1503  * x,y" doesn't guarantee that x alone is distinct. So we cannot check for
1504  * this optimization unless semi_rhs_exprs consists only of simple Vars
1505  * referencing subquery outputs. (Possibly we could do something with
1506  * expressions in the subquery outputs, too, but for now keep it simple.)
1507  */
1508  if (rel->rtekind == RTE_SUBQUERY)
1509  {
1510  RangeTblEntry *rte = planner_rt_fetch(rel->relid, root);
1511 
1513  {
1514  List *sub_tlist_colnos;
1515 
1516  sub_tlist_colnos = translate_sub_tlist(sjinfo->semi_rhs_exprs,
1517  rel->relid);
1518 
1519  if (sub_tlist_colnos &&
1521  sub_tlist_colnos,
1522  sjinfo->semi_operators))
1523  {
1524  pathnode->umethod = UNIQUE_PATH_NOOP;
1525  pathnode->path.rows = rel->rows;
1526  pathnode->path.startup_cost = subpath->startup_cost;
1527  pathnode->path.total_cost = subpath->total_cost;
1528  pathnode->path.pathkeys = subpath->pathkeys;
1529 
1530