*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.124 2002/09/04 20:31:21 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.125 2002/09/24 18:38:23 tgl Exp $
*
*-------------------------------------------------------------------------
*/
/*
* Now make a modifiable copy of the subquery that we can run
- * OffsetVarNodes on.
+ * OffsetVarNodes and IncrementVarSublevelsUp on.
*/
subquery = copyObject(subquery);
/*
- * Adjust varnos in subquery so that we can append its
+ * Adjust level-0 varnos in subquery so that we can append its
* rangetable to upper query's.
*/
rtoffset = length(parse->rtable);
OffsetVarNodes((Node *) subquery, rtoffset, 0);
/*
+ * Upper-level vars in subquery are now one level closer to their
+ * parent than before.
+ */
+ IncrementVarSublevelsUp((Node *) subquery, -1, 1);
+
+ /*
* Replace all of the top query's references to the subquery's
* outputs with copies of the adjusted subtlist items, being
* careful not to replace any of the jointree structure.