Parallel plans and "union all" subquery - Mailing list pgsql-hackers

From Phil Florent
Subject Parallel plans and "union all" subquery
Date
Msg-id DB7PR05MB6265AB99FA115C4355AC974CBAFD0@DB7PR05MB6265.eurprd05.prod.outlook.com
Whole thread Raw
Responses Re: Parallel plans and "union all" subquery
List pgsql-hackers

Hi,


I have a question about parallel plans. I also posted it on the general list but perhaps it's a question for hackers. Here is my test case :


select version();
version


----------------------------------------------------------------------------------------------------------------------------------
PostgreSQL 13.1 (Ubuntu 13.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit


create unlogged table drop_me as select generate_series(1,7e7) n1;
SELECT 70000000


explain
select count(*)
from (select
n1
from drop_me
) s;


QUERY PLAN
----------------------------------------------------------------------------------------------
Finalize Aggregate (cost=675319.13..675319.14 rows=1 width=8)
-> Gather (cost=675318.92..675319.13 rows=2 width=8)
Workers Planned: 2
-> Partial Aggregate (cost=674318.92..674318.93 rows=1 width=8)
-> Parallel Seq Scan on drop_me (cost=0.00..601402.13 rows=29166713 width=0)
JIT:
Functions: 4
Options: Inlining true, Optimization true, Expressions true, Deforming true


Parallel plan, 1s


explain
select count(*)
from (select
n1
from drop_me
union all
select
n1
from drop_me) ua;


QUERY PLAN
--------------------------------------------------------------------------------------------------------------
Finalize Aggregate (cost=1640315.00..1640315.01 rows=1 width=8)
-> Gather (cost=1640314.96..1640314.99 rows=2 width=8)
Workers Planned: 2
-> Partial Aggregate (cost=1640304.96..1640304.97 rows=1 width=8)
-> Parallel Append (cost=0.00..1494471.40 rows=58333426 width=0)
-> Parallel Seq Scan on drop_me (cost=0.00..601402.13 rows=29166713 width=0)
-> Parallel Seq Scan on drop_me drop_me_1 (cost=0.00..601402.13 rows=29166713 width=0)
JIT:
Functions: 6
Options: Inlining true, Optimization true, Expressions true, Deforming true


Parallel plan, 2s2


explain
select count(*)
from (select
n1
from drop_me
union all
values(1)) ua;


QUERY PLAN
--------------------------------------------------------------------------------
Aggregate (cost=2934739.24..2934739.25 rows=1 width=8)
-> Append (cost=0.00..2059737.83 rows=70000113 width=32)
-> Seq Scan on drop_me (cost=0.00..1009736.12 rows=70000112 width=6)
-> Subquery Scan on "*SELECT* 2" (cost=0.00..0.02 rows=1 width=32)
-> Result (cost=0.00..0.01 rows=1 width=4)
JIT:
Functions: 4
Options: Inlining true, Optimization true, Expressions true, Deforming true


No parallel plan, 2s6


I read the documentation but I don't get the reason of the "noparallel" seq scan of drop_me in the last case ?


Best regards,

Phil

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Removal of currtid()/currtid2() and some table AM cleanup
Next
From: Andy Fan
Date:
Subject: Re: Hybrid Hash/Nested Loop joins and caching results from subplans