聚簇因子
2013-02-05 12:24
351 查看
1、聚簇因子(clustering_factor):是使用B树索引进行区间扫描的成本很重要因素,反映数据在表中分布的随机程度
2、聚簇因子的计算方法:
①扫描索引
②比较某行的ROWID和前一行的ROWID,如果这两个ROWID不属于同一个数据块,那么聚簇因子增加1
③整个索引扫描完毕后,就得到了该索引的集群因子
--对选择最优查询路径影响最大的只有列的选择率和聚簇因子3、实验测试create table t1 as
select trunc((rownum-1)/100) id,
rpad(rownum,100) t_pad
from dba_source
where rownum <= 10000;
create index t1_idx1 on t1(id);
exec dbms_stats.gather_table_stats(user,'t1',method_opt=>'FOR ALL COLUMNS SIZE 1',cascade=>TRUE);
create table t2 as
select mod(rownum,100) id,
rpad(rownum,100) t_pad
from dba_source
where rownum <= 10000;
create index t2_idx1 on t2(id);
exec dbms_stats.gather_table_stats(user,'t2',method_opt=>'FOR ALL COLUMNS SIZE 1',cascade=>TRUE);
select count(*) ct from t1 where id = 1 ;
select count(*) ct from t2 where id = 1 ;
--索引的聚簇因子
select t.table_name||'.'||i.index_name idx_name,
i.clustering_factor, t.blocks, t.num_rows
from user_indexes i, user_tables t
where i.table_name = t.table_name
and t.table_name in ('T1','T2')
order by t.table_name, i.index_name;
--计算索引的聚簇因子
select t.table_name||'.'||i.index_name idx_name,
i.clustering_factor, t.blocks, t.num_rows
from all_indexes i, all_tables t
where i.table_name = t.table_name
and t.table_name = 'EMPLOYEES'
and t.owner = 'HR'
and i.index_name = 'EMP_DEPARTMENT_IX'
order by t.table_name, i.index_name;
select department_id, last_name, blk_no,
lag (blk_no,1,blk_no) over (order by department_id) prev_blk_no,
case when blk_no != lag (blk_no,1,blk_no) over (order by department_id)
or rownum = 1
then '*** +1'
else null
end cluf_ct
from (
select department_id, last_name,
dbms_rowid.rowid_block_number(rowid) blk_no
from hr.employees
where department_id is not null
order by department_id
);
2、聚簇因子的计算方法:
①扫描索引
②比较某行的ROWID和前一行的ROWID,如果这两个ROWID不属于同一个数据块,那么聚簇因子增加1
③整个索引扫描完毕后,就得到了该索引的集群因子
--对选择最优查询路径影响最大的只有列的选择率和聚簇因子3、实验测试create table t1 as
select trunc((rownum-1)/100) id,
rpad(rownum,100) t_pad
from dba_source
where rownum <= 10000;
create index t1_idx1 on t1(id);
exec dbms_stats.gather_table_stats(user,'t1',method_opt=>'FOR ALL COLUMNS SIZE 1',cascade=>TRUE);
create table t2 as
select mod(rownum,100) id,
rpad(rownum,100) t_pad
from dba_source
where rownum <= 10000;
create index t2_idx1 on t2(id);
exec dbms_stats.gather_table_stats(user,'t2',method_opt=>'FOR ALL COLUMNS SIZE 1',cascade=>TRUE);
select count(*) ct from t1 where id = 1 ;
select count(*) ct from t2 where id = 1 ;
--索引的聚簇因子
select t.table_name||'.'||i.index_name idx_name,
i.clustering_factor, t.blocks, t.num_rows
from user_indexes i, user_tables t
where i.table_name = t.table_name
and t.table_name in ('T1','T2')
order by t.table_name, i.index_name;
--计算索引的聚簇因子
select t.table_name||'.'||i.index_name idx_name,
i.clustering_factor, t.blocks, t.num_rows
from all_indexes i, all_tables t
where i.table_name = t.table_name
and t.table_name = 'EMPLOYEES'
and t.owner = 'HR'
and i.index_name = 'EMP_DEPARTMENT_IX'
order by t.table_name, i.index_name;
select department_id, last_name, blk_no,
lag (blk_no,1,blk_no) over (order by department_id) prev_blk_no,
case when blk_no != lag (blk_no,1,blk_no) over (order by department_id)
or rownum = 1
then '*** +1'
else null
end cluf_ct
from (
select department_id, last_name,
dbms_rowid.rowid_block_number(rowid) blk_no
from hr.employees
where department_id is not null
order by department_id
);
相关文章推荐
- Oracle 基础篇 --- 聚簇因子(clustering_factor)
- Oracle11gR2-聚簇因子浅析
- Oracle聚簇因子(clustering factor)
- Oracle 聚簇因子(Clustering factor)及一次性能优化诊断
- (3)聚簇因子(CLUSTERING_FACTOR )——上
- 索引的聚簇因子分析
- 聚簇因子
- 索引 的聚簇因子对能否用到该索引的影响的实验
- (3)校正聚簇因子(CLUSTERING_FACTOR )——下
- oracle 聚簇因子对查询性能的影响
- cluster factor(聚簇因子值)计算
- 一个执行计划异常变更的案例 - 外传之聚簇因子(Clustering Factor)
- 聚簇因子
- 一次简单的性能优化诊断,聚簇因子过高导致全表扫描。
- 【转】聚簇因子
- 聚簇因子
- oracle 聚簇因子对查询性能的影响
- oracle 聚簇因子对查询性能的影响
- 聚簇因子
- 聚簇因子