PostgreSQL 10.0 preview 功能增强 - OLAP增强 向量聚集索引(列存储扩展)

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

标签

PostgreSQL , 10.0 , Vertical Clustered Index (columnar store extension) , 列存储 , 向量聚集索引


背景

未来数据库OLTP+OLAP逐渐模糊化,需求逐渐融合是一个大的趋势,如果你的数据库只支持OLTP的场景,未来可能会成为业务的绊脚石。

在这方面PostgreSQL每年发布的新版本,都给用户很大的惊喜,OLTP已经具备非常强大的竞争力(性能、功能、稳定性、成熟度、案例、跨行业应用等),而OLAP方面,新增的feature也是层出不穷。

《PostgreSQL 10.0 preview 性能增强 - OLAP提速框架, Faster Expression Evaluation Framework(含JIT)》

《分析加速引擎黑科技 - LLVM、列存、多核并行、算子复用 大联姻 - 一起来开启PostgreSQL的百宝箱》

《PostgreSQL 向量化执行插件(瓦片式实现) 10x提速OLAP》

PostgreSQL 10.0将要整合的一个功能:

Vertical Clustered Index (columnar store extension) , 列存储 , 向量聚集索引。

这个模块是Fujitsu实验室提供的,一种新增的VCI索引访问接口,这么做可以最小化数据库的改动。

用户仅需要在原来的堆表上创建VCI即可(向量聚集索引),索引将以向量聚集形式组织,提升查询性能。

VCI有两方面的优化,索引数据分为两个部分:

1. 写优化部分(WOS)

行格式存储(类似堆表),同时携带xmin/xmax标记(事务号),所以如果更新WOS中的数据,和更新PostgreSQL原有的堆表一样效率很高。

PostgreSQL backend process或者autovacuum会持续自动的将WOS中已经frozen的记录(即对所有事务可见的记录),转移到ROS(读优化部分)存储。

ROS存储中,没有版本信息(XMIN/XMAX),有tuple id,可以通过tuple id访问ROS中的记录。(没有版本信息,如何判断可见性呢?后面讲)

2. 读优化部分(ROS)

ROS为列存储,每列一个或一批文件,在ROS中,记录是以extent来组织的,每个extent存储262,144行记录,可以方便的建立堆表TID to ROS CRID的映射关系。

插入vci记录,与插入索引一样。(插入WOS,后台自动将frozen记录合并到ROS)

删除vci记录,如果数据只在WOS中,删除和删堆表记录一样,做标记,如果数据已经从WOS合并到ROS,那么需要维护一个向量,这个向量中包含被删除的记录在ROS中的tuple id, 以及删除该记录的事务的xact id等。读取ROS时,根据这个向量,过滤ros中对应的tuple id.

更新vci记录,与删除类似。

目前提供的性能测试数据

pic

pic

pic

讨论

Hi All,  

Fujitsu was interested in developing a columnar storage extension with  
minimal  
changes the server backend.  

The columnar store is implemented as an extension using index access  
methods.  
This can be easily enhanced with pluggable storage methods once they are  
available.  

A new index method (VCI) is added to create columnar index on the table.  

The following is the basic design idea of the columnar extension,  

This has the on-disk columnar representation. So, even after crash,  
the columnar format is recovered to the state when it was crashed.  

To provide performance benefit for both read and write operations,  
the data is stored in two formats  

1) write optimized storage (WOS)  
2) read optimized storage (ROS).  

This is useful for the users where there is a great chance of data  
modification  
that is newly added instead of the old data.  

WOS  
====  

write optimized storage is the data of all columns that are part of VCI are  
stored in a row wise format. All the newly added data is stored in WOS  
relation with xmin/xmax information also. If user wants to update/delete the  
newly added data, it doesn't affect the performance much compared to  
deleting the data from columnar storage.  

The tuples which don't have multiple copies or frozen data will be moved  
from WOS to ROS periodically by the background worker process or autovauum  
process. Every column data is stored separately in it's relation file. There  
is no transaction information is present in ROS. The data in ROS can be  
referred with tuple ID.  

In this approach, the column data is present in both heap and columnar  
storage.  

ROS  
====  

This is the place, where all the column data is stored in columnar format.  
The data from WOS to ROS is converted by background workers continously  
based  
on the tuple visibility check. Whenever the tuple is frozen and it gets  
moved  
from WOS to ROS.  

The Data in ROS is stored in extents. One extent contains of 262,144 rows.  
Because  
of fixed number of records in an extent it is easy to map the heap record  
to the columnar  
record with TID to CRID map.  

Insert  
=====  

The insert operation is just like inserting a data into an index.  

Select  
=====  

Because of two storage formats, during the select operation, the data in WOS  
is converted into Local ROS for the statement to be executed. The conversion  
cost depends upon the number of tuples present in the WOS file. This  
may add some performance overhead for select statements. The life of the  
Local  
ROS is till the end of query context.  

Delete  
=====  

During the delete operation, whenever the data is deleted in heap at the  
same  
time the data in WOS file is marked as deleted similar like heap. But in  
case  
if the data is already migrated from WOS to ROS, then we will maintain some  
delete vector to store the details of tuple id, transaction information and  
etc.  
During the data read from ROS file, it is verified against delete vector  
and  
confirms whether the record is visible or not? All the delete vectors  
data is applied to ROS periodically.  

More details of internal relations and their usage is available in the  
README.  
Still it needs more updates to explain full details of the columnar index  
design.  

The concept of Vertical clustered index columnar extension is from Fujitsu  
Labs, Japan.  

Following is the brief schedule of patches that are required  
for a better performing columnar store.  

1. Minimal server changes (new relkind "CSTORE" option)  
2. Base storage patch  
3. Support for moving data from WOS to ROS  
4. Local ROS support  
5. Custom scan support to read the data from ROS and Local ROS  
6. Background worker support for data movement  
7. Expression state support in VCI  
8. Aggregation support in VCI  
9. Pg_dump support for the new type of relations  
10. psql \d command support for CSTORE relations  
11. Parallelism support  
12. Compression support  
13. In-memory support with dynamic shared memory  

Currently I attached only patches for 1 and 2. These will provide the  
basic changes that are required in PostgreSQL core to the extension  
to work.  

I have to rebase/rewrite the rest of the patches to the latest master,  
and share them with community.  

Any Comments on the approach?  

Regards,  
Hari Babu  
Fujitsu Australia  

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

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

参考

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

https://www.postgresql.org/message-id/flat/CAJrrPGfaC7WC9NK6PTTy6YN-NN+hCy8xOLAh2doYhVg5d6HsAA@mail.gmail.com#CAJrrPGfaC7WC9NK6PTTy6YN-NN+hCy8xOLAh2doYhVg5d6HsAA@mail.gmail.com

《分析加速引擎黑科技 - LLVM、列存、多核并行、算子复用 大联姻 - 一起来开启PostgreSQL的百宝箱》

《PostgreSQL 向量化执行插件(瓦片式实现) 10x提速OLAP》

《PostgreSQL 10.0 preview 性能增强 - OLAP提速框架, Faster Expression Evaluation Framework(含JIT)》

相关实践学习
数据库实验室挑战任务-初级任务
本场景介绍如何开通属于你的免费云数据库,在RDS-MySQL中完成对学生成绩的详情查询,执行指定类型SQL。
阿里云云原生数据仓库AnalyticDB MySQL版 使用教程
云原生数据仓库AnalyticDB MySQL版是一种支持高并发低延时查询的新一代云原生数据仓库,高度兼容MySQL协议以及SQL:92、SQL:99、SQL:2003标准,可以对海量数据进行即时的多维分析透视和业务探索,快速构建企业云上数据仓库。 了解产品 https://www.aliyun.com/product/ApsaraDB/ads
相关文章
|
3月前
|
SQL 运维 关系型数据库
基于AnalyticDB PostgreSQL的实时物化视图研发实践
AnalyticDB PostgreSQL企业数据智能平台是构建数据智能的全流程平台,提供可视化实时任务开发 + 实时数据洞察,让您轻松平移离线任务,使用SQL和简单配置即可完成整个实时数仓的搭建。
359 1
|
2月前
|
存储 NoSQL MongoDB
Python爬虫之非关系型数据库存储#5
MongoDB、Redis【2月更文挑战第18天】
43 1
|
2月前
|
SQL 关系型数据库 MySQL
Python爬虫之关系型数据库存储#5
python MySQL 增删改查操作【2月更文挑战第17天】
28 1
|
3月前
|
存储 关系型数据库 MySQL
美柚:消息2.0引入PolarDB-M支撑大表并发和存储
美柚旗下的移动互联网软件包括美柚、宝宝记、柚子街等丰富的产品矩阵,为广大女性用户提供全面的健康管理、知识科普、线上购物、互联网医疗等服务。
|
7月前
|
关系型数据库 OLAP 数据库
如何克隆AnalyticDB PostgreSQL实例
AnalyticDB PostgreSQL版支持基于已有实例,快速克隆出一个完全相同的实例。
269 0
|
3月前
|
人工智能 关系型数据库 MySQL
一键实现穿衣自由|揭秘淘宝AI试衣间硬核技术:AnalyticDB MySQL向量在线召回
在AI试衣间功能的背后,阿里云瑶池旗下的云原生数据仓库AnalyticDB MySQL提供了高维向量低延时的在线向量召回检索服务,下面将进行介绍。
|
4月前
|
关系型数据库 OLAP 数据库连接
AnalyticDB PostgreSQL版目前不支持使用外部数据包装器
AnalyticDB PostgreSQL版目前不支持使用外部数据包装器
85 3
|
4月前
|
SQL 关系型数据库 C语言
PostgreSQL【应用 03】Docker部署的PostgreSQL扩展SQL之C语言函数(编写、编译、载入)计算向量余弦距离实例分享
PostgreSQL【应用 03】Docker部署的PostgreSQL扩展SQL之C语言函数(编写、编译、载入)计算向量余弦距离实例分享
45 0
|
4月前
|
关系型数据库 数据库 PostgreSQL
PostgreSQL【应用 01】使用Vector插件实现向量相似度查询(Docker部署的PostgreSQL安装pgvector插件说明)和Milvus向量库对比
PostgreSQL【应用 01】使用Vector插件实现向量相似度查询(Docker部署的PostgreSQL安装pgvector插件说明)和Milvus向量库对比
169 1
|
4月前
|
存储 关系型数据库 MySQL
存储成本最高降至原来的5%,PolarDB分布式冷数据归档的业务实践
国内某家兼具投资理财、文化旅游、票务为一体的大型综合型集团公司,2015年成立至今,由于业务高速发展,业务数据增长非常快,数据库系统屡次不堪重负。该公司数据库运维总监介绍,他们目前业务压力比较大的是票务和订单系统,他们的平台每天新增几千万的订单数据,订单的数据来自于各个终端,近几年每个月以300G的数据规模在高速增长,由于数据不断增加,数据库系统迄今为止迭代过了3次。

相关产品

  • 云原生数据库 PolarDB