diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2000-04-14 00:19:17 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2000-04-14 00:19:17 +0000 |
commit | 9d91db4fdeaa32d2680b08fe15f62599ffd22c83 (patch) | |
tree | eeb2455cf168fe3ec3da077365ec448592cad734 /src/backend/optimizer/plan/subselect.c | |
parent | 2e67ecaf6f30b56411a75ceb5987f487a54387e9 (diff) | |
download | postgresql-9d91db4fdeaa32d2680b08fe15f62599ffd22c83.tar.gz postgresql-9d91db4fdeaa32d2680b08fe15f62599ffd22c83.zip |
Repair bug reported by Wickstrom: backend would crash if WHERE clause
contained a sub-SELECT nested within an AND/OR tree that cnfify()
thought it should rearrange. Same physical sub-SELECT node could
end up linked into multiple places in resulting expression tree.
This is harmless for most node types, but not for SubLink.
Repair bug by making physical copies of subexpressions that get
logically duplicated by cnfify(). Also, tweak the heuristic that
decides whether it's a good idea to do cnfify() --- we don't really
want that to happen when it would cause multiple copies of a subselect
to be generated, I think.
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r-- | src/backend/optimizer/plan/subselect.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c index 3493bfda245..373b05d42fe 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.35 2000/04/12 17:15:22 momjian Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/subselect.c,v 1.36 2000/04/14 00:19:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -136,6 +136,13 @@ 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... + */ + if (subquery == NULL) + elog(ERROR, "make_subplan: invalid expression structure (subquery already processed?)"); + /* * For an EXISTS subplan, tell lower-level planner to expect that only * the first tuple will be retrieved. For ALL and ANY subplans, we @@ -194,7 +201,7 @@ make_subplan(SubLink *slink) node->plan_id = PlannerPlanId++; node->rtable = subquery->rtable; node->sublink = slink; - slink->subselect = NULL; /* cool ?! */ + slink->subselect = NULL; /* cool ?! see error check above! */ /* make parParam list of params coming from current query level */ foreach(lst, plan->extParam) |