The comments do a good job justifying this, but as far as I know it would be the only instance of this pattern in the entire source tree. Are we really sure we want to deviate from the idea of having the memory context tree be a tree? And is it really so bad if the memory used to report memory contexts is included in the output?
This was implemented in response to a review suggestion [1]. If required, it can be updated to create one under CurrentMemoryContext.
Like LWLockAcquire, all of this code supposes that there's a transaction available to manage resource acquisition and release and to clean up after errors. I doubt that any of this is safe without a transaction.
Starting a transaction from CFI works for a client backend but
not for auxiliary processes. When I try to execute StartTransaction()
from a checkpointer process, the following assertion fails,