pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: pgsql-general@postgresql.org
Subject: Re: Number of parallel workers chosen by the optimizer for parallel append
Date: Fri, 04 Dec 2020 11:28:19 +0100
Message-ID: <5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at> (raw)
In-Reply-To: <d56c6b20ac6e9d7a69f0d695400bd229c203576c.camel@cybertec.at>
References: <d56c6b20ac6e9d7a69f0d695400bd229c203576c.camel@cybertec.at>

On Wed, 2020-11-25 at 17:36 +0100, Laurenz Albe wrote:
> I have a partitioned table, each partition has "parallel_workers = 10" set.
> 
>   SET max_parallel_workers_per_gather = 8;
> 
>   SET enable_partitionwise_aggregate = on;
> 
>   EXPLAIN (COSTS OFF)
>   SELECT applicant_name, count(ipc_4)
>   FROM laurenz.z_flat
>   GROUP BY applicant_name;
> 
>                       QUERY PLAN                    
>   --------------------------------------------------
>    Gather
>      Workers Planned: 4
>      ->  Parallel Append
>            ->  HashAggregate
>                  Group Key: z_flat_3.applicant_name
>                  ->  Seq Scan on xyz_4 z_flat_3
>            ->  HashAggregate
>                  Group Key: z_flat.applicant_name
>                  ->  Seq Scan on xyz_1 z_flat
>            [8 more such partition scans]
>   (33 rows)
> 
> How does the optimizer decide to use 4 parallel workers?
> 
> No matter what I try, I cannot influence that number.

I figured it out.

This is automatically calculated from the number of partitions, and the
number of parallel workers is

  ld(#partitions) + 1

where "ld" is the logarithm of base 2 (function "fls" in the source).

It might be nice to make this configurable, but since we don't have
storage parameters on partitioned tables, I wonder how.

Yours,
Laurenz Albe
-- 
Cybertec | https://www.cybertec-postgresql.com






view thread (3+ messages)

Message-ID: <5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at>
Permalink:  ../5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at/
Also on:    postgresql.org/message-id/5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: laurenz.albe@cybertec.at
  Subject: Re: Number of parallel workers chosen by the optimizer for parallel append
  In-Reply-To: <5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at>
  References: <d56c6b20ac6e9d7a69f0d695400bd229c203576c.camel@cybertec.at> <5e1fd40aabddb1447f051c860e359cd0ec9b5301.camel@cybertec.at>

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

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