Trigger stmt_beg and stmt_end for top-level statement blocks of PL/pgSQL
authorMichael Paquier <michael@paquier.xyz>
Sun, 30 Dec 2018 05:35:15 +0000 (14:35 +0900)
committerMichael Paquier <michael@paquier.xyz>
Sun, 30 Dec 2018 05:35:15 +0000 (14:35 +0900)
PL/pgSQL provides a set of callbacks which can be used for extra
instrumentation of functions written in this language called at function
setup, begin and end, as well as statement begin and end.  When calling
a routine, a trigger, or an event trigger, statement callbacks are not
getting called for the top-level statement block leading to an
inconsistent handling compared to the other statements.  This
inconsistency can potentially complicate extensions doing
instrumentation work on top of PL/pgSQL, so this commit makes sure that
all statement blocks, including the top-level one, go through the
correct corresponding callbacks.

Author: Pavel Stehule
Reviewed-by: Michael Paquier
Discussion: https://postgr.es/m/CAFj8pRArEANsaUjo5in9_iQt0vKf9ecwDAmsdN_EBwL13ps12A@mail.gmail.com

src/pl/plpgsql/src/pl_exec.c

index 42358c2ebe4ebf6ab8cd5c882e7540e6602bc09f..f292fcad2d8b4fe405452f8552d94a8a1d9afde7 100644 (file)
@@ -585,7 +585,7 @@ plpgsql_exec_function(PLpgSQL_function *func, FunctionCallInfo fcinfo,
         */
        estate.err_text = NULL;
        estate.err_stmt = (PLpgSQL_stmt *) (func->action);
-       rc = exec_stmt_block(&estate, func->action);
+       rc = exec_stmt(&estate, (PLpgSQL_stmt *) func->action);
        if (rc != PLPGSQL_RC_RETURN)
        {
                estate.err_stmt = NULL;
@@ -955,7 +955,7 @@ plpgsql_exec_trigger(PLpgSQL_function *func,
         */
        estate.err_text = NULL;
        estate.err_stmt = (PLpgSQL_stmt *) (func->action);
-       rc = exec_stmt_block(&estate, func->action);
+       rc = exec_stmt(&estate, (PLpgSQL_stmt *) func->action);
        if (rc != PLPGSQL_RC_RETURN)
        {
                estate.err_stmt = NULL;
@@ -1116,7 +1116,7 @@ plpgsql_exec_event_trigger(PLpgSQL_function *func, EventTriggerData *trigdata)
         */
        estate.err_text = NULL;
        estate.err_stmt = (PLpgSQL_stmt *) (func->action);
-       rc = exec_stmt_block(&estate, func->action);
+       rc = exec_stmt(&estate, (PLpgSQL_stmt *) func->action);
        if (rc != PLPGSQL_RC_RETURN)
        {
                estate.err_stmt = NULL;