Skip to content

Commit e8be8ff

Browse files
committed
Further tweaking of logic that decides when to materialize an uncorrelated
subplan: do it if subplan has subplans itself, and always do it if the subplan is an indexscan. (I originally set it to materialize an indexscan only if the indexqual is fairly selective, but I dunno what I was thinking ... an unselective indexscan is still expensive ...)
1 parent bbe1ff7 commit e8be8ff

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/backend/optimizer/plan/subselect.c

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.29 2000/03/02 04:08:16 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.30 2000/03/11 23:53:41 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -302,8 +302,8 @@ make_subplan(SubLink *slink)
302302
* the top of an uncorrelated/undirect correlated subplan, which lets
303303
* us do the work of evaluating the subplan only once. We do this
304304
* if the subplan's top plan node is anything more complicated than
305-
* a sequential or index scan, and we do it even for those plan types
306-
* if the qual appears selective enough to eliminate many tuples.
305+
* a plain sequential scan, and we do it even for seqscan if the
306+
* qual appears selective enough to eliminate many tuples.
307307
*/
308308
if (node->parParam == NIL)
309309
{
@@ -312,28 +312,19 @@ make_subplan(SubLink *slink)
312312
switch (nodeTag(plan))
313313
{
314314
case T_SeqScan:
315-
{
316-
Selectivity qualsel;
317-
318-
qualsel = clauselist_selectivity(subquery, plan->qual, 0);
319-
/* Is 10% selectivity a good threshold?? */
320-
use_material = qualsel < 0.10;
321-
break;
322-
}
323-
case T_IndexScan:
324-
{
325-
List *indxqual = ((IndexScan *) plan)->indxqualorig;
326-
Selectivity qualsel;
327-
328-
qualsel = clauselist_selectivity(subquery, plan->qual, 0);
329-
qualsel *= clauselist_selectivity(subquery, indxqual, 0);
330-
/* Note: if index is lossy, we just double-counted the
331-
* index selectivity. Worth fixing?
332-
*/
333-
/* Is 10% selectivity a good threshold?? */
334-
use_material = qualsel < 0.10;
315+
if (plan->initPlan || plan->subPlan)
316+
use_material = true;
317+
else
318+
{
319+
Selectivity qualsel;
320+
321+
qualsel = clauselist_selectivity(subquery,
322+
plan->qual,
323+
0);
324+
/* Is 10% selectivity a good threshold?? */
325+
use_material = qualsel < 0.10;
326+
}
335327
break;
336-
}
337328
case T_Material:
338329
case T_Sort:
339330
/* Don't add another Material node if there's one already,

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