Skip to content

Commit cce442d

Browse files
committed
Dept. of second thoughts: clause_selectivity shouldn't try to cache its
result for jointypes associated with IN processing.
1 parent 9091e8d commit cce442d

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/backend/optimizer/path/clausesel.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -417,17 +417,38 @@ clause_selectivity(Query *root,
417417
* If possible, cache the result of the selectivity calculation for
418418
* the clause. We can cache if varRelid is zero or the clause
419419
* 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.
423427
*/
424428
if (varRelid == 0 ||
425429
bms_is_subset_singleton(rinfo->clause_relids, varRelid))
426430
{
427-
/* Cacheable --- do we already have the result? */
428-
if (rinfo->this_selec >= 0)
429-
return rinfo->this_selec;
430-
cacheable = true;
431+
switch (jointype)
432+
{
433+
case JOIN_INNER:
434+
case JOIN_LEFT:
435+
case JOIN_FULL:
436+
case JOIN_RIGHT:
437+
/* Cacheable --- do we already have the result? */
438+
if (rinfo->this_selec >= 0)
439+
return rinfo->this_selec;
440+
cacheable = true;
441+
break;
442+
443+
case JOIN_UNION:
444+
/* unimplemented anyway... */
445+
case JOIN_IN:
446+
case JOIN_REVERSE_IN:
447+
case JOIN_UNIQUE_OUTER:
448+
case JOIN_UNIQUE_INNER:
449+
/* unsafe to cache */
450+
break;
451+
}
431452
}
432453

433454
/* Proceed with examination of contained clause */

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy