Re: plpgsql plugin - stmt_beg/end is not called for top level block of statements

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: plpgsql plugin - stmt_beg/end is not called for top level block of statements
Date: 2018-12-28 02:26:35
Message-ID: 20181228022635.GF3210@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Dec 26, 2018 at 07:02:04AM +0100, Pavel Stehule wrote:
> is called two times, what is not expected, if you don't know some about
> this inconsistency.
>
> So it is reason, why I don't think so current behave is correct. On second
> hand, the impact is very small - only few extensions uses plpgsql plugin
> API, and workaround is not hard. So I can live with current state if nobody
> see this issue (sure - it is minor issue).

Hm. Using the following functions based on the code of above, I can
see the following numbers if I place some trackers (elog(WARNING)
entries) at the beginning of each callback part of plpgsql_check.c to
measure how many times a callback is done:
CREATE OR REPLACE FUNCTION public.f2()
RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE x int;
BEGIN
x := 2;
RETURN;
END;
$$;
CREATE OR REPLACE FUNCTION public.f3()
RETURNS void
LANGUAGE plpgsql
AS $$
DECLARE x int;
BEGIN
BEGIN
x := 3;
RETURN;
END;
END
$$;

On HEAD, for plpgsql_check_function_tb('f2()'):
- stmt_beg is called 4 times.
- stmt_end is called 3 times.
- func_setup is called 2 times.
- func_beg is called 2 times.
- func_end is called 2 times.
For plpgsql_check_function_tb('f3()'):
- stmt_beg is called 3 times.
- stmt_end is called 3 times.
- func_setup is called 1 time.
- func_beg is called 1 time.
- func_end is called 2 times.

So based on the previous example f2 gets over f3 one extra stmt_beg,
one extra func_beg and one extra func_setup.

With patched HEAD, I got for f2:
- stmt_beg is called 6 times.
- stmt_end is called 5 times.
- func_setup is called 2 times.
- func_beg is called 2 times.
- func_end is called 2 times.
And for f3:
- stmt_beg is called 6 times.
- stmt_end is called 5 times.
- func_setup is called 2 times.
- func_beg is called 2 times.
- func_end is called 2 times.
--
Michael

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Masahiko Sawada 2018-12-28 02:43:44 Re: [HACKERS] Block level parallel vacuum
Previous Message Michael Paquier 2018-12-28 01:41:43 Re: Minor comment fix for pg_config_manual.h