【IT168 专稿】在上一系列文章中,我们先后介绍了Gbase 8a,Infobright,InfiniDB, MonetDB,SybaseIQ等5种列式数据库的功能,利用tpc-h模型scala=1和10的数据作了测试,并和传统行存储的Oracle数据库作了对比,得到了一些结论。本文将介绍另一种重要的新型列存储数据库Ingres VectorWise的功能特点,同样采用tpc-h scala=10数据评估它的性能,为用户数据库选型提供参考。
Ingres是关系数据库软件中的元老级产品,70 年代开始于加利福尼亚大学伯克利分校的一个研究项目,它的代码使用BSD许可证。从 80 年代中期起,在Ingres 基础上产生了很多商业数据库软件,包括 Sybase、Microsoft SQL Server、Informix 和许多其他的系统。在 80 年代中期启动的后继项目 Postgres,产生了 PostgreSQL,在开源数据库市场份额仅次于MySQL。由于Ingres有它自己的查询语言Quel,导致它对SQL语言的支持比较晚,从而慢慢淡出了主流用户的视线,但Ingres仍在继续发展,先后发布了Ingres 2006等产品,目前最新版是10.0。Ingres公司和荷兰的CWI研究院合作推出的VectorWise是基于Ingres10.0和MonetDB/X100这2种各自领域的领先产品,可以说是系出名门。2010年6月发布1.0版,2011年3月31日,发布了获取了tpc-h的100GB数据量的第一排名的1.5版。详细信息见http://www.tpc.org/tpch/results/tpch_perf_results.asp。本文即针对VectorWise 1.5版展开测试。
系列文章回顾:
一、测试平台
本次测试基于Intel Xeon 7550*8的PC服务器上用VMWare VSphere 4.1管理的虚拟机,虚拟机的逻辑CPU个数是8,内存100GB,存储为8个300GB SAS本地磁盘,采用一块512M缓存RAID卡,按RAID5方式组成磁盘阵列。操作系统采用和RHEL 5相同的核心级别的RedFlag Asian Linux Sever 3.0 x64。
二、安装
(一)VectorWise的安装步骤
VectorWise的评估版安装包可从网站http://www.ingres.com/downloads/vectorwise获取,Linux x86-64平台同时提供了rpm和非rpm二种安装包,前者简便易行,适合于初学者,后者提供更多的定制选项,适合于熟练用户。下面分别介绍这2种安装包的安装步骤。rpm安装包文件名是ingresvw-1.5-141-NPTL-eval-linux-x86_64.tgz,大约38MB,包含了服务器端核心和基于字符终端的命令行工具。这里NPTL 是Native POSIX ThreadingLibrary 的缩写。
http://esd.ingres.com/上提供了详细的用户手册,内容包括概念、安装、管理和维护、基准测试、功能特性和系统限制等方面,基本涵盖了用户日常使用的各方面。至于更详细的SQL命令和网络配置步骤,需要参考Ingres 10.0的相关文档。
1. rpm安装
将下载回来的安装包解压到临时目录,可以观察到安装文件的目录结构,其中rpm目录包含了所有的组件,ingresvw-1.5.0-141.x86_64.rpm是服务器核心组件,ingresvw-dbms-1.5.0-141.x86_64.rpm包括各种管理工具和命令行访问工具,ingresvw-net-1.5.0-141.x86_64.rpm是网络访问组件。一般情况下,无需选择,直接都安装即可。在rpm安装命令行中可用—prefix参数指定软件安装路径。注意必须首先用rpm-ivh libaio*.rpm命令安装Linux异步I/O库,才能安装VectorWise,如果系统已经安装过libaio库,则省略这一步。
[root@redflag11012602 i]# ls
ingresvw-1.5.0-141-NPTL-eval-linux-x86_64
[root@redflag11012602 i]# cd *64
[root@redflag11012602 ingresvw-1.5.0-141-NPTL-eval-linux-x86_64]# ll
总计 212
drwxrwxr-x 2 500 users4096 03-29 00:07 bin
-rwxr-xr-x 1 500 users 18698 03-28 23:49 ingres_express_install.sh
-rwxr-xr-x 1 500 users 3230 03-28 23:49 ingres_install
-rw-r--r-- 1 500 users 11057 03-29 00:07 LICENSE
drwxrwxr-x 3 500 users4096 03-29 00:07 locale
-rw-rw-r-- 1 500 users 3054 03-31 02:45 md5sum.txt
drwxrwxr-x 2 500 users4096 03-29 00:07 pixmaps
-rw-r--r-- 1 500 users 74971 03-31 02:33 readme_a64_lnx_nptl.html
-rw-rw-r-- 1 500 users 70478 03-31 02:33 readme.html
drwxrwxr-x 2 500 users4096 03-29 00:07 rpm
[root@redflag11012602 ingresvw-1.5.0-141-NPTL-eval-linux-x86_64]# cd rpm
[root@redflag11012602 rpm]# ll
总计 40384
-rw-r--r-- 1 500 users 20291416 03-29 00:07 ingresvw-1.5.0-141.x86_64.rpm
-rw-r--r-- 1 500 users 18077987 03-29 00:07 ingresvw-dbms-1.5.0-141.x86_64.rpm
-rw-r--r-- 1 500 users 2928528 03-29 00:07 ingresvw-net-1.5.0-141.x86_64.rpm
[root@redflag11012602 rpm]# mkdir /user1/app/vw15
[root@redflag11012602 rpm]# rpm -ivh--prefix=/user1/app/vw15 *rpm
Preparing... ########################################### [100%]
1:ingresvw ########################################### [ 33%]
2:ingresvw-dbms ########################################### [ 67%]
3:ingresvw-net ########################################### [100%]
Building the password validation program 'ingvalidpw'.
Executable successfully installed.
安装程序自动创建了操作系统的ingres用户,并在/home/ingres目录下添加了访问VectorWise各种命令的用于添加环境变量和路径的脚本文件,有适用于各种shell的不同文件,比如对应bash的.ingVWbash,用cat输出它的内容可以观察到它定义了II_SYSTEM环境变量指向ingres的根目录,并且添加了VectorWise的可执行文件所在目录到系统搜索路径和库路径,最后指定了终端显示类型为konsolel,这种终端类型用西文制表符显示分隔线,在西文状态下显示更美观。用户可以将.ingVWbash添加到.bash_profile的末尾,这样,只要以ingres用户登录,即自动执行.ingVWbash脚本。
[root@redflag11012602 home]# ls
haclusteringresoracle
[root@redflag11012602 home]# cd ingres
[root@redflag11012602 ingres]# ls
Desktop
[root@redflag11012602 ingres]# ls -la
总计 68
drwx------ 5 ingres ingres 4096 04-03 18:08 .
drwxr-xr-x 5 root root 4096 04-03 18:08 ..
-rw-r--r-- 1 ingres ingres 33 04-03 18:08 .bash_logout
-rw-r--r-- 1 ingres ingres 176 04-03 18:08 .bash_profile
-rw-r--r-- 1 ingres ingres 124 04-03 18:08 .bashrc
drwxr-xr-x 3 ingres ingres 4096 04-03 18:08 Desktop
-rw-r--r-- 1 ingres ingres 515 04-03 18:08 .emacs
-rw-r--r-- 1 ingres ingres 1072 04-03 18:08 .fonts.conf.ja
-rw-r--r-- 1 ingres ingres 516 04-03 18:08 .fonts.conf.ko
-rw-r--r-- 1 ingres ingres 1072 04-03 18:08 .fonts.conf.zh
-rw-r--r-- 1 ingres ingres 56 04-03 18:08 .gtkrc-2.0
lrwxrwxrwx 1 ingres ingres 24 04-03 18:08 .ingVWbash -> /user1/app/vw15/.ingVWsh
-rw-r--r-- 1 ingres ingres 418 04-03 18:08 .ingVWcsh
-rw-r--r-- 1 ingres ingres 444 04-03 18:08 .ingVWsh
lrwxrwxrwx 1 ingres ingres 25 04-03 18:08 .ingVWtcsh -> /user1/app/vw15/.ingVWcsh
drwxr-xr-x 3 ingres ingres 4096 04-03 18:08 .kde
drwxr-xr-x 4 ingres ingres 4096 04-03 18:08 .mozilla
-rw-r--r-- 1 ingres ingres 658 04-03 18:08 .zshrc
[root@redflag11012602 ingres]# cat .ingVWsh
# ingresvw environment for VW installation
# Generated at installation time, any changes made will be lost
export II_SYSTEM=/user1/app/vw15
export PATH=$II_SYSTEM/ingres/bin:$II_SYSTEM/ingres/utility:$PATH
if [ "$LD_LIBRARY_PATH" ] ; then
LD_LIBRARY_PATH=/usr/local/lib:$II_SYSTEM/ingres/lib:$LD_LIBRARY_PATH
else
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$II_SYSTEM/ingres/lib
fi
export LD_LIBRARY_PATH
export TERM_INGRES=konsolel
[root@redflag11012602 ingres]# . /home/ingres/.ingVWbash
2.非rpm安装
如果需要更多个性化地设置,rpm安装方式可能不能满足要求,那么用户可以下载ingresvw-1.5-141-NPTL-eval-linux-ingbuild-x86_64.tgz安装包,大约43MB。安装步骤如下:
(1)创建ingres用户组和ingres用户
[root@redflag11012602 tmp]# useradd ingres -g ingres
[root@redflag11012602 tmp]# passwd ingres
Changing password for user ingres.
New UNIX password:
BAD PASSWORD: it is based on a dictionary word
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
(2)以root用户解压缩安装包,执行install.sh,但选择ingres用户安装
[root@redflag11012602 ingres]# cd /user1/software
[root@redflag11012602 software]# tar zxf
ingresvw-1.5.0-141-NPTL-eval-linux-ingbuild-x86_64.tgz
[root@redflag11012602 software]# cd *-ingbuild-x86_64
[root@redflag11012602 ingresvw-1.5.0-141-NPTL-eval-linux-ingbuild-x86_64]# ll
总计 60540
-rwxr-xr-x 1 ingres users 18698 03-28 23:49 ingres_express_install.sh
-rw-rw-r-- 1 ingres users 61716480 03-29 00:07 ingres.tar
-rwxr-xr-x 1 ingres users 13677 03-28 23:49 install.sh
-rw-r--r-- 1 ingres users 11057 03-28 23:48 LICENSE
-rw-r--r-- 1 ingres users 74971 03-31 02:33 readme_a64_lnx_nptl.html
-rw-rw-r-- 1 ingres users 70478 03-31 02:33 readme.html
[root@redflag11012602 ingresvw-1.5.0-141-NPTL-eval-linux-ingbuild-x86_64]# ./install.sh
Ingres VectorWise 1.5.0
Please choose a location in which to install Ingres VectorWise
(II_SYSTEM:default /opt/Ingres/IngresVW):
/user1/app/tmp
Please choose a user to install Ingres VectorWise as
(default ingres):
Creating /user1/app/tmp...
II_SYSTEM: /user1/app/tmp
Distribution:
/user1/app/tmp/ingresvw-1.5.0-141-NPTL-eval-linux-ingbuild-x86_64/./ingres.tar
Installation owner: ingres
后面还有很多选项,用户可以根据自己需要修改默认值,这里不一一列举。
(3)以ingres用户访问(需修改.bash_profile)
# .bash_profile
# Get the aliases and functions
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
#.ingVWbash
# ingresvw environment for VW installation
# Generated at installation time, any changes made will be lost
export II_SYSTEM=/user1/app/tmp
export PATH=$II_SYSTEM/ingres/bin:$II_SYSTEM/ingres/utility:$PATH
if [ "$LD_LIBRARY_PATH" ] ; then
LD_LIBRARY_PATH=/usr/local/lib:$II_SYSTEM/ingres/lib:$LD_LIBRARY_PATH
else
LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:$II_SYSTEM/ingres/lib
fi
export LD_LIBRARY_PATH
export TERM_INGRES=dumb
启动VectorWise服务有2种方式,一种是用ingstart命令,注意不能用root用户执行这个命令,另一种方式是用服务的方式启动,必须以 root用户执行/sbin/serviceingresVW start命令。只有rpm安装的软件才支持第2种方式。
Starting Ingres as root is not permitted.
[root@redflag11012602 ingres]# su - ingres
[ingres@redflag11012602 ~]$ ingstart
-bash: ingstart: command not found
[ingres@redflag11012602 ~]$ . /home/ingres/.ingVWbash
[ingres@redflag11012602 ~]$ ingstart
VectorWise/ingstart
No VectorWise servers have been configured to start up.
[ingres@redflag11012602 ~]$ /sbin/service ingresVW start
Only 'root' can control this service
[ingres@redflag11012602 ~]$ exit
logout
[root@redflag11012602 ingres]# /sbin/service ingresVW start
Ingres, instance VW has not been setup
Running setup for Ingres 1.5.0-141...
Running setup for dbms... OK
Running setup for net... OK
Running iisudbms... OK
Running iisudas... OK
Running iisuodbc... OK
Starting Ingres, instance VW: [确定]
(二)创建数据库
启动VectorWise服务后,就可以用createdb命令创建数据库了,可以以root用户或ingres用户创建,但root用户创建的表只有经过root用户授权才能被其他用户访问。为了便于后续的操作,我们选择使用ingres用户创建数据库。
[ingres@redflag11012602 ~]$ . /home/ingres/.ingVWbash
[ingres@redflag11012602 ~]$ createdb tpch
Creating database 'tpch' . . .
Creating DBMS System Catalogs . . .
Modifying DBMS System Catalogs . . .
Creating Standard Catalog Interface . . .
Creating Front-end System Catalogs . . .
Creation of database 'tpch' completed successfully.
(三)连接和访问数据库
数据库创建成功后,用sql 数据库名的方式即可连接到指定数据库,进行各种操作。
[ingres@redflag11012602 ~]$ sql tpch
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Sun Apr3 03:16:14 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* select 1\g
Executing . . .
lqqqqqqk
xcol1x
tqqqqqqu
x 1x
mqqqqqqj
(1 row)
continue
* \q
Your SQL statement(s) have been committed.
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Sun Apr3 03:18:41 2011
注意在sql命令行中必须用\g作为一个SQL命令的结束符。
我们观察到,当终端显示类型为konsolel时,如果将输出内容复制到其他文本编辑器,分隔线就变成了西文字母x、q等,不便于辨认,我们重新设定终端显示类型为dumb,使用普通的符号分隔线,这样就容易辨认输出结果了。我们也可以在.ingVWbash 中写入exportTERM_INGRES=dumb,一劳永逸地解决这个问题。
三、VectorWise的功能测试
(一)SQL语句的功能特点
VectorWise支持事务的DML操作,包括insert,update和delete。Commit提交一个事务,rollback回滚,这与绝大部分数据库没有区别,不再详细展开。VectorWise支持约束和索引、主键,外键,但有一些限制条件。索引和约束只能对空表进行添加。
Executing . . .
E_VW1053 Index on non-empty table not allowed.
(Mon Apr4 23:46:02 2011)
continue
支持对已有数据表的结构重定义,包括增加、删除列。注意删除列要加restrict关键字。
Executing . . .
(0 rows)
continue
* help nation\g
Executing . . .
Name: nation
Owner: ingres
Created: 03-apr-2011 04:18:27
Type: user table
Version: II10.0
Column Information:
Key
Column Name Type Length Nulls Defaults Seq
n_nationkey integer 4 no no
n_name char 25 no no
n_regionkey integer 4 no no
n_comment varchar 152yes null
n_col varchar 10yes null
continue
* alter table nation drop n_col\g
Executing . . .
E_US0F0A line 1, Syntax error on 'EOF'.The correct syntax is:
ALTER TABLE tablename
ADD [CONSTRAINT constraint_name] constraint_clause
| DROP CONSTRAINT constraint_name RESTRICT | CASCADE
| ADD [COLUMN] columnname format [default_clause] [null_clause]
[column_constraint]
| DROP [COLUMN] column_name RESTRICT | CASCADE
| RENAME TO new_table_name
| RENAME [COLUMN] old_column_name TO new_column_name
| ALTER [COLUMN] columnname format [default_clause] [null_clause]
(Mon Apr4 23:48:46 2011)
continue
* alter table nation drop n_col restrict\g
Executing . . .
(0 rows)
continue
不支持分区、分析函数和groupby的rollup、cube扩展。
不支持表的重命名。
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Mon Apr4 22:13:58 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* alter table li rename to lineitem\g
Executing . . .
E_US2506 RENAME TABLE: Cannot rename table 'li'. Rename not supported for
VectorWise tables.
(Mon Apr4 22:14:15 2011)
continue
* \q
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 22:18:31 2011
不支持With子查询。但错误信息却是表不存在。
Executing . . .
E_US0845 Table 't' does not exist or is not owned by you.
(Tue Apr5 01:36:40 2011)
VectorWise还有一些特色功能,例如在默认的列存储之外,还支持VECTORWISE_ROW行式存储结构,用于有效地存储少量行但大量列的表,支持在其它开发语言中嵌入式sql等。由于超出了列存储的范围,这里就不再测试了。
(二)数据库信息查询
我们用du命令只能得到数据文件的大小,而VectorWise使用一个数据文件保存多个表的内容,如果要了解某个表的空间占用情况,VectorWise提供了命令iivwinfo用来查看数据库的相关信息,-tbu参数用来查看各个表使用的数据块。-t 参数指定需要查看的表。
/user1/app/vw15/ingres/bin/iivwinfo
Using settings:
database : 'tpch'
table : ''
Connecting to VW server at port '44216'
Executing query
+------------------------+--------------------+
|table_name |block_count |
|str |slng |
+------------------------+--------------------+
|nation | 4|
|region | 3|
|part | 247|
|supplier | 32|
|partsupp | 2094|
|customer | 452|
|orders | 2445|
|li | 5761|
+------------------------+--------------------+
(8 rows)
[ingres@redflag11012602 ~]$ iivwinfo -t li -tbu tpch
/user1/app/vw15/ingres/bin/iivwinfo
Using settings:
database : 'tpch'
table : 'li'
Connecting to VW server at port '44216'
Executing query
+------------------------+--------------------+
|table_name |block_count |
|str |slng |
+------------------------+--------------------+
|li | 5761|
+------------------------+--------------------+
(1 row)
如果不加任何参数,直接运行iivwinfo 数据库名,那么输出关于数据库的信息。
/user1/app/vw15/ingres/bin/iivwinfo
Using settings:
database : 'tpch'
table : ''
Connecting to VW server at port '44216'
Executing query
+------------------------------------+--------------------------------------------+
|stat |value |
|varchar(36) |varchar(44) |
+------------------------------------+--------------------------------------------+
|memory.query_allocated |20883904 |
|memory.query_maximum |52807965081 |
|memory.query_virtual_allocated |13455104 |
|memory.query_virtual_maximum |70368744177664 |
|memory.update_allocated |0 |
|memory.update_maximum |13201991270 |
|memory.committed_transactions |0 |
|memory.bufferpool_allocated |5787090944 |
|memory.bufferpool_maximum |26403667968 |
|bm.block_size |524288 |
|bm.group_size |8 |
|bm.columnspace_total_blocks |262144 |
|bm.columnspace_free_blocks |251106 |
|bm.bufferpool_total_blocks |50361 |
|bm.bufferpool_free_blocks |50361 |
|bm.bufferpool_used_blocks |0 |
|bm.bufferpool_cached_blocks |11038 |
|bm.columnspace_location
|/user1/app/vw15/ingres/data/vectorwise/tpch/CBM/default/0|
|system.active_sessions |0 |
|system.log_file_size |3066877 |
|system.threshold_log_condense |33554432 |
+------------------------------------+--------------------------------------------+
(21 rows)
我们可以通过块大小乘以块数目得出某个表占用的实际空间。比如li表,5761*512KB。在sql工具内部,提供了help命令可以查看各种数据库对象(表、索引等)的信息。Help table 表名可以查看表的存储、结构和统计信息。
Executing . . .
Name: li
Owner: ingres
Created: 04-apr-2011 22:07:47
Location: ii_database
Type: user table
Version: II10.0
Page size: 8192
Cache priority: 0
Alter table version:0
Alter table totwidth: 143
Row width: 143
Number of rows: 59986052
Storage structure: vectorwise
Compression: none
Duplicate Rows: allowed
Number of pages: 3
Overflow data pages:0
Journaling: disabled
Base table for view:no
Permissions: none
Integrities: none
Optimizer statistics: yes; see avg count below, more info in the iistats catalog
Column Information:
KeyAvg Count
Column Name Type Length Nulls Defaults SeqPer Value
l_orderkey integer 4 no no 23.8
l_partkey integer 4 no no 29.9
l_suppkey integer 4 no no 599.9
l_linenumber integer 4 no no 8569436.0
l_quantity decimal(15, 2) 15 no no 1199721.0
l_extendedprice decimal(15, 2) 15 no no 57.1
l_discount decimal(15, 2) 15 no no 5453277.5
l_tax decimal(15, 2) 15 no no 6665117.0
l_returnflag char 1 no no 19995350.0
l_linestatus char 1 no no 29993026.0
l_shipdate ansidate no no 23747.4
l_commitdate ansidate no no 24325.2
l_receiptdate ansidate no no 23533.2
l_shipinstruct char 25 no no 14996513.0
l_shipmode char 10 no no 8569436.0
l_comment varchar 44 no no 17.0
Secondary indexes: none
Help表名则可以查看更为简略的表的结构信息。
* help li\g
Executing . . .
Name: li
Owner: ingres
Created: 04-apr-2011 22:07:47
Type: user table
Version: II10.0
Column Information:
Key
Column Name Type Length Nulls Defaults Seq
l_orderkey integer 4 no no
l_partkey integer 4 no no
l_suppkey integer 4 no no
l_linenumber integer 4 no no
l_quantity decimal(15, 2) 15 no no
l_extendedprice decimal(15, 2) 15 no no
l_discount decimal(15, 2) 15 no no
l_tax decimal(15, 2) 15 no no
l_returnflag char 1 no no
l_linestatus char 1 no no
l_shipdate ansidate no no
l_commitdate ansidate no no
l_receiptdate ansidate no no
l_shipinstruct char 25 no no
l_shipmode char 10 no no
l_comment varchar 44 no no
continue
至于更多的help选项,可以用help help\g命令查看,这里不再赘述。
四、性能测试
测试项目包含三方面,第一是加载,数据仓库要处理的数据量巨大,数据加载能力是选择数据库软件要考虑的重要因素之一,我们将测试包括外部文本数据加载和从数据库内部抽取部分数据到其他表的性能。第二是压缩,数据压缩时常被作为列式存储数据库的一个卖点来宣传,因此我们单独把它拿出来测试。由于多数数据库没有单独的表压缩命令,都是依靠参数指定是否压缩或根本无法指定不压缩(Sybase IQ),只测试压缩后的占用空间对原始外部文件的压缩率。第三是测试重点,数据查询,分别采用tpc-h scala=10,SSB (星型模式基准)scala=10以及用户真实的大规模数据作全表分组查询。
TPC-H是一个业界公认的数据仓库性能测试基准,比较公正和中立,它定义了8个标准数据库表:customer,lineitem,nation,orders,partsupp,part,region,supplier,各表之间的关系见tpc.org网站的官方文档,一个数据生成工具(dbgen)和一个查询生成工具(qgen)。此外TPC-H定义了不同的数据仓库容量(size),包括:1GB、100GB、300GB、1000GB等。dbgen工具可以通过传递不同的参数值,生成不同数据库尺寸下的表数据,非常灵活。 Qgen可以随机产生相同条件的不同取值的查询,我们这里为了简化,只取一次产生的查询语句。
SSB是麻省州立大学波士顿校区的研究人员在tpc-h模型基础上变换出来的一个数据模型,具体的描述参见http://www.cs.umb.edu/~poneil/StarSchemaB.PDF,它主要将tpc-h的雪花模型修改为星型模式,将lineitem表和orders表合并,并对一些表和数据列进行了裁减。这个模型的scala虽然沿用了tpc-h的计数方式,但实际上对于相同的scala只是记录数保持相等,而实际数据量大大缩小了,已经偏离了原来scala为几就是几GB数据的含义。
(一)数据加载
1.从外部文本文件导入
VectorWise提供了二种导入外部文件的方式,sql工具中的COPY命令和使用专用的iivwfastload工具。我们导入前先用重定向方式执行创建表的脚本。然后首先采用用户指南推荐的最快的导入方式, 用iivwfastload执行导入。命令行参数:
iivwfastload -database数据库名 -table 表名 -datafile 文本数据文件完整路径-fdelim 列分隔符 -rdelim 行分隔符,其中行列分隔符需要用一对''括起来。支持\n等转义符写法。
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Sun Apr3 04:18:27 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * *
* * * * * Executing . . .
continue
*
Your SQL statement(s) have been committed.
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Sun Apr3 04:18:27 2011
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table customer-datafile
/user1/app/vw15/customer.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:23:14 CST
/user1/app/vw15/ingres/bin/iivwfastload
Using settings:
database : 'tpch'
table : 'customer'
datafile : '/user1/app/vw15/customer.tbl'
fdelim : '|'
rdelim : '\n'
ingreschar : NO
nullvalue: ''
verifycount: YES
updatecount: YES
attrs : ''
tmpfile : /tmp/iivwfastload.tmp
Connecting to X100 server at port '44216'
Looking up table 'customer'
Analyzing the table info
Generating the loading request
Loading OK, returning 1500000
Loaded 1500000 records, verified table count OK (0 -> 1500000)
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:23:20 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table lineitem-datafile
/user1/app/vw15/lineitem.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:27:17 CST
Loading OK, returning 59986052
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:31:17 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table orders-datafile
/user1/app/vw15/orders.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:32:26 CST
Loading OK, returning 15000000
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:33:12 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table part-datafile
/user1/app/vw15/part.tbl -fdelim '|' -rdelim '\n
';date
2011年 04月 03日 星期日 19:33:25 CST
Loading OK, returning 2000000
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:33:30 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table partsupp-datafile
/user1/app/vw15/partsupp.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:34:07 CST
Loading OK, returning 8000000
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:34:25 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table nation-datafile
/user1/app/vw15/nation.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:34:37 CST
Loading OK, returning 25
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:34:37 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table supplier-datafile
/user1/app/vw15/supplier.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:34:53 CST
Loading OK, returning 100000
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:34:53 CST
[ingres@redflag11012602 ~]$ date;iivwfastload -database tpch -table region-datafile
/user1/app/vw15/region.tbl -fdelim '|' -rdelim '\n';date
2011年 04月 03日 星期日 19:35:09 CST
Loading OK, returning 5
Updated catalog statistics
Goodbye
2011年 04月 03日 星期日 19:35:09 CST
[ingres@redflag11012602 ~]$ pwd
/home/ingres
我们看到,导入总用时5分15秒,其中最大的lineitem表用了大约4分钟。导入完成后,用du命令查看数据文件占用的空间大小,并和用于导入的文本文件作比较。
[ingres@redflag11012602 vw15]$ ls
customer.tbl ingres nation.tblpartsupp.tblregion.tbl
tpc-h_orig21_ingres.sql
dss_ingres.ddllineitem.tblorders.tblpart.tbl supplier.tbl
[ingres@redflag11012602 vw15]$ cd ingres
[ingres@redflag11012602 ingres]$ ls
binckpdatademodmpfilesjnlliblogsigutilityvdbaversion.relwork
[ingres@redflag11012602 ingres]$ cd data
[ingres@redflag11012602 data]$ ls
defaultvectorwise
[ingres@redflag11012602 data]$ du -s vectorwise
5701788 vectorwise
[ingres@redflag11012602 data]$ cd vectorwise
[ingres@redflag11012602 vectorwise]$ ls
tpchvectorwise.conf
[ingres@redflag11012602 vectorwise]$ ls tpch
authpassCBM
[ingres@redflag11012602 vectorwise]$ cd tpch/CBM
[ingres@redflag11012602 CBM]$ ls
defaultlockLOG
[ingres@redflag11012602 CBM]$ ls default
0
[ingres@redflag11012602 CBM]$ cd default
[ingres@redflag11012602 default]$ ll
总计 5699800
-rw------- 1 ingres ingres 5899419648 04-03 19:35 0
[ingres@redflag11012602 default]$ du -s /user1/app/vw15/*tbl
240816/user1/app/vw15/customer.tbl
7659556 /user1/app/vw15/lineitem.tbl
4 /user1/app/vw15/nation.tbl
1724536 /user1/app/vw15/orders.tbl
1185592 /user1/app/vw15/partsupp.tbl
240552/user1/app/vw15/part.tbl
4 /user1/app/vw15/region.tbl
13964 /user1/app/vw15/supplier.tbl
[ingres@redflag11012602 default]$
数据文件0的大小是5701788KB,而8个tbl文件占用的空间大小是11065024KB,导入后数据大约是原始文件的52%,压缩了近一半。压缩率虽不算高,但我们一直强调,现今存储价格日益低廉,压缩不是目的,而是提高查询效率的手段,因此,即使没有压缩,只要查询高效,同样是“好数据库”。下面,我们来测试COPY命令的导入,由于VectorWise没有truncate table命令,因此先删除lineitem表,并用建表脚本重建它。
Executing . . .
continue
* commit\g
Executing . . .
continue
* \q
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 19:25:57 2011
[ingres@redflag11012602 ~]$ sql tpch
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Mon Apr4 19:26:02 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Executing . . .
E_US07DA Duplicate object name 'nation'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'region'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'part'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'supplier'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'partsupp'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'customer'.
(Mon Apr4 19:26:02 2011)
E_US07DA Duplicate object name 'orders'.
(Mon Apr4 19:26:02 2011)
continue
*
Your SQL statement(s) have been committed.
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 19:26:02 2011
[ingres@redflag11012602 ~]$ sql tpch
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Mon Apr4 19:26:16 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* select count(*) from lineitem;
* \g
Executing . . .
+----------------------+
|col1 |
+----------------------+
| 0|
+----------------------+
(1 row)
continue
* COPY TABLE lineitem (
*l_orderkey = 'c0|',
*l_partkey = 'c0|',
*l_suppkey = 'c0|',
*l_linenumber = 'c0|',
*l_quantity = 'c0|',
*l_extendedprice = 'c0|',
*l_discount = 'c0|',
*l_tax = 'c0|',
*l_returnflag = 'c0|',
*l_linestatus = 'c0|',
*l_shipdate = 'c0|',
*l_commitdate = 'c0|',
*l_receiptdate = 'c0|',
*l_shipinstruct = 'c0|',
*l_shipmode = 'c0|',
*l_comment = 'c0nl'
* ) FROM '/user1/app/vw15/lineitem.tbl' \t\g\t
Mon Apr4 19:28:51 2011
Executing . . .
(59986052 rows)
Mon Apr4 19:42:33 2011
* commit\g
Executing . . .
continue
[ingres@redflag11012602 ingres]$ du -s data
5763656 data
[ingres@redflag11012602 ingres]$ cd
导入同样的lineitem.tbl文件,copy命令用了13分42秒,比iivwfastload多用了约3倍的时间,但是copy命令也有自己的优势,它可以单独为每一列设定不同的列分隔符,并可以用不存在的列名跳过文本文件中不需要的列,比iivwfastload具有更大的灵活性。用copy 命令导入的数据文件比iivwfastload略大,我们在下文再比较二者的查询性能。
2.从数据库内部抽取数据到其他表
数据库从库内转移数据的方法,VectorWise支持create table new as select * fromorg这种方式。
我们从lineitem表复制所有记录保存到li表,用时是80秒。比iivwfastload工具导入还快了大约2倍。li表在创建的同时,也是被压缩的。
Mon Apr4 22:07:47 2011
Executing . . .
(59986052 rows)
Mon Apr4 22:09:07 2011
* commit\g
Executing . . .
continue
* \q
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 22:11:26 2011
[ingres@redflag11012602 ~]$ du -s /user1/app/vw15/ingres/data
8657204 /user1/app/vw15/ingres/data
值得注意的,如果删除表,数据文件并不会收缩,但原来属于被删除的表的空间可以被新插入的数据所利用。
INGRES TERMINAL MONITOR Copyright 2010 Ingres Corporation
VectorWise Linux Version VW 1.5.0 (a64.lnx/141)NPTL login
Mon Apr4 22:12:55 2011
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* drop table lineitem\g
Executing . . .
continue
* commit\g
Executing . . .
continue
* \q
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 22:13:10 2011
[ingres@redflag11012602 ~]$ du -s /user1/app/vw15/ingres/data
8657316 /user1/app/vw15/ingres/data
(二)数据查询
下面各个测试项目列出的均是采用系统默认参数的结果。
1. tpch查询测试
我们将从tpch.org网站下载的源代码编译后,采用dbgen -s10生成一套10GB规模的数据,用qgen产生查询SQL语句,只针对VectorWise数据库作语法修改,尽量不改变语句的结构。主要变动是修改limit关键字为first关键字,并把它移到select字段列表的前面,另外,为了更加精确的计时,没有采用\t命令,而采用插入select local_time的方式,可以精确到毫秒。
先来观察用iivwfastload工具导入的数据的查询:
分别查看优化前和优化后的数据。优化前大约需要100秒,优化后只要45秒,速度提高了1倍多。优化(统计分析)用时大约1分钟。
>tpch_vw15_result_opt.txt;date
2011年 04月 03日 星期日 19:38:04 CST
2011年 04月 03日 星期日 19:39:45 CST
[ingres@redflag11012602 ~]$ date;optimizedb tpch ;date
2011年 04月 03日 星期日 20:34:17 CST
I_OP0958 Row count for table 'customer' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'lineitem' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'nation' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'orders' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'part' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'partsupp' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'region' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'supplier' not available from catalogs. Counting rows.
2011年 04月 03日 星期日 20:35:19 CST
[ingres@redflag11012602 ~]$ date;sql tpch < /user1/app/vw15/tpc-h_orig21_ingres.sql
>tpch_vw15_result_opt1.txt;date
2011年 04月 03日 星期日 20:35:52 CST
2011年 04月 03日 星期日 20:36:37 CST
数据还是同样的数据,不过改用copy命令导入:也查看优化前和优化后的数据。优化前大约需要76秒,但此时只有lineitem表没有统计信息,优化后只要44秒,和使用iivwfastload导入没有区别。
>tpch_vw15_result_copy.txt;date
2011年 04月 05日 星期二 11:22:55 CST
2011年 04月 05日 星期二 11:24:11 CST
[ingres@redflag11012602 ~]$ tail tpch_vw15_result_copy.txt
|col1 |
+-------------------------------+
|20:24:11.385388 |
+-------------------------------+
(1 row)
*
Your SQL statement(s) have been committed.
VectorWise Version VW 1.5.0 (a64.lnx/141)NPTL logout
Mon Apr4 20:24:11 2011
[ingres@redflag11012602 ~]$ grep "|20:" tpch_vw15_result_copy.txt | awk -F"[|: ]"
'{tn=$2*3600+$3*60+$4;getline;to=$2*3600+$3*60+$4;print ++i,to-tn}'
1 1.72552
2 0.146294
3 1.7055
4 2.96347
5 19.2783
6 0.19391
7 4.51213
8 1.55683
9 9.75753
10 1.58815
11 0.122789
12 1.18767
13 1.827
14 0.449243
15 0.324796
16 2.39804
17 0.315481
18 4.67244
19 2.0843
20 2.97518
21 15.9141
22 0.393896
[ingres@redflag11012602 ~]$ optimizedb tpch
I_OP0958 Row count for table 'customer' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'lineitem' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'nation' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'orders' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'part' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'partsupp' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'region' not available from catalogs. Counting rows.
I_OP0958 Row count for table 'supplier' not available from catalogs. Counting rows.
[ingres@redflag11012602 ~]$ date;sql tpch < /user1/app/vw15/tpc-h_orig21_ingres.sql
>tpch_vw15_result_copy.txt;date
2011年 04月 05日 星期二 11:29:03 CST
2011年 04月 05日 星期二 11:29:47 CST
[ingres@redflag11012602 ~]$ grep "|20:" tpch_vw15_result_copy.txt | awk -F"[|: ]"
'{tn=$2*3600+$3*60+$4;getline;to=$2*3600+$3*60+$4;print ++i,to-tn}'
1 0.651289
2 0.145184
3 2.1528
4 3.12139
5 1.45904
6 0.128153
7 1.14407
8 0.824642
9 3.36685
10 3.14761
11 0.110343
12 0.848261
13 1.58433
14 0.414913
15 0.225124
16 2.32214
17 0.304058
18 4.3753
19 0.734187
20 2.61108
21 13.5403
22 0.39558
可以用statdump命令删除表的统计信息,-t参数指定要删除的表。
I_OP092A statdump: statistics for database 'tpch', table 'customer', column
'c_custkey' deleted.
I_OP092A statdump: statistics for database 'tpch', table 'customer', column 'c_name'
deleted.
I_OP092A statdump: statistics for database 'tpch', table 'customer', column
'c_address' deleted.
前几篇文章已经对各种数据库的 tpc-h查询性能做过详细比较,这里仅选择最快的Sybase IQ和VectorWise 作一个对比(字体加粗者为VectorWise时间更短的结果)。可见对于经过统计分析的表,在10G这个数据量,目前在测试中VectorWise是无敌的。何况这是完全没有对系统参数进行修改的情况下执行的。如果经过有经验的用户的调整,可望获得更好的结果。
原始tpch scala=10测试记录 (单位:秒)
我们看到,VectorWise在这方面表现不错,基本上所有的原始脚本都能执行,而且基本没有执行特别慢的语句,所有查询都能在15秒以内完成。支持SQL标准支持的date''、interval''和extract from用法。
五、小结
连续测试了这么多种列存储数据库,不免有一些审美疲劳,每种数据库都有自己独特的优势,而对其它不具备这方面功能的产品,就是一个劣势了。用户的实际需求虽然千差万别,但作为一个分析型数据库,或者数据仓库应用,用户最看重的,不外乎ETL和查询性能。
VectorWise作为新兴的列式存储的一员,依托Ingres的强大背景和CWI的研究成果,总体表现不错。查询性能目前是最快的。
VectorWise支持大多数的SQL标准写法,日期类型也能完整支持。它还支持用户自定义索引和主键,给用户查询带来了方便。
VectorWise的数据加载工具iivwfastload使用非常便利,性能也还不错,对于分隔符不太规则的原始文本文件,copy命令能解决比如文件的最后一个列的分隔符问题等。
VectorWise对tpc-h测试数据的压缩率一般在2倍左右。当存储数据仓库的大量数据时,能有效地减少数据的存储空间,提供更多的空间供用户使用。
VectorWise用户手册中指出,它充分利用了现代CPU的先进功能,比如多级流水线、较大的cache,SSE指令集等。在廉价的x86_64硬件条件下,甚至是笔记本电脑上也能提供强悍的查询性能。目前已经在电信、网络和电子商务公司得到应用。
综上所述,VectorWise是一款功能较全面、性能较强大、兼容性较好的列式数据库软件,完全可以进入主流用户市场,如果能在分析函数、with子查询、group by扩展等方面再作些改进,那么替代主流商用分析型数据库也是不无可能的。