|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.63 2004/01/04 03:51:52 tgl Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/optimizer/path/clausesel.c,v 1.64 2004/01/05 16:44:40 tgl Exp $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
@@ -417,17 +417,38 @@ clause_selectivity(Query *root,
|
417 | 417 | * If possible, cache the result of the selectivity calculation for
|
418 | 418 | * the clause. We can cache if varRelid is zero or the clause
|
419 | 419 | * contains only vars of that relid --- otherwise varRelid will affect
|
420 |
| - * the result, so mustn't cache. We ignore the possibility that |
421 |
| - * jointype will affect the result, which should be okay because outer |
422 |
| - * join clauses will always be examined with the same jointype value. |
| 420 | + * the result, so mustn't cache. We also have to be careful about |
| 421 | + * the jointype. It's OK to cache when jointype is JOIN_INNER or |
| 422 | + * one of the outer join types (any given outer-join clause should |
| 423 | + * always be examined with the same jointype, so result won't change). |
| 424 | + * It's not OK to cache when jointype is one of the special types |
| 425 | + * associated with IN processing, because the same clause may be |
| 426 | + * examined with different jointypes and the result should vary. |
423 | 427 | */
|
424 | 428 | if (varRelid==0||
|
425 | 429 | bms_is_subset_singleton(rinfo->clause_relids,varRelid))
|
426 | 430 | {
|
427 |
| -/* Cacheable --- do we already have the result? */ |
428 |
| -if (rinfo->this_selec >=0) |
429 |
| -returnrinfo->this_selec; |
430 |
| -cacheable= true; |
| 431 | +switch (jointype) |
| 432 | +{ |
| 433 | +caseJOIN_INNER: |
| 434 | +caseJOIN_LEFT: |
| 435 | +caseJOIN_FULL: |
| 436 | +caseJOIN_RIGHT: |
| 437 | +/* Cacheable --- do we already have the result? */ |
| 438 | +if (rinfo->this_selec >=0) |
| 439 | +returnrinfo->this_selec; |
| 440 | +cacheable= true; |
| 441 | +break; |
| 442 | + |
| 443 | +caseJOIN_UNION: |
| 444 | +/* unimplemented anyway... */ |
| 445 | +caseJOIN_IN: |
| 446 | +caseJOIN_REVERSE_IN: |
| 447 | +caseJOIN_UNIQUE_OUTER: |
| 448 | +caseJOIN_UNIQUE_INNER: |
| 449 | +/* unsafe to cache */ |
| 450 | +break; |
| 451 | +} |
431 | 452 | }
|
432 | 453 |
|
433 | 454 | /* Proceed with examination of contained clause */
|
|