Skip to content

Commit 9131902

Browse files
committed
Back-patch primary fix for planner recursion bug.
1 parent daee6ca commit 9131902

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/backend/optimizer/plan/planner.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.79 2000/04/12 17:15:22 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.79.2.1 2000/07/27 23:53:29 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -53,6 +53,22 @@ Plan *
5353
planner(Query *parse)
5454
{
5555
Plan *result_plan;
56+
Index save_PlannerQueryLevel;
57+
List *save_PlannerInitPlan;
58+
List *save_PlannerParamVar;
59+
int save_PlannerPlanId;
60+
61+
/*
62+
* The planner can be called recursively (an example is when
63+
* eval_const_expressions tries to simplify an SQL function).
64+
* So, global state variables must be saved and restored.
65+
*
66+
* (Perhaps these should be moved into the Query structure instead?)
67+
*/
68+
save_PlannerQueryLevel = PlannerQueryLevel;
69+
save_PlannerInitPlan = PlannerInitPlan;
70+
save_PlannerParamVar = PlannerParamVar;
71+
save_PlannerPlanId = PlannerPlanId;
5672

5773
/* Initialize state for subselects */
5874
PlannerQueryLevel = 1;
@@ -81,6 +97,12 @@ planner(Query *parse)
8197
/* final cleanup of the plan */
8298
set_plan_references(result_plan);
8399

100+
/* restore state for outer planner, if any */
101+
PlannerQueryLevel = save_PlannerQueryLevel;
102+
PlannerInitPlan = save_PlannerInitPlan;
103+
PlannerParamVar = save_PlannerParamVar;
104+
PlannerPlanId = save_PlannerPlanId;
105+
84106
return result_plan;
85107
}
86108

0 commit comments

Comments
 (0)