Re: Wrong plan with extra parallel workers - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: Wrong plan with extra parallel workers
Date
Msg-id CAA4eK1JMgdood_M9o4Xj_ou-tQvbLrLRrcy0Y9znFYMbf2hfAA@mail.gmail.com
Whole thread Raw
In response to Wrong plan with extra parallel workers  (Guilherme Pereira <guiperpt@gmail.com>)
List pgsql-hackers
On Fri, Apr 27, 2018 at 2:48 PM, Guilherme Pereira <guiperpt@gmail.com> wrote:
> Hi,
>
> Having a strange situation, where adding extra parallel workers
> (max_parallel_workers_per_gather), the planner chooses a different plan,

I think I can see what is going on here.  The planner chooses a
different plan because the cost of that plan
(cost=1001.10..31949141.56) is cheap as compared to the original plan
(cost=31676816.72..32928717.16)

> with nested loops, which makes the query twice as slow.

It is slow because it needs to transmit many rows (rows=23845842) from
workers to master backend.

> Strangely with the
> COUNT_DISTINCT implementation from Tomas Vondra
> (https://github.com/tvondra/count_distinct) it scales nicely (almost
> linearly) with the workers.
>

The main difference is that count_distinct is a parallel_safe
aggregate function which can be allowed to push down to workers which
in turn lead to very few rows (rows=9) being transferred from workers
to master backend.

I think ideally it should not have picked the plan which leads to
transmitting so many rows, but the cost turns out to be lesser.

-- 
With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Stephen Frost
Date:
Subject: Re: "could not reattach to shared memory" on buildfarm member dory
Next
From: Amit Kapila
Date:
Subject: Re: Toast issues with OldestXmin going backwards