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

Function plpgsql_inline_handler

src/pl/plpgsql/src/pl_handler.c:322–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

320PG_FUNCTION_INFO_V1(plpgsql_inline_handler);
321
322Datum
323plpgsql_inline_handler(PG_FUNCTION_ARGS)
324{
325 LOCAL_FCINFO(fake_fcinfo, 0);
326 InlineCodeBlock *codeblock = castNode(InlineCodeBlock, DatumGetPointer(PG_GETARG_DATUM(0)));
327 PLpgSQL_function *func;
328 FmgrInfo flinfo;
329 EState *simple_eval_estate;
330 ResourceOwner simple_eval_resowner;
331 Datum retval;
332 int rc;
333
334 /*
335 * Connect to SPI manager
336 */
337 if ((rc = SPI_connect_ext(codeblock->atomic ? 0 : SPI_OPT_NONATOMIC)) != SPI_OK_CONNECT)
338 elog(ERROR, "SPI_connect failed: %s", SPI_result_code_string(rc));
339
340 /* Compile the anonymous code block */
341 func = plpgsql_compile_inline(codeblock->source_text);
342
343 /* Mark the function as busy, just pro forma */
344 func->use_count++;
345
346 /*
347 * Set up a fake fcinfo with just enough info to satisfy
348 * plpgsql_exec_function(). In particular note that this sets things up
349 * with no arguments passed.
350 */
351 MemSet(fake_fcinfo, 0, SizeForFunctionCallInfo(0));
352 MemSet(&flinfo, 0, sizeof(flinfo));
353 fake_fcinfo->flinfo = &flinfo;
354 flinfo.fn_oid = InvalidOid;
355 flinfo.fn_mcxt = CurrentMemoryContext;
356
357 /*
358 * Create a private EState and resowner for simple-expression execution.
359 * Notice that these are NOT tied to transaction-level resources; they
360 * must survive any COMMIT/ROLLBACK the DO block executes, since we will
361 * unconditionally try to clean them up below. (Hence, be wary of adding
362 * anything that could fail between here and the PG_TRY block.) See the
363 * comments for shared_simple_eval_estate.
364 *
365 * Because this resowner isn't tied to the calling transaction, we can
366 * also use it as the "procedure" resowner for any CALL statements. That
367 * helps reduce the opportunities for failure here.
368 */
369 simple_eval_estate = CreateExecutorState();
370 simple_eval_resowner =
371 ResourceOwnerCreate(NULL, "PL/pgSQL DO block simple expressions");
372
373 /* And run the function */
374 PG_TRY();
375 {
376 retval = plpgsql_exec_function(func, fake_fcinfo,
377 simple_eval_estate,
378 simple_eval_resowner,
379 simple_eval_resowner, /* see above */

Callers

nothing calls this directly

Calls 13

SPI_connect_extFunction · 0.85
SPI_result_code_stringFunction · 0.85
plpgsql_compile_inlineFunction · 0.85
CreateExecutorStateFunction · 0.85
ResourceOwnerCreateFunction · 0.85
plpgsql_exec_functionFunction · 0.85
plpgsql_subxact_cbFunction · 0.85
FreeExecutorStateFunction · 0.85
ResourceOwnerDeleteFunction · 0.85

Tested by

no test coverage detected