| 1001 | } |
| 1002 | |
| 1003 | int |
| 1004 | SPI_keepplan(SPIPlanPtr plan) |
| 1005 | { |
| 1006 | ListCell *lc; |
| 1007 | |
| 1008 | if (plan == NULL || plan->magic != _SPI_PLAN_MAGIC || |
| 1009 | plan->saved || plan->oneshot) |
| 1010 | return SPI_ERROR_ARGUMENT; |
| 1011 | |
| 1012 | /* |
| 1013 | * Mark it saved, reparent it under CacheMemoryContext, and mark all the |
| 1014 | * component CachedPlanSources as saved. This sequence cannot fail |
| 1015 | * partway through, so there's no risk of long-term memory leakage. |
| 1016 | */ |
| 1017 | plan->saved = true; |
| 1018 | MemoryContextSetParent(plan->plancxt, CacheMemoryContext); |
| 1019 | |
| 1020 | foreach(lc, plan->plancache_list) |
| 1021 | { |
| 1022 | CachedPlanSource *plansource = (CachedPlanSource *) lfirst(lc); |
| 1023 | |
| 1024 | SaveCachedPlan(plansource); |
| 1025 | } |
| 1026 | |
| 1027 | return 0; |
| 1028 | } |
| 1029 | |
| 1030 | SPIPlanPtr |
| 1031 | SPI_saveplan(SPIPlanPtr plan) |