Commit 21fb95da authored by Tom Lane's avatar Tom Lane

Use a fresh copy of query_list when making a second plan in GetCachedPlan.

The code path that tried a generic plan, didn't like it, and then made a
custom plan was mistakenly passing the same copy of the query_list to the
planner both times.  This doesn't work too well for nontrivial queries,
since the planner tends to scribble on its input.  Diagnosis and fix by
Yamamoto Takashi.
parent 2a571bc2
...@@ -697,7 +697,8 @@ CheckCachedPlan(CachedPlanSource *plansource) ...@@ -697,7 +697,8 @@ CheckCachedPlan(CachedPlanSource *plansource)
/* /*
* BuildCachedPlan: construct a new CachedPlan from a CachedPlanSource. * BuildCachedPlan: construct a new CachedPlan from a CachedPlanSource.
* *
* qlist should be the result value from a previous RevalidateCachedQuery. * qlist should be the result value from a previous RevalidateCachedQuery,
* or it can be set to NIL if we need to re-copy the plansource's query_list.
* *
* To build a generic, parameter-value-independent plan, pass NULL for * To build a generic, parameter-value-independent plan, pass NULL for
* boundParams. To build a custom plan, pass the actual parameter values via * boundParams. To build a custom plan, pass the actual parameter values via
...@@ -980,6 +981,13 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams, ...@@ -980,6 +981,13 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
* plan. * plan.
*/ */
customplan = choose_custom_plan(plansource, boundParams); customplan = choose_custom_plan(plansource, boundParams);
/*
* If we choose to plan again, we need to re-copy the query_list,
* since the planner probably scribbled on it. We can force
* BuildCachedPlan to do that by passing NIL.
*/
qlist = NIL;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment