aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/subselect.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-07-18 21:41:14 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-07-18 21:41:14 +0000
commit6869810637f0f6204e2037c227dafad33a8ce3c1 (patch)
tree38afa150b12448ae8b540995788ceb3802886132 /src/backend/optimizer/plan/subselect.c
parentab04f4de7a187c4715b871675b3afa17fc59c9e1 (diff)
downloadpostgresql-6869810637f0f6204e2037c227dafad33a8ce3c1.tar.gz
postgresql-6869810637f0f6204e2037c227dafad33a8ce3c1.zip
Fix an old thinko in SS_make_initplan_from_plan, which is used when optimizing
a MIN or MAX aggregate call into an indexscan: the initplan is being made at the current query nesting level and so we shouldn't increment query_level. Though usually harmless, this mistake could lead to bogus "plan should not reference subplan's variable" failures on complex queries. Per bug report from David Sanchez i Gregori.
Diffstat (limited to 'src/backend/optimizer/plan/subselect.c')
-rw-r--r--src/backend/optimizer/plan/subselect.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/backend/optimizer/plan/subselect.c b/src/backend/optimizer/plan/subselect.c
index f041628e684..fdfa2ee87b2 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
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.112.2.1 2006/12/06 19:40:08 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/subselect.c,v 1.112.2.2 2007/07/18 21:41:14 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1306,10 +1306,14 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
Param *prm;
/*
- * Set up for a new level of subquery. This is just to keep
- * SS_finalize_plan from becoming confused.
+ * We must run SS_finalize_plan(), since that's normally done before a
+ * subplan gets put into the initplan list. However it will try to attach
+ * any pre-existing initplans to this one, which we don't want (they are
+ * siblings not children of this initplan). So, a quick kluge to hide
+ * them. (This is something else that could perhaps be cleaner if we did
+ * extParam/allParam processing in setrefs.c instead of here? See notes
+ * for materialize_finished_plan.)
*/
- PlannerQueryLevel++;
PlannerInitPlan = NIL;
/*
@@ -1317,8 +1321,7 @@ SS_make_initplan_from_plan(PlannerInfo *root, Plan *plan,
*/
SS_finalize_plan(plan, root->parse->rtable);
- /* Return to outer subquery context */
- PlannerQueryLevel--;
+ /* Restore outer initplan list */
PlannerInitPlan = saved_initplan;
/*