diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-27 04:42:32 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2001-01-27 04:42:32 +0000 |
commit | f44639e1bf87c317c51e6882bef035614f25c7e6 (patch) | |
tree | c94454e0001eba37cb43267a0cd9f234807166bc /src | |
parent | 352871ac9338e856b9a1cb7783148e6ac80dd84a (diff) | |
download | postgresql-f44639e1bf87c317c51e6882bef035614f25c7e6.tar.gz postgresql-f44639e1bf87c317c51e6882bef035614f25c7e6.zip |
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).
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index fbbb5aeac96..9faf6b95e80 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.100 2001/01/24 19:42:59 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.101 2001/01/27 04:42:32 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -279,7 +279,13 @@ pull_up_subqueries(Query *parse, Node *jtnode) /* * First, recursively pull up the subquery's subqueries, * so that this routine's processing is complete for its - * jointree and rangetable. + * jointree and rangetable. NB: if the same subquery is + * referenced from multiple jointree items (which can't happen + * normally, but might after rule rewriting), then we will invoke + * this processing multiple times on that subquery. OK because + * nothing will happen after the first time. We do have to be + * careful to copy everything we pull up, however, or risk + * having chunks of structure multiply linked. */ subquery->jointree = (FromExpr *) pull_up_subqueries(subquery, (Node *) subquery->jointree); @@ -288,7 +294,8 @@ pull_up_subqueries(Query *parse, Node *jtnode) * no adjustments will be needed in the subquery's rtable). */ rtoffset = length(parse->rtable); - parse->rtable = nconc(parse->rtable, subquery->rtable); + parse->rtable = nconc(parse->rtable, + copyObject(subquery->rtable)); /* * Make copies of the subquery's jointree and targetlist * with varnos adjusted to match the merged rangetable. |