Re: broken logic of simple_eval_resowner after CALL and COMMIT inside procedure - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: broken logic of simple_eval_resowner after CALL and COMMIT inside procedure
Date
Msg-id CAFj8pRBWy9FkmNqLP0agd=jMWsqnF80-1r5DmidgSm0RHEf+uA@mail.gmail.com
Whole thread Raw
In response to broken logic of simple_eval_resowner after CALL and COMMIT inside procedure  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-hackers


po 12. 10. 2020 v 16:15 odesílatel Pavel Stehule <pavel.stehule@gmail.com> napsal:
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;

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);

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;
<-->}

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.)

Pavel

Regards

Pavel


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: broken logic of simple_eval_resowner after CALL and COMMIT inside procedure
Next
From: "Shinoda, Noriyoshi (PN Japan A&PS Delivery)"
Date:
Subject: RE: Resetting spilled txn statistics in pg_stat_replication