|
8 | 8 | *
|
9 | 9 | *
|
10 | 10 | * 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 $ |
12 | 12 | *
|
13 | 13 | *-------------------------------------------------------------------------
|
14 | 14 | */
|
|
70 | 70 | optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
|
71 | 71 | {
|
72 | 72 | Query *parse = root->parse;
|
| 73 | + FromExpr *jtnode; |
73 | 74 | RangeTblRef *rtr;
|
74 | 75 | RangeTblEntry *rte;
|
75 | 76 | RelOptInfo *rel;
|
@@ -102,14 +103,19 @@ optimize_minmax_aggregates(PlannerInfo *root, List *tlist, Path *best_path)
|
102 | 103 | * We also restrict the query to reference exactly one table, since join
|
103 | 104 | * conditions can't be handled reasonably. (We could perhaps handle a
|
104 | 105 | * 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. |
106 | 108 | */
|
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)) |
112 | 117 | return NULL;
|
| 118 | + rtr = (RangeTblRef *) jtnode; |
113 | 119 | rte = rt_fetch(rtr->rtindex, parse->rtable);
|
114 | 120 | if (rte->rtekind != RTE_RELATION || rte->inh)
|
115 | 121 | return NULL;
|
|
0 commit comments