forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commita90c950
committed
Prevent overly large and NaN row estimates in relations
Given a query with enough joins, it was possible that the query planner,after multiplying the row estimates with the join selectivity that theestimated number of rows would exceed the limits of the double data typeand become infinite.To give an indication on how extreme a case is required to hit this, theparticular example case reported required 379 joins to a table without anystatistics, which resulted in the 1.0/DEFAULT_NUM_DISTINCT being used forthe join selectivity. This eventually caused the row estimates to goinfinite and resulted in an assert failure in initial_cost_mergejoin()where the infinite row estimated was multiplied by an outerstartsel of 0.0resulting in NaN. The failing assert verified that NaN <= Inf, which isfalse.To get around this we use clamp_row_est() to cap row estimates at amaximum of 1e100. This value is thought to be low enough that costsderived from it would remain within the bounds of what the double type canrepresent.Aside from fixing the failing Assert, this also has the added benefit ofmaking it so add_path() will still receive proper numerical values ascosts which will allow it to make more sane choices when determining thecheaper path in extreme cases such as the one described above.Additionally, we also get rid of the isnan() checks in the join costingfunctions. The actual case which originally triggered those checks to beadded in the first place never made it to the mailing lists. It seemslikely that the new code being added to clamp_row_est() will result inthose becoming checks redundant, so just remove them.The fairly harmless assert failure problem does also exist in thebackbranches, however, a more minimalistic fix will be applied there.Reported-by: Onder KalaciReviewed-by: Tom LaneDiscussion:https://postgr.es/m/DM6PR21MB1211FF360183BCA901B27F04D80B0@DM6PR21MB1211.namprd21.prod.outlook.com1 parentd5a9a66 commita90c950
1 file changed
+22
-13
lines changedLines changed: 22 additions & 13 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
107 | 107 |
| |
108 | 108 |
| |
109 | 109 |
| |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
110 | 117 |
| |
111 | 118 |
| |
112 | 119 |
| |
| |||
189 | 196 |
| |
190 | 197 |
| |
191 | 198 |
| |
192 |
| - | |
193 |
| - | |
194 |
| - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
195 | 203 |
| |
196 |
| - | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
197 | 207 |
| |
198 | 208 |
| |
199 | 209 |
| |
| |||
2737 | 2747 |
| |
2738 | 2748 |
| |
2739 | 2749 |
| |
2740 |
| - | |
2741 |
| - | |
| 2750 | + | |
| 2751 | + | |
2742 | 2752 |
| |
2743 |
| - | |
| 2753 | + | |
2744 | 2754 |
| |
2745 |
| - | |
2746 | 2755 |
| |
2747 | 2756 |
| |
2748 | 2757 |
| |
| |||
2952 | 2961 |
| |
2953 | 2962 |
| |
2954 | 2963 |
| |
2955 |
| - | |
2956 |
| - | |
| 2964 | + | |
| 2965 | + | |
2957 | 2966 |
| |
2958 |
| - | |
| 2967 | + | |
2959 | 2968 |
| |
2960 | 2969 |
| |
2961 | 2970 |
| |
| |||
3185 | 3194 |
| |
3186 | 3195 |
| |
3187 | 3196 |
| |
3188 |
| - | |
3189 |
| - | |
| 3197 | + | |
| 3198 | + | |
3190 | 3199 |
| |
3191 | 3200 |
| |
3192 | 3201 |
| |
|
0 commit comments
Comments
(0)