You normally shouldn'd need to do this frequently - what's your use case? UnregisterXactCallback() is O(N), so workloads registering / unregistering a lot of callbacks would be problematic.
It's not about workloads or efficiency. Here is the use case:
I want to register a callback for some subtransaction, and only run this callback once
when the subtransaction ends, no matter if it was committed or cancelled.
It's reasonable to unregister the callback at the end of the callback, or I have to call UnregisterSubXactCallback() somewhere. Because SubXact_callbacks/Xact_callbacks
is only set by Unregister*XactCallback(). The question now becomes
1. where to call UnregisterSubXactCallback()
2. ensure that calling UnregisterSubXactCallback() is not triggered in the current callback
This patch enables us to safely delete the current callback when the callback finishes to
implement run callback once and unregister in one place.