|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.32 2000/03/23 00:58:36 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/clausesel.c,v 1.33 2000/03/23 23:35:47 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -186,20 +186,32 @@ clauselist_selectivity(Query *root,
|
186 | 186 | /* Successfully matched a pair of range clauses */
|
187 | 187 | Selectivity s2 = rqlist->hibound + rqlist->lobound - 1.0;
|
188 | 188 |
|
189 |
| - if (s2 > 0.0) |
190 |
| - { |
191 |
| - /* All our hard work has paid off! */ |
192 |
| - s1 *= s2; |
193 |
| - } |
194 |
| - else |
| 189 | + /* |
| 190 | + * A zero or slightly negative s2 should be converted into a |
| 191 | + * small positive value; we probably are dealing with a very |
| 192 | + * tight range and got a bogus result due to roundoff errors. |
| 193 | + * However, if s2 is very negative, then we probably have |
| 194 | + * default selectivity estimates on one or both sides of the |
| 195 | + * range. In that case, insert a not-so-wildly-optimistic |
| 196 | + * default estimate. |
| 197 | + */ |
| 198 | + if (s2 <= 0.0) |
195 | 199 | {
|
196 |
| - /* One or both is probably a default estimate, |
197 |
| - * so supply a default estimate for the selectivity |
198 |
| - * of the range query. We rather optimistically assume |
199 |
| - * that the range is tight... |
200 |
| - */ |
201 |
| - s1 *= 0.01; |
| 200 | + if (s2 < -0.01) |
| 201 | + { |
| 202 | + /* No data available --- use a default estimate that |
| 203 | + * is small, but not real small. |
| 204 | + */ |
| 205 | + s2 = 0.01; |
| 206 | + } |
| 207 | + else |
| 208 | + { |
| 209 | + /* It's just roundoff error; use a small positive value */ |
| 210 | + s2 = 1.0e-10; |
| 211 | + } |
202 | 212 | }
|
| 213 | + /* Merge in the selectivity of the pair of clauses */ |
| 214 | + s1 *= s2; |
203 | 215 | }
|
204 | 216 | else
|
205 | 217 | {
|
|
0 commit comments