Обсуждение: broken logic of simple_eval_resowner after CALL and COMMIT inside procedure
Hi
Inline handler creates simple_eval_resowner (without parent).
Inside plpgsql_estate_setup this value is assigned to estate->simple_eval_resowner
<-->if (simple_eval_resowner)
<--><-->estate->simple_eval_resowner = simple_eval_resowner;
<-->else
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;
<--><-->estate->simple_eval_resowner = simple_eval_resowner;
<-->else
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;
When we call procedure with inner COMMIT, then when "before_lxid != after_lxid" following code is
executed.
<--><-->estate->simple_eval_estate = NULL;
<--><-->estate->simple_eval_resowner = NULL;
<--><-->plpgsql_create_econtext(estate);
<--><-->estate->simple_eval_resowner = NULL;
<--><-->plpgsql_create_econtext(estate);
and
fragment from plpgsql_create_econtext
<-->/*
<--> * Likewise for the simple-expression resource owner.
<--> */
<-->if (estate->simple_eval_resowner == NULL)
<-->{
<--><-->if (shared_simple_eval_resowner == NULL)
<--><--><-->shared_simple_eval_resowner =
<--><--><--><-->ResourceOwnerCreate(TopTransactionResourceOwner,
<--><--><--><--><--><--><--><--><-->"PL/pgSQL simple expressions");
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;
<-->}
<--> * Likewise for the simple-expression resource owner.
<--> */
<-->if (estate->simple_eval_resowner == NULL)
<-->{
<--><-->if (shared_simple_eval_resowner == NULL)
<--><--><-->shared_simple_eval_resowner =
<--><--><--><-->ResourceOwnerCreate(TopTransactionResourceOwner,
<--><--><--><--><--><--><--><--><-->"PL/pgSQL simple expressions");
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;
<-->}
In this case simple_eval_resowner from inline handler is overwritten and only shared_simple_eval_resowner will be used.
So is it "estate->simple_eval_resowner = NULL;" error (without other conditions)?
Regards
Pavel
Re: broken logic of simple_eval_resowner after CALL and COMMIT inside procedure
От
Pavel Stehule
Дата:
po 12. 10. 2020 v 16:15 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:
HiInline handler creates simple_eval_resowner (without parent).Inside plpgsql_estate_setup this value is assigned to estate->simple_eval_resowner<-->if (simple_eval_resowner)
<--><-->estate->simple_eval_resowner = simple_eval_resowner;
<-->else
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;When we call procedure with inner COMMIT, then when "before_lxid != after_lxid" following code isexecuted.<--><-->estate->simple_eval_estate = NULL;
<--><-->estate->simple_eval_resowner = NULL;
<--><-->plpgsql_create_econtext(estate);andfragment from plpgsql_create_econtext<-->/*
<--> * Likewise for the simple-expression resource owner.
<--> */
<-->if (estate->simple_eval_resowner == NULL)
<-->{
<--><-->if (shared_simple_eval_resowner == NULL)
<--><--><-->shared_simple_eval_resowner =
<--><--><--><-->ResourceOwnerCreate(TopTransactionResourceOwner,
<--><--><--><--><--><--><--><--><-->"PL/pgSQL simple expressions");
<--><-->estate->simple_eval_resowner = shared_simple_eval_resowner;
<-->}In this case simple_eval_resowner from inline handler is overwritten and only shared_simple_eval_resowner will be used.So is it "estate->simple_eval_resowner = NULL;" error (without other conditions)?
Probably it is described
*
* (However, if a DO block executes COMMIT or ROLLBACK, then exec_stmt_commit
* or exec_stmt_rollback will unlink it from the DO's simple-expression EState
* and create a new shared EState that will be used thenceforth. The original
* EState will be cleaned up when we get back to plpgsql_inline_handler. This
* is a bit ugly, but it isn't worth doing better, since scenarios like this
* can't result in indefinite accumulation of state trees.)
* (However, if a DO block executes COMMIT or ROLLBACK, then exec_stmt_commit
* or exec_stmt_rollback will unlink it from the DO's simple-expression EState
* and create a new shared EState that will be used thenceforth. The original
* EState will be cleaned up when we get back to plpgsql_inline_handler. This
* is a bit ugly, but it isn't worth doing better, since scenarios like this
* can't result in indefinite accumulation of state trees.)
Pavel
RegardsPavel