PostgreSQL 10.0 preview sharding增强 - 支持Append节点并行

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
云原生数据库 PolarDB 分布式版,标准版 2核8GB
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

标签

PostgreSQL , 10.0 , 多核并行 , Append


背景

Append节点通常出现在多个表union , union all或者查询包含多个分区的主表时。

需要对每个子表,或者每个subquery进行查询,然后在将结果合并。

PostgreSQL 10.0增加了一个并行模式即Append节点的并行,多个Append节点,可以并行的执行。、

从而大大的提升效率。

postgres_fdw的异步化调用,也需要Append并行的支持。

Currently an Append plan node does not execute its subplans in  
parallel. There is no distribution of workers across its subplans. The  
second subplan starts running only after the first subplan finishes,  
although the individual subplans may be running parallel scans.  

Secondly, we create a partial Append path for an appendrel, but we do  
that only if all of its member subpaths are partial paths. If one or  
more of the subplans is a non-parallel path, there will be only a  
non-parallel Append. So whatever node is sitting on top of Append is  
not going to do a parallel plan; for example, a select count(*) won't  
divide it into partial aggregates if the underlying Append is not  
partial.  

The attached patch removes both of the above restrictions.  There has  
already been a mail thread [1] that discusses an approach suggested by  
Robert Haas for implementing this feature. This patch uses this same  
approach.  

Attached is pgbench_create_partition.sql (derived from the one  
included in the above thread) that distributes pgbench_accounts table  
data into 3 partitions pgbench_account_[1-3]. The below queries use  
this schema.  

Consider a query such as :  
select count(*) from pgbench_accounts;  

Now suppose, these two partitions do not allow parallel scan :  
alter table pgbench_accounts_1 set (parallel_workers=0);  
alter table pgbench_accounts_2 set (parallel_workers=0);  

On HEAD, due to some of the partitions having non-parallel scans, the  
whole Append would be a sequential scan :  

 Aggregate  
   ->  Append  
         ->  Index Only Scan using pgbench_accounts_pkey on pgbench_accounts  
         ->  Seq Scan on pgbench_accounts_1  
         ->  Seq Scan on pgbench_accounts_2  
         ->  Seq Scan on pgbench_accounts_3  

Whereas, with the patch, the Append looks like this :  

 Finalize Aggregate  
   ->  Gather  
         Workers Planned: 6  
         ->  Partial Aggregate  
               ->  Parallel Append  
                     ->  Parallel Seq Scan on pgbench_accounts  
                     ->  Seq Scan on pgbench_accounts_1  
                     ->  Seq Scan on pgbench_accounts_2  
                     ->  Parallel Seq Scan on pgbench_accounts_3  

Above, Parallel Append is generated, and it executes all these  
subplans in parallel, with 1 worker executing each of the sequential  
scans, and multiple workers executing each of the parallel subplans.  


======= Implementation details ========  

------- Adding parallel-awareness -------  

In a given worker, this Append plan node will be executing just like  
the usual partial Append node. It will run a subplan until completion.  
The subplan may or may not be a partial parallel-aware plan like  
parallelScan. After the subplan is done, Append will choose the next  
subplan. It is here where it will be different than the current  
partial Append plan: it is parallel-aware. The Append nodes in the  
workers will be aware that there are other Append nodes running in  
parallel. The partial Append will have to coordinate with other Append  
nodes while choosing the next subplan.  

------- Distribution of workers --------  

The coordination info is stored in a shared array, each element of  
which describes the per-subplan info. This info contains the number of  
workers currently executing the subplan, and the maximum number of  
workers that should be executing it at the same time. For non-partial  
sublans, max workers would always be 1. For choosing the next subplan,  
the Append executor will sequentially iterate over the array to find a  
subplan having the least number of workers currently being executed,  
AND which is not already being executed by the maximum number of  
workers assigned for the subplan. Once it gets one, it increments  
current_workers, and releases the Spinlock, so that other workers can  
choose their next subplan if they are waiting.  

This way, workers would be fairly distributed across subplans.  

The shared array needs to be initialized and made available to  
workers. For this, we can do exactly what sequential scan does for  
being parallel-aware : Using function ExecAppendInitializeDSM()  
similar to ExecSeqScanInitializeDSM() in the backend to allocate the  
array. Similarly, for workers, have ExecAppendInitializeWorker() to  
retrieve the shared array.  

这个patch的讨论,详见邮件组,本文末尾URL。

PostgreSQL社区的作风非常严谨,一个patch可能在邮件组中讨论几个月甚至几年,根据大家的意见反复的修正,patch合并到master已经非常成熟,所以PostgreSQL的稳定性也是远近闻名的。

参考

https://commitfest.postgresql.org/13/987/

https://www.postgresql.org/message-id/flat/CAJ3gD9dy0K_E8r727heqXoBmWZ83HwLFwdcaSSmBQ1+S+vRuUQ@mail.gmail.com#CAJ3gD9dy0K_E8r727heqXoBmWZ83HwLFwdcaSSmBQ1+S+vRuUQ@mail.gmail.com

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
1月前
|
关系型数据库 分布式数据库 数据库
PolarDB常见问题之数据库不能自己减少节点如何解决
PolarDB是阿里云推出的下一代关系型数据库,具有高性能、高可用性和弹性伸缩能力,适用于大规模数据处理场景。本汇总囊括了PolarDB使用中用户可能遭遇的一系列常见问题及解答,旨在为数据库管理员和开发者提供全面的问题指导,确保数据库平稳运行和优化使用体验。
|
3月前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL版标准版计算节点规格详解
PolarDB MySQL版标准版计算节点规格详解
119 1
|
4月前
|
存储 安全 关系型数据库
PolarDB行列存节点的路由不是通过proxy路由的 是节点内部的路由吗?
PolarDB行列存节点的路由不是通过proxy路由的 是节点内部的路由吗?
19 0
|
5月前
|
消息中间件 存储 关系型数据库
PostgreSQL技术大讲堂 - 第33讲:并行查询管理
PostgreSQL从小白到专家,技术大讲堂 - 第33讲:并行查询管理
289 1
|
4月前
|
关系型数据库 MySQL 分布式数据库
PolarDB MySQL版并行查询技术探索与实践
PolarDB MySQL版并行查询技术探索与实践 PolarDB MySQL版在企业级查询加速特性上进行了深度技术探索,其中并行查询作为其重要组成部分,已经在线稳定运行多年,持续演进。本文将详细介绍并行查询的背景、挑战、方案、特性以及实践。
108 2
|
2月前
|
Oracle 关系型数据库 分布式数据库
PolarDB for PostgreSQL报错问题之跨节点执行报错如何解决
PolarDB for PostgreSQL是基于PostgreSQL开发的一款云原生关系型数据库服务,它提供了高性能、高可用性和弹性扩展的特性;本合集将围绕PolarDB(pg)的部署、管理和优化提供指导,以及常见问题的排查和解决办法。
|
4月前
|
SQL 关系型数据库 分布式数据库
深度解析PolarDB数据库并行查询技术
深度解析PolarDB数据库并行查询技术:加速SQL执行的关键问题和核心技术 随着数据规模的不断扩大,用户SQL的执行时间越来越长,这不仅对数据库的优化能力提出更高的要求,并且对数据库的执行模式也提出了新的挑战。为了解决这个问题,许多数据库系统,包括Oracle、SQL Server等,都开始提供并行查询引擎的支持,以充分利用系统资源,达到加速SQL执行的效果。本文将深入探讨基于代价进行并行优化、并行执行的云数据库的并行查询引擎的关键问题和核心技术。
123 2
|
11月前
|
存储 弹性计算 关系型数据库
实践教程之如何对PolarDB-X的存储节点发起备库重搭
PolarDB-X 为了方便用户体验,提供了免费的实验环境,您可以在实验环境里体验 PolarDB-X 的安装部署和各种内核特性。除了免费的实验,PolarDB-X 也提供免费的视频课程,手把手教你玩转 PolarDB-X 分布式数据库。本期实验将指导您如何对PolarDB-X的存储节点发起备库重搭。
|
存储 SQL 人工智能
PolarDB 弹性并行查询(ePQ)功能使用白皮书
1 法律声明阿里云提醒您在阅读或使用本文档之前仔细阅读、充分理解本法律声明各条款的内容。如果您 阅读或使用本文档,您的阅读或使用行为将被视为对本声明全部内容的认可。您应当通过阿里云网站或阿里云提供的其他授权通道下载、获取本文档,且仅能用于自身的 合法合规的业务活动。本文档的内容视为阿里云的保密信息,您应当严格遵守保密义务; 未经 阿里云事先书面同意,您不得向任何第三方披露本手册内容或提供给任何第三
452 0
PolarDB 弹性并行查询(ePQ)功能使用白皮书
|
存储 运维 Kubernetes
PolarDB-X 数据节点备库重搭
本文主要介绍PolarDB-X中DN(数据节点)备库重搭的背景,以及polardbx-operator上是如何实现DN备库重搭的。
PolarDB-X 数据节点备库重搭

相关产品

  • 云原生数据库 PolarDB