Re: Re: fix cost subqueryscan wrong parallel cost

From: Richard Guo <guofenglinux(at)gmail(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Re: fix cost subqueryscan wrong parallel cost
Date: 2022-04-29 08:35:59
Message-ID: CAMbWs4_QVQXaTZsUYUdqm8dumCsrDdiSF5Oatg_m7wdrZ8tWZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 29, 2022 at 12:53 AM Robert Haas <robertmhaas(at)gmail(dot)com> wrote:

> Gather doesn't require a parallel aware subpath, just a parallel-safe
> subpath. In a case like this, the parallel seq scan will divide the
> rows from the underlying relation across the three processes executing
> it. Each process will pass the rows it receives through its own copy
> of the subquery scan. Then, the Gather node will collect all the rows
> from all the workers to produce the final result.
>
> It's an extremely important feature of parallel query that the
> parallel-aware node doesn't have to be immediately beneath the Gather.
> You need to have a parallel-aware node in there someplace, but it
> could be separated from the gather by any number of levels e.g.
>
> Gather
> -> Nested Loop
> -> Nested Loop
> -> Nested Loop
> -> Parallel Seq Scan
> -> Index Scan
> -> Index Scan
> -> Index Scan
>

Thanks for the explanation. That's really helpful to understand the
parallel query mechanism.

So for the nodes between Gather and parallel-aware node, how should we
calculate their estimated rows?

Currently subquery scan is using rel->rows (if no parameterization),
which I believe is not correct. That's not the size the subquery scan
node in each worker needs to handle, as the rows have been divided
across workers by the parallel-aware node.

Using subpath->rows is not correct either, as subquery scan node may
have quals.

It seems to me the right way is to divide the rel->rows among all the
workers.

Thanks
Richard

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Smith 2022-04-29 09:05:11 Re: Multi-Master Logical Replication
Previous Message Peter Eisentraut 2022-04-29 08:13:48 Re: SQL JSON compliance