103 #define LOG2(x) (log(x) / 0.693147180559945)
110 #define APPEND_CPU_COST_MULTIPLIER 0.5
118 #define MAXIMUM_ROWCOUNT 1e100
167 Cost *rescan_startup_cost,
Cost *rescan_total_cost);
187 List **restrictlist);
189 int parallel_workers);
192 static double page_size(
double tuples,
int width);
211 else if (nrows <= 1.0)
242 return (
x < (
double) LONG_MAX) ? (long)
x : LONG_MAX;
257 Cost startup_cost = 0;
260 double spc_seq_page_cost;
285 disk_run_cost = spc_seq_page_cost * baserel->
pages;
290 startup_cost += qpqual_cost.
startup;
292 cpu_run_cost = cpu_per_tuple * baserel->
tuples;
303 cpu_run_cost /= parallel_divisor;
320 path->
total_cost = startup_cost + cpu_run_cost + disk_run_cost;
334 Cost startup_cost = 0;
339 double spc_seq_page_cost,
340 spc_random_page_cost,
361 &spc_random_page_cost,
366 spc_random_page_cost : spc_seq_page_cost;
372 run_cost += spc_page_cost * baserel->
pages;
384 startup_cost += qpqual_cost.
startup;
386 run_cost += cpu_per_tuple * baserel->
tuples;
410 Cost startup_cost = 0;
446 Cost input_startup_cost,
Cost input_total_cost,
449 Cost startup_cost = 0;
451 Cost comparison_cost;
479 startup_cost += comparison_cost * N * logN;
482 run_cost += path->
path.
rows * comparison_cost * logN;
497 path->
path.
total_cost = (startup_cost + run_cost + input_total_cost);
527 Cost startup_cost = 0;
529 Cost cpu_run_cost = 0;
530 Cost indexStartupCost;
533 double indexCorrelation,
535 double spc_seq_page_cost,
536 spc_random_page_cost;
541 double tuples_fetched;
542 double pages_fetched;
543 double rand_heap_pages;
588 amcostestimate(root, path, loop_count,
589 &indexStartupCost, &indexTotalCost,
590 &indexSelectivity, &indexCorrelation,
602 startup_cost += indexStartupCost;
603 run_cost += indexTotalCost - indexStartupCost;
610 &spc_random_page_cost,
652 (
double)
index->pages,
656 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
658 rand_heap_pages = pages_fetched;
660 max_IO_cost = (pages_fetched * spc_random_page_cost) / loop_count;
672 pages_fetched = ceil(indexSelectivity * (
double) baserel->
pages);
676 (
double)
index->pages,
680 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
682 min_IO_cost = (pages_fetched * spc_random_page_cost) / loop_count;
692 (
double)
index->pages,
696 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
698 rand_heap_pages = pages_fetched;
701 max_IO_cost = pages_fetched * spc_random_page_cost;
704 pages_fetched = ceil(indexSelectivity * (
double) baserel->
pages);
707 pages_fetched = ceil(pages_fetched * (1.0 - baserel->
allvisfrac));
709 if (pages_fetched > 0)
711 min_IO_cost = spc_random_page_cost;
712 if (pages_fetched > 1)
713 min_IO_cost += (pages_fetched - 1) * spc_seq_page_cost;
727 rand_heap_pages = -1;
755 csquared = indexCorrelation * indexCorrelation;
757 run_cost += max_IO_cost + csquared * (min_IO_cost - max_IO_cost);
767 startup_cost += qpqual_cost.
startup;
770 cpu_run_cost += cpu_per_tuple * tuples_fetched;
784 cpu_run_cost /= parallel_divisor;
787 run_cost += cpu_run_cost;
815 foreach(lc, qual_clauses)
824 result =
lappend(result, rinfo);
871 double pages_fetched;
877 T = (pages > 1) ? (
double) pages : 1.0;
881 total_pages =
Max(total_pages, 1.0);
897 (2.0 *
T * tuples_fetched) / (2.0 *
T + tuples_fetched);
898 if (pages_fetched >=
T)
901 pages_fetched = ceil(pages_fetched);
907 lim = (2.0 *
T *
b) / (2.0 *
T -
b);
908 if (tuples_fetched <= lim)
911 (2.0 *
T * tuples_fetched) / (2.0 *
T + tuples_fetched);
916 b + (tuples_fetched - lim) * (
T -
b) /
T;
918 pages_fetched = ceil(pages_fetched);
920 return pages_fetched;
985 Path *bitmapqual,
double loop_count)
987 Cost startup_cost = 0;
994 double tuples_fetched;
995 double pages_fetched;
996 double spc_seq_page_cost,
997 spc_random_page_cost;
1015 loop_count, &indexTotalCost,
1018 startup_cost += indexTotalCost;
1019 T = (baserel->
pages > 1) ? (
double) baserel->
pages : 1.0;
1023 &spc_random_page_cost,
1024 &spc_seq_page_cost);
1033 if (pages_fetched >= 2.0)
1034 cost_per_page = spc_random_page_cost -
1035 (spc_random_page_cost - spc_seq_page_cost)
1036 * sqrt(pages_fetched /
T);
1038 cost_per_page = spc_random_page_cost;
1040 run_cost += pages_fetched * cost_per_page;
1053 startup_cost += qpqual_cost.
startup;
1055 cpu_run_cost = cpu_per_tuple * tuples_fetched;
1063 cpu_run_cost /= parallel_divisor;
1069 run_cost += cpu_run_cost;
1088 *cost = ((
IndexPath *) path)->indextotalcost;
1089 *selec = ((
IndexPath *) path)->indexselectivity;
1154 totalCost += subCost;
1199 totalCost += subCost;
1222 Cost startup_cost = 0;
1224 bool isCurrentOf =
false;
1230 double spc_random_page_cost;
1244 foreach(l, tidquals)
1294 &spc_random_page_cost,
1298 run_cost += spc_random_page_cost * ntuples;
1307 run_cost += cpu_per_tuple * ntuples;
1333 Cost startup_cost = 0;
1340 double spc_random_page_cost;
1341 double spc_seq_page_cost;
1356 pages = ceil(selectivity * baserel->
pages);
1369 ntuples = selectivity * baserel->
tuples;
1370 nseqpages = pages - 1.0;
1383 &spc_random_page_cost,
1384 &spc_seq_page_cost);
1387 run_cost += spc_random_page_cost + spc_seq_page_cost * nseqpages;
1402 run_cost += cpu_per_tuple * ntuples;
1463 startup_cost = qpqual_cost.
startup;
1486 Cost startup_cost = 0;
1524 startup_cost += qpqual_cost.
startup;
1526 run_cost += cpu_per_tuple * baserel->
tuples;
1547 Cost startup_cost = 0;
1580 startup_cost += qpqual_cost.
startup;
1582 run_cost += cpu_per_tuple * baserel->
tuples;
1603 Cost startup_cost = 0;
1627 startup_cost += qpqual_cost.
startup;
1629 run_cost += cpu_per_tuple * baserel->
tuples;
1653 Cost startup_cost = 0;
1674 startup_cost += qpqual_cost.
startup;
1676 run_cost += cpu_per_tuple * baserel->
tuples;
1694 Cost startup_cost = 0;
1715 startup_cost += qpqual_cost.
startup;
1717 run_cost += cpu_per_tuple * baserel->
tuples;
1731 Cost startup_cost = 0;
1749 startup_cost += qpqual_cost.
startup;
1751 run_cost += cpu_per_tuple * baserel->
tuples;
1774 total_rows = nrterm->
rows;
1783 total_rows += 10 * rterm->
rows;
1794 runion->
rows = total_rows;
1812 return (
IsA(expr,
Var) && ((
Var *) expr)->varno == 0);
1824 double width = -1.0;
1865 if (width <=
sizeof(
Datum))
1874 return 1.0 + 0.125 *
LOG2(width /
sizeof(
Datum));
1928 Cost comparison_cost,
double tuples,
double output_tuples,
1931 Cost per_tuple_cost = 0.0;
1934 double tuplesPerPrevGroup = tuples;
1935 double totalFuncCost = 1.0;
1936 bool has_fake_var =
false;
1950 output_tuples = (heapSort) ? 2.0 * output_tuples : tuples;
1954 per_tuple_cost += comparison_cost;
1956 return per_tuple_cost * tuples;
1964 foreach(lc, pathkeys)
1970 Cost funcCost = 1.0;
2008 totalFuncCost += funcCost;
2025 tuplesPerPrevGroup, NULL, NULL,
2028 else if (tuples > 4.0)
2036 nGroups = ceil(2.0 + sqrt(tuples) * (
i + 1) /
list_length(pathkeys));
2045 if (
i >= nPresortedKeys)
2053 correctedNGroups = ceil(output_tuples / tuplesPerPrevGroup);
2057 correctedNGroups = nGroups;
2059 correctedNGroups =
Max(1.0, ceil(correctedNGroups));
2061 per_tuple_cost += totalFuncCost *
LOG2(correctedNGroups);
2075 tuplesPerPrevGroup =
Min(tuplesPerPrevGroup,
2076 ceil(1.5 * tuplesPerPrevGroup / nGroups));
2082 if (tuplesPerPrevGroup <= 1.0)
2104 per_tuple_cost += comparison_cost;
2106 return tuples * per_tuple_cost;
2117 0, tuples, tuples,
false);
2160 double tuples,
int width,
2161 Cost comparison_cost,
int sort_mem,
2162 double limit_tuples)
2165 double output_bytes;
2166 double output_tuples;
2167 long sort_mem_bytes = sort_mem * 1024L;
2177 if (limit_tuples > 0 && limit_tuples < tuples)
2179 output_tuples = limit_tuples;
2184 output_tuples = tuples;
2185 output_bytes = input_bytes;
2188 if (output_bytes > sort_mem_bytes)
2193 double npages = ceil(input_bytes / BLCKSZ);
2194 double nruns = input_bytes / sort_mem_bytes;
2197 double npageaccesses;
2201 comparison_cost, tuples,
2207 if (nruns > mergeorder)
2208 log_runs = ceil(log(nruns) / log(mergeorder));
2211 npageaccesses = 2.0 * npages * log_runs;
2213 *startup_cost += npageaccesses *
2216 else if (tuples > 2 * output_tuples || input_bytes > sort_mem_bytes)
2220 comparison_cost, tuples,
2221 output_tuples,
true);
2227 comparison_cost, tuples,
2257 Cost input_startup_cost,
Cost input_total_cost,
2258 double input_tuples,
int width,
Cost comparison_cost,
int sort_mem,
2259 double limit_tuples)
2263 input_run_cost = input_total_cost - input_startup_cost;
2264 double group_tuples,
2266 Cost group_startup_cost,
2268 group_input_run_cost;
2272 bool unknown_varno =
false;
2274 Assert(presorted_keys != 0);
2280 if (input_tuples < 2.0)
2308 foreach(l, pathkeys)
2320 unknown_varno =
true;
2328 if (
i >= presorted_keys)
2337 group_tuples = input_tuples / input_groups;
2338 group_input_run_cost = input_run_cost / input_groups;
2347 cost_tuplesort(root, pathkeys, &group_startup_cost, &group_run_cost,
2348 1.5 * group_tuples, width, comparison_cost, sort_mem,
2355 startup_cost = group_startup_cost
2356 + input_startup_cost + group_input_run_cost;
2364 run_cost = group_run_cost
2365 + (group_run_cost + group_startup_cost) * (input_groups - 1)
2366 + group_input_run_cost * (input_groups - 1);
2377 path->
rows = input_tuples;
2396 List *pathkeys,
Cost input_cost,
double tuples,
int width,
2397 Cost comparison_cost,
int sort_mem,
2398 double limit_tuples)
2406 comparison_cost, sort_mem,
2412 startup_cost += input_cost;
2414 path->
rows = tuples;
2444 arrlen =
Min(parallel_workers, numpaths);
2449 foreach(cell, subpaths)
2453 if (path_index == arrlen)
2455 costarr[path_index++] =
subpath->total_cost;
2462 min_index = arrlen - 1;
2474 if (path_index++ == numpaths)
2477 costarr[min_index] +=
subpath->total_cost;
2480 for (min_index =
i = 0;
i < arrlen;
i++)
2482 if (costarr[
i] < costarr[min_index])
2488 for (max_index =
i = 0;
i < arrlen;
i++)
2490 if (costarr[
i] > costarr[max_index])
2494 return costarr[max_index];
2517 if (pathkeys ==
NIL)
2607 else if (i < apath->path.parallel_workers)
2618 if (i < apath->first_partial_path)
2622 double subpath_parallel_divisor;
2676 List *pathkeys,
int n_streams,
2677 Cost input_startup_cost,
Cost input_total_cost,
2680 Cost startup_cost = 0;
2682 Cost comparison_cost;
2689 N = (n_streams < 2) ? 2.0 : (
double) n_streams;
2696 startup_cost += comparison_cost * N * logN;
2699 run_cost += tuples * comparison_cost * logN;
2707 path->
startup_cost = startup_cost + input_startup_cost;
2708 path->
total_cost = startup_cost + run_cost + input_total_cost;
2725 Cost input_startup_cost,
Cost input_total_cost,
2726 double tuples,
int width)
2728 Cost startup_cost = input_startup_cost;
2729 Cost run_cost = input_total_cost - input_startup_cost;
2731 long work_mem_bytes =
work_mem * 1024L;
2733 path->
rows = tuples;
2755 if (nbytes > work_mem_bytes)
2757 double npages = ceil(nbytes / BLCKSZ);
2781 Cost *rescan_startup_cost,
Cost *rescan_total_cost)
2787 double calls = mpath->
calls;
2790 double hash_mem_bytes;
2791 double est_entry_bytes;
2792 double est_cache_entries;
2814 est_cache_entries = floor(hash_mem_bytes / est_entry_bytes);
2849 evict_ratio = 1.0 -
Min(est_cache_entries, ndistinct) / ndistinct;
2857 hit_ratio = 1.0 / ndistinct *
Min(est_cache_entries, ndistinct) -
2858 (ndistinct / calls);
2861 hit_ratio =
Max(hit_ratio, 0.0);
2895 startup_cost = input_startup_cost * (1.0 - hit_ratio);
2903 *rescan_startup_cost = startup_cost;
2904 *rescan_total_cost = total_cost;
2921 int numGroupCols,
double numGroups,
2923 Cost input_startup_cost,
Cost input_total_cost,
2924 double input_tuples,
double input_width)
2926 double output_tuples;
2932 if (aggcosts == NULL)
2936 aggcosts = &dummy_aggcosts;
2963 startup_cost = input_total_cost;
2975 startup_cost = input_startup_cost;
2976 total_cost = input_total_cost;
2989 output_tuples = numGroups;
2994 startup_cost = input_total_cost;
3003 total_cost = startup_cost;
3007 output_tuples = numGroups;
3026 double pages_written = 0.0;
3027 double pages_read = 0.0;
3029 double hashentrysize;
3032 uint64 ngroups_limit;
3045 &ngroups_limit, &num_partitions);
3047 nbatches =
Max((numGroups * hashentrysize) / mem_limit,
3048 numGroups / ngroups_limit);
3050 nbatches =
Max(ceil(nbatches), 1.0);
3051 num_partitions =
Max(num_partitions, 2);
3058 depth = ceil(log(nbatches) / log(num_partitions));
3065 pages_written = pages_read = pages * depth;
3072 pages_written *= 2.0;
3080 startup_cost += spill_cost;
3081 total_cost += spill_cost;
3093 startup_cost += qual_cost.
startup;
3104 path->
rows = output_tuples;
3118 List *windowFuncs,
int numPartCols,
int numOrderCols,
3119 Cost input_startup_cost,
Cost input_total_cost,
3120 double input_tuples)
3126 startup_cost = input_startup_cost;
3127 total_cost = input_total_cost;
3138 foreach(lc, windowFuncs)
3147 startup_cost += argcosts.
startup;
3152 startup_cost += argcosts.
startup;
3160 startup_cost += argcosts.
startup;
3163 total_cost += wfunccost * input_tuples;
3177 path->
rows = input_tuples;
3192 int numGroupCols,
double numGroups,
3194 Cost input_startup_cost,
Cost input_total_cost,
3195 double input_tuples)
3197 double output_tuples;
3201 output_tuples = numGroups;
3202 startup_cost = input_startup_cost;
3203 total_cost = input_total_cost;
3220 startup_cost += qual_cost.
startup;
3231 path->
rows = output_tuples;
3263 Path *outer_path,
Path *inner_path,
3266 Cost startup_cost = 0;
3268 double outer_path_rows = outer_path->
rows;
3269 Cost inner_rescan_start_cost;
3270 Cost inner_rescan_total_cost;
3271 Cost inner_run_cost;
3272 Cost inner_rescan_run_cost;
3276 &inner_rescan_start_cost,
3277 &inner_rescan_total_cost);
3289 if (outer_path_rows > 1)
3290 run_cost += (outer_path_rows - 1) * inner_rescan_start_cost;
3293 inner_rescan_run_cost = inner_rescan_total_cost - inner_rescan_start_cost;
3313 run_cost += inner_run_cost;
3314 if (outer_path_rows > 1)
3315 run_cost += (outer_path_rows - 1) * inner_rescan_run_cost;
3322 workspace->
total_cost = startup_cost + run_cost;
3342 double outer_path_rows = outer_path->
rows;
3343 double inner_path_rows = inner_path->
rows;
3351 if (outer_path_rows <= 0)
3352 outer_path_rows = 1;
3353 if (inner_path_rows <= 0)
3354 inner_path_rows = 1;
3389 double outer_matched_rows;
3390 double outer_unmatched_rows;
3403 outer_unmatched_rows = outer_path_rows - outer_matched_rows;
3410 ntuples = outer_matched_rows * inner_path_rows * inner_scan_frac;
3437 run_cost += inner_run_cost * inner_scan_frac;
3438 if (outer_matched_rows > 1)
3439 run_cost += (outer_matched_rows - 1) * inner_rescan_run_cost * inner_scan_frac;
3447 run_cost += outer_unmatched_rows *
3448 inner_rescan_run_cost / inner_path_rows;
3471 ntuples += outer_unmatched_rows * inner_path_rows;
3474 run_cost += inner_run_cost;
3475 if (outer_unmatched_rows >= 1)
3476 outer_unmatched_rows -= 1;
3478 outer_matched_rows -= 1;
3481 if (outer_matched_rows > 0)
3482 run_cost += outer_matched_rows * inner_rescan_run_cost * inner_scan_frac;
3485 if (outer_unmatched_rows > 0)
3486 run_cost += outer_unmatched_rows * inner_rescan_run_cost;
3494 ntuples = outer_path_rows * inner_path_rows;
3499 startup_cost += restrict_qual_cost.
startup;
3501 run_cost += cpu_per_tuple * ntuples;
3545 Path *outer_path,
Path *inner_path,
3546 List *outersortkeys,
List *innersortkeys,
3549 Cost startup_cost = 0;
3551 double outer_path_rows = outer_path->
rows;
3552 double inner_path_rows = inner_path->
rows;
3553 Cost inner_run_cost;
3565 if (outer_path_rows <= 0)
3566 outer_path_rows = 1;
3567 if (inner_path_rows <= 0)
3568 inner_path_rows = 1;
3581 if (mergeclauses && jointype !=
JOIN_FULL)
3591 opathkeys = outersortkeys ? outersortkeys : outer_path->
pathkeys;
3592 ipathkeys = innersortkeys ? innersortkeys : inner_path->
pathkeys;
3602 elog(
ERROR,
"left and right pathkeys do not match in mergejoin");
3627 outerstartsel = 0.0;
3632 innerstartsel = 0.0;
3639 outerstartsel = innerstartsel = 0.0;
3640 outerendsel = innerendsel = 1.0;
3647 outer_skip_rows = rint(outer_path_rows * outerstartsel);
3648 inner_skip_rows = rint(inner_path_rows * innerstartsel);
3652 Assert(outer_skip_rows <= outer_rows);
3653 Assert(inner_skip_rows <= inner_rows);
3660 outerstartsel = outer_skip_rows / outer_path_rows;
3661 innerstartsel = inner_skip_rows / inner_path_rows;
3662 outerendsel = outer_rows / outer_path_rows;
3663 innerendsel = inner_rows / inner_path_rows;
3665 Assert(outerstartsel <= outerendsel);
3666 Assert(innerstartsel <= innerendsel);
3685 * (outerendsel - outerstartsel);
3693 * (outerendsel - outerstartsel);
3711 * (innerendsel - innerstartsel);
3719 * (innerendsel - innerstartsel);
3734 workspace->
total_cost = startup_cost + run_cost + inner_run_cost;
3778 double inner_path_rows = inner_path->
rows;
3793 double mergejointuples,
3798 if (inner_path_rows <= 0)
3799 inner_path_rows = 1;
3881 rescannedtuples = 0;
3884 rescannedtuples = mergejointuples - inner_path_rows;
3886 if (rescannedtuples < 0)
3887 rescannedtuples = 0;
3895 rescanratio = 1.0 + (rescannedtuples / inner_rows);
3906 bare_inner_cost = inner_run_cost * rescanratio;
3921 mat_inner_cost = inner_run_cost +
3953 else if (innersortkeys ==
NIL &&
3978 run_cost += mat_inner_cost;
3980 run_cost += bare_inner_cost;
3989 startup_cost += merge_qual_cost.
startup;
3990 startup_cost += merge_qual_cost.
per_tuple *
3991 (outer_skip_rows + inner_skip_rows * rescanratio);
3993 ((outer_rows - outer_skip_rows) +
3994 (inner_rows - inner_skip_rows) * rescanratio);
4005 startup_cost += qp_qual_cost.
startup;
4007 run_cost += cpu_per_tuple * mergejointuples;
4103 Path *outer_path,
Path *inner_path,
4107 Cost startup_cost = 0;
4109 double outer_path_rows = outer_path->
rows;
4110 double inner_path_rows = inner_path->
rows;
4111 double inner_path_rows_total = inner_path_rows;
4116 size_t space_allowed;
4175 double outerpages =
page_size(outer_path_rows,
4177 double innerpages =
page_size(inner_path_rows,
4188 workspace->
total_cost = startup_cost + run_cost;
4214 double outer_path_rows = outer_path->
rows;
4215 double inner_path_rows = inner_path->
rows;
4225 double hashjointuples;
4226 double virtualbuckets;
4261 virtualbuckets = (double) numbuckets * (
double) numbatches;
4275 innerbucketsize = 1.0 / virtualbuckets;
4280 innerbucketsize = 1.0;
4282 foreach(hcl, hashclauses)
4301 if (thisbucketsize < 0)
4319 if (thisbucketsize < 0)
4332 if (innerbucketsize > thisbucketsize)
4333 innerbucketsize = thisbucketsize;
4334 if (innermcvfreq > thismcvfreq)
4335 innermcvfreq = thismcvfreq;
4366 double outer_matched_rows;
4384 startup_cost += hash_qual_cost.
startup;
4385 run_cost += hash_qual_cost.
per_tuple * outer_matched_rows *
4386 clamp_row_est(inner_path_rows * innerbucketsize * inner_scan_frac) * 0.5;
4402 (outer_path_rows - outer_matched_rows) *
4407 hashjointuples = outer_path_rows - outer_matched_rows;
4409 hashjointuples = outer_matched_rows;
4423 startup_cost += hash_qual_cost.
startup;
4424 run_cost += hash_qual_cost.
per_tuple * outer_path_rows *
4441 startup_cost += qp_qual_cost.
startup;
4443 run_cost += cpu_per_tuple * hashjointuples;
4511 sp_cost.
per_tuple += 0.50 * plan_run_cost;
4556 Cost *rescan_startup_cost,
4557 Cost *rescan_total_cost)
4570 *rescan_startup_cost = 0;
4579 if (((
HashPath *) path)->num_batches == 1)
4582 *rescan_startup_cost = 0;
4583 *rescan_total_cost = path->total_cost - path->startup_cost;
4588 *rescan_startup_cost = path->startup_cost;
4589 *rescan_total_cost = path->total_cost;
4603 path->pathtarget->width);
4604 long work_mem_bytes =
work_mem * 1024L;
4606 if (nbytes > work_mem_bytes)
4609 double npages = ceil(nbytes / BLCKSZ);
4613 *rescan_startup_cost = 0;
4614 *rescan_total_cost = run_cost;
4630 path->pathtarget->width);
4631 long work_mem_bytes =
work_mem * 1024L;
4633 if (nbytes > work_mem_bytes)
4636 double npages = ceil(nbytes / BLCKSZ);
4640 *rescan_startup_cost = 0;
4641 *rescan_total_cost = run_cost;
4647 rescan_startup_cost, rescan_total_cost);
4650 *rescan_startup_cost = path->startup_cost;
4651 *rescan_total_cost = path->total_cost;
4672 context.
root = root;
4685 *cost = context.
total;
4697 context.
root = root;
4703 *cost = context.
total;
4869 &iofunc, &typioparam);
4874 &iofunc, &typisvarlena);
4896 foreach(lc, rcexpr->
opnos)
4922 elog(
ERROR,
"cannot handle unplanned sub-select");
5057 foreach(l, restrictlist)
5062 joinquals =
lappend(joinquals, rinfo);
5066 joinquals = restrictlist;
5118 avgmatch = nselec * innerrel->
rows / jselec;
5120 avgmatch =
Max(1.0, avgmatch);
5161 indexclauses = ((
IndexPath *) innerpath)->indexclauses;
5169 indexclauses = ((
IndexPath *) bmqual)->indexclauses;
5269 tuples = selec * outer_tuples * inner_tuples;
5320 List *param_clauses)
5340 if (nrows > rel->
rows)
5404 List *restrict_clauses)
5426 if (nrows > rel->
rows)
5448 List *restrictlist_in)
5451 List *restrictlist = restrictlist_in;
5491 foreach(l, restrictlist)
5496 pushedquals =
lappend(pushedquals, rinfo);
5498 joinquals =
lappend(joinquals, rinfo);
5542 nrows = outer_rows * inner_rows * fkselec * jselec;
5546 nrows = outer_rows * inner_rows * fkselec * jselec;
5547 if (nrows < outer_rows)
5552 nrows = outer_rows * inner_rows * fkselec * jselec;
5553 if (nrows < outer_rows)
5555 if (nrows < inner_rows)
5560 nrows = outer_rows * fkselec * jselec;
5564 nrows = outer_rows * (1.0 - fkselec * jselec);
5569 elog(
ERROR,
"unrecognized join type: %d", (
int) jointype);
5597 List **restrictlist)
5601 List *worklist = *restrictlist;
5618 ref_is_outer =
false;
5621 ref_is_outer =
true;
5647 if (worklist == *restrictlist)
5651 foreach(cell, worklist)
5654 bool remove_it =
false;
5658 for (
i = 0;
i < fkinfo->
nkeys;
i++)
5697 removedlist =
lappend(removedlist, rinfo);
5727 if (removedlist ==
NIL ||
5772 double ref_tuples =
Max(ref_rel->
tuples, 1.0);
5774 fkselec *= ref_rel->
rows / ref_tuples;
5784 double ref_tuples =
Max(ref_rel->
tuples, 1.0);
5786 fkselec *= 1.0 / ref_tuples;
5801 for (
int i = 0;
i < fkinfo->
nkeys;
i++)
5828 *restrictlist = worklist;
5871 int32 item_width = 0;
5902 Var *var = (
Var *) texpr;