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