Re: Why the sql is not executed in parallel mode

From: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
To: jimmy <mpokky(at)126(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Why the sql is not executed in parallel mode
Date: 2018-09-19 03:21:53
Message-ID: CAEepm=03s4Yih+c0pCTfKi0O8zgq-P4VfCVEk5VVXcR6aXHm4A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

On Wed, Sep 19, 2018 at 1:53 PM jimmy <mpokky(at)126(dot)com> wrote:
>
> Why the sql is not executed in parallel mode, does the sql has some problem?
> with sql1 as

Hello Jimmy,

WITH is the problem. From the manual[1]: "The following operations
are always parallel restricted. Scans of common table expressions
(CTEs). ...". That means that these CTEs can only be scanned in the
leader process.

If you rewrite the query using sub selects it might do better. FWIW
there is a project to make WITH work like subselects automatically in
a future release of PostgreSQL:

https://www.postgresql.org/message-id/flat/87sh48ffhb(dot)fsf(at)news-spur(dot)riddles(dot)org(dot)uk

[1] https://www.postgresql.org/docs/10/static/parallel-safety.html

--
Thomas Munro
http://www.enterprisedb.com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Munro 2018-09-19 03:29:57 Re: how to know whether query data from memory after pg_prewarm
Previous Message jimmy 2018-09-19 01:53:28 Why the sql is not executed in parallel mode

Browse pgsql-performance by date

  From Date Subject
Next Message Pavel Stehule 2018-09-19 08:30:31 Re: [HACKERS] proposal: schema variables
Previous Message jimmy 2018-09-19 01:53:28 Why the sql is not executed in parallel mode