On Mon, May 5, 2025 at 11:19 AM DIPESH DHAMELIYA
<dipeshdhameliya125@gmail.com> wrote:
>
> Hello everyone,
>
> With the commit 556f7b7bc18d34ddec45392965c3b3038206bb62, Any plpgsql function that returns scalar value would not be
ableto use parallelism to evaluate a return statement. It will not be considered for parallel execution because we are
passingmaxtuples = 2 to exec_run_select from exec_eval_expr to evaluate the return expression of the function.
>
I could not find commit '556f7b7bc18d34ddec45392965c3b3038206bb62' in
git log on the master branch, but here is my analysis after looking at
your patch.
I don't think we can remove the 'maxtuples' parameter from
exec_run_select(). In this particular case, the query itself is
returning a single tuple, so we are good. Still, in other cases where
the query returns more tuples, it makes sense to stop the execution as
soon as we have got enough tuples otherwise, it will do the execution
until we produce all the tuples. Consider the below example where we
just need to use the first tuple, but if we apply your patch, the
executor will end up processing all the tuples, and it will impact the
performance. So IMHO, the benefit you get by enabling a parallelism
in some cases may hurt badly in other cases, as you will end up
processing more tuples than required.
CREATE OR REPLACE FUNCTION get_first_user_email()
RETURNS TEXT AS $$
DECLARE
user_email TEXT;
BEGIN
user_email = (SELECT email FROM users);
RETURN user_email;
END;
$$ LANGUAGE plpgsql;
--
Regards,
Dilip Kumar
EnterpriseDB: http://www.enterprisedb.com