我们今天是要和大家一起讨论的是DB2 V9.7 分区索引空间占用和扫描性能,我们大家都知道分区表主要是应用在表比较大的背景下,所以我们使用大表才能测试出性能。下面我们创建测试表。

清单 7. 创建测试大表
- drop table t1;
 - CREATE TABLE t1
 - ( l_orderkey INTEGER NOT NULL, l_partkey
 - INTEGER, l_suppkey INTEGER, l_shipdate date, padding1 char(30)
 - )
 - PARTITION BY RANGE(l_shipdate)
 - (
 - STARTING '2008-01-01' ENDING '2008-12-31' EVERY 1 MONTH
 - )
 - ;
 - INSERT INTO t1 (l_orderkey, l_partkey, l_suppkey,l_shipdate,padding1)
 - WITH TEMP (COUNTER, l_orderkey, l_partkey, l_suppkey,l_shipdate,padding1) AS
 - ( VALUES (0, MOD(INT(RAND() * 12000000), 25), MOD(INT(RAND() * 12000000), 30),
 - MOD(INT(RAND() * 12000000), 30), DATE(MOD(INT(RAND() * 12000000), 366)+733042), 'A')
 - UNION ALL SELECT (COUNTER + 1), MOD(INT(RAND() * 12000000), 25),
 - MOD(INT(RAND() * 12000000), 30), MOD(INT(RAND() * 12000000), 30),
 - DATE(MOD(INT(RAND() * 12000000), 366)+733042), 'A' FROM TEMP
 - WHERE (COUNTER + 1) < 12000000
 - )
 - SELECT l_orderkey, l_partkey, l_suppkey,l_shipdate,padding1
 - FROM TEMP
 - ;
 
我们创建的表包含 1200 万行数据,按照月份每个月一个分区,分区列 l_shipdate 的数据分布在’ 2008-01-01 ’和’ 2008-12-31 ’之间,且均匀分布。注意 733042 是日期 2008-01-01 在 DB2 内以天数的表达形式,是通过 days() 函数获得的。
我们首先在列 l_orderkey 上创建非DB2 V9.7 分区索引。
清单 8. 创建非分区索引
- db2 "Create index idx_nopart_l_orderkey on t1(l_orderkey) not partitioned"
 - db2 "runstats on table db2inst1.t1 and indexes all"
 - db2 "select substr(INDNAME,1,25) idx_name,NLEVELS,NLEAF,INDCARD
 - from syscat.indexes where tabname='T1'"
 - DX_NAME NLEVELS NLEAF INDCARD
 - IDX_NOPART_L_ORDERKEY 3 16831 12000000
 
清单 8 表明,非分区索引 B 树高度为 3 层,具有 16831 个叶子页面。
清单 9. 测试非DB2 V9.7 分区索引性能
- db2 set current explain mode yes
 - db2 values current timestamp
 - 1
 - 2009-07-07-15.46.24.863000
 - db2 "select count(*) from t1 "
 - 1
 - ----------- 12000000
 - db2 values current timestamp
 - 1
 - 2009-07-07-15.46.27.394000
 - db2exfmt -d sample -w -1 -n % -s % -# 0 -t
 - Total Cost: 24109.7
 - Query Degree: 1
 - Rows RETURN ( 1) Cost I/O
 - | 1 GRPBY ( 2) 24109.7 17002 | 1.2e+007 IXSCAN ( 3) 23259.5 17002 | 1.2e+007
 - INDEX: ADMINISTRATOR
 - IDX_NOPART_L_ORDERKEY Q1
 
清单 9 表明使用索引 IDX_NOPART_L_ORDERKEY 统计表 T1 的总行数时,估计总成本为 24109.7,IO 次数估计为 17002,实际花费时间为 2.45 秒。
清单 10. 创建分区索引
- db2 "Create index idx_part_l_orderkey on t1(l_orderkey) partitioned"
 - db2 "runstats on table db2inst1.t1 and indexes all"
 - db2 "select substr(INDNAME,1,25) idx_name,DATAPARTITIONID,NLEVELS,NLEAF,INDCARD
 - from syscat.indexpartitions"
 - IDX_NAME DATAPARTITIONID NLEVELS NLEAF INDCARD
 - IDX_PART_L_ORDERKEY 0 3 1134 1021133
 - IDX_PART_L_ORDERKEY 1 3 1062 956131
 - IDX_PART_L_ORDERKEY 2 3 1136 1023293
 - IDX_PART_L_ORDERKEY 3 3 1098 988650
 - IDX_PART_L_ORDERKEY 4 3 1134 1021552
 - IDX_PART_L_ORDERKEY 5 3 1100 990715
 - IDX_PART_L_ORDERKEY 6 3 1134 1020850
 - IDX_PART_L_ORDERKEY 7 3 1137 1023727
 - IDX_PART_L_ORDERKEY 8 3 1101 991839
 - IDX_PART_L_ORDERKEY 9 3 1133 1020225
 - IDX_PART_L_ORDERKEY 10 3 1078 970906
 - IDX_PART_L_ORDERKEY 11 3 1078 970979
 
清单 10 表明,分区索引 idx_part_l_orderkey 具有 12 个分区,B 树高度为 3 层,合计具有 13325 个叶子页面,叶子页面数比非分区索引下降 20% 。
清单 11. 测试DB2 V9.7 分区索引性能
- db2 set current explain mode yes
 - db2 values current timestamp
 - 1
 - 2009-07-07-15.59.09.722000
 - db2 "select count(*) from t1 "
 - 1
 - ----------- 12000000
 - db2 values current timestamp
 - 1
 - 2009-07-07-15.59.11.910000
 - db2exfmt -d sample -w -1 -n % -s % -# 0 -t
 - Total Cost: 24109.7
 - Query Degree: 1 Total Cost: 22059.4
 - Query Degree: 1
 - Rows RETURN ( 1) Cost I/O | 1 GRPBY ( 2)
 - 22059.4 14178.4 | 1.2e+007 IXSCAN ( 3) 21209.2 14178.4 | 1.2e+007
 - INDEX: ADMINISTRATOR
 - IDX_PART_L_ORDERKEY Q1
 
清单 11 表明使用索引 IDX_PART_L_ORDERKEY 统计表 T1 的总行数时,估计总成本为 22059.4,比非分区索引下降 8.5%,IO 次数估计为 14178.4,比非分区索引下降 16%, 实际花费时间为 2.19 秒,比非分区索引下降 10% 。
上述测试表明,DB2 V9.7 分区索引在空间占用、扫描性能方面比非分区索引具有一定的性能优势。
                文章名称:DB2V9.7分区索引空间占用和扫描性能的描述
                
                文章链接:http://www.csdahua.cn/qtweb/news31/389581.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网