美文网首页
GreenPlum分区表和非分区压测对比

GreenPlum分区表和非分区压测对比

作者: YuVicky | 来源:发表于2020-11-27 15:06 被阅读0次

背景

  之前有对Greenplum进行TPC-H测试,参考文章为[TPC-H测试](https://help.aliyun.com/document_detail/156160.html?spm=a2c4g.11186623.6.662.552a2dcaJdRHLG),其中的表主要是列存表,没有对表进行分区处理,查询起来非常慢,其中的Q1 sql查询(查询表lineitem)时间达到600s,单表(lineitem)最大数据量为27亿。因此,本次在之前测试的基础上,对lineitem表进行分区处理,对比分区前后的结果。

机器配置

 1. 测试的Greenplum集群由18个计算节点,三台宿主机,每台宿主机有8个CPU核,32GB内存。
 2. 单独用一台服务器(centos7 8核16G)运行benchmarksql工具来生成TPC-C负载,向Greenplum实例发送请求。
 3. 表lineitem数据量为27亿

分区操作sql

按年分区sql:
create table lineitem_partition (    
    l_orderkey    bigint not null,        
    l_partkey     integer not null,    
    l_suppkey     integer not null,    
    l_linenumber  integer not null,    
    l_quantity    DECIMAL(15,2) not null,    
    l_extendedprice  DECIMAL(15,2) not null,    
    l_discount    DECIMAL(15,2) not null,    
    l_tax         DECIMAL(15,2) not null,    
    l_returnflag  char(1) not null,    
    l_linestatus  char(1) not null,    
    l_shipdate    date not null,    
    l_commitdate  date not null,    
    l_receiptdate date not null,    
    l_shipinstruct char(25) not null,   
    l_shipmode     char(10) not null,    
    l_comment      varchar(44) not null)
with (appendonly=true, orientation=column)
distributed by (l_orderkey) partition by range(l_shipdate)(
        PARTITION p1992 START ('1992-01-01'::date) inclusive END ('1993-01-01'::date) exclusive,
    PARTITION p1993 START ('1993-01-01'::date) inclusive END ('1994-01-01'::date) exclusive,
    PARTITION p1994 START ('1994-01-01'::date) inclusive END ('1995-01-01'::date) exclusive,
    PARTITION p1995 START ('1995-01-01'::date) inclusive END ('1996-01-01'::date) exclusive,
    PARTITION p1996 START ('1996-01-01'::date) inclusive END ('1997-01-01'::date) exclusive,
    PARTITION p1997 START ('1997-01-01'::date) inclusive END ('1998-01-01'::date) exclusive,
    PARTITION p1998 START ('1998-01-01'::date) inclusive END ('1999-01-01'::date) inclusive
); ```
--------------------------------------------------------------------------------------------------------
``` 按月分区sql:
create table lineitem_partition_month (        
        l_orderkey    bigint not null,            
        l_partkey     integer not null,       
        l_suppkey     integer not null,       
        l_linenumber  integer not null,        
        l_quantity    DECIMAL(15,2) not null,          
        l_extendedprice  DECIMAL(15,2) not null,        
        l_discount    DECIMAL(15,2) not null,        
        l_tax         DECIMAL(15,2) not null,        
        l_returnflag  char(1) not null,        
        l_linestatus  char(1) not null,        
        l_shipdate    date not null,        
        l_commitdate  date not null,        
        l_receiptdate date not null,        
        l_shipinstruct char(25) not null,       
        l_shipmode     char(10) not null,        
        l_comment      varchar(44) not null
)with (appendonly=true, orientation=column)
  distributed by (l_orderkey) 
  partition by range(l_shipdate)(    
        PARTITION p_ START ('1992-01-01'::date) inclusive END ('1993-01-01'::date) exclusive every ('1 month'::interval)));```
--------------------------------------------------------------------------------------------------------
```  测试sql1(时间范围为1年):
select
    l_returnflag,
    l_linestatus,
    sum(l_quantity) as sum_qty,
    sum(l_extendedprice) as sum_base_price,
    sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
    sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
    avg(l_quantity) as avg_qty,
    avg(l_extendedprice) as avg_price,
    avg(l_discount) as avg_disc,
    count(*) as count_order
from
    lineitem_partition_month
where
    l_shipdate <= date '1998-12-31' and l_shipdate >= date '1998-01-01'
group by
    l_returnflag,
    l_linestatus
order by
    l_returnflag,
    l_linestatus;
select
    l_returnflag,
    l_linestatus,
    sum(l_quantity) as sum_qty,
    sum(l_extendedprice) as sum_base_price,
    sum(l_extendedprice * (1 - l_discount)) as sum_disc_price,
    sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge,
    avg(l_quantity) as avg_qty,
    avg(l_extendedprice) as avg_price,
    avg(l_discount) as avg_disc,
    count(*) as count_order
from
    lineitem_partition_month
where
    l_shipdate <= date '1998-12-31' and l_shipdate >= date '1998-12-01'
group by
    l_returnflag,
    l_linestatus
order by
    l_returnflag,
    l_linestatus;

测试结果

测试sql1

表的类型 sql查询时间
普通表 116.2s
按年分区 97.50s
按月分区 68.34s

测试sql2

表的类型 sql查询时间
普通表 3s
按月分区 54.99s

测试结论

1. Greenplum中分区表其目的也是用来避免扫描大表的全部内容,而分区表能够提升查询性能。分区是不会更改数据在segments之间的物理分布,而是对大表进行逻辑上的划分。
2. 需要注意的是,分区操作以及分区所依据的键需要结合业务进行判断,如例子中的业务是需要根据时间进行分组查询的,这也是大数据情况下很经典的查询方法,因此我们根据时间进行了分区操作。由上也可看到,分区粒度按月比按年的查询速度更快,按年分区也会比普通未分区表的查询速度快。但是数据量较小的情况并不需要进行分区,在数据量达到亿级别时,分区才能很好的发挥它的优势。
3. 虽然分区操作能加快大表的查询速度,但是我们注意查询语句的用法,比如当我们把where 条件语句改成 `where l_shipdate <= date '1998-10-31' - interval '30 day' ` ,同样是查询单月的数据,但是查询时间能达到30s以上,因此,在需要加快查询速度的情况下,sql语句的写法是否能够完全契合当前表的设置也很重要。

相关文章

  • GreenPlum分区表和非分区压测对比

    背景 机器配置 分区操作sql 测试结果 测试sql1 表的类型sql查询时间普通表116.2s按年分区97.50...

  • MBR分区与GPT分区

    Linux系统中有两种常见的分区表 MBR分区表(主引导记录分区表)和 GPT分区表(GUID分区表) MBR分区...

  • 分区工具fdisk和gdisk、分区信息的同步

    同步内存信息与硬盘分区表(内核重新读取硬盘分区表) 交互式操作 非交互式操作

  • Vertica的这些事(九)—— vertica存储统计信息

    vertica存储统计信息: 表数量: 分区表数量: 总表占大小: 分区表总大小: 分区表大小(前10): 分区表...

  • Mysql 分区表

    MySQL分区表支持RANGE,LIST,HASH,KEY,COLUMNS多种分区算法。 分区表的唯一索引和主键索...

  • Impala分区表

    摘要:Impala,分区表,hdfs 分区表 分区表就是将某个分区的数据的单独存放,当使用where语句是针对某个...

  • MySQL-31.分区表

    分区表有什么问题,为什么公司规范不让使用分区表呢? 1.分区表是什么? 为了说明分区表的组织形式,先创建一个表 t...

  • HIVE 表设计优化1 分区表

    1. 分区表和分桶表 1. 分区表 分区表实际上就是对应一个HDFS文件系统上的独立的文件夹,该文件夹下是该分区所...

  • HiveSQL分区-DML

    分区 创建分区表 以性别分区;分区字段不可与表列名重复! 载入分区表数据 介绍load-data:Hive-DML...

  • PostgreSQL实现数据表分区

    1.建表 2.创建子表(分区表) 根据主表的创建日期月份来建立分区 3.给分区表创建主键 继承主表的分区表无法继承...

网友评论

      本文标题:GreenPlum分区表和非分区压测对比

      本文链接:https://www.haomeiwen.com/subject/drcxwktx.html