PostgreSQL 10.0 preview 多核并行增强 - tuplesort 多核并行创建索引

简介:

标签

PostgreSQL , 10.0 , 并行增强 , 多核并行创建索引


背景

PostgreSQL 10.0的多核并行有了诸多增强,比如多核并行排序,可以用于提升创建btree索引的速度。

As some of you know, I've been working on parallel sort. I think I've  
gone as long as I can without feedback on the design (and I see that  
we're accepting stuff for September CF now), so I'd like to share what  
I came up with. This project is something that I've worked on  
inconsistently since late last year. It can be thought of as the  
Postgres 10 follow-up to the 9.6 work on external sorting.  

Attached WIP patch series:  

* Adds a parallel sorting capability to tuplesort.c.  

* Adds a new client of this capability: btbuild()/nbtsort.c can now  
create B-Trees in parallel.  

Most of the complexity here relates to the first item; the tuplesort  
module has been extended to support sorting in parallel. This is  
usable in principle by every existing tuplesort caller, without any  
restriction imposed by the newly expanded tuplesort.h interface. So,  
for example, randomAccess MinimalTuple support has been added,  
although it goes unused for now.  

I went with CREATE INDEX as the first client of parallel sort in part  
because the cost model and so on can be relatively straightforward.  
Even CLUSTER uses the optimizer to determine if a sort strategy is  
appropriate, and that would need to be taught about parallelism if its  
tuplesort is to be parallelized. I suppose that I'll probably try to  
get CLUSTER (with a tuplesort) done in the Postgres 10 development  
cycle too, but not just yet.  

For now, I would prefer to focus discussion on tuplesort itself. If  
you can only look at one part of this patch, please look at the  
high-level description of the interface/caller contract that was added  
to tuplesort.h.  

Performance  
===========  

Without further ado, I'll demonstrate how the patch series improves  
performance in one case. This benchmark was run on an AWS server with  
many disks. A d2.4xlarge instance was used, with 16 vCPUs, 122 GiB  
RAM, 12 x 2 TB HDDs, running Amazon Linux. Apparently, this AWS  
instance type can sustain 1,750 MB/second of I/O, which I was able to  
verify during testing (when a parallel sequential scan ran, iotop  
reported read throughput slightly above that for multi-second bursts).  
Disks were configured in software RAID0. These instances have disks  
that are optimized for sequential performance, which suits the patch  
quite well. I don't usually trust AWS EC2 for performance testing, but  
it seemed to work well here (results were pretty consistent).  

Setup:  

CREATE TABLE parallel_sort_test AS  
    SELECT hashint8(i) randint,  
    md5(i::text) collate "C" padding1,  
    md5(i::text || '2') collate "C" padding2  
    FROM generate_series(0, 1e9::bigint) i;  

CHECKPOINT;  

This leaves us with a parallel_sort_test table that is 94 GB in size.  

SET maintenance_work_mem = '8GB';  

-- Serial case (external sort, should closely match master branch):  
CREATE INDEX serial_idx ON parallel_sort_test (randint) WITH  
(parallel_workers = 0);  

Total time: 00:15:42.15  

-- Patch with 8 tuplesort "sort-and-scan" workers (leader process  
participates as a worker here):  
CREATE INDEX patch_8_idx ON parallel_sort_test (randint) WITH  
(parallel_workers = 7);  

Total time: 00:06:03.86  

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

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

参考

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

https://www.postgresql.org/message-id/flat/CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com#CAM3SWZQKM=Pzc=CAHzRixKjp2eO5Q0Jg1SoFQqeXFQ647JiwqQ@mail.gmail.com

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
6月前
|
存储 监控 关系型数据库
B-tree不是万能药:PostgreSQL索引失效的7种高频场景与破解方案
在PostgreSQL优化实践中,B-tree索引虽承担了80%以上的查询加速任务,但因多种原因可能导致索引失效,引发性能骤降。本文深入剖析7种高频失效场景,包括隐式类型转换、函数包裹列、前导通配符等,并通过实战案例揭示问题本质,提供生产验证的解决方案。同时,总结索引使用决策矩阵与关键原则,助你让索引真正发挥作用。
433 0
|
监控 关系型数据库 数据库
PostgreSQL的索引优化策略?
【8月更文挑战第26天】PostgreSQL的索引优化策略?
498 1
|
10月前
|
SQL 关系型数据库 OLAP
云原生数据仓库AnalyticDB PostgreSQL同一个SQL可以实现向量索引、全文索引GIN、普通索引BTREE混合查询,简化业务实现逻辑、提升查询性能
本文档介绍了如何在AnalyticDB for PostgreSQL中创建表、向量索引及混合检索的实现步骤。主要内容包括:创建`articles`表并设置向量存储格式,创建ANN向量索引,为表增加`username`和`time`列,建立BTREE索引和GIN全文检索索引,并展示了查询结果。参考文档提供了详细的SQL语句和配置说明。
337 2
|
11月前
|
JSON 关系型数据库 PostgreSQL
PostgreSQL 9种索引的原理和应用场景
PostgreSQL 支持九种主要索引类型,包括 B-Tree、Hash、GiST、SP-GiST、GIN、BRIN、Bitmap、Partial 和 Unique 索引。每种索引适用于不同场景,如 B-Tree 适合范围查询和排序,Hash 仅用于等值查询,GiST 支持全文搜索和几何数据查询,GIN 适用于多值列和 JSON 数据,BRIN 适合非常大的表,Bitmap 适用于低基数列,Partial 只对部分数据创建索引,Unique 确保列值唯一。
|
SQL 关系型数据库 MySQL
SQL Server、MySQL、PostgreSQL:主流数据库SQL语法异同比较——深入探讨数据类型、分页查询、表创建与数据插入、函数和索引等关键语法差异,为跨数据库开发提供实用指导
【8月更文挑战第31天】SQL Server、MySQL和PostgreSQL是当今最流行的关系型数据库管理系统,均使用SQL作为查询语言,但在语法和功能实现上存在差异。本文将比较它们在数据类型、分页查询、创建和插入数据以及函数和索引等方面的异同,帮助开发者更好地理解和使用这些数据库。尽管它们共用SQL语言,但每个系统都有独特的语法规则,了解这些差异有助于提升开发效率和项目成功率。
1633 0
|
6月前
|
存储 关系型数据库 测试技术
拯救海量数据:PostgreSQL分区表性能优化实战手册(附压测对比)
本文深入解析PostgreSQL分区表的核心原理与优化策略,涵盖性能痛点、实战案例及压测对比。首先阐述分区表作为继承表+路由规则的逻辑封装,分析分区裁剪失效、全局索引膨胀和VACUUM堆积三大性能杀手,并通过电商订单表崩溃事件说明旧分区维护的重要性。接着提出四维设计法优化分区策略,包括时间范围分区黄金法则与自动化维护体系。同时对比局部索引与全局索引性能,展示后者在特定场景下的优势。进一步探讨并行查询优化、冷热数据分层存储及故障复盘,解决分区锁竞争问题。
821 2
|
关系型数据库 分布式数据库 数据库
|
关系型数据库 分布式数据库 PolarDB
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
《阿里云产品手册2022-2023 版》——PolarDB for PostgreSQL
562 0
|
存储 缓存 关系型数据库
|
存储 SQL 并行计算
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍(中)
PolarDB for PostgreSQL 开源必读手册-开源PolarDB for PostgreSQL架构介绍
691 0

相关产品

  • 云原生数据库 PolarDB
  • 云数据库 RDS PostgreSQL 版
  • 推荐镜像

    更多