CLUSTERING FACTOR

本文探讨了Oracle数据库中Clustering Factor的概念及其重要性。通过创建不同分布方式的数据表及索引,展示了Clustering Factor如何反映数据的聚集程度,并解释了它对查询性能的影响。

The clustering_factor is a single number that represents the degree to which data is

randomly distributed through a table, and the concept of creating a number to represent the

data scatter in a table is a good one. Unfortunately, some recent, and not-so-recent, features of

Oracle can turn this magic number into a liability.

SQL> create table t as select * from dba_objects order by dbms_random.value; SQL> create table t2 as select * from dba_objects order by object_id; Table created. SQL> create index ind_t2 on t2(object_id); Index created. SQL> create index ind_t on t(object_id); Index created. SQL> exec dbms_stats.gather_table_stats(user,'t',cascade=>true); PL/SQL procedure successfully completed. SQL> exec dbms_stats.gather_table_stats(user,'t2',cascade=>true); PL/SQL procedure successfully completed. SQL> select idx.index_name,tab.table_name,tab.num_rows,tab.blocks,idx.clustering_factor from user_indexes idx inner join user_tables tab on idx.table_name=tab.table_name order by tab.table_name; INDEX_NAME TABLE_NAME NUM_ROWS BLOCKS CLUSTERING_FACTOR ------------------------------ ------------------------------ ---------- ---------- ----------------- IND_T T 72482 1058 72418 IND_T2 T2 72481 1058 1032 CLUSTERING_FACTOR与表块数接近代表该列更接近于有序。

当Clustering Factor的值越高,进行索引区间扫描的成本越高,这个时候cbo很有可能会选择全表扫描(数据不好模拟额),物理组织上更加“零散”,

这个例子可以从某种程度上解析:“为什么同一份数据在不同机器上跑,性能不一样?”。

http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1032431852141

http://forums.oracle.com/forums/thread.jspa?threadID=682158

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值