CREATE OR REPLACE FUNCTION wrapperFunction()
RETURNS bytea AS
$BODY$
BEGIN
SELECT function1() || function2();
END;
$BODY$
LANGUAGE plpgsql
Is there a way to make calls to function1
and function2
parallel?
(they are read only, no side effects and independent)
2
Answers
No, you cannot do that.
To call two functions in parallel, you need to have two database sessions.
You can mark functions as parallel safe.
This requires that your function is actually safe (otherwise you can end up with wrong answers, etc.), and it’s up to the query planner to actually determine that the functions will run in parallel.
There’s also quite a few limitations that your function need to adhere to:
So the answer is "it depends". It might be easier to cache the result in some way (update a computed column) or make it answerable by a join – if possible.