如何降低索引的clustering_factor
2013-03-27 22:20
337 查看
如何降低索引的clustering_factor 2012-06-08 22:40:19
分类: Oracle
环境:
OS:Red Hat Linux As 5
DB:10.2.0.4
我们知道判断一个索引的好坏可以通过该索引的clustering_factor高低来衡量,clustering_factor越低,索引的使用效果就越好,那怎么样才能降低索引的clustering_factor呢,通常使用的方法是让表的索引字段值按顺序存储,下面通过一个例子说明.
1.创建表并构造无序的数据
create table scott.tb_index_test
(
id number not null,
name varchar2(30)
);
create index scott.idx_tb_index_test on scott.tb_index_test(id);
declare
l_random_value number;
begin
for i in 1 .. 100000 loop
l_random_value := round(dbms_random.value(1,100000));
insert into scott.tb_index_test(id) values (l_random_value);
commit;
end loop;
end;
2.分析表
begin
dbms_stats.gather_table_stats(ownname => 'SCOTT',
tabname => 'TB_INDEX_TEST',
cascade => true);
end;
3.查看索引当前的clustering_factor
SQL> select ui.clustering_factor, ui.num_rows, ui.index_type, ui.distinct_keys
from dba_indexes ui where ui.table_name = 'TB_INDEX_TEST';
CLUSTERING_FACTOR NUM_ROWS INDEX_TYPE DISTINCT_KEYS
----------------- ---------- --------------------------- -------------
99742 100000 NORMAL 100000
4.将表中的数据按照索引字段存储
create table scott.tmp as select * from scott.tb_index_test;
truncate table scott.tb_index_test;
insert into scott.tb_index_test select * from scott.tmp order by id;
5.再次分析表
begin
dbms_stats.gather_table_stats(ownname => 'SCOTT',
tabname => 'TB_INDEX_TEST',
cascade => true);
end;
6.这个时候索引的clustering_factor明显降低了
SQL> select ui.clustering_factor, ui.num_rows, ui.index_type, ui.distinct_keys
from dba_indexes ui where ui.table_name = 'TB_INDEX_TEST';
CLUSTERING_FACTOR NUM_ROWS INDEX_TYPE DISTINCT_KEYS
----------------- ---------- --------------------------- -------------
372 100000 NORMAL 100000
-- The End --
分类: Oracle
环境:
OS:Red Hat Linux As 5
DB:10.2.0.4
我们知道判断一个索引的好坏可以通过该索引的clustering_factor高低来衡量,clustering_factor越低,索引的使用效果就越好,那怎么样才能降低索引的clustering_factor呢,通常使用的方法是让表的索引字段值按顺序存储,下面通过一个例子说明.
1.创建表并构造无序的数据
create table scott.tb_index_test
(
id number not null,
name varchar2(30)
);
create index scott.idx_tb_index_test on scott.tb_index_test(id);
declare
l_random_value number;
begin
for i in 1 .. 100000 loop
l_random_value := round(dbms_random.value(1,100000));
insert into scott.tb_index_test(id) values (l_random_value);
commit;
end loop;
end;
2.分析表
begin
dbms_stats.gather_table_stats(ownname => 'SCOTT',
tabname => 'TB_INDEX_TEST',
cascade => true);
end;
3.查看索引当前的clustering_factor
SQL> select ui.clustering_factor, ui.num_rows, ui.index_type, ui.distinct_keys
from dba_indexes ui where ui.table_name = 'TB_INDEX_TEST';
CLUSTERING_FACTOR NUM_ROWS INDEX_TYPE DISTINCT_KEYS
----------------- ---------- --------------------------- -------------
99742 100000 NORMAL 100000
4.将表中的数据按照索引字段存储
create table scott.tmp as select * from scott.tb_index_test;
truncate table scott.tb_index_test;
insert into scott.tb_index_test select * from scott.tmp order by id;
5.再次分析表
begin
dbms_stats.gather_table_stats(ownname => 'SCOTT',
tabname => 'TB_INDEX_TEST',
cascade => true);
end;
6.这个时候索引的clustering_factor明显降低了
SQL> select ui.clustering_factor, ui.num_rows, ui.index_type, ui.distinct_keys
from dba_indexes ui where ui.table_name = 'TB_INDEX_TEST';
CLUSTERING_FACTOR NUM_ROWS INDEX_TYPE DISTINCT_KEYS
----------------- ---------- --------------------------- -------------
372 100000 NORMAL 100000
-- The End --
相关文章推荐
- 如何降低索引的clustering_factor (转)
- DBA_INDEXES.CLUSTERING_FACTOR 索引的群集因子初探
- Oracle indexclustering factor 索引聚簇因子
- Clustering Factor过高导致查询没走索引
- 网站改版如何降低损失
- papervision3d大场景时 如何降低cpu占用率
- 在MySQL中如何为连接添加索引
- 仿微信通讯录如何得到侧栏索引的搜索字符
- 通过代理添加的qcombobox,如何通过界面获取内容索引等
- 使用伪hash降低索引长度
- 应用性能优化: 如何将应用延迟降低为 0 ms
- 如何应对并发-关于数据索引
- 如何使用mysql 命令行 查看mysql表大小、数据大小、索引大小
- Oracle 11g Release 1 (11.1) Oracle Text 如何创建 CONTEXT 索引
- 如何知道mysql中sql语句索引是否生效
- SQL Server如何识别真实和自动创建的索引
- Clustering Factor: Row Migration’s Victim(转载)
- 关于如何在java中实现中文首字母索引排序的问题
- 数据库索引<二> 如何创建索引
- Clustering Factor影响数据删除速度一例