pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
cpu-intensive immutable function and parallel scan
3+ messages / 3 participants
[nested] [flat]

* cpu-intensive immutable function and parallel scan
@ 2021-06-22 07:06  Niels Jespersen <NJN@dst.dk>
  0 siblings, 1 reply; 3+ messages in thread

From: Niels Jespersen @ 2021-06-22 07:06 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hello all

I have a cpu-intensive plpython3u function that computes a result on the value from a single column value from a simple select.This looks largely like this.

select function_name (t1.val1, 'constant1') from t1 where t1.p = '202012_1' and t1.val1 is not null;

The function is marked immutable and parallel safe.

The time spent in the function is quite substantial. The same execution plan for a query that invokes the funtion and a query that does not results in a 15-times slowdown. Explain analyze show that both queries use 5 parallel workers.

I think I could achieve some speedup by parallelizing further, distributing the cpu-work among additional workers. But, how do I achive that best?

In Oracle I would either use a parallel-hint or an alter session force parallel query parallel 8.

Regards Niels

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: cpu-intensive immutable function and parallel scan
@ 2021-06-22 07:09  David Rowley <dgrowleyml@gmail.com>
  parent: Niels Jespersen <NJN@dst.dk>
  0 siblings, 1 reply; 3+ messages in thread

From: David Rowley @ 2021-06-22 07:09 UTC (permalink / raw)
  To: Niels Jespersen <NJN@dst.dk>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

On Tue, 22 Jun 2021 at 19:06, Niels Jespersen <NJN@dst.dk> wrote:
> I think I could achieve some speedup by parallelizing further, distributing the cpu-work among additional workers. But, how do I achive that best?

You'll want to ensure max_parallel_workers_per_gather is set high
enough and you have max_parallel_workers set to something high enough.
You can then do:

alter table t1 set (parallel_workers = <number of workers>);

David





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: cpu-intensive immutable function and parallel scan
@ 2021-06-22 13:29  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David Rowley <dgrowleyml@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Tom Lane @ 2021-06-22 13:29 UTC (permalink / raw)
  To: David Rowley <dgrowleyml@gmail.com>; +Cc: Niels Jespersen <NJN@dst.dk>; pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

David Rowley <dgrowleyml@gmail.com> writes:
> On Tue, 22 Jun 2021 at 19:06, Niels Jespersen <NJN@dst.dk> wrote:
>> I think I could achieve some speedup by parallelizing further, distributing the cpu-work among additional workers. But, how do I achive that best?

> You'll want to ensure max_parallel_workers_per_gather is set high
> enough and you have max_parallel_workers set to something high enough.
> You can then do:
> alter table t1 set (parallel_workers = <number of workers>);

Also, if you don't have a fairly high COST value set on the function,
try raising that to make the planner understand that it's expensive.
My recollection is that the amount of parallelism it goes for is partly
predicated on the estimated query cost.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2021-06-22 13:29 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-06-22 07:06 cpu-intensive immutable function and parallel scan Niels Jespersen <NJN@dst.dk>
2021-06-22 07:09 ` David Rowley <dgrowleyml@gmail.com>
2021-06-22 13:29   ` Tom Lane <tgl@sss.pgh.pa.us>

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