PostgreSQL 10.0 preview 性能增强 - 分区表性能增强(plan阶段加速)

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

标签

PostgreSQL , 10.0 , 分区表 , 子表 , 元信息搜索性能增强


背景

PostgreSQL 10.0 增强了分区表的子表搜索性能,对于涉及分区表包含子表特别多的QUERY,可以提升性能。

性能分析

get_tabstat_entry, find_all_inheritors成为主要瓶颈。

Hello.  

I decided to figure out whether current implementation of declarative  
partitioning has any bottlenecks when there is a lot of partitions. Here  
is what I did [1].  


-- init schema  

\timing on  

CREATE TABLE part_test (pk int not null, k int, v varchar(128)) PARTITION BY RANGE(pk);  

do $$  
declare  
    i integer;  
begin  
    for i in 1 .. 10000  
    loop  
        raise notice 'i = %', i;  
        execute ('CREATE TABLE part_test_' || i ||  
                 ' PARTITION OF part_test FOR VALUES FROM (' ||  
                 (1 + (i-1)*1000) || ') to (' || ( (i * 1000) + 1) || ');'  
                );  
    end loop;  
end $$;  

-- fill tables with some data  

do $$  
declare  
    i integer;  
begin  
    for i in 1 .. 100*1000  
    loop  
        raise notice 'i = %', i;  
        execute ('insert into part_test values ( ceil(random()*(10000-1)*1000), ceil(random()*10000*1000), '''' || ceil(random()*10000*1000) );');  
    end loop;  
end $$;  


Then:  


# 2580 is some pk that exists  
echo 'select * from part_test where pk = 2580;' > t.sql  
pgbench -j 7 -c 7 -f t.sql -P 1 -T 300 eax  


`perf top` showed to bottlenecks [2]. A stacktrace for the first one  
looks like this [3]:  


0x00000000007a42e2 in get_tabstat_entry (rel_id=25696, isshared=0 '\000') at pgstat.c:1689  
1689                if (entry->t_id == rel_id)  
#0  0x00000000007a42e2 in get_tabstat_entry (rel_id=25696, isshared=0 '\000') at pgstat.c:1689  
#1  0x00000000007a4275 in pgstat_initstats (rel=0x7f4af3fd41f8) at pgstat.c:1666  
#2  0x00000000004c7090 in relation_open (relationId=25696, lockmode=0) at heapam.c:1137  
#3  0x00000000004c72c9 in heap_open (relationId=25696, lockmode=0) at heapam.c:1291  
(skipped)  


And here is a stacktrace for the second bottleneck [4]:  


0x0000000000584fb1 in find_all_inheritors (parentrelId=16393, lockmode=1, numparents=0x0) at pg_inherits.c:199  
199             forboth(lo, rels_list, li, rel_numparents)  
#0  0x0000000000584fb1 in find_all_inheritors (parentrelId=16393, lockmode=1, numparents=0x0) at pg_inherits.c:199  
#1  0x000000000077fc9f in expand_inherited_rtentry (root=0x1badcb8, rte=0x1b630b8, rti=1) at prepunion.c:1408  
#2  0x000000000077fb67 in expand_inherited_tables (root=0x1badcb8) at prepunion.c:1335  
#3  0x0000000000767526 in subquery_planner (glob=0x1b63cc0, parse=0x1b62fa0, parent_root=0x0, hasRecursion=0 '\000', tuple_fraction=0) at planner.c:568  
(skipped)  


The first one could be easily fixed by introducing a hash table  
(rel_id -> pgStatList entry). Perhaps hash table should be used only  
after some threshold. Unless there are any objections I will send a  
corresponding patch shortly.  

I didn't explored the second bottleneck closely yet but at first glance  
it doesn't look much more complicated.  

Please don't hesitate to share your thoughts regarding this matter.  

[1] http://afiskon.ru/s/e3/5f47af9102_benchmark.txt  
[2] http://afiskon.ru/s/00/2008c4ae66_temp.png  
[3] http://afiskon.ru/s/23/650f0afc89_stack.txt  
[4] http://afiskon.ru/s/03/a7e685a4db_stack2.txt  

--   
Best regards,  
Aleksander Alekseev  

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

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

参考

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

https://www.postgresql.org/message-id/flat/20170228142509.GA19777@e733.localdomain#20170228142509.GA19777@e733.localdomain

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
4月前
|
存储 SQL 关系型数据库
PolarDB这个sql行存和列存性能差别好大 ,为什么?
PolarDB这个sql行存和列存性能差别好大 ,为什么?
33 0
|
4月前
|
存储 关系型数据库 数据库
postgresql|数据库|提升查询性能的物化视图解析
postgresql|数据库|提升查询性能的物化视图解析
156 0
|
6月前
|
监控 关系型数据库 数据库
《PostgreSQL性能大提升:实用优化技巧》
《PostgreSQL性能大提升:实用优化技巧》
334 0
|
3月前
|
关系型数据库 MySQL Serverless
阿里云云原生数据库 PolarDB MySQL Serverless:卓越的性能与无与伦比的弹性
阿里云原生数据库 PolarDB MySQL Serverless 拥有卓越性能和无与伦比的弹性。通过实验体验,深入了解其基本管理和配置、智能弹性伸缩特性和全局一致性特性。实验包括主节点和只读节点的弹性压测以及全局一致性测试,旨在亲身体验 PolarDB 的强大性能。通过实验,可以更好地在实际业务场景中应用 PolarDB,并根据需求进行性能优化和调整。
681 2
|
6月前
|
SQL 监控 关系型数据库
PostgreSQL普通表转换成分区表
如何使用pg_rewrite扩展将普遍表转换成分区表
277 0
|
3月前
|
存储 关系型数据库 分布式数据库
阿里云PolarDB解决乐麦多源数据存储性能问题
乐麦通过使用PolarDB数据库,使整个系统之间的数据查询分析更加高效
390 3
|
3月前
|
关系型数据库 数据挖掘 分布式数据库
报名预约|体验PolarDB澎湃性能与高性价比在线直播
「飞天技术沙龙数据库技术周」直播聚焦PolarDB产品体验
|
4月前
|
存储 SQL 关系型数据库
PolarDB-x 比mysql查询性能怎么样?速度快吗
PolarDB-x 比mysql查询性能怎么样?速度快吗
156 0
|
4月前
|
存储 关系型数据库 MySQL
PolarDB的性能对比
PolarDB的性能对比
124 1
|
6月前
|
存储 关系型数据库 Go
《深入PostgreSQL的存储引擎:原理与性能》
《深入PostgreSQL的存储引擎:原理与性能》
210 0

相关产品

  • 云原生数据库 PolarDB