Skip to content

Commit 21fb95d

Browse files
committed
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.
1 parent 2a571bc commit 21fb95d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/backend/utils/cache/plancache.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,8 @@ CheckCachedPlan(CachedPlanSource *plansource)
697697
/*
698698
* BuildCachedPlan: construct a new CachedPlan from a CachedPlanSource.
699699
*
700-
* qlist should be the result value from a previous RevalidateCachedQuery.
700+
* qlist should be the result value from a previous RevalidateCachedQuery,
701+
* or it can be set to NIL if we need to re-copy the plansource's query_list.
701702
*
702703
* To build a generic, parameter-value-independent plan, pass NULL for
703704
* boundParams. To build a custom plan, pass the actual parameter values via
@@ -980,6 +981,13 @@ GetCachedPlan(CachedPlanSource *plansource, ParamListInfo boundParams,
980981
* plan.
981982
*/
982983
customplan = choose_custom_plan(plansource, boundParams);
984+
985+
/*
986+
* If we choose to plan again, we need to re-copy the query_list,
987+
* since the planner probably scribbled on it. We can force
988+
* BuildCachedPlan to do that by passing NIL.
989+
*/
990+
qlist = NIL;
983991
}
984992
}
985993

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy