首页 > 数据库 >PostgreSQL与openGauss之分区性能

PostgreSQL与openGauss之分区性能

时间:2024-03-14 17:58:20浏览次数:13  
标签:hash 分区 partition col1 part ms table PostgreSQL openGauss

PostgreSQL 与 openGauss 之分区性能

概述

PostgreSQL 与 openGauss 分区表定义差异,请参考https://www.modb.pro/db/41393。

openGauss1.1.0 开始支持 hash/list 分区,hash 分区表最多支持 64 个分区,否则会报:

ERROR: Un-support feature
DETAIL: The partition’s length should be less than 65.

本次对 PostgreSQL 和 openGauss 64 个子分区表的常规操作对比。

服务器配置:虚拟机 8G4C50G

数据库版本:PostgreSQL13.1、openGauss1.1.0

添加分区表

PostgreSQL 数据库:

--创建父表
CREATE TABLE partition_table(
 id          int,
 col1        character varying(16),
 create_time timestamptz
) PARTITION BY HASH(id);

--添加分区
SELECT 'CREATE TABLE partition_table_' || n || ' PARTITION of partition_table FOR VALUES WITH (MODULUS 64, REMAINDER  ' || n || ');' FROM generate_series(0,63) as n ;\gexec

--初始化数据
INSERT INTO partition_table(id,col1,create_time) SELECT round(100000000*random()), n || '_col1',now() FROM generate_series(1,10000000) n;

--添加索引
CREATE INDEX ON partition_table USING BTREE(id);
CREATE INDEX ON partition_table USING BTREE(col1);

openGauss 数据库:

--创建分区表
create table partition_table(
	id int,
	col1 varchar(16),
	create_time timestamptz default now())
partition by hash(id)
(partition part_hash_1,
partition part_hash_2,
partition part_hash_3,
partition part_hash_4,
partition part_hash_5,
partition part_hash_6,
partition part_hash_7,
partition part_hash_8,
partition part_hash_9,
partition part_hash_10,
partition part_hash_11,
partition part_hash_12,
partition part_hash_13,
partition part_hash_14,
partition part_hash_15,
partition part_hash_16,
partition part_hash_17,
partition part_hash_18,
partition part_hash_19,
partition part_hash_20,
partition part_hash_21,
partition part_hash_22,
partition part_hash_23,
partition part_hash_24,
partition part_hash_25,
partition part_hash_26,
partition part_hash_27,
partition part_hash_28,
partition part_hash_29,
partition part_hash_30,
partition part_hash_31,
partition part_hash_32,
partition part_hash_33,
partition part_hash_34,
partition part_hash_35,
partition part_hash_36,
partition part_hash_37,
partition part_hash_38,
partition part_hash_39,
partition part_hash_40,
partition part_hash_41,
partition part_hash_42,
partition part_hash_43,
partition part_hash_44,
partition part_hash_45,
partition part_hash_46,
partition part_hash_47,
partition part_hash_48,
partition part_hash_49,
partition part_hash_50,
partition part_hash_51,
partition part_hash_52,
partition part_hash_53,
partition part_hash_54,
partition part_hash_55,
partition part_hash_56,
partition part_hash_57,
partition part_hash_58,
partition part_hash_59,
partition part_hash_60,
partition part_hash_61,
partition part_hash_62,
partition part_hash_63,
partition part_hash_64);

--初始化数据
INSERT INTO partition_table(id,col1,create_time) SELECT round(100000000*random()), n || '_col1',now() FROM generate_series(1,10000000) n;

--添加全局索引
CREATE INDEX ON partition_table USING BTREE(id);
CREATE INDEX ON partition_table USING BTREE(col1);

--添加本地索引
CREATE INDEX ON partition_table USING BTREE(id) local;
CREATE INDEX ON partition_table USING BTREE(col1) local;

测试方法

采用 pgbench 压测工具,自定义压测脚本的方式来对比。

cat bench.sql
\set idpp random(1,100000)
--insert into partition_table values(:idpp,:idpp||'_col1',now());
--update partition_table set create_time=now() where id=:idpp;
--update partition_table set create_time=now() where col1=:idpp||'_col1';
--select * from partition_table where id=:idpp;
--select * from partition_table where col1=:idpp||'_col1';

pgbench -p 5432 -j 30 -c 30 -M prepared -T 30 -n yunlong -f bench.sql

结果对比

  

分区键查询

非分区键查询

分区键更新

非分区键更新

插入

PostgreSQL

0.594 ms

7.978 ms

1.612 ms

17.413 ms

17.2ms

openGauss(全局索引)

0.612 ms

0.758 ms

10.450 ms

88.151 ms

78.082 ms

openGauss(本地索引)

5.635 ms

6.765 ms

15.187 ms

94.614 ms

84.927 ms

结果对比发现,

1、Postgresql13.1 版本在分区方面总来看优越于 openGauss1.1.0。

2、opengauss 全局索引会比本地索引性能更好,但全局索引维护成本高。

3、非分区键查询,带全局索引的 opengauss 查询性能最快。

此测试受限于服务器环境,数据仅做参考比对。

标签:hash,分区,partition,col1,part,ms,table,PostgreSQL,openGauss
From: https://www.cnblogs.com/renxyz/p/18073584

相关文章

  • PostgreSQL与openGauss之关键字
    PostgreSQL与openGauss之关键字日常数据库运维的过程中可能对数据库关键字关注点并不是很高,但在程序开发的过程中,数据库对象建模要尽可能的避开数据库关键字的使用,否则在后续开发过程中需要用到各种转译的方法来将关键字转换为普通字符,会非常的麻烦。最近在openGauss上执行......
  • openGauss分区使用样例
    openGauss分区使用样例概述openGauss1.1.0版本开始,分区方式分为三种,分别是RANGE、HASH和LIST,官方文档中对于分区表的使用样例比较少,这里对各种分区使用方式做一下整理,方便以后快速调整使用。范围分区VALUESLESSTHAN语法格式分区策略的分区键最多支持4列分区键支持......
  • openGauss行存与列存
    openGauss行存与列存列存表限制列存表不支持数组。列存表的数量建议不超过1000个。列存表的表级约束只支持PARTIALCLUSTERKEY,不支持主外键等表级约束。列存表的字段约束只支持NULL、NOTNULL和DEFAULT常量值。列存表不支持alter命令修改字段约束。列存表支持......
  • openGauss监控之exporter部署
    openGauss监控之exporter部署概述opengauss_exporter是为openGauss数据库量身打造的数据采集工具,配合当前最受欢迎的监控报警框架prometheus+grafana组合实时展示数据库信息,为openGauss数据库的平稳运行保驾护航。opengauss_exporter同openGauss数据库一样是开源......
  • PostgreSQL从入门到精通教程 - 第46讲:poc-tpch测试
       PostgreSQL从小白到专家,是从入门逐渐能力提升的一个系列教程,内容包括对PG基础的认知、包括安装使用、包括角色权限、包括维护管理、、等内容,希望对热爱PG、学习PG的同学们有帮助,欢迎持续关注CUUGPG技术大讲堂。 第46讲:POC-TPCH测试  内容1:TPC-H介绍内容2:TPC-H......
  • MogDB openGauss 角色切换后sequence为什么不连续
    本文出处:https://www.modb.pro/db/569272背景今天在客户现场做高可用切换测试,为了验证数据库节点角色切换后无数据丢失,我单独创建一张使用了自增sequence的表,通过vip方式访问数据库,并1s插入一条数据。因为数据库本身是通过benchmarksql工具加压的,数据库服务器的CPU使......
  • MogDB openGauss wal日志解析工具 mog_xlogdump
    MogDB/openGausswal日志解析工具mog_xlogdump本文出处:https://www.modb.pro/db/398124概述mog_xlogdump是云和恩墨独立开发的wal日志离线解析工具。熟悉PG的小伙伴应该都使用pg_xlogdump/pg_waldump查看过PG数据库的wal文件,解析的wal数据结果是没有办法直接拿......
  • MogDB-openGauss default privileges 使用方法
    MogDB/openGaussdefaultprivileges使用方法权限是用户访问数据库对象的首要条件,每个新增用户默认属于PUBLIC角色组成员,也就是具有PUBLIC角色组的权限,但在日常业务使用中,仅仅具有PUBLIC权限是远远不够的,还需要具有额外的权限,在MogDB/openGauss数据库支持的业务中经常需......
  • openGauss 由于RemoveIPC未关闭导致数据库crash
    openGauss由于RemoveIPC未关闭导致数据库crashsemop引发的数据库crash--主库FATAL:semop(id=xxxxx)failed:IdentifierremovedFATAL:semctl(xxxxxx,11,SETVAL,0)failed:Invalidargument--备库FATAL:semctl(xxxxxx,11,SETVAL,0)failed:InvalidargumentLOG......
  • MogDB openGauss 自定义snmptrapd告警信息
    MogDB/openGauss自定义snmptrapd告警信息本文出处:https://www.modb.pro/db/232391在之前的文章MogDB/openGauss监控告警配置介绍了如何通过alertmanager模块将报警通过snmp推送出去,但是在实际使用中,默认的报警规则信息并不能很好的满足snmp服务端的需求,需要定制化报警......