Skip to content

Commit 56e59ed

Browse files
committed
Fix a performance regression in 8.2: optimization of MIN/MAX into indexscans
had stopped working for tables buried inside views or sub-selects. This is because I had gotten rid of the simplify_jointree() preprocessing step, and optimize_minmax_aggregates() wasn't smart enough to deal with a non-canonical FromExpr. Per gripe from Bill Howe.
1 parent 91e18db commit 56e59ed

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/backend/optimizer/plan/planagg.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.25 2007/01/09 02:14:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.26 2007/02/06 06:50:26 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -70,6 +70,7 @@ Plan *
7070
optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
7171
{
7272
Query *parse = root->parse;
73+
FromExpr *jtnode;
7374
RangeTblRef *rtr;
7475
RangeTblEntry *rte;
7576
RelOptInfo *rel;
@@ -102,14 +103,19 @@ optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
102103
* We also restrict the query to reference exactly one table, since join
103104
* conditions can't be handled reasonably. (We could perhaps handle a
104105
* query containing cartesian-product joins, but it hardly seems worth the
105-
* trouble.)
106+
* trouble.) However, the single real table could be buried in several
107+
* levels of FromExpr.
106108
*/
107-
Assert(parse->jointree != NULL && IsA(parse->jointree, FromExpr));
108-
if (list_length(parse->jointree->fromlist) != 1)
109-
return NULL;
110-
rtr = (RangeTblRef *) linitial(parse->jointree->fromlist);
111-
if (!IsA(rtr, RangeTblRef))
109+
jtnode = parse->jointree;
110+
while (IsA(jtnode, FromExpr))
111+
{
112+
if (list_length(jtnode->fromlist) != 1)
113+
return NULL;
114+
jtnode = linitial(jtnode->fromlist);
115+
}
116+
if (!IsA(jtnode, RangeTblRef))
112117
return NULL;
118+
rtr = (RangeTblRef *) jtnode;
113119
rte = rt_fetch(rtr->rtindex, parse->rtable);
114120
if (rte->rtekind != RTE_RELATION || rte->inh)
115121
return NULL;

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