aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2000-08-06 04:13:22 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2000-08-06 04:13:22 +0000
commit465a3b0a2494091450da12975fece1613fdcc68a (patch)
treeb79de77c50b5d3ba06cfbe7ec0a209145db01a70
parent75b61043b0e95b2ff1f8b9d82c8ecf6a23519b3c (diff)
downloadpostgresql-465a3b0a2494091450da12975fece1613fdcc68a.tar.gz
postgresql-465a3b0a2494091450da12975fece1613fdcc68a.zip
Copy sub-Query nodes to avoid trouble when same sub-Query is linked to
multiple times in the parsetree (can happen in COALESCE or BETWEEN contexts, for example). This is a pretty grotty solution --- it will do for now, but perhaps we can do better when we redesign querytrees. What we need is a consistent policy about whether querytrees should be considered read-only structures or not ...
-rw-r--r--src/backend/optimizer/plan/subselect.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index 6d69171f1b4..b0772b83f1c 100644
--- a/src/backend/optimizer/plan/subselect.c
+++ b/src/backend/optimizer/plan/subselect.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.39 2000/07/12 02:37:09 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.40 2000/08/06 04:13:22 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -134,14 +134,25 @@ make_subplan(SubLink *slink)
PlannerQueryLevel++; /* we become child */
- /* Check to see if this node was already processed; if so we have
- * trouble. Someday should change tree representation so that we can
- * cope with multiple links to the same subquery, but for now...
+ /*
+ * Check to see if this node was already processed; if so we have
+ * trouble. We check to see if the linked-to Query appears to have
+ * been planned already, too.
*/
if (subquery == NULL)
+ elog(ERROR, "make_subplan: invalid expression structure (SubLink already processed?)");
+ if (subquery->base_rel_list != NIL)
elog(ERROR, "make_subplan: invalid expression structure (subquery already processed?)");
/*
+ * Copy the source Query node. This is a quick and dirty kluge to resolve
+ * the fact that the parser can generate trees with multiple links to the
+ * same sub-Query node, but the planner wants to scribble on the Query.
+ * Try to clean this up when we do querytree redesign...
+ */
+ subquery = (Query *) copyObject(subquery);
+
+ /*
* For an EXISTS subplan, tell lower-level planner to expect that only
* the first tuple will be retrieved. For ALL and ANY subplans, we
* will be able to stop evaluating if the test condition fails, so