Skip to content

SPI_keepplan with configurable memory context #43

Answered by yrashk
yrashk asked this question in Q&A
Discussion options

You must be logged in to vote

@robertmhaas provided a great answer on Discord:

When you call SPI_keepplan(), it calls SavedCachePlan() on each CachedPlanSource, which adds it to a global linked list called saved_plan_list. So if a saved plan where destroyed by deleting the memory context that contains it, then saved_plan_list would end up with garbage pointers in it, and the next access to that list would probably seg fault. So the purpose of putting the plan under CachedMemoryContext is to make sure that you always get rid of the plan using SPI_freeplan rather than any other tricky method. In theory, if you put it in some other memory context but still always explicitly used SPI_freeplan, everything would be fine. B…

Replies: 1 comment

Comment options

yrashk
Oct 18, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by yrashk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant