试试使用MariaDB ColumnStore

虽然不为人所知,但MariaDB有一个称为“MariaDB ColumnStore”的列型数据库引擎(也许只是我不知道而已)。觉得很有趣,所以稍微试了一下。

准备Linux环境.目前,MariaDB ColumnStore可以运行在以下任一环境中。

    • RHEL/CentOS v6, v7

 

    • Ubuntu 16.04 LTS

 

    • Debian v8

 

    SUSE 12

这次我使用Mac上的Vagrant+VirtualBox来建立了CentOS 7.2虚拟机。
步骤是参考了这里。
如果是在Windows,我认为你可以模仿这些步骤应该没问题。

可以从Vagrantbox.es网站获取Vagrant的镜像。选择那些已经关闭了SELinux和防火墙的镜像会使后续步骤更加容易。

安装准备按照网站上的步骤进行,但是这次不需要建立分布式并行结构,更不用说有SAN存储等,只需要在独立的情况下进行简单的操作,因此相关部分几乎不存在。
需要完成的只有以下几点。

安装Boost库。

yum -y install boost

安装开发人员工具

yum groupinstall "Developer Tools"
yum install cmake

安装其他软件包

yum -y install expect perl perl-DBI openssl zlib file sudo libaio rsync snappy net-tools perl-DBD-MySQL

安装和配置MariaDB ColumnStore

安装RPM软件包有一个RPM包可用,所以我们将安装它。您可以从这里下载。
根据您是以ROOT用户身份安装还是普通用户身份安装,步骤会有些不同,但这次我们将以ROOT用户身份进行安装。请先切换到ROOT用户,然后按照以下步骤进行。

wget https://downloads.mariadb.com/ColumnStore/1.0.10/centos/x86_64/7/mariadb-columnstore-1.0.10-1-centos7.x86_64.rpm.tar.gz
tar xvzf mariadb-columnstore-1.0.10-1-centos7.x86_64.rpm.tar.gz
rpm -ivh mariadb-columnstore-1.0.10-1-*.rpm

设置向导安装完RPM包后,执行配置向导。

/usr/local/mariadb/columnstore/bin/postConfigure

然后,根据上述的设定,会每次询问您,请逐个输入确认。

There are 2 options when configuring the System Server Type: single and multi

  'single'  - Single-Server install is used when there will only be 1 server configured
              on the system. It can also be used for production systems, if the plan is
              to stay single-server.

  'multi'   - Multi-Server install is used when you want to configure multiple servers now or
              in the future. With Multi-Server install, you can still configure just 1 server
              now and add on addition servers/modules in the future.

Select the type of System Server install [1=single, 2=multi] (2) >  1

Performing a Single Server Install.
Enter System Name (columnstore-1) > mymcs1

由于这是一个测试,请输入1(single)来选择System Server的安装类型。但实际运行时,需要选择2(multi)。选择single后似乎无法再添加模块。

请查看以下步骤获取有关设置详细信息。

设置别名完成设置向导后,执行创建别名的命令。

. /usr/local/mariadb/columnstore/bin/columnstoreAlias

使用此选项,您可以使用ColumnStore的SQL控制台mcsmysql和管理控制台mcsadmin。

mcsmysql的使用方法几乎与普通的mysql控制台相同。
请查看此处以获取mcsadmin的使用方法。

文字编码的配置我想要使用UTF-8,所以我会在my.cnf和Columnstore.xml中添加以下的描述。

[client]
default-character-set=utf8
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
init-connect=’SET NAMES utf8’
<SystemConfig>
   <SystemLang>en_US.utf8</SystemLang>

更改设置后,请重新启动ColumnStore。

mcsadmin restartSystem

创建用于测试的数据
我想要输入数据并试用一下,看看有多快。
首先要创建数据库和表,具体如下。

[root@localhost ~]# mcsmysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 15
Server version: 10.1.25-MariaDB Columnstore 1.0.10-1

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database hoge;
Query OK, 1 row affected (0.01 sec)

MariaDB [(none)]> use hoge;
Database changed
MariaDB [hoge]> create table mcstest (id int, dt date, category varchar(10), value int) engine=columnstore default character set=utf8;
Query OK, 0 rows affected (0.92 sec)

重要的是在创建表时指定了engine=columnstore。
如果不加入这个指定,将会选择默认的引擎(在版本10.1中是XtraDB)。

在这张表格中插入的文本数据如下所示。我已经准备了1亿条记录。

1|2006-01-19|RR|3714|
2|2004-08-07|YT|4074|
3|2011-07-27|AG|4865|
4|2014-09-07|IR|1386|
5|2004-01-06|ZT|2588|

使用导入工具将上述数据导入。

/usr/local/mariadb/columnstore/bin/cpimport hoge mcstest testdata.txt

SQL的测量
我们来执行SQL并测试一下速度吧。
我们将把相同数量的数据插入先前在同一个Vagrant上安装的PostgreSQL中,然后进行比较。
(所有单位均以秒为单位)

SELECT COUNT(*) FROM mcstest;

-> MCS: 3.385
-> PG: 11.907
SELECT SUM(value) FROM mcstest;

-> MCS: 4.528
-> PG: 14.772
SELECT category, SUM(value) FROM mcstest GROUP BY category ORDER BY category;

-> MCS: 17.357
-> PG: 28.185
SELECT category, SUM(value) FROM mcstest WHERE category IN ('AA','BB','CC','DD','EE') GROUP BY category ORDER BY category;

-> MCS: 6.573
-> PG: 25.008
SELECT category, SUM(value) FROM mcstest WHERE dt BETWEEN '2017-01-01' and '2017-07-31' GROUP BY category ORDER BY category;

-> MCS: 6.125
-> PG: 14.216
SELECT category, SUM(value) FROM mcstest WHERE category IN ('AA','BB','CC','DD','EE') and dt BETWEEN '2017-01-01' and '2017-07-31' GROUP BY category ORDER BY category;

-> MCS: 5.189
-> PG: 13.862
SELECT AVG(value) FROM mcstest WHERE value>5000;

-> MCS: 3.339
-> PG: 17.075
SELECT 
   T0.C0,
   T0.C1,
   T1.C1
FROM (
   SELECT DISTINCT
      mcstest.category AS C0,
      SUM(mcstest.value) AS C1
   FROM mcstest
   WHERE (
      mcstest.dt BETWEEN '2016-01-01' AND '2016-12-31'
   )
   GROUP BY 
      mcstest.category
) T0
LEFT OUTER JOIN (
   SELECT DISTINCT
      mcstest.category AS C0,
      SUM(mcstest.value) AS C1
   FROM mcstest
   WHERE (
      mcstest.dt BETWEEN '2015-01-01' AND '2015-12-31'
   )
   GROUP BY 
      mcstest.category
) T1
ON T0.C0 = T1.C0

-> MCS: 11.455
-> PG: 30.701

两者都是完全没有调整的原始状态,性能大约提升了大致3倍。
由于可以进行分散和并行处理,还有很大的潜力可以发展,不是吗?
我想在另一个机会上尝试更详细的测量。

额外福利:来自Yellowfin的连接
既然这么方便,我也来确认一下与Yellowfin的连接。

在Yellowfin的初始状态下,没有捆绑MariaDB的JDBC驱动程序,但可以通过添加来使用。
MariaDB的JDBC驱动程序可以在这里找到。
请下载mariadb-java-client-x.x.x.jar。

只要将驱动程序添加到Yellowfin中,之后就可以正常使用了。

datasource.png

bannerAds