|
8 | 8 | * |
9 | 9 | * |
10 | 10 | * IDENTIFICATION |
11 | | - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.75 2000/02/15 20:49:18 tgl Exp $ |
| 11 | + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.76 2000/02/21 01:13:04 tgl Exp $ |
12 | 12 | * |
13 | 13 | *------------------------------------------------------------------------- |
14 | 14 | */ |
@@ -291,30 +291,46 @@ union_planner(Query *parse, |
291 | 291 | /* Initial assumption is we need all the tuples */ |
292 | 292 | tuple_fraction = 0.0; |
293 | 293 | /* |
294 | | - * Check for a LIMIT. |
295 | | - * |
296 | | - * For now, we deliberately ignore the OFFSET clause, so that |
297 | | - * queries with the same LIMIT and different OFFSETs will get |
298 | | - * the same queryplan and therefore generate consistent results |
299 | | - * (to the extent the planner can guarantee that, anyway). |
300 | | - * XXX Perhaps it would be better to use the OFFSET too, and tell |
301 | | - * users to specify ORDER BY if they want consistent results |
302 | | - * across different LIMIT queries. |
| 294 | + * Check for a LIMIT clause. |
303 | 295 | */ |
304 | 296 | if (parse->limitCount != NULL) |
305 | 297 | { |
306 | 298 | if (IsA(parse->limitCount, Const)) |
307 | 299 | { |
308 | | - Const *ccount = (Const *) parse->limitCount; |
309 | | - tuple_fraction = (double) ((int) (ccount->constvalue)); |
310 | | - /* the constant can legally be either 0 ("ALL") or a |
311 | | - * positive integer; either is consistent with our |
312 | | - * conventions for tuple_fraction. |
| 300 | + Const *limitc = (Const *) parse->limitCount; |
| 301 | + int count = (int) (limitc->constvalue); |
| 302 | + |
| 303 | + /* |
| 304 | + * The constant can legally be either 0 ("ALL") or a |
| 305 | + * positive integer. If it is not ALL, we also need |
| 306 | + * to consider the OFFSET part of LIMIT. |
313 | 307 | */ |
| 308 | + if (count > 0) |
| 309 | + { |
| 310 | + tuple_fraction = (double) count; |
| 311 | + if (parse->limitOffset != NULL) |
| 312 | + { |
| 313 | + if (IsA(parse->limitOffset, Const)) |
| 314 | + { |
| 315 | + int offset; |
| 316 | + |
| 317 | + limitc = (Const *) parse->limitOffset; |
| 318 | + offset = (int) (limitc->constvalue); |
| 319 | + if (offset > 0) |
| 320 | + tuple_fraction += (double) offset; |
| 321 | + } |
| 322 | + else |
| 323 | + { |
| 324 | + /* It's a PARAM ... punt ... */ |
| 325 | + tuple_fraction = 0.10; |
| 326 | + } |
| 327 | + } |
| 328 | + } |
314 | 329 | } |
315 | 330 | else |
316 | 331 | { |
317 | | - /* It's a PARAM ... don't know exactly what the limit |
| 332 | + /* |
| 333 | + * COUNT is a PARAM ... don't know exactly what the limit |
318 | 334 | * will be, but for lack of a better idea assume 10% |
319 | 335 | * of the plan's result is wanted. |
320 | 336 | */ |
|
0 commit comments