103 #define LOG2(x) (log(x) / 0.693147180559945)
110 #define APPEND_CPU_COST_MULTIPLIER 0.5
118 #define MAXIMUM_ROWCOUNT 1e100
168 Cost *rescan_startup_cost,
Cost *rescan_total_cost);
188 List **restrictlist);
190 int parallel_workers);
194 static double page_size(
double tuples,
int width);
213 else if (nrows <= 1.0)
244 return (
x < (
double) LONG_MAX) ? (long)
x : LONG_MAX;
259 Cost startup_cost = 0;
262 double spc_seq_page_cost;
287 disk_run_cost = spc_seq_page_cost * baserel->
pages;
292 startup_cost += qpqual_cost.
startup;
294 cpu_run_cost = cpu_per_tuple * baserel->
tuples;
296 startup_cost += path->pathtarget->cost.startup;
297 cpu_run_cost += path->pathtarget->cost.per_tuple * path->
rows;
305 cpu_run_cost /= parallel_divisor;
322 path->
total_cost = startup_cost + cpu_run_cost + disk_run_cost;
336 Cost startup_cost = 0;
341 double spc_seq_page_cost,
342 spc_random_page_cost,
363 &spc_random_page_cost,
368 spc_random_page_cost : spc_seq_page_cost;
374 run_cost += spc_page_cost * baserel->
pages;
386 startup_cost += qpqual_cost.
startup;
388 run_cost += cpu_per_tuple * baserel->
tuples;
390 startup_cost += path->pathtarget->cost.startup;
391 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
412 Cost startup_cost = 0;
448 Cost input_startup_cost,
Cost input_total_cost,
451 Cost startup_cost = 0;
453 Cost comparison_cost;
481 startup_cost += comparison_cost * N * logN;
484 run_cost += path->
path.
rows * comparison_cost * logN;
499 path->
path.
total_cost = (startup_cost + run_cost + input_total_cost);
526 bool indexonly = (path->
path.
pathtype == T_IndexOnlyScan);
529 Cost startup_cost = 0;
531 Cost cpu_run_cost = 0;
532 Cost indexStartupCost;
535 double indexCorrelation,
537 double spc_seq_page_cost,
538 spc_random_page_cost;
543 double tuples_fetched;
544 double pages_fetched;
545 double rand_heap_pages;
561 if (path->
path.param_info)
590 amcostestimate(root, path, loop_count,
591 &indexStartupCost, &indexTotalCost,
592 &indexSelectivity, &indexCorrelation,
604 startup_cost += indexStartupCost;
605 run_cost += indexTotalCost - indexStartupCost;
612 &spc_random_page_cost,
654 (
double)
index->pages,
658 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
660 rand_heap_pages = pages_fetched;
662 max_IO_cost = (pages_fetched * spc_random_page_cost) / loop_count;
674 pages_fetched = ceil(indexSelectivity * (
double) baserel->
pages);
678 (
double)
index->pages,
682 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
684 min_IO_cost = (pages_fetched * spc_random_page_cost) / loop_count;
694 (
double)
index->pages,
698 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
700 rand_heap_pages = pages_fetched;
703 max_IO_cost = pages_fetched * spc_random_page_cost;
706 pages_fetched = ceil(indexSelectivity * (
double) baserel->
pages);
709 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
711 if (pages_fetched > 0)
713 min_IO_cost = spc_random_page_cost;
714 if (pages_fetched > 1)
715 min_IO_cost += (pages_fetched - 1) * spc_seq_page_cost;
729 rand_heap_pages = -1;
757 csquared = indexCorrelation * indexCorrelation;
759 run_cost += max_IO_cost + csquared * (min_IO_cost - max_IO_cost);
769 startup_cost += qpqual_cost.
startup;
772 cpu_run_cost += cpu_per_tuple * tuples_fetched;
775 startup_cost += path->
path.pathtarget->cost.startup;
776 cpu_run_cost += path->
path.pathtarget->cost.per_tuple * path->
path.
rows;
786 cpu_run_cost /= parallel_divisor;
789 run_cost += cpu_run_cost;
817 foreach(lc, qual_clauses)
821 if (rinfo->pseudoconstant)
826 result =
lappend(result, rinfo);
873 double pages_fetched;
879 T = (pages > 1) ? (
double) pages : 1.0;
883 total_pages =
Max(total_pages, 1.0);
899 (2.0 *
T * tuples_fetched) / (2.0 *
T + tuples_fetched);
900 if (pages_fetched >=
T)
903 pages_fetched = ceil(pages_fetched);
909 lim = (2.0 *
T *
b) / (2.0 *
T -
b);
910 if (tuples_fetched <= lim)
913 (2.0 *
T * tuples_fetched) / (2.0 *
T + tuples_fetched);
918 b + (tuples_fetched - lim) * (
T -
b) /
T;
920 pages_fetched = ceil(pages_fetched);
922 return pages_fetched;
987 Path *bitmapqual,
double loop_count)
989 Cost startup_cost = 0;
996 double tuples_fetched;
997 double pages_fetched;
998 double spc_seq_page_cost,
999 spc_random_page_cost;
1017 loop_count, &indexTotalCost,
1020 startup_cost += indexTotalCost;
1021 T = (baserel->
pages > 1) ? (
double) baserel->
pages : 1.0;
1025 &spc_random_page_cost,
1026 &spc_seq_page_cost);
1035 if (pages_fetched >= 2.0)
1036 cost_per_page = spc_random_page_cost -
1037 (spc_random_page_cost - spc_seq_page_cost)
1038 * sqrt(pages_fetched /
T);
1040 cost_per_page = spc_random_page_cost;
1042 run_cost += pages_fetched * cost_per_page;
1055 startup_cost += qpqual_cost.
startup;
1057 cpu_run_cost = cpu_per_tuple * tuples_fetched;
1065 cpu_run_cost /= parallel_divisor;
1071 run_cost += cpu_run_cost;
1074 startup_cost += path->pathtarget->cost.startup;
1075 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1090 *cost = ((
IndexPath *) path)->indextotalcost;
1091 *selec = ((
IndexPath *) path)->indexselectivity;
1156 totalCost += subCost;
1201 totalCost += subCost;
1224 Cost startup_cost = 0;
1226 bool isCurrentOf =
false;
1232 double spc_random_page_cost;
1246 foreach(l, tidquals)
1296 &spc_random_page_cost,
1300 run_cost += spc_random_page_cost * ntuples;
1309 run_cost += cpu_per_tuple * ntuples;
1312 startup_cost += path->pathtarget->cost.startup;
1313 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1335 Cost startup_cost = 0;
1342 double spc_random_page_cost;
1343 double spc_seq_page_cost;
1358 pages = ceil(selectivity * baserel->
pages);
1371 ntuples = selectivity * baserel->
tuples;
1372 nseqpages = pages - 1.0;
1385 &spc_random_page_cost,
1386 &spc_seq_page_cost);
1389 run_cost += spc_random_page_cost + spc_seq_page_cost * nseqpages;
1404 run_cost += cpu_per_tuple * ntuples;
1407 startup_cost += path->pathtarget->cost.startup;
1408 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1425 bool trivial_pathtarget)
1478 if (qpquals ==
NIL && trivial_pathtarget)
1483 startup_cost = qpqual_cost.
startup;
1488 startup_cost += path->
path.pathtarget->cost.startup;
1489 run_cost += path->
path.pathtarget->cost.per_tuple * path->
path.
rows;
1506 Cost startup_cost = 0;
1544 startup_cost += qpqual_cost.
startup;
1546 run_cost += cpu_per_tuple * baserel->
tuples;
1549 startup_cost += path->pathtarget->cost.startup;
1550 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1567 Cost startup_cost = 0;
1600 startup_cost += qpqual_cost.
startup;
1602 run_cost += cpu_per_tuple * baserel->
tuples;
1605 startup_cost += path->pathtarget->cost.startup;
1606 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1623 Cost startup_cost = 0;
1647 startup_cost += qpqual_cost.
startup;
1649 run_cost += cpu_per_tuple * baserel->
tuples;
1652 startup_cost += path->pathtarget->cost.startup;
1653 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1673 Cost startup_cost = 0;
1694 startup_cost += qpqual_cost.
startup;
1696 run_cost += cpu_per_tuple * baserel->
tuples;
1699 startup_cost += path->pathtarget->cost.startup;
1700 run_cost += path->pathtarget->cost.per_tuple * path->
rows;
1714 Cost startup_cost = 0;
1735 startup_cost += qpqual_cost.
startup;
1737 run_cost += cpu_per_tuple * baserel->
tuples;
1751 Cost startup_cost = 0;
1769 startup_cost += qpqual_cost.
startup;
1771 run_cost += cpu_per_tuple * baserel->
tuples;
1794 total_rows = nrterm->
rows;
1803 total_rows += 10 * rterm->
rows;
1814 runion->
rows = total_rows;
1815 runion->pathtarget->width =
Max(nrterm->pathtarget->width,
1816 rterm->pathtarget->width);
1857 double tuples,
int width,
1858 Cost comparison_cost,
int sort_mem,
1859 double limit_tuples)
1862 double output_bytes;
1863 double output_tuples;
1864 long sort_mem_bytes = sort_mem * 1024L;
1877 if (limit_tuples > 0 && limit_tuples < tuples)
1879 output_tuples = limit_tuples;
1884 output_tuples = tuples;
1885 output_bytes = input_bytes;
1888 if (output_bytes > sort_mem_bytes)
1893 double npages = ceil(input_bytes / BLCKSZ);
1894 double nruns = input_bytes / sort_mem_bytes;
1897 double npageaccesses;
1904 *startup_cost = comparison_cost * tuples *
LOG2(tuples);
1909 if (nruns > mergeorder)
1910 log_runs = ceil(log(nruns) / log(mergeorder));
1913 npageaccesses = 2.0 * npages * log_runs;
1915 *startup_cost += npageaccesses *
1918 else if (tuples > 2 * output_tuples || input_bytes > sort_mem_bytes)
1926 *startup_cost = comparison_cost * tuples *
LOG2(2.0 * output_tuples);
1931 *startup_cost = comparison_cost * tuples *
LOG2(tuples);
1960 Cost input_startup_cost,
Cost input_total_cost,
1961 double input_tuples,
int width,
Cost comparison_cost,
int sort_mem,
1962 double limit_tuples)
1966 input_run_cost = input_total_cost - input_startup_cost;
1967 double group_tuples,
1969 Cost group_startup_cost,
1971 group_input_run_cost;
1974 bool unknown_varno =
false;
1982 if (input_tuples < 2.0)
2010 foreach(l, pathkeys)
2022 unknown_varno =
true;
2038 group_tuples = input_tuples / input_groups;
2039 group_input_run_cost = input_run_cost / input_groups;
2046 group_tuples, width, comparison_cost, sort_mem,
2053 startup_cost = group_startup_cost + input_startup_cost +
2054 group_input_run_cost;
2062 run_cost = group_run_cost + (group_run_cost + group_startup_cost) *
2063 (input_groups - 1) + group_input_run_cost * (input_groups - 1);
2078 path->
rows = input_tuples;
2097 List *pathkeys,
Cost input_cost,
double tuples,
int width,
2098 Cost comparison_cost,
int sort_mem,
2099 double limit_tuples)
2107 comparison_cost, sort_mem,
2113 startup_cost += input_cost;
2115 path->
rows = tuples;
2144 arrlen =
Min(parallel_workers, numpaths);
2149 foreach(cell, subpaths)
2153 if (path_index == arrlen)
2155 costarr[path_index++] =
subpath->total_cost;
2162 min_index = arrlen - 1;
2173 if (path_index++ == numpaths)
2176 costarr[min_index] +=
subpath->total_cost;
2180 for (
int i = 0;
i < arrlen;
i++)
2182 if (costarr[
i] < costarr[min_index])
2189 for (
int i = 0;
i < arrlen;
i++)
2191 if (costarr[
i] > costarr[max_index])
2195 return costarr[max_index];
2218 if (pathkeys ==
NIL)
2308 else if (i < apath->path.parallel_workers)
2319 if (i < apath->first_partial_path)
2323 double subpath_parallel_divisor;
2377 List *pathkeys,
int n_streams,
2378 Cost input_startup_cost,
Cost input_total_cost,
2381 Cost startup_cost = 0;
2383 Cost comparison_cost;
2390 N = (n_streams < 2) ? 2.0 : (
double) n_streams;
2397 startup_cost += comparison_cost * N * logN;
2400 run_cost += tuples * comparison_cost * logN;
2408 path->
startup_cost = startup_cost + input_startup_cost;
2409 path->
total_cost = startup_cost + run_cost + input_total_cost;
2426 Cost input_startup_cost,
Cost input_total_cost,
2427 double tuples,
int width)
2429 Cost startup_cost = input_startup_cost;
2430 Cost run_cost = input_total_cost - input_startup_cost;
2432 long work_mem_bytes =
work_mem * 1024L;
2434 path->
rows = tuples;
2456 if (nbytes > work_mem_bytes)
2458 double npages = ceil(nbytes / BLCKSZ);
2482 Cost *rescan_startup_cost,
Cost *rescan_total_cost)
2489 double calls = mpath->
calls;
2490 int width = mpath->
subpath->pathtarget->width;
2492 double hash_mem_bytes;
2493 double est_entry_bytes;
2494 double est_cache_entries;
2518 est_cache_entries = floor(hash_mem_bytes / est_entry_bytes);
2553 evict_ratio = 1.0 -
Min(est_cache_entries, ndistinct) / ndistinct;
2561 hit_ratio = ((calls - ndistinct) / calls) *
2562 (est_cache_entries /
Max(ndistinct, est_cache_entries));
2564 Assert(hit_ratio >= 0 && hit_ratio <= 1.0);
2598 startup_cost = input_startup_cost * (1.0 - hit_ratio);
2606 *rescan_startup_cost = startup_cost;
2607 *rescan_total_cost = total_cost;
2624 int numGroupCols,
double numGroups,
2626 Cost input_startup_cost,
Cost input_total_cost,
2627 double input_tuples,
double input_width)
2629 double output_tuples;
2635 if (aggcosts == NULL)
2639 aggcosts = &dummy_aggcosts;
2666 startup_cost = input_total_cost;
2678 startup_cost = input_startup_cost;
2679 total_cost = input_total_cost;
2692 output_tuples = numGroups;
2697 startup_cost = input_total_cost;
2706 total_cost = startup_cost;
2710 output_tuples = numGroups;
2729 double pages_written = 0.0;
2730 double pages_read = 0.0;
2732 double hashentrysize;
2735 uint64 ngroups_limit;
2748 &ngroups_limit, &num_partitions);
2750 nbatches =
Max((numGroups * hashentrysize) / mem_limit,
2751 numGroups / ngroups_limit);
2753 nbatches =
Max(ceil(nbatches), 1.0);
2754 num_partitions =
Max(num_partitions, 2);
2761 depth = ceil(log(nbatches) / log(num_partitions));
2768 pages_written = pages_read = pages * depth;
2775 pages_written *= 2.0;
2783 startup_cost += spill_cost;
2784 total_cost += spill_cost;
2796 startup_cost += qual_cost.
startup;
2807 path->
rows = output_tuples;
2827 double input_tuples)
2830 double partition_tuples;
2831 double return_tuples;
2840 double num_partitions;
2848 partition_tuples = input_tuples / num_partitions;
2853 partition_tuples = input_tuples;
2867 partition_tuples, NULL,
2870 peer_tuples = partition_tuples / num_groups;
2881 return_tuples = partition_tuples;
2888 return_tuples = 1.0;
2898 return_tuples = partition_tuples;
2900 return_tuples = peer_tuples;
2909 return_tuples = 1.0;
2920 return_tuples = 1.0;
2925 double end_offset_value;
2930 if (endOffset->constisnull)
2939 end_offset_value = 1.0;
2959 partition_tuples / peer_tuples *
2978 return_tuples = end_offset_value + 1.0;
2983 return_tuples = peer_tuples * (end_offset_value + 1.0);
2992 return_tuples = 1.0;
3002 return_tuples = 1.0;
3012 return_tuples =
Min(return_tuples + 1.0, partition_tuples);
3020 return_tuples =
Min(return_tuples, partition_tuples);
3042 Cost input_startup_cost,
Cost input_total_cost,
3043 double input_tuples)
3047 double startup_tuples;
3055 startup_cost = input_startup_cost;
3056 total_cost = input_total_cost;
3067 foreach(lc, windowFuncs)
3076 startup_cost += argcosts.
startup;
3081 startup_cost += argcosts.
startup;
3089 startup_cost += argcosts.
startup;
3092 total_cost += wfunccost * input_tuples;
3106 path->
rows = input_tuples;
3121 if (startup_tuples > 1.0)
3122 path->
startup_cost += (total_cost - startup_cost) / input_tuples *
3123 (startup_tuples - 1.0);
3136 int numGroupCols,
double numGroups,
3138 Cost input_startup_cost,
Cost input_total_cost,
3139 double input_tuples)
3141 double output_tuples;
3145 output_tuples = numGroups;
3146 startup_cost = input_startup_cost;
3147 total_cost = input_total_cost;
3164 startup_cost += qual_cost.
startup;
3175 path->
rows = output_tuples;
3207 Path *outer_path,
Path *inner_path,
3210 Cost startup_cost = 0;
3212 double outer_path_rows = outer_path->
rows;
3213 Cost inner_rescan_start_cost;
3214 Cost inner_rescan_total_cost;
3215 Cost inner_run_cost;
3216 Cost inner_rescan_run_cost;
3220 &inner_rescan_start_cost,
3221 &inner_rescan_total_cost);
3233 if (outer_path_rows > 1)
3234 run_cost += (outer_path_rows - 1) * inner_rescan_start_cost;
3237 inner_rescan_run_cost = inner_rescan_total_cost - inner_rescan_start_cost;
3257 run_cost += inner_run_cost;
3258 if (outer_path_rows > 1)
3259 run_cost += (outer_path_rows - 1) * inner_rescan_run_cost;
3266 workspace->
total_cost = startup_cost + run_cost;
3286 double outer_path_rows = outer_path->
rows;
3287 double inner_path_rows = inner_path->
rows;
3295 if (outer_path_rows <= 0)
3296 outer_path_rows = 1;
3297 if (inner_path_rows <= 0)
3298 inner_path_rows = 1;
3300 if (path->
jpath.path.param_info)
3301 path->
jpath.path.rows = path->
jpath.path.param_info->ppi_rows;
3303 path->
jpath.path.rows = path->
jpath.path.parent->rows;
3306 if (path->
jpath.path.parallel_workers > 0)
3310 path->
jpath.path.rows =
3333 double outer_matched_rows;
3334 double outer_unmatched_rows;
3347 outer_unmatched_rows = outer_path_rows - outer_matched_rows;
3354 ntuples = outer_matched_rows * inner_path_rows * inner_scan_frac;
3381 run_cost += inner_run_cost * inner_scan_frac;
3382 if (outer_matched_rows > 1)
3383 run_cost += (outer_matched_rows - 1) * inner_rescan_run_cost * inner_scan_frac;
3391 run_cost += outer_unmatched_rows *
3392 inner_rescan_run_cost / inner_path_rows;
3415 ntuples += outer_unmatched_rows * inner_path_rows;
3418 run_cost += inner_run_cost;
3419 if (outer_unmatched_rows >= 1)
3420 outer_unmatched_rows -= 1;
3422 outer_matched_rows -= 1;
3425 if (outer_matched_rows > 0)
3426 run_cost += outer_matched_rows * inner_rescan_run_cost * inner_scan_frac;
3429 if (outer_unmatched_rows > 0)
3430 run_cost += outer_unmatched_rows * inner_rescan_run_cost;
3438 ntuples = outer_path_rows * inner_path_rows;
3443 startup_cost += restrict_qual_cost.
startup;
3445 run_cost += cpu_per_tuple * ntuples;
3448 startup_cost += path->
jpath.path.pathtarget->cost.startup;
3449 run_cost += path->
jpath.path.pathtarget->cost.per_tuple * path->
jpath.path.rows;
3451 path->
jpath.path.startup_cost = startup_cost;
3452 path->
jpath.path.total_cost = startup_cost + run_cost;
3489 Path *outer_path,
Path *inner_path,
3490 List *outersortkeys,
List *innersortkeys,
3493 Cost startup_cost = 0;
3495 double outer_path_rows = outer_path->
rows;
3496 double inner_path_rows = inner_path->
rows;
3497 Cost inner_run_cost;
3509 if (outer_path_rows <= 0)
3510 outer_path_rows = 1;
3511 if (inner_path_rows <= 0)
3512 inner_path_rows = 1;
3525 if (mergeclauses && jointype !=
JOIN_FULL)
3535 opathkeys = outersortkeys ? outersortkeys : outer_path->
pathkeys;
3536 ipathkeys = innersortkeys ? innersortkeys : inner_path->
pathkeys;
3543 opathkey->pk_eclass->ec_collation != ipathkey->pk_eclass->ec_collation ||
3546 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
3552 outer_path->parent->relids))
3571 outerstartsel = 0.0;
3577 innerstartsel = 0.0;
3584 outerstartsel = innerstartsel = 0.0;
3585 outerendsel = innerendsel = 1.0;
3592 outer_skip_rows = rint(outer_path_rows * outerstartsel);
3593 inner_skip_rows = rint(inner_path_rows * innerstartsel);
3597 Assert(outer_skip_rows <= outer_rows);
3598 Assert(inner_skip_rows <= inner_rows);
3605 outerstartsel = outer_skip_rows / outer_path_rows;
3606 innerstartsel = inner_skip_rows / inner_path_rows;
3607 outerendsel = outer_rows / outer_path_rows;
3608 innerendsel = inner_rows / inner_path_rows;
3610 Assert(outerstartsel <= outerendsel);
3611 Assert(innerstartsel <= innerendsel);
3622 outer_path->pathtarget->width,
3630 * (outerendsel - outerstartsel);
3638 * (outerendsel - outerstartsel);
3648 inner_path->pathtarget->width,
3656 * (innerendsel - innerstartsel);
3664 * (innerendsel - innerstartsel);
3679 workspace->
total_cost = startup_cost + run_cost + inner_run_cost;
3723 double inner_path_rows = inner_path->
rows;
3738 double mergejointuples,
3743 if (inner_path_rows <= 0)
3744 inner_path_rows = 1;
3747 if (path->
jpath.path.param_info)
3748 path->
jpath.path.rows = path->
jpath.path.param_info->ppi_rows;
3750 path->
jpath.path.rows = path->
jpath.path.parent->rows;
3753 if (path->
jpath.path.parallel_workers > 0)
3757 path->
jpath.path.rows =
3826 rescannedtuples = 0;
3829 rescannedtuples = mergejointuples - inner_path_rows;
3831 if (rescannedtuples < 0)
3832 rescannedtuples = 0;
3840 rescanratio = 1.0 + (rescannedtuples / inner_rows);
3851 bare_inner_cost = inner_run_cost * rescanratio;
3866 mat_inner_cost = inner_run_cost +
3898 else if (innersortkeys ==
NIL &&
3915 inner_path->pathtarget->width) >
3923 run_cost += mat_inner_cost;
3925 run_cost += bare_inner_cost;
3934 startup_cost += merge_qual_cost.
startup;
3935 startup_cost += merge_qual_cost.
per_tuple *
3936 (outer_skip_rows + inner_skip_rows * rescanratio);
3938 ((outer_rows - outer_skip_rows) +
3939 (inner_rows - inner_skip_rows) * rescanratio);
3950 startup_cost += qp_qual_cost.
startup;
3952 run_cost += cpu_per_tuple * mergejointuples;
3955 startup_cost += path->
jpath.path.pathtarget->cost.startup;
3956 run_cost += path->
jpath.path.pathtarget->cost.per_tuple * path->
jpath.path.rows;
3958 path->
jpath.path.startup_cost = startup_cost;
3959 path->
jpath.path.total_cost = startup_cost + run_cost;
3977 foreach(lc, rinfo->scansel_cache)
3981 cache->
collation == pathkey->pk_eclass->ec_collation &&
4003 cache->
collation = pathkey->pk_eclass->ec_collation;
4011 rinfo->scansel_cache =
lappend(rinfo->scansel_cache, cache);
4048 Path *outer_path,
Path *inner_path,
4052 Cost startup_cost = 0;
4054 double outer_path_rows = outer_path->
rows;
4055 double inner_path_rows = inner_path->
rows;
4056 double inner_path_rows_total = inner_path_rows;
4061 size_t space_allowed;
4102 inner_path->pathtarget->width,
4120 double outerpages =
page_size(outer_path_rows,
4121 outer_path->pathtarget->width);
4122 double innerpages =
page_size(inner_path_rows,
4123 inner_path->pathtarget->width);
4133 workspace->
total_cost = startup_cost + run_cost;
4159 double outer_path_rows = outer_path->
rows;
4160 double inner_path_rows = inner_path->
rows;
4170 double hashjointuples;
4171 double virtualbuckets;
4177 if (path->
jpath.path.param_info)
4178 path->
jpath.path.rows = path->
jpath.path.param_info->ppi_rows;
4180 path->
jpath.path.rows = path->
jpath.path.parent->rows;
4183 if (path->
jpath.path.parallel_workers > 0)
4187 path->
jpath.path.rows =
4206 virtualbuckets = (double) numbuckets * (
double) numbatches;
4220 innerbucketsize = 1.0 / virtualbuckets;
4225 innerbucketsize = 1.0;
4227 foreach(hcl, hashclauses)
4242 inner_path->parent->relids))
4245 thisbucketsize = restrictinfo->right_bucketsize;
4246 if (thisbucketsize < 0)
4252 &restrictinfo->right_mcvfreq,
4253 &restrictinfo->right_bucketsize);
4254 thisbucketsize = restrictinfo->right_bucketsize;
4256 thismcvfreq = restrictinfo->right_mcvfreq;
4261 inner_path->parent->relids));
4263 thisbucketsize = restrictinfo->left_bucketsize;
4264 if (thisbucketsize < 0)
4270 &restrictinfo->left_mcvfreq,
4271 &restrictinfo->left_bucketsize);
4272 thisbucketsize = restrictinfo->left_bucketsize;
4274 thismcvfreq = restrictinfo->left_mcvfreq;
4277 if (innerbucketsize > thisbucketsize)
4278 innerbucketsize = thisbucketsize;
4279 if (innermcvfreq > thismcvfreq)
4280 innermcvfreq = thismcvfreq;
4311 double outer_matched_rows;
4329 startup_cost += hash_qual_cost.
startup;
4330 run_cost += hash_qual_cost.
per_tuple * outer_matched_rows *
4331 clamp_row_est(inner_path_rows * innerbucketsize * inner_scan_frac) * 0.5;
4347 (outer_path_rows - outer_matched_rows) *
4352 hashjointuples = outer_path_rows - outer_matched_rows;
4354 hashjointuples = outer_matched_rows;
4368 startup_cost += hash_qual_cost.
startup;
4369 run_cost += hash_qual_cost.
per_tuple * outer_path_rows *
4386 startup_cost += qp_qual_cost.
startup;
4388 run_cost += cpu_per_tuple * hashjointuples;
4391 startup_cost += path->
jpath.path.pathtarget->cost.startup;
4392 run_cost += path->
jpath.path.pathtarget->cost.per_tuple * path->
jpath.path.rows;
4394 path->
jpath.path.startup_cost = startup_cost;
4395 path->
jpath.path.total_cost = startup_cost + run_cost;
4445 Cost plan_run_cost =
plan->total_cost -
plan->startup_cost;
4456 sp_cost.
per_tuple += 0.50 * plan_run_cost;
4501 Cost *rescan_startup_cost,
4502 Cost *rescan_total_cost)
4506 case T_FunctionScan:
4515 *rescan_startup_cost = 0;
4524 if (((
HashPath *) path)->num_batches == 1)
4527 *rescan_startup_cost = 0;
4528 *rescan_total_cost = path->total_cost - path->startup_cost;
4533 *rescan_startup_cost = path->startup_cost;
4534 *rescan_total_cost = path->total_cost;
4538 case T_WorkTableScan:
4548 path->pathtarget->width);
4549 long work_mem_bytes =
work_mem * 1024L;
4551 if (nbytes > work_mem_bytes)
4554 double npages = ceil(nbytes / BLCKSZ);
4558 *rescan_startup_cost = 0;
4559 *rescan_total_cost = run_cost;
4575 path->pathtarget->width);
4576 long work_mem_bytes =
work_mem * 1024L;
4578 if (nbytes > work_mem_bytes)
4581 double npages = ceil(nbytes / BLCKSZ);
4585 *rescan_startup_cost = 0;
4586 *rescan_total_cost = run_cost;
4592 rescan_startup_cost, rescan_total_cost);
4595 *rescan_startup_cost = path->startup_cost;
4596 *rescan_total_cost = path->total_cost;
4617 context.
root = root;
4630 *cost = context.
total;
4642 context.
root = root;
4648 *cost = context.
total;
4667 if (rinfo->eval_cost.startup < 0)
4679 if (rinfo->orclause)
4688 if (rinfo->pseudoconstant)
4694 rinfo->eval_cost = locContext.
total;
4814 &iofunc, &typioparam);
4819 &iofunc, &typisvarlena);
4841 foreach(lc, rcexpr->opnos)
4866 elog(
ERROR,
"cannot handle unplanned sub-select");
5001 foreach(l, restrictlist)
5006 joinquals =
lappend(joinquals, rinfo);
5010 joinquals = restrictlist;
5024 norm_sjinfo.type = T_SpecialJoinInfo;
5066 avgmatch = nselec * innerrel->
rows / jselec;
5068 avgmatch =
Max(1.0, avgmatch);
5091 Relids joinrelids = joinpath->path.parent->relids;
5101 if (innerpath->param_info == NULL)
5108 case T_IndexOnlyScan:
5109 indexclauses = ((
IndexPath *) innerpath)->indexclauses;
5111 case T_BitmapHeapScan:
5117 indexclauses = ((
IndexPath *) bmqual)->indexclauses;
5139 foreach(lc, innerpath->param_info->ppi_clauses)
5144 innerpath->parent->relids,
5193 sjinfo.type = T_SpecialJoinInfo;
5221 tuples = selec * outer_tuples * inner_tuples;
5272 List *param_clauses)
5292 if (nrows > rel->
rows)
5356 List *restrict_clauses)
5378 if (nrows > rel->
rows)
5441 foreach(l, restrictlist)
5446 pushedquals =
lappend(pushedquals, rinfo);
5448 joinquals =
lappend(joinquals, rinfo);
5492 nrows = outer_rows * inner_rows * fkselec * jselec;
5496 nrows = outer_rows * inner_rows * fkselec * jselec;
5497 if (nrows < outer_rows)
5502 nrows = outer_rows * inner_rows * fkselec * jselec;
5503 if (nrows < outer_rows)
5505 if (nrows < inner_rows)
5510 nrows = outer_rows * fkselec * jselec;
5514 nrows = outer_rows * (1.0 - fkselec * jselec);
5519 elog(
ERROR,
"unrecognized join type: %d", (
int) jointype);
5547 List **restrictlist)
5551 List *worklist = *restrictlist;
5568 ref_is_outer =
false;
5571 ref_is_outer =
true;
5597 if (worklist == *restrictlist)
5601 foreach(cell, worklist)
5604 bool remove_it =
false;
5608 for (
i = 0;
i < fkinfo->
nkeys;
i++)
5610 if (rinfo->parent_ec)
5625 if (fkinfo->
eclass[
i] == rinfo->parent_ec)
5647 removedlist =
lappend(removedlist, rinfo);
5677 if (removedlist ==
NIL ||
5722 double ref_tuples =
Max(ref_rel->
tuples, 1.0);
5724 fkselec *= ref_rel->
rows / ref_tuples;
5734 double ref_tuples =
Max(ref_rel->
tuples, 1.0);
5736 fkselec *= 1.0 / ref_tuples;
5751 for (
int i = 0;
i < fkinfo->
nkeys;
i++)
5778 *restrictlist = worklist;
5821 int32 item_width = 0;
5852 Var *var = (
Var *) texpr;