The following documentation comment has been logged on the website: Page: https://www.postgresql.org/docs/15/index-functions.html Description:
So, if I cache something in ii_AmCache during a call to my aminsert callback... When, if ever, does it get freed? Having looked at example code, I don't actually see anything doing this in insert paths, so presumably there's some point at which this happens automatically, possibly as part of the Memory Context thing, maybe related to the ii_Context which seems to be getting used, but I can't find anything anywhere documenting that. This may well be completely obvious, or intended to be implied by "it can allocate space in indexInfo->ii_Context", but it's not exceptionally obvious to me as a newcomer to the code. (By contrast, the ambuild docs say to palloc a data structure, but don't mention a context for it; no idea whether it should be in a particular context.) Actually, in full generality, I have not been able to find a section of the documentation which explains the memory-context stuff at all. I found a blog post elsewhere suggesting that it's just "the memory context will be freed and thus everything associated with it". This implies that there's no straightforward way for an index to do end-of-insert maintenance after all the inserts from a given query are complete, except to do it after every tuple just in case it's the last tuple, I guess?