mirror of
https://github.com/postgres/postgres.git
synced 2025-05-05 09:19:17 +03:00
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.
This commit is contained in:
parent
5338847fcd
commit
a95abdf856
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.22 2006/10/04 00:29:54 momjian Exp $
|
* $PostgreSQL: pgsql/src/backend/optimizer/plan/planagg.c,v 1.22.2.1 2007/02/06 06:50:33 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -69,6 +69,7 @@ Plan *
|
|||||||
optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
|
optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
|
||||||
{
|
{
|
||||||
Query *parse = root->parse;
|
Query *parse = root->parse;
|
||||||
|
FromExpr *jtnode;
|
||||||
RangeTblRef *rtr;
|
RangeTblRef *rtr;
|
||||||
RangeTblEntry *rte;
|
RangeTblEntry *rte;
|
||||||
RelOptInfo *rel;
|
RelOptInfo *rel;
|
||||||
@ -101,14 +102,19 @@ optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
|
|||||||
* We also restrict the query to reference exactly one table, since join
|
* We also restrict the query to reference exactly one table, since join
|
||||||
* conditions can't be handled reasonably. (We could perhaps handle a
|
* conditions can't be handled reasonably. (We could perhaps handle a
|
||||||
* query containing cartesian-product joins, but it hardly seems worth the
|
* query containing cartesian-product joins, but it hardly seems worth the
|
||||||
* trouble.)
|
* trouble.) However, the single real table could be buried in several
|
||||||
|
* levels of FromExpr.
|
||||||
*/
|
*/
|
||||||
Assert(parse->jointree != NULL && IsA(parse->jointree, FromExpr));
|
jtnode = parse->jointree;
|
||||||
if (list_length(parse->jointree->fromlist) != 1)
|
while (IsA(jtnode, FromExpr))
|
||||||
|
{
|
||||||
|
if (list_length(jtnode->fromlist) != 1)
|
||||||
return NULL;
|
return NULL;
|
||||||
rtr = (RangeTblRef *) linitial(parse->jointree->fromlist);
|
jtnode = linitial(jtnode->fromlist);
|
||||||
if (!IsA(rtr, RangeTblRef))
|
}
|
||||||
|
if (!IsA(jtnode, RangeTblRef))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
rtr = (RangeTblRef *) jtnode;
|
||||||
rte = rt_fetch(rtr->rtindex, parse->rtable);
|
rte = rt_fetch(rtr->rtindex, parse->rtable);
|
||||||
if (rte->rtekind != RTE_RELATION || rte->inh)
|
if (rte->rtekind != RTE_RELATION || rte->inh)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user