PostgreSQL fixed length wide-table VS MonetDB

本文涉及的产品
云原生数据库 PolarDB MySQL 版,通用型 2核8GB 50GB
云原生数据库 PolarDB PostgreSQL 版,标准版 2核4GB 50GB
简介:
注意这里所有的对比都是针对的PostgreSQL行存储, 没有使用cstore_fdw插件, 如果要在PG中使用列存储, 可以考虑一下.
参考 : 
本文对比一下MonetDB和PostgreSQL定长字段, 宽表的查询性能和导入性能.
篇幅太长, 测试环境和测试方法见以下BLOG : 

本文所述为PostgreSQL的性能, 因为目前PostgreSQL一条SQL只会用到1个核, 所以查询性能比MonetDB更差.
导入性能相比MonetDB也差3倍以上.
关联查询的性能差10倍以上.

COPY导入, 比MonetDB相差3倍以上(MonetDB约20秒导入一个文件).
#!/bin/bash

psql <<EOF
\timing
copy t1 from '/data01/postgres/1.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/2.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/3.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/4.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/5.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/6.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/7.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/8.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/9.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/10.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/11.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/12.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/13.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/14.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/15.sql' with csv delimiter '|';
copy t1 from '/data01/postgres/16.sql' with csv delimiter '|';
insert into t2 select * from t1;
insert into t3 select * from t1;
insert into t4 select * from t1;
insert into t5 select * from t1;
insert into t6 select * from t1;
insert into t7 select * from t1;
insert into t8 select * from t1;
insert into t9 select * from t1;
insert into t10 select * from t1;
insert into t11 select * from t1;
insert into t12 select * from t1;
insert into t13 select * from t1;
insert into t14 select * from t1;
insert into t15 select * from t1;
insert into t16 select * from t1;
insert into t17 select * from t1;
\q
EOF


COPY 3125000
Time: 68897.498 ms
COPY 3125000
Time: 69565.301 ms
COPY 3125000
Time: 68971.917 ms
COPY 3125000
Time: 69336.123 ms
COPY 3125000
Time: 69610.727 ms
COPY 3125000
Time: 69873.498 ms
COPY 3125000
Time: 69081.138 ms
COPY 3125000
Time: 69257.640 ms
COPY 3125000
Time: 69753.672 ms
COPY 3125000
Time: 69835.120 ms
COPY 3125000
Time: 69432.020 ms
COPY 3125000
Time: 70308.638 ms
COPY 3125000
Time: 69506.058 ms
COPY 3125000
Time: 69737.094 ms
COPY 3125000
Time: 70411.739 ms
COPY 3125000
Time: 70517.957 ms


INSERT INTO TBL SELECT * FROM TBL性能, 比MonetDB差8倍以上.(MonetDB约30秒导入一个文件)
INSERT 0 50000000
Time: 289370.747 ms
INSERT 0 50000000
Time: 257491.025 ms
INSERT 0 50000000
Time: 257894.757 ms
INSERT 0 50000000
Time: 259908.577 ms
INSERT 0 50000000
Time: 260986.957 ms
INSERT 0 50000000
Time: 261555.060 ms
INSERT 0 50000000
Time: 256580.829 ms
INSERT 0 50000000
Time: 257066.953 ms
INSERT 0 50000000
Time: 259537.231 ms
INSERT 0 50000000
Time: 257184.911 ms
INSERT 0 50000000
Time: 260310.793 ms
INSERT 0 50000000
Time: 261124.638 ms
INSERT 0 50000000
Time: 261805.074 ms
INSERT 0 50000000
Time: 270812.470 ms
INSERT 0 50000000
Time: 274241.552 ms


不计索引, 容量比MonetDB大20%. (MonetDB占用11.7G一个表)
postgres=# \dt+
                    List of relations
 Schema | Name | Type  |  Owner   |  Size   | Description 
--------+------+-------+----------+---------+-------------
 public | t1   | table | postgres | 13 GB   | 
 public | t10  | table | postgres | 13 GB   | 
 public | t11  | table | postgres | 13 GB   | 
 public | t12  | table | postgres | 13 GB   | 
 public | t13  | table | postgres | 13 GB   | 
 public | t14  | table | postgres | 13 GB   | 
 public | t15  | table | postgres | 13 GB   | 
 public | t16  | table | postgres | 13 GB   | 
 public | t2   | table | postgres | 13 GB   | 
 public | t3   | table | postgres | 13 GB   | 
 public | t4   | table | postgres | 13 GB   | 
 public | t5   | table | postgres | 13 GB   | 
 public | t6   | table | postgres | 13 GB   | 
 public | t7   | table | postgres | 13 GB   | 
 public | t8   | table | postgres | 13 GB   | 
 public | t9   | table | postgres | 13 GB   | 
(17 rows)


查询性能结果, 性能比MonetDB差 10倍-200倍.

postgres=# select count(distinct c1) from t1;
  count   
----------
 50000000
(1 row)
Time: 60618.999 ms  -- MonetDB 1800毫秒, 相差34倍
postgres=# select count(distinct c1) from t2;
  count   
----------
 50000000
(1 row)
Time: 58741.355 ms  -- MonetDB 1800毫秒, 相差33倍
执行计划一致
postgres=# explain select count(distinct c1) from t2;
                             QUERY PLAN                              
---------------------------------------------------------------------
 Aggregate  (cost=2291667.10..2291667.11 rows=1 width=4)
   ->  Seq Scan on t2  (cost=0.00..2166667.08 rows=50000008 width=4)
(2 rows)
Time: 0.648 ms
postgres=# explain select count(distinct c1) from t1;
                             QUERY PLAN                              
---------------------------------------------------------------------
 Aggregate  (cost=2153595.00..2153595.01 rows=1 width=4)
   ->  Seq Scan on t1  (cost=0.00..2056209.40 rows=38954240 width=4)
(2 rows)
Time: 0.583 ms

postgres=# select count(*) from (select c1,c11,c21,c31,c41,c51,c60 from t1 group by c1,c11,c21,c31,c41,c51,c60) as t;
  count   
----------
 50000000
(1 row)
Time: 112570.233 ms  -- MonetDB 2300毫秒, 相差49倍

postgres=# select count(*) from (select t1.c1 from t1 join t2 on t1.c2=t2.c3) as t;
  count   
----------
 49996801
(1 row)
Time: 328024.604 ms  -- MonetDB 27500毫秒, 相差12倍

postgres=# select count(*) from (select t1.c1 from t1 join t2 on t1.c2=t2.c3 join t3 on t1.c3=t3.c5) as t;
  count   
----------
 49995545
(1 row)
Time: 736429.344 ms  -- MonetDB 72000毫秒, 相差10倍

postgres=# select count(*) from (select t1.c1 from t1 join t2 on t1.c2=t2.c3 join t3 on t1.c3=t3.c5 join t4 on t3.c5=t4.c6) as t;
  count   
----------
 50001556
(1 row)
Time: 923087.347 ms  -- MonetDB 103000毫秒, 相差9倍

select count(*) from (
select t1.c1 from t1 
join t2 on t1.c2=t2.c3 
join t3 on t2.c3=t3.c4 
join t4 on t3.c4=t4.c5
join t5 on t4.c5=t5.c6
) as t;
  count   
----------
 50024539
(1 row)
Time: 980814.633 ms  -- MonetDB 125000毫秒, 相差8倍

select count(*) from (
select t1.c1 from t1 
join t2 on t1.c2=t2.c3 
join t3 on t2.c3=t3.c4 
join t4 on t3.c4=t4.c5
join t5 on t4.c5=t5.c6
where t1.c60 < 100000
) as t;
 count 
-------
 98744
(1 row)
Time: 212111.783 ms  -- MonetDB 12800毫秒, 相差17倍

因为空间不够了, 所以t17表没有用到, 所以PostgreSQL只关联了16个表.
select count(*) from (
select t1.c1 from t1 
join t2 on t1.c2=t2.c3 
join t3 on t2.c3=t3.c4 
join t4 on t3.c4=t4.c5
join t5 on t4.c5=t5.c6
join t6 on t5.c5=t6.c6
join t7 on t6.c5=t7.c6
join t8 on t7.c5=t8.c6
join t9 on t8.c5=t9.c6
join t10 on t9.c5=t10.c6
join t11 on t10.c5=t11.c6
join t12 on t11.c5=t12.c6
join t13 on t12.c5=t13.c6
join t14 on t13.c5=t14.c6
join t15 on t14.c5=t15.c6
join t16 on t15.c5=t16.c6
) as t;
  count   
----------
 50304982
(1 row)
Time: 5306055.745 ms  -- MonetDB 310000毫秒, 相差17倍

select count(*) from (
select t1.c1 from t1 
join t2 on t1.c2=t2.c3 
join t3 on t2.c3=t3.c4 
join t4 on t3.c4=t4.c5
join t5 on t4.c5=t5.c6
join t6 on t5.c5=t6.c6
join t7 on t6.c5=t7.c6
join t8 on t7.c5=t8.c6
join t9 on t8.c5=t9.c6
join t10 on t9.c5=t10.c6
join t11 on t10.c5=t11.c6
join t12 on t11.c5=t12.c6
join t13 on t12.c5=t13.c6
join t14 on t13.c5=t14.c6
join t15 on t14.c5=t15.c6
join t16 on t15.c5=t16.c6
where t1.c60 < 100000
) as t;
 count 
-------
 93771
(1 row)
Time: 2198719.164 ms  -- MonetDB 45600毫秒, 相差48倍

select count(*) from (
select t1.c1 from t1 
join t2 on t1.c1=t2.c3 
join t3 on t2.c3=t3.c4 
join t4 on t3.c4=t4.c5
join t5 on t4.c5=t5.c6
join t6 on t5.c5=t6.c6
join t7 on t6.c5=t7.c6
join t8 on t7.c5=t8.c6
join t9 on t8.c5=t9.c6
join t10 on t9.c5=t10.c6
join t11 on t10.c5=t11.c6
join t12 on t11.c5=t12.c6
join t13 on t12.c5=t13.c6
join t14 on t13.c5=t14.c6
join t15 on t14.c5=t15.c6
join t16 on t15.c5=t16.c6
) as t;
  count   
----------
 50183000
(1 row)
Time: 3980422.581 ms  -- MonetDB 262000毫秒, 相差15倍


接下来的话将对比一下PostgreSQL使用cstore_fdw和MonetDB的性能.

[参考]

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍如何基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
3月前
|
SQL 关系型数据库 PostgreSQL
CTE vs 子查询:深入拆解PostgreSQL复杂SQL的隐藏性能差异
本文深入探讨了PostgreSQL中CTE(公共表表达式)与子查询的选择对SQL性能的影响。通过分析两者底层机制,揭示CTE的物化特性及子查询的优化融合优势,并结合多场景案例对比执行效率。最终给出决策指南,帮助开发者根据数据量、引用次数和复杂度选择最优方案,同时提供高级优化技巧和版本演进建议,助力SQL性能调优。
223 1
|
关系型数据库 PostgreSQL
PostgreSQL 计算字符串字符数函数(CHAR_LENGTH(str))和字符串长度函数(LENGTH(str))
PostgreSQL 计算字符串字符数函数(CHAR_LENGTH(str))和字符串长度函数(LENGTH(str))
2842 0
|
10月前
|
存储 关系型数据库 MySQL
MySQL vs. PostgreSQL:选择适合你的开源数据库
在众多开源数据库中,MySQL和PostgreSQL无疑是最受欢迎的两个。它们都有着强大的功能、广泛的社区支持和丰富的生态系统。然而,它们在设计理念、性能特点、功能特性等方面存在着显著的差异。本文将从这三个方面对MySQL和PostgreSQL进行比较,以帮助您选择更适合您需求的开源数据库。
509 4
|
关系型数据库 MySQL 数据库
探究数据库开源协议:PostgreSQL vs MySQL
探究数据库开源协议:PostgreSQL vs MySQL
|
存储 关系型数据库 MySQL
【专栏】在众多开源数据库中,MySQL和PostgreSQL无疑是最受欢迎的两个
【4月更文挑战第27天】MySQL与PostgreSQL是两大主流开源数据库,各有特色。MySQL注重简单、便捷和高效,适合读操作密集场景,而PostgreSQL强调灵活、强大和兼容,擅长并发写入与复杂查询。MySQL支持多种存储引擎和查询缓存,PostgreSQL则具备扩展性、强事务支持和高可用特性。选择时应考虑项目需求、团队技能和预期收益。
202 2
|
关系型数据库 MySQL 数据处理
MySQL vs. PostgreSQL:选择适合你的开源数据库
在当今信息时代,开源数据库成为许多企业和开发者的首选。本文将比较两个主流的开源数据库——MySQL和PostgreSQL,分析它们的特点、优势和适用场景,以帮助读者做出明智的选择。
|
存储 关系型数据库 MySQL
如何选择最适合你的数据库解决方案:PostgreSQL VS MySQL 技术选型对比
如何选择最适合你的数据库解决方案:PostgreSQL VS MySQL 技术选型对比
420 1
|
存储 算法 Oracle
PostgreSQL的MVCC vs InnoDB的MVCC
PostgreSQL的MVCC vs InnoDB的MVCC
216 0
PostgreSQL的MVCC vs InnoDB的MVCC
|
存储 SQL 关系型数据库
【数据库选型】ClickHouse vs PostgreSQL vs TimescaleDB
在过去的一年里,我们不断听到的一个数据库是ClickHouse,这是一个由Yandex最初构建并开源的面向列的OLAP数据库。
|
Web App开发 SQL Oracle
PostgreSQL vs PPAS 差异 - Oracle评估、迁移、验证、性能调优
标签 PostgreSQL , PPAS , 阿里云 背景 1、ppas手册(高度兼容Oracle): https://www.enterprisedb.com/docs/en/11.0/EPAS_Oracompat_Ref_Guide_v11/toc.
1957 0