Skip to content

Commit 3017000

Browse files
committed
Back-patch fix to copy sub-Query nodes before planning them. This
fixes problems with subselects appearing in contexts like COALESCE or BETWEEN, where parser will make multiple links to same subexpression.
1 parent c3aab02 commit 3017000

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/backend/optimizer/plan/subselect.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.36 2000/04/14 00:19:16 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.36.2.1 2000/09/23 21:00:05 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -136,13 +136,24 @@ make_subplan(SubLink *slink)
136136

137137
PlannerQueryLevel++; /* we become child */
138138

139-
/* Check to see if this node was already processed; if so we have
140-
* trouble. Someday should change tree representation so that we can
141-
* cope with multiple links to the same subquery, but for now...
139+
/*
140+
* Check to see if this node was already processed; if so we have
141+
* trouble. We check to see if the linked-to Query appears to have
142+
* been planned already, too.
142143
*/
143144
if (subquery == NULL)
145+
elog(ERROR, "make_subplan: invalid expression structure (SubLink already processed?)");
146+
if (subquery->base_rel_list != NIL)
144147
elog(ERROR, "make_subplan: invalid expression structure (subquery already processed?)");
145148

149+
/*
150+
* Copy the source Query node. This is a quick and dirty kluge to resolve
151+
* the fact that the parser can generate trees with multiple links to the
152+
* same sub-Query node, but the planner wants to scribble on the Query.
153+
* Try to clean this up when we do querytree redesign...
154+
*/
155+
subquery = (Query *) copyObject(subquery);
156+
146157
/*
147158
* For an EXISTS subplan, tell lower-level planner to expect that only
148159
* the first tuple will be retrieved. For ALL and ANY subplans, we

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy