PostgreSQL 并行计算解说 之21 - parallel partition table wise agg

本文涉及的产品
阿里云百炼推荐规格 ADB PostgreSQL,4核16GB 100GB 1个月
云原生数据库 PolarDB MySQL 版,通用型 2核4GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介: 标签 PostgreSQL , cpu 并行 , smp 并行 , 并行计算 , gpu 并行 , 并行过程支持 背景 PostgreSQL 11 优化器已经支持了非常多场合的并行。简单估计,已支持27余种场景的并行计算。 parallel seq scan

标签

PostgreSQL , cpu 并行 , smp 并行 , 并行计算 , gpu 并行 , 并行过程支持


背景

PostgreSQL 11 优化器已经支持了非常多场合的并行。简单估计,已支持27余种场景的并行计算。

parallel seq scan                                            
                                            
parallel index scan                                            
                                            
parallel index only scan                                            
                                            
parallel bitmap scan                                            
                                            
parallel filter                                            
                                        
parallel hash agg                                        
                                        
parallel group agg                                        
                                            
parallel cte                                            
                                            
parallel subquery                                            
                                            
parallel create table                                            
                                            
parallel create index                                            
                                            
parallel select into                                            
                                            
parallel CREATE MATERIALIZED VIEW                                            
                                            
parallel 排序 : gather merge                                             
                                            
parallel nestloop join                                            
                                            
parallel hash join                                            
                                            
parallel merge join                                            
                                            
parallel 自定义并行聚合                                            
                                            
parallel 自定义并行UDF                                            
                                            
parallel append                                            
                                            
parallel union                                            
                                            
parallel fdw table scan                                            
                                            
parallel partition join                                            
                                            
parallel partition agg                                            
                                            
parallel gather                                    
                            
parallel gather merge                            
                                            
parallel rc 并行                                            
                                            
parallel rr 并行                                            
                                            
parallel GPU 并行                                            
                                            
parallel unlogged table          
        
lead parallel      

接下来进行一一介绍。

关键知识请先自行了解:

1、优化器自动并行度算法 CBO

《PostgreSQL 9.6 并行计算 优化器算法浅析》

《PostgreSQL 11 并行计算算法,参数,强制并行度设置》

parallel partition table wise agg

并行分区表智能聚合(类似MPP)

当分区表聚合操作的分组字段为分区字段时,PostgreSQL优化器会选择并行分区智能聚合。

《PostgreSQL 11 preview - 分区表智能并行聚合、分组计算(已类似MPP架构,性能暴增)》

《PostgreSQL 11 preview - 分区表智能并行JOIN (已类似MPP架构,性能暴增)》

数据量:10亿

场景 数据量 关闭并行 开启并行 并行度 开启并行性能提升倍数
parallel partition table wise agg 10亿 191 秒 8 秒 24 23.9 倍

例子,24个分区的HASH分区表。

CREATE unlogged TABLE ccc (      
    order_id     bigint not null,      
    cust_id      bigint not null,      
    status       text      
) PARTITION BY HASH (cust_id);      
    
do language plpgsql $$    
declare    
begin    
  for i in 0..23 loop    
    execute format('CREATE unlogged TABLE %s%s PARTITION OF %s FOR VALUES WITH (MODULUS %s, REMAINDER %s)', 'ccc', i, 'ccc', 24, i);     
    execute format('alter table %s%s set(parallel_workers =64)', 'ccc',i);    
  end loop;    
end;    
$$;    
    
postgres=# \d ccc    
            Unlogged table "public.ccc"    
  Column  |  Type  | Collation | Nullable | Default     
----------+--------+-----------+----------+---------    
 order_id | bigint |           | not null |     
 cust_id  | bigint |           | not null |     
 status   | text   |           |          |     
Partition key: HASH (cust_id)    
Number of partitions: 24 (Use \d+ to list them.)    

写入10亿数据

insert into ccc select i, random()*960 from generate_series(1,1000000000) t(i);    
vacuum (analyze,verbose) ccc;    
postgres=# show max_worker_processes ;      
 max_worker_processes       
----------------------      
 128      
(1 row)      
postgres=# set min_parallel_table_scan_size =0;      
postgres=# set min_parallel_index_scan_size =0;      
postgres=# set parallel_tuple_cost =0;      
postgres=# set parallel_setup_cost =0;      
postgres=# set max_parallel_workers=128;      
postgres=# set max_parallel_workers_per_gather =24;      
postgres=# set enable_parallel_hash =on;      
postgres=# set enable_parallel_append =off;      
postgres=# set enable_partitionwise_aggregate =on;      
postgres=# set work_mem ='128MB';      

1、关闭并行,耗时: 191 秒。

postgres=# set max_parallel_workers_per_gather =0;      
postgres=# set enable_parallel_append =off;      
postgres=# set enable_partitionwise_aggregate =off;      
      
      
postgres=# explain select cust_id,count(*) from ccc group by cust_id;     
                                 QUERY PLAN                                      
-----------------------------------------------------------------------------    
 HashAggregate  (cost=25405409.32..25405418.93 rows=961 width=16)    
   Group Key: ccc0.cust_id    
   ->  Append  (cost=0.00..20405411.99 rows=999999466 width=8)    
         ->  Seq Scan on ccc0  (cost=0.00..641839.96 rows=41663296 width=8)    
         ->  Seq Scan on ccc1  (cost=0.00..625842.88 rows=40624888 width=8)    
         ->  Seq Scan on ccc2  (cost=0.00..722092.24 rows=46872124 width=8)    
         ->  Seq Scan on ccc3  (cost=0.00..545581.20 rows=35414920 width=8)    
         ->  Seq Scan on ccc4  (cost=0.00..657705.92 rows=42693192 width=8)    
         ->  Seq Scan on ccc5  (cost=0.00..609843.00 rows=39586300 width=8)    
         ->  Seq Scan on ccc6  (cost=0.00..625934.32 rows=40630732 width=8)    
         ->  Seq Scan on ccc7  (cost=0.00..673876.80 rows=43742880 width=8)    
         ->  Seq Scan on ccc8  (cost=0.00..601729.04 rows=39059604 width=8)    
         ->  Seq Scan on ccc9  (cost=0.00..609919.96 rows=39591296 width=8)    
         ->  Seq Scan on ccc10  (cost=0.00..674124.76 rows=43758976 width=8)    
         ->  Seq Scan on ccc11  (cost=0.00..529544.24 rows=34373924 width=8)    
         ->  Seq Scan on ccc12  (cost=0.00..818443.04 rows=53127004 width=8)    
         ->  Seq Scan on ccc13  (cost=0.00..674104.80 rows=43757680 width=8)    
         ->  Seq Scan on ccc14  (cost=0.00..786195.28 rows=51033728 width=8)    
         ->  Seq Scan on ccc15  (cost=0.00..609709.04 rows=39577604 width=8)    
         ->  Seq Scan on ccc16  (cost=0.00..633745.96 rows=41137896 width=8)    
         ->  Seq Scan on ccc17  (cost=0.00..673962.32 rows=43748432 width=8)    
         ->  Seq Scan on ccc18  (cost=0.00..802380.08 rows=52083808 width=8)    
         ->  Seq Scan on ccc19  (cost=0.00..529621.20 rows=34378920 width=8)    
         ->  Seq Scan on ccc20  (cost=0.00..642042.32 rows=41676432 width=8)    
         ->  Seq Scan on ccc21  (cost=0.00..401251.50 rows=26046150 width=8)    
         ->  Seq Scan on ccc22  (cost=0.00..673891.04 rows=43743804 width=8)    
         ->  Seq Scan on ccc23  (cost=0.00..642033.76 rows=41675876 width=8)    
(27 rows)    
    
postgres=# select cust_id,count(*) from ccc group by cust_id;     
 cust_id |  count      
---------+---------    
     652 | 1041702    
     273 | 1041730    
      51 | 1043333    
     951 | 1041738    
      70 | 1042693    
     839 | 1042059    
     350 | 1040677    
     539 | 1042402    
     758 | 1042199    
     874 | 1043176    
     278 | 1041664    
     946 | 1041442    
     176 | 1041523    
     576 | 1041131    
     292 | 1041236    
     929 | 1041554    
     663 | 1041569    
     770 | 1041953    
      22 | 1041484    
..........................    
     790 | 1041575    
     828 | 1042024    
(961 rows)    
    
Time: 191475.978 ms (03:11.476)    

2、开启并行,耗时: 8 秒。

postgres=# set max_parallel_workers_per_gather =24;      
postgres=# set enable_parallel_append =off;      
postgres=# set enable_partitionwise_aggregate =on;      
      
postgres=# explain select cust_id,count(*) from ccc group by cust_id;     
                                              QUERY PLAN                                                   
-------------------------------------------------------------------------------------------------------    
 Append  (cost=251248.61..6031194.59 rows=961 width=16)    
   ->  Finalize GroupAggregate  (cost=251248.61..251278.60 rows=40 width=16)    
         Group Key: ccc0.cust_id    
         ->  Gather Merge  (cost=251248.61..251273.40 rows=960 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=251248.03..251248.13 rows=40 width=16)    
                     Sort Key: ccc0.cust_id    
                     ->  Partial HashAggregate  (cost=251246.56..251246.96 rows=40 width=16)    
                           Group Key: ccc0.cust_id    
                           ->  Parallel Seq Scan on ccc0  (cost=0.00..242566.71 rows=1735971 width=8)    
   ->  Finalize GroupAggregate  (cost=244986.56..245015.80 rows=39 width=16)    
         Group Key: ccc1.cust_id    
         ->  Gather Merge  (cost=244986.56..245010.73 rows=936 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=244985.98..244986.07 rows=39 width=16)    
                     Sort Key: ccc1.cust_id    
                     ->  Partial HashAggregate  (cost=244984.56..244984.95 rows=39 width=16)    
                           Group Key: ccc1.cust_id    
                           ->  Parallel Seq Scan on ccc1  (cost=0.00..236521.04 rows=1692704 width=8)    
   ->  Finalize GroupAggregate  (cost=282669.29..282703.03 rows=45 width=16)    
         Group Key: ccc2.cust_id    
         ->  Gather Merge  (cost=282669.29..282697.18 rows=1080 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=282668.71..282668.82 rows=45 width=16)    
                     Sort Key: ccc2.cust_id    
                     ->  Partial HashAggregate  (cost=282667.02..282667.47 rows=45 width=16)    
                           Group Key: ccc2.cust_id    
                           ->  Parallel Seq Scan on ccc2  (cost=0.00..272901.68 rows=1953068 width=8)    
   ->  Finalize GroupAggregate  (cost=213567.74..213593.23 rows=34 width=16)    
         Group Key: ccc3.cust_id    
         ->  Gather Merge  (cost=213567.74..213588.81 rows=816 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=213567.16..213567.25 rows=34 width=16)    
                     Sort Key: ccc3.cust_id    
                     ->  Partial HashAggregate  (cost=213565.96..213566.30 rows=34 width=16)    
                           Group Key: ccc3.cust_id    
                           ->  Parallel Seq Scan on ccc3  (cost=0.00..206187.97 rows=1475597 width=8)    
   ->  Finalize GroupAggregate  (cost=257459.33..257490.07 rows=41 width=16)    
         Group Key: ccc4.cust_id    
         ->  Gather Merge  (cost=257459.33..257484.74 rows=984 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=257458.75..257458.86 rows=41 width=16)    
                     Sort Key: ccc4.cust_id    
                     ->  Partial HashAggregate  (cost=257457.24..257457.65 rows=41 width=16)    
                           Group Key: ccc4.cust_id    
                           ->  Parallel Seq Scan on ccc4  (cost=0.00..248562.83 rows=1778883 width=8)    
   ->  Finalize GroupAggregate  (cost=238722.97..238751.46 rows=38 width=16)    
         Group Key: ccc5.cust_id    
         ->  Gather Merge  (cost=238722.97..238746.52 rows=912 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=238722.39..238722.48 rows=38 width=16)    
                     Sort Key: ccc5.cust_id    
                     ->  Partial HashAggregate  (cost=238721.01..238721.39 rows=38 width=16)    
                           Group Key: ccc5.cust_id    
                           ->  Parallel Seq Scan on ccc5  (cost=0.00..230474.01 rows=1649401 width=8)    
   ->  Finalize GroupAggregate  (cost=245023.21..245052.45 rows=39 width=16)    
         Group Key: ccc6.cust_id    
         ->  Gather Merge  (cost=245023.21..245047.38 rows=936 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=245022.63..245022.72 rows=39 width=16)    
                     Sort Key: ccc6.cust_id    
                     ->  Partial HashAggregate  (cost=245021.21..245021.60 rows=39 width=16)    
                           Group Key: ccc6.cust_id    
                           ->  Parallel Seq Scan on ccc6  (cost=0.00..236556.47 rows=1692947 width=8)    
   ->  Finalize GroupAggregate  (cost=263789.43..263820.92 rows=42 width=16)    
         Group Key: ccc7.cust_id    
         ->  Gather Merge  (cost=263789.43..263815.46 rows=1008 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=263788.85..263788.96 rows=42 width=16)    
                     Sort Key: ccc7.cust_id    
                     ->  Partial HashAggregate  (cost=263787.30..263787.72 rows=42 width=16)    
                           Group Key: ccc7.cust_id    
                           ->  Parallel Seq Scan on ccc7  (cost=0.00..254674.20 rows=1822620 width=8)    
   ->  Finalize GroupAggregate  (cost=235547.21..235575.70 rows=38 width=16)    
         Group Key: ccc8.cust_id    
         ->  Gather Merge  (cost=235547.21..235570.76 rows=912 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=235546.63..235546.73 rows=38 width=16)    
                     Sort Key: ccc8.cust_id    
                     ->  Partial HashAggregate  (cost=235545.25..235545.63 rows=38 width=16)    
                           Group Key: ccc8.cust_id    
                           ->  Parallel Seq Scan on ccc8  (cost=0.00..227407.83 rows=1627484 width=8)    
   ->  Finalize GroupAggregate  (cost=238753.52..238782.01 rows=38 width=16)    
         Group Key: ccc9.cust_id    
         ->  Gather Merge  (cost=238753.52..238777.07 rows=912 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=238752.94..238753.03 rows=38 width=16)    
                     Sort Key: ccc9.cust_id    
                     ->  Partial HashAggregate  (cost=238751.56..238751.94 rows=38 width=16)    
                           Group Key: ccc9.cust_id    
                           ->  Parallel Seq Scan on ccc9  (cost=0.00..230503.37 rows=1649637 width=8)    
   ->  Finalize GroupAggregate  (cost=263886.49..263917.98 rows=42 width=16)    
         Group Key: ccc10.cust_id    
         ->  Gather Merge  (cost=263886.49..263912.52 rows=1008 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=263885.91..263886.02 rows=42 width=16)    
                     Sort Key: ccc10.cust_id    
                     ->  Partial HashAggregate  (cost=263884.36..263884.78 rows=42 width=16)    
                           Group Key: ccc10.cust_id    
                           ->  Parallel Seq Scan on ccc10  (cost=0.00..254767.91 rows=1823291 width=8)    
   ->  Finalize GroupAggregate  (cost=207290.45..207315.19 rows=33 width=16)    
         Group Key: ccc11.cust_id    
         ->  Gather Merge  (cost=207290.45..207310.90 rows=792 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=207289.87..207289.95 rows=33 width=16)    
                     Sort Key: ccc11.cust_id    
                     ->  Partial HashAggregate  (cost=207288.70..207289.03 rows=33 width=16)    
                           Group Key: ccc11.cust_id    
                           ->  Parallel Seq Scan on ccc11  (cost=0.00..200127.47 rows=1432247 width=8)    
   ->  Finalize GroupAggregate  (cost=320379.91..320418.15 rows=51 width=16)    
         Group Key: ccc12.cust_id    
         ->  Gather Merge  (cost=320379.91..320411.52 rows=1224 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=320379.33..320379.46 rows=51 width=16)    
                     Sort Key: ccc12.cust_id    
                     ->  Partial HashAggregate  (cost=320377.38..320377.89 rows=51 width=16)    
                           Group Key: ccc12.cust_id    
                           ->  Parallel Seq Scan on ccc12  (cost=0.00..309309.25 rows=2213625 width=8)    
   ->  Finalize GroupAggregate  (cost=263878.68..263910.17 rows=42 width=16)    
         Group Key: ccc13.cust_id    
         ->  Gather Merge  (cost=263878.68..263904.71 rows=1008 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=263878.10..263878.21 rows=42 width=16)    
                     Sort Key: ccc13.cust_id    
                     ->  Partial HashAggregate  (cost=263876.55..263876.97 rows=42 width=16)    
                           Group Key: ccc13.cust_id    
                           ->  Parallel Seq Scan on ccc13  (cost=0.00..254760.37 rows=1823237 width=8)    
   ->  Finalize GroupAggregate  (cost=307756.52..307793.26 rows=49 width=16)    
         Group Key: ccc14.cust_id    
         ->  Gather Merge  (cost=307756.52..307786.89 rows=1176 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=307755.94..307756.07 rows=49 width=16)    
                     Sort Key: ccc14.cust_id    
                     ->  Partial HashAggregate  (cost=307754.08..307754.57 rows=49 width=16)    
                           Group Key: ccc14.cust_id    
                           ->  Parallel Seq Scan on ccc14  (cost=0.00..297122.05 rows=2126405 width=8)    
   ->  Finalize GroupAggregate  (cost=238670.96..238699.45 rows=38 width=16)    
         Group Key: ccc15.cust_id    
         ->  Gather Merge  (cost=238670.96..238694.51 rows=912 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=238670.38..238670.48 rows=38 width=16)    
                     Sort Key: ccc15.cust_id    
                     ->  Partial HashAggregate  (cost=238669.00..238669.38 rows=38 width=16)    
                           Group Key: ccc15.cust_id    
                           ->  Parallel Seq Scan on ccc15  (cost=0.00..230423.67 rows=1649067 width=8)    
   ->  Finalize GroupAggregate  (cost=248080.23..248110.22 rows=40 width=16)    
         Group Key: ccc16.cust_id    
         ->  Gather Merge  (cost=248080.23..248105.02 rows=960 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=248079.65..248079.75 rows=40 width=16)    
                     Sort Key: ccc16.cust_id    
                     ->  Partial HashAggregate  (cost=248078.19..248078.59 rows=40 width=16)    
                           Group Key: ccc16.cust_id    
                           ->  Parallel Seq Scan on ccc16  (cost=0.00..239507.79 rows=1714079 width=8)    
   ->  Finalize GroupAggregate  (cost=263822.24..263853.73 rows=42 width=16)    
         Group Key: ccc17.cust_id    
         ->  Gather Merge  (cost=263822.24..263848.27 rows=1008 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=263821.66..263821.77 rows=42 width=16)    
                     Sort Key: ccc17.cust_id    
                     ->  Partial HashAggregate  (cost=263820.11..263820.53 rows=42 width=16)    
                           Group Key: ccc17.cust_id    
                           ->  Parallel Seq Scan on ccc17  (cost=0.00..254706.07 rows=1822807 width=8)    
   ->  Finalize GroupAggregate  (cost=314097.79..314135.28 rows=50 width=16)    
         Group Key: ccc18.cust_id    
         ->  Gather Merge  (cost=314097.79..314128.78 rows=1200 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=314097.21..314097.33 rows=50 width=16)    
                     Sort Key: ccc18.cust_id    
                     ->  Partial HashAggregate  (cost=314095.30..314095.80 rows=50 width=16)    
                           Group Key: ccc18.cust_id    
                           ->  Parallel Seq Scan on ccc18  (cost=0.00..303244.20 rows=2170220 width=8)    
   ->  Finalize GroupAggregate  (cost=207320.57..207345.31 rows=33 width=16)    
         Group Key: ccc19.cust_id    
         ->  Gather Merge  (cost=207320.57..207341.02 rows=792 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=207319.99..207320.07 rows=33 width=16)    
                     Sort Key: ccc19.cust_id    
                     ->  Partial HashAggregate  (cost=207318.83..207319.15 rows=33 width=16)    
                           Group Key: ccc19.cust_id    
                           ->  Parallel Seq Scan on ccc19  (cost=0.00..200156.55 rows=1432455 width=8)    
   ->  Finalize GroupAggregate  (cost=251327.81..251357.81 rows=40 width=16)    
         Group Key: ccc20.cust_id    
         ->  Gather Merge  (cost=251327.81..251352.61 rows=960 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=251327.23..251327.33 rows=40 width=16)    
                     Sort Key: ccc20.cust_id    
                     ->  Partial HashAggregate  (cost=251325.77..251326.17 rows=40 width=16)    
                           Group Key: ccc20.cust_id    
                           ->  Parallel Seq Scan on ccc20  (cost=0.00..242643.18 rows=1736518 width=8)    
   ->  Finalize GroupAggregate  (cost=157070.25..157089.00 rows=25 width=16)    
         Group Key: ccc21.cust_id    
         ->  Gather Merge  (cost=157070.25..157085.75 rows=600 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=157069.67..157069.74 rows=25 width=16)    
                     Sort Key: ccc21.cust_id    
                     ->  Partial HashAggregate  (cost=157068.84..157069.09 rows=25 width=16)    
                           Group Key: ccc21.cust_id    
                           ->  Parallel Seq Scan on ccc21  (cost=0.00..151642.56 rows=1085256 width=8)    
   ->  Finalize GroupAggregate  (cost=263795.01..263826.50 rows=42 width=16)    
         Group Key: ccc22.cust_id    
         ->  Gather Merge  (cost=263795.01..263821.04 rows=1008 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=263794.43..263794.53 rows=42 width=16)    
                     Sort Key: ccc22.cust_id    
                     ->  Partial HashAggregate  (cost=263792.88..263793.29 rows=42 width=16)    
                           Group Key: ccc22.cust_id    
                           ->  Parallel Seq Scan on ccc22  (cost=0.00..254679.58 rows=1822658 width=8)    
   ->  Finalize GroupAggregate  (cost=251324.47..251354.46 rows=40 width=16)    
         Group Key: ccc23.cust_id    
         ->  Gather Merge  (cost=251324.47..251349.26 rows=960 width=16)    
               Workers Planned: 24    
               ->  Sort  (cost=251323.89..251323.99 rows=40 width=16)    
                     Sort Key: ccc23.cust_id    
                     ->  Partial HashAggregate  (cost=251322.42..251322.82 rows=40 width=16)    
                           Group Key: ccc23.cust_id    
                           ->  Parallel Seq Scan on ccc23  (cost=0.00..242639.95 rows=1736495 width=8)    
(217 rows)    
    
postgres=# select cust_id,count(*) from ccc group by cust_id;     
 cust_id |  count      
---------+---------    
      16 | 1041453    
      34 | 1042275    
      54 | 1039714    
      60 | 1040715    
      81 | 1041507    
     108 | 1042387    
     119 | 1041137    
     151 | 1041746    
     153 | 1042255    
     186 | 1041705    
..................................    
     588 | 1040386    
     629 | 1043353    
     686 | 1041974    
     690 | 1040047    
     693 | 1042870    
     725 | 1042487    
     765 | 1040199    
     770 | 1041953    
     795 | 1042219    
     801 | 1042153    
     807 | 1041840    
     821 | 1041773    
     870 | 1041345    
     874 | 1043176    
     895 | 1042988    
     915 | 1040430    
     934 | 1043436    
     951 | 1041738    
(961 rows)    
    
Time: 8142.401 ms (00:08.142)    

其他知识

1、优化器自动并行度算法 CBO

《PostgreSQL 9.6 并行计算 优化器算法浅析》

《PostgreSQL 11 并行计算算法,参数,强制并行度设置》

2、function, op 识别是否支持parallel

postgres=# select proparallel,proname from pg_proc;                                            
 proparallel |                   proname                                                                
-------------+----------------------------------------------                                            
 s           | boolin                                            
 s           | boolout                                            
 s           | byteain                                            
 s           | byteaout                                            

3、subquery mapreduce unlogged table

对于一些情况,如果期望简化优化器对非常非常复杂的SQL并行优化的负担,可以自己将SQL拆成几段,中间结果使用unlogged table保存,类似mapreduce的思想。unlogged table同样支持parallel 计算。

4、vacuum,垃圾回收并行。

5、dblink 异步调用并行

《PostgreSQL VOPS 向量计算 + DBLINK异步并行 - 单实例 10亿 聚合计算跑进2秒》

《PostgreSQL 相似搜索分布式架构设计与实践 - dblink异步调用与多机并行(远程 游标+记录 UDF实例)》

《PostgreSQL dblink异步调用实现 并行hash分片JOIN - 含数据交、并、差 提速案例 - 含dblink VS pg 11 parallel hash join VS pg 11 智能分区JOIN》

暂时不允许并行的场景(将来PG会继续扩大支持范围):

1、修改行,锁行,除了create table as , select into, create mview这几个可以使用并行。

2、query 会被中断时,例如cursor , loop in PL/SQL ,因为涉及到中间处理,所以不建议开启并行。

3、paralle unsafe udf ,这种UDF不会并行

4、嵌套并行(udf (内部query并行)),外部调用这个UDF的SQL不会并行。(主要是防止large parallel workers )

5、SSI 隔离级别

参考

https://www.postgresql.org/docs/11/parallel-plans.html

《PostgreSQL 11 并行计算算法,参数,强制并行度设置》

《PostgreSQL 11 preview - 并行计算 增强 汇总》

《PostgreSQL 10 自定义并行计算聚合函数的原理与实践 - (含array_agg合并多个数组为单个一元数组的例子)》

《PostgreSQL 9.6 并行计算 优化器算法浅析》

 

免费领取阿里云RDS PostgreSQL实例、ECS虚拟机

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
2月前
|
SQL 关系型数据库 数据库
PostgreSQL数据库报错 ERROR: multiple default values specified for column "" of table "" 如何解决?
PostgreSQL数据库报错 ERROR: multiple default values specified for column "" of table "" 如何解决?
312 59
|
SQL 移动开发 关系型数据库
PostgreSQL 执行计划,成本公式解说,代价因子校准,自动跟踪SQL执行计划(三)|学习笔记
快速学习PostgreSQL 执行计划,成本公式解说,代价因子校准,自动跟踪SQL执行计划(三)
PostgreSQL 执行计划,成本公式解说,代价因子校准,自动跟踪SQL执行计划(三)|学习笔记
|
SQL 弹性计算 算法
PostgreSQL 普通表在线转换为分区表 - online exchange to partition table
标签 PostgreSQL , 分区表 , 在线转换 背景 非分区表,如何在线(不影响业务)转换为分区表? 方法1,pg_pathman分区插件 《PostgreSQL 9.5+ 高效分区表实现 - pg_pathman》 使用非堵塞式的迁移接口 partition_table_concurrently( relation REGCLASS,
2734 0
|
SQL 算法 关系型数据库
PostgreSQL 普通表在线转换为分区表 - online exchange to partition table
PostgreSQL 普通表在线转换为分区表 - online exchange to partition table
2788 0
|
SQL 分布式计算 并行计算
PostgreSQL 并行计算解说 之13 - parallel OLAP : 中间结果 parallel with unlogged table
标签 PostgreSQL , cpu 并行 , smp 并行 , 并行计算 , gpu 并行 , 并行过程支持 背景 PostgreSQL 11 优化器已经支持了非常多场合的并行。简单估计,已支持27余种场景的并行计算。 parallel seq scan parallel
643 0
|
SQL 分布式计算 并行计算
PostgreSQL 并行计算解说 之14 - parallel index scan
标签 PostgreSQL , cpu 并行 , smp 并行 , 并行计算 , gpu 并行 , 并行过程支持 背景 PostgreSQL 11 优化器已经支持了非常多场合的并行。简单估计,已支持27余种场景的并行计算。 parallel seq scan paral
1185 0
|
关系型数据库 分布式数据库 PolarDB
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
364 0
|
存储 缓存 关系型数据库
|
存储 SQL 并行计算
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍(中)
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍
419 0
|
存储 算法 安全
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍(下)
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍
383 0
下一篇
无影云桌面