MCPcopy Create free account
hub / github.com/apache/cloudberry / plpgsql_create_econtext

Function plpgsql_create_econtext

src/pl/plpgsql/src/pl_exec.c:8237–8298  ·  view source on GitHub ↗

* plpgsql_create_econtext --- create an eval_econtext for the current function * * We may need to create a new shared_simple_eval_estate too, if there's not * one already for the current transaction. The EState will be cleaned up at * transaction end. Ditto for shared_simple_eval_resowner. */

Source from the content-addressed store, hash-verified

8235 * transaction end. Ditto for shared_simple_eval_resowner.
8236 */
8237static void
8238plpgsql_create_econtext(PLpgSQL_execstate *estate)
8239{
8240 SimpleEcontextStackEntry *entry;
8241
8242 /*
8243 * Create an EState for evaluation of simple expressions, if there's not
8244 * one already in the current transaction. The EState is made a child of
8245 * TopTransactionContext so it will have the right lifespan.
8246 *
8247 * Note that this path is never taken when beginning a DO block; the
8248 * required EState was already made by plpgsql_inline_handler. However,
8249 * if the DO block executes COMMIT or ROLLBACK, then we'll come here and
8250 * make a shared EState to use for the rest of the DO block. That's OK;
8251 * see the comments for shared_simple_eval_estate. (Note also that a DO
8252 * block will continue to use its private cast hash table for the rest of
8253 * the block. That's okay for now, but it might cause problems someday.)
8254 */
8255 if (estate->simple_eval_estate == NULL)
8256 {
8257 MemoryContext oldcontext;
8258
8259 if (shared_simple_eval_estate == NULL)
8260 {
8261 oldcontext = MemoryContextSwitchTo(TopTransactionContext);
8262 shared_simple_eval_estate = CreateExecutorState();
8263 MemoryContextSwitchTo(oldcontext);
8264 }
8265 estate->simple_eval_estate = shared_simple_eval_estate;
8266 }
8267
8268 /*
8269 * Likewise for the simple-expression resource owner.
8270 */
8271 if (estate->simple_eval_resowner == NULL)
8272 {
8273 if (shared_simple_eval_resowner == NULL)
8274 shared_simple_eval_resowner =
8275 ResourceOwnerCreate(TopTransactionResourceOwner,
8276 "PL/pgSQL simple expressions");
8277 estate->simple_eval_resowner = shared_simple_eval_resowner;
8278 }
8279
8280 /*
8281 * Create a child econtext for the current function.
8282 */
8283 estate->eval_econtext = CreateExprContext(estate->simple_eval_estate);
8284
8285 /*
8286 * Make a stack entry so we can clean up the econtext at subxact end.
8287 * Stack entries are kept in TopTransactionContext for simplicity.
8288 */
8289 entry = (SimpleEcontextStackEntry *)
8290 MemoryContextAlloc(TopTransactionContext,
8291 sizeof(SimpleEcontextStackEntry));
8292
8293 entry->stack_econtext = estate->eval_econtext;
8294 entry->xact_subxid = GetCurrentSubTransactionId();

Callers 5

exec_stmt_blockFunction · 0.85
exec_stmt_callFunction · 0.85
plpgsql_estate_setupFunction · 0.85
exec_stmt_commitFunction · 0.85
exec_stmt_rollbackFunction · 0.85

Calls 6

MemoryContextSwitchToFunction · 0.85
CreateExecutorStateFunction · 0.85
ResourceOwnerCreateFunction · 0.85
CreateExprContextFunction · 0.85
MemoryContextAllocFunction · 0.85

Tested by

no test coverage detected