1616 *
1717 *
1818 * IDENTIFICATION
19- * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.12 2003/09/25 06:58:00 petere Exp $
19+ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.13 2003/10/13 23:48:16 tgl Exp $
2020 *
2121 *-------------------------------------------------------------------------
2222 */
@@ -148,9 +148,10 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
148148 * If we are inside an outer join, only pull up subqueries whose
149149 * targetlists are nullable --- otherwise substituting their tlist
150150 * entries for upper Var references would do the wrong thing (the
151- * results wouldn't become NULL when they're supposed to). XXX
152- * This could be improved by generating pseudo-variables for such
153- * expressions; we'd have to figure out how to get the pseudo-
151+ * results wouldn't become NULL when they're supposed to).
152+ *
153+ * XXX This could be improved by generating pseudo-variables for
154+ * such expressions; we'd have to figure out how to get the pseudo-
154155 * variables evaluated at the right place in the modified plan
155156 * tree. Fix it someday.
156157 *
@@ -167,23 +168,25 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
167168List * rt ;
168169
169170/*
170- * First, pull up any IN clauses within the subquery's WHERE,
171+ * First make a modifiable copy of the subquery. This avoids
172+ * problems if the same subquery is referenced from multiple
173+ * jointree items (which can't happen normally, but might after
174+ * rule rewriting).
175+ */
176+ subquery = copyObject (subquery );
177+
178+ /*
179+ * Pull up any IN clauses within the subquery's WHERE,
171180 * so that we don't leave unoptimized INs behind.
172181 */
173182if (subquery -> hasSubLinks )
174183subquery -> jointree -> quals = pull_up_IN_clauses (subquery ,
175184subquery -> jointree -> quals );
176185
177186/*
178- *Now, recursively pull up the subquery's subqueries, so that
187+ *Recursively pull up the subquery's subqueries, so that
179188 * this routine's processing is complete for its jointree and
180- * rangetable.NB: if the same subquery is referenced from
181- * multiple jointree items (which can't happen normally, but
182- * might after rule rewriting), then we will invoke this
183- * processing multiple times on that subquery.OK because
184- * nothing will happen after the first time. We do have to be
185- * careful to copy everything we pull up, however, or risk
186- * having chunks of structure multiply linked.
189+ * rangetable.
187190 *
188191 * Note: 'false' is correct here even if we are within an outer
189192 * join in the upper query; the lower query starts with a
@@ -193,12 +196,6 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
193196pull_up_subqueries (subquery , (Node * )subquery -> jointree ,
194197 false);
195198
196- /*
197- * Now make a modifiable copy of the subquery that we can run
198- * OffsetVarNodes and IncrementVarSublevelsUp on.
199- */
200- subquery = copyObject (subquery );
201-
202199/*
203200 * Adjust level-0 varnos in subquery so that we can append its
204201 * rangetable to upper query's.