Oracle用HASH簇表优化latch hit过低
2017-09-02 11:00
169 查看
部署测试环境
以SYS用户在HR中建立与DBA_OBJECTS相同的表,重复插入得到100万行,并且添加一列ID,为这列添加连续的值,并建立唯一索引。将AWR快照的产生时间设为10分钟。
在五个窗口并行执行:
建立簇表所需信息
HASHKEYS=distinct valuesSIZE=(avg_row_len*total_rows/HashKeys)*1.1 1.2可能更保险。
HR@ prod> select num_distinct from user_tab_columns where table_name = 'TEST_LARGE' and column_name = 'ID' ; NUM_DISTINCT ------------ 1164720 HR@ prod> select avg_row_len , num_rows from user_tables where table_name = 'TEST_LARGE' ; AVG_ROW_LEN NUM_ROWS ----------- ---------- 102 1164720 HR@ prod> select 102*1.2 "size" from dual ; size ---------- 122.4
建立簇表
将原表重命名:alter table test_large rename to test_large1 ;
建立簇(注意,簇会分配空间,大小为 SIZE*HASHKEYS),相当于建立好了框架,加了single table可以控制本簇只能放一个表:
create cluster cluster_bl(id number(7)) hashkeys 1164720 single table hash is id size 150 ;
将原表移至簇中(注意:这个表没有段,是放在簇中的):
create table test_large cluster cluster_bl ( id ) as select * from test_large1 ;
为了支持范围查询,可以为这个表添加主键。这样就可以范围查询了。
当以簇键为条件访问表时,不会使用索引。
进行性能测试
以下两个脚本同时运行,一个访问的是HASH聚簇表,一个访问的是加了主键索引的堆表,比较哪个执行更快:[oracle@dbsvr1 ~]$ cat test_latch_hit.sh #!/bin/bash start=0 while true do sqlplus hr/hr << eof declare rec hr.test_large1%rowtype ; i number ; j number ; begin j := mod(abs(dbms_random.random()) , 1140000 ) ; for i in 1..3000 loop select * into rec from hr.test_large1 where id = i + j ; end loop ; end ; / quit eof let start=start+1 echo $start done [oracle@dbsvr1 ~]$ cat test_latch_hit1.sh #!/bin/bash start=0 while true do sqlplus hr/hr << eof declare rec hr.test_large%rowtype ; i number ; j number ; begin j := mod(abs(dbms_random.random()) , 1140000 ) ; for i in 1..3000 loop select * into rec from hr.test_large where id = i + j ; end loop ; end ; / quit eof let start=start+1 echo $start done
实验结果表明,访问HASH聚簇表比用索引访问堆表快1.1倍左右。这是在没有latch竞争的情况下做的测试。
性能测试二(并发性能)
为了探索latch对索引访问的影响,采用8个窗口并发的方式进行了测试。在6分钟的时间里,索引访问方式第一个窗口的执行数是285最后一个窗口的执行数是134。
同样的时间里,散列聚簇表的访问方式第一个是308最后一个是277,各个窗口间的差异不大,这应该并行上的差距。
所以用HASH聚簇表来优化某些静态表(不常更新的表)是可行的。可以访问性能以及并发性能。
相关文章推荐
- ORACLE SQL语句优化技术分析
- oracle的索引类型及sql优化总结(一)
- Oracle SQL性能优化
- Oracle 多表查询优化
- Oracle学习总结(7)—— 常用的数据库索引优化语句总结
- oracle 如何优化一个语句
- Oracle性能优化
- 30个Oracle语句优化规则详解
- ORACLE的优化器
- ORACLE SQL优化 续
- Oracle SQL 性能优化技巧
- Oracle 优化器(Optimizer)
- ORACLE SQL优化之ORA-03150&ORA-02055&ORA-02063
- Oracle SQL 'or' 的优化,最近的案例一则。
- Oracle之SQL语句优化(第二篇)
- Oracle的update语句优化研究
- Oracle优化——星型联结转换(star_transformation_enabled)
- ORACLE 11G 性能诊断优化之ASH实战分析详解
- Oracle PL/SQL 优化与调整 -- Bulk 说明
- Oracle性能优化之物化视图管理_超越OCP精通Oracle视频教程培训39