Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f44639e

Browse files
committed
Don't crash if subquery appears multiple times in jointree. This should
not happen anyway, but let's try not to get completely confused if it does (due to rewriter bugs or whatever).
1 parent 352871a commit f44639e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* 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 $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -279,7 +279,13 @@ pull_up_subqueries(Query *parse, Node *jtnode)
279279
/*
280280
* First, recursively pull up the subquery's subqueries,
281281
* 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.
283289
*/
284290
subquery->jointree = (FromExpr *)
285291
pull_up_subqueries(subquery, (Node *) subquery->jointree);
@@ -288,7 +294,8 @@ pull_up_subqueries(Query *parse, Node *jtnode)
288294
* no adjustments will be needed in the subquery's rtable).
289295
*/
290296
rtoffset = length(parse->rtable);
291-
parse->rtable = nconc(parse->rtable, subquery->rtable);
297+
parse->rtable = nconc(parse->rtable,
298+
copyObject(subquery->rtable));
292299
/*
293300
* Make copies of the subquery's jointree and targetlist
294301
* with varnos adjusted to match the merged rangetable.

0 commit comments

Comments
 (0)