8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.100 2001/01/24 19 :42:59 momjian Exp $
11
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.101 2001/01/27 04 :42:32 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -279,7 +279,13 @@ pull_up_subqueries(Query *parse, Node *jtnode)
279
279
/*
280
280
* First, recursively pull up the subquery's subqueries,
281
281
* so that this routine's processing is complete for its
282
- * jointree and rangetable.
282
+ * jointree and rangetable. NB: if the same subquery is
283
+ * referenced from multiple jointree items (which can't happen
284
+ * normally, but might after rule rewriting), then we will invoke
285
+ * this processing multiple times on that subquery. OK because
286
+ * nothing will happen after the first time. We do have to be
287
+ * careful to copy everything we pull up, however, or risk
288
+ * having chunks of structure multiply linked.
283
289
*/
284
290
subquery -> jointree = (FromExpr * )
285
291
pull_up_subqueries (subquery , (Node * ) subquery -> jointree );
@@ -288,7 +294,8 @@ pull_up_subqueries(Query *parse, Node *jtnode)
288
294
* no adjustments will be needed in the subquery's rtable).
289
295
*/
290
296
rtoffset = length (parse -> rtable );
291
- parse -> rtable = nconc (parse -> rtable , subquery -> rtable );
297
+ parse -> rtable = nconc (parse -> rtable ,
298
+ copyObject (subquery -> rtable ));
292
299
/*
293
300
* Make copies of the subquery's jointree and targetlist
294
301
* with varnos adjusted to match the merged rangetable.
0 commit comments