|
107 | 107 | */
|
108 | 108 | #define APPEND_CPU_COST_MULTIPLIER 0.5
|
109 | 109 |
|
| 110 | +/* |
| 111 | + * Maximum value for row estimates. We cap row estimates to this to help |
| 112 | + * ensure that costs based on these estimates remain within the range of what |
| 113 | + * double can represent. add_path() wouldn't act sanely given infinite or NaN |
| 114 | + * cost values. |
| 115 | + */ |
| 116 | +#define MAXIMUM_ROWCOUNT 1e100 |
110 | 117 |
|
111 | 118 | double seq_page_cost = DEFAULT_SEQ_PAGE_COST;
|
112 | 119 | double random_page_cost = DEFAULT_RANDOM_PAGE_COST;
|
@@ -189,11 +196,14 @@ double
|
189 | 196 | clamp_row_est(double nrows)
|
190 | 197 | {
|
191 | 198 | /*
|
192 |
| - * Force estimate to be at least one row, to make explain output look |
193 |
| - * better and to avoid possible divide-by-zero when interpolating costs. |
194 |
| - * Make it an integer, too. |
| 199 | + * Avoid infinite and NaN row estimates. Costs derived from such values |
| 200 | + * are going to be useless. Also force the estimate to be at least one |
| 201 | + * row, to make explain output look better and to avoid possible |
| 202 | + * divide-by-zero when interpolating costs. Make it an integer, too. |
195 | 203 | */
|
196 |
| - if (nrows <= 1.0) |
| 204 | + if (nrows > MAXIMUM_ROWCOUNT || isnan(nrows)) |
| 205 | + nrows = MAXIMUM_ROWCOUNT; |
| 206 | + else if (nrows <= 1.0) |
197 | 207 | nrows = 1.0;
|
198 | 208 | else
|
199 | 209 | nrows = rint(nrows);
|
@@ -2737,12 +2747,11 @@ final_cost_nestloop(PlannerInfo *root, NestPath *path,
|
2737 | 2747 | QualCost restrict_qual_cost;
|
2738 | 2748 | double ntuples;
|
2739 | 2749 |
|
2740 |
| - /* Protect some assumptions below that rowcounts aren't zero or NaN */ |
2741 |
| - if (outer_path_rows <= 0 || isnan(outer_path_rows)) |
| 2750 | + /* Protect some assumptions below that rowcounts aren't zero */ |
| 2751 | + if (outer_path_rows <= 0) |
2742 | 2752 | outer_path_rows = 1;
|
2743 |
| - if (inner_path_rows <= 0 || isnan(inner_path_rows)) |
| 2753 | + if (inner_path_rows <= 0) |
2744 | 2754 | inner_path_rows = 1;
|
2745 |
| - |
2746 | 2755 | /* Mark the path with the correct row estimate */
|
2747 | 2756 | if (path->path.param_info)
|
2748 | 2757 | path->path.rows = path->path.param_info->ppi_rows;
|
@@ -2952,10 +2961,10 @@ initial_cost_mergejoin(PlannerInfo *root, JoinCostWorkspace *workspace,
|
2952 | 2961 | innerendsel;
|
2953 | 2962 | Path sort_path; /* dummy for result of cost_sort */
|
2954 | 2963 |
|
2955 |
| - /* Protect some assumptions below that rowcounts aren't zero or NaN */ |
2956 |
| - if (outer_path_rows <= 0 || isnan(outer_path_rows)) |
| 2964 | + /* Protect some assumptions below that rowcounts aren't zero */ |
| 2965 | + if (outer_path_rows <= 0) |
2957 | 2966 | outer_path_rows = 1;
|
2958 |
| - if (inner_path_rows <= 0 || isnan(inner_path_rows)) |
| 2967 | + if (inner_path_rows <= 0) |
2959 | 2968 | inner_path_rows = 1;
|
2960 | 2969 |
|
2961 | 2970 | /*
|
@@ -3185,8 +3194,8 @@ final_cost_mergejoin(PlannerInfo *root, MergePath *path,
|
3185 | 3194 | rescannedtuples;
|
3186 | 3195 | double rescanratio;
|
3187 | 3196 |
|
3188 |
| - /* Protect some assumptions below that rowcounts aren't zero or NaN */ |
3189 |
| - if (inner_path_rows <= 0 || isnan(inner_path_rows)) |
| 3197 | + /* Protect some assumptions below that rowcounts aren't zero */ |
| 3198 | + if (inner_path_rows <= 0) |
3190 | 3199 | inner_path_rows = 1;
|
3191 | 3200 |
|
3192 | 3201 | /* Mark the path with the correct row estimate */
|
|
0 commit comments