Re: [PATCH] Allow parallelism for plpgsql return expression after commit 556f7b7 - Mailing list pgsql-hackers

From Dilip Kumar
Subject Re: [PATCH] Allow parallelism for plpgsql return expression after commit 556f7b7
Date
Msg-id CAFiTN-uPdCpUMeYjY8m3F47VQ-5G5tpNzxY37PX8Zt+MeSaaHg@mail.gmail.com
Whole thread Raw
In response to [PATCH] Allow parallelism for plpgsql return expression after commit 556f7b7  (DIPESH DHAMELIYA <dipeshdhameliya125@gmail.com>)
Responses Re: [PATCH] Allow parallelism for plpgsql return expression after commit 556f7b7
List pgsql-hackers
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



pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: Add comment explaining why queryid is int64 in pg_stat_statements
Next
From: Tatsuo Ishii
Date:
Subject: Re: Adding null patch entry to cfbot/CommitFest