No parallel plan on an union all subquery

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

No parallel plan on an union all subquery

Phil Florent
Hi,

I have a question about parallel plans. 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, OK, 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