【Postgres-XL】并行查询之谜

单机的postgresql并发查询

开启了并发查询,查看查询计划

Gather  (cost=1.65..1419.84 rows=325 width=452) (actual time=50.680..218.201 rows=36004 loops=1)
  Workers Planned: 2
  Workers Launched: 2
  ->  Append  (cost=1.65..1419.84 rows=137 width=452) (actual time=6.576..155.120 rows=12001 loops=3)
        ->  Parallel Bitmap Heap Scan on china_roads_partition_0  (cost=1.65..3.17 rows=1 width=488) (actual time=0.288..0.288 rows=0 loops=3)
        ->  Parallel Bitmap Heap Scan on china_roads_partition_1  (cost=1.65..3.17 rows=1 width=488) (actual time=0.288..0.288 rows=0 loops=3)
        ->  Parallel Bitmap Heap Scan on china_roads_partition_2  (cost=1.65..3.17 rows=1 width=488) (actual time=0.288..0.288 rows=0 loops=3)

在命令行查看进程,可以看到新建的worker,是并行查询无疑

postgres  4523  103  0.0 3468548 14856 ?       Rs   14:47   0:03 postgres: bgworker: parallel worker for PID 4512   
postgres  4524  104  0.0 3468684 14468 ?       Rs   14:47   0:03 postgres: bgworker: parallel worker for PID 4512

可是相同的SQL到PGXL执行,却没有并发

Postgres-XL并发

可分为2层并行
1、datanode并行查询
2、每个datanode创建的多个worker并行查询(可是实践证明这层没有开启)

PGXL的Coordinator、DataNode都是postgresql实例,我保证了postgresql.conf里的并行查询相关的参数一致

Coordinator的查询计划
协调器Coordinator处理来自应用程序的SQL语句,并确定应涉及哪个Datanode并为每个Datanode生成本地SQL语句,然后Remote

Remote Subquery Scan on all (datanode1,datanode2)  (cost=0.14..24.55 rows=3 width=488) (actual time=10.823..656.854 rows=53997 loops=1)
Planning time: 0.298 ms
Execution time: 664.866 ms

Coordinator与datanode建立连接就新建了一个postgres进程(如果连接池里还没有连接),状态是Remote

postgres 32338 16450  0 11:23 ?        00:00:00 postgres: postgres postgres 1xx.16.1.3(61885) SELECT
postgres 32524 16558 12 11:38 ?        00:00:03 postgres: postgres postgres 1xx.16.1.10(54738) REMOTE SUBPLAN (coord1:32338) (C:coord1:32338)
postgres 32526 16557 11 11:38 ?        00:00:02 postgres: postgres postgres 1xx.16.1.10(55352) REMOTE SUBPLAN (coord1:32338) (C:coord1:32338)
postgres 32528 16450  0 11:38 ?        00:00:00 postgres: postgres postgres 1xx.16.1.3(62120) idle

但是datanode并没有启动并行查询的多个worker进程!
Postgres-XL-10r1难道还没有好好地利用Postgresql的并行查询?

翻阅资料发现

Postgres-XL 10r1是继Postgres-XL 9.5r1之后的第一个主要版本。因此,此版本包含PostgreSQL 9.6和10版本中的大多数主要增强功能 。这是此类增强功能的简短列表,但除非另有说明,否则所有其他增强功能也适用。

E.2.3.1。PostgreSQL 10的主要增强功能

  • 声明式表分区

  • 改进的查询并行性

  • 总体性能显着改善

  • 改善监控

E.2.3.2。PostgreSQL 9.6的主要增强功能

  • 并行执行顺序扫描,联接和聚合

  • 避免在真空冻结操作期间不必要地扫描页面

  • 大幅提升性能,尤其是在多CPU套接字服务器上的可扩展性方面

  • 全文搜索现在可以搜索短语(多个相邻单词)

试试哈希联接(Hash Join),果然开启了并行查询
在这里插入图片描述
在这里插入图片描述

Gather在Coordinator上,Coordinator通过增加连接Remote,导致datanode增加postgres进程进行并行查询

单机Postgresql则是本机Gather,通过增加worker进程进行并行查询

postgres 14390  4176  0 09:33 ?        00:00:03 postgres: postgres postgres 1xx.16.1.3(55061) idle
postgres 14392  4284  0 09:33 ?        00:00:02 postgres: postgres postgres 1xx.16.1.1x(36192) idle
postgres 14394  4283  0 09:33 ?        00:00:01 postgres: postgres postgres 1xx.16.1.1x(36806) idle
postgres 14448  4176  0 09:39 ?        00:00:00 postgres: postgres postgres 1xx.16.1.3(55281) idle
postgres 14514  4176  0 09:39 ?        00:00:00 postgres: postgres postgres 1xx.16.1.3(55283) idle
postgres 14697  4176  0 09:39 ?        00:00:00 postgres: postgres postgres 1xx.16.1.3(55285) idle
postgres 15245  4284  0 09:41 ?        00:00:01 postgres: postgres postgres 1xx.16.1.1x(36904) idle
postgres 15247  4283  0 09:41 ?        00:00:01 postgres: postgres postgres 1xx.16.1.1x(37518) idle
postgres 15249  4284  0 09:41 ?        00:00:01 postgres: postgres postgres 1xx.16.1.1x(36912) idle
postgres 15251  4283  0 09:41 ?        00:00:01 postgres: postgres postgres 1xx.16.1.1x(37526) idle

再试试聚合,额,没有并行
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值