public inbox for [email protected]  
help / color / mirror / Atom feed
From: Laurenz Albe <[email protected]>
To: Jim Vanns <[email protected]>
To: pgsql-general <[email protected]>
Subject: Re: Parallel workers via functions?
Date: Tue, 28 Jan 2025 05:47:11 +0100
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAH7vdhPr9BJ2TjbVU0RepN92eUFmWorukAGEyhBqpx8gF67xdQ@mail.gmail.com>
References: <CAH7vdhPr9BJ2TjbVU0RepN92eUFmWorukAGEyhBqpx8gF67xdQ@mail.gmail.com>

On Mon, 2025-01-27 at 18:08 +0000, Jim Vanns wrote:
> If I have a function that is marked 'stable parallel safe' and returns
> a table, can a calling function or procedure (marked volatile parallel
> unsafe) still take advantage of the parallel workers from the first
> function - as the data source. I.e.
> 
> func_a(); // selects, returns table, parallel safe
> func_b() {
>    insert into foo
>    select * from func_a(); // Will func_a still execute parallel
> workers to fetch the data?
> }
> 
> Or even if func_b() uses 'create temporary table as select * from
> func_a()' and then insert?
> 
> I ask because when I simply call func_a() from a psql shell, I see the
> parallel workers run and everything is nice and swift. But when called
> from a data-modifying function like func_b(), no workers are spawned
> :( Even from the read-part of the code.
> 
> Are there differences in functions vs. stored procedures that might
> affect the behaviour of the planner to disregard workers?

See https://www.postgresql.org/docs/current/when-can-parallel-query-be-used.html

The problem here is the INSERT.  Data modifying statements won't use
parallel query.

There are exceptions: CREATE TABLE ... AS SELECT ... should be able
to use parallel query.

Yours,
Laurenz Albe






reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Parallel workers via functions?
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox