*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.148 2003/02/15 21:39:58 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.149 2003/03/05 18:38:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
int parentRTindex = parse->resultRelation;
Oid parentOID = getrelid(parentRTindex, parse->rtable);
+ int mainrtlength = length(parse->rtable);
List *subplans = NIL;
List *tlist = NIL;
List *l;
{
int childRTindex = lfirsti(l);
Oid childOID = getrelid(childRTindex, parse->rtable);
+ int subrtlength;
Query *subquery;
Plan *subplan;
/* Generate plan */
subplan = grouping_planner(subquery, 0.0 /* retrieve all tuples */ );
subplans = lappend(subplans, subplan);
+ /*
+ * It's possible that additional RTEs got added to the rangetable
+ * due to expansion of inherited source tables (see allpaths.c).
+ * If so, we must copy 'em back to the main parse tree's rtable.
+ *
+ * XXX my goodness this is ugly. Really need to think about ways
+ * to rein in planner's habit of scribbling on its input.
+ */
+ subrtlength = length(subquery->rtable);
+ if (subrtlength > mainrtlength)
+ {
+ List *subrt = subquery->rtable;
+
+ while (mainrtlength-- > 0) /* wish we had nthcdr() */
+ subrt = lnext(subrt);
+ parse->rtable = nconc(parse->rtable, subrt);
+ mainrtlength = subrtlength;
+ }
/* Save preprocessed tlist from first rel for use in Append */
if (tlist == NIL)
tlist = subplan->targetlist;