Add custom extension states to QueryDesc Extensions sometimes need to carry private data from one executor hook to another for a given query. ExecutorEnd() can run in a different context than ExecutorStart(), so backend-wide variables cannot be used for that.
This commit adds a way for loadable modules to attach private state to a QueryDesc, modeled in the same fashion as what is already done for PlannerGlobal, PlannerInfo, RelOptInfo and ExplainState. GetQueryDescExtensionId() maps an extension name to a backend-local ID. SetQueryDescExtensionState() and GetQueryDescExtensionState() store and fetch an opaque pointer for that ID. The array of pointers is allocated in the memory context of the QueryDesc, and is freed by FreeQueryDesc(). What the pointers refer to is owned by the extensions. There are no users of this facility yet. A follow-up commit will make use of it. Some potential use cases have been identified for pg_stat_statements and auto_explain, where both need to be able to co-exist in peace. Extensions living outside of core may also find a use for it. Author: Michael Paquier <[email protected]> Reviewed-by: Sami Imseih <[email protected]> Discussion: https://postgr.es/m/CAEcQ1bZrgwKsauC=03otebklk77zc_hynjhtp3oudpxs++u...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e5d5d1ad1e3aa495609e19fa716dcea6a39db1bb Modified Files -------------- src/backend/tcop/pquery.c | 107 +++++++++++++++++++++++++++++++++++++++- src/include/executor/execdesc.h | 9 ++++ 2 files changed, 114 insertions(+), 2 deletions(-)
