首页 > 数据库 > Oracle > Clustoring Factor(二)
A>create table t
2 as
3 select rownum id1,dbms_random.random id2,rpad('*',200,'*') data
4 from all_objects;
Table created.
A>create index organized on t(id1);
Index created.
A>create index disorganized on t(id2);
Index created.
A>select index_name, clustering_factor from user_indexes where table_name = 'T';
INDEX_NAME CLUSTERING_FACTOR
-------------------- -----------------
DISORGANIZED 57643
ORGANIZED 1748
--id1列有序,所以CLUF小接近块数;相反id2列随机无序,所以CLUF大接近行数
A>exec dbms_stats.gather_table_stats( user, 'T' );
PL/SQL procedure successfully completed.
select num_rows, blocks from user_tables where table_name = 'T';
NUM_ROWS BLOCKS
---------- ----------
57670 1784
--下面是重点
--它表明:一般情况下,从物理存储上看的话,一个表只可能按照一个列有序存放
--举个例子,甲乙两人综合素质相当,但在具体领域又各有千秋,在音乐上甲胜乙,所以甲>乙;在绘画上乙胜甲,所以乙>甲
A>A>create table t2 as select * from t order by id2;
Table created.
A>create index id1_idx on t2(id1);
Index created.
A>A>create index id2_idx on t2(id2);
Index created.
A>select index_name, clustering_factor from user_indexes where table_name = 'T2';
INDEX_NAME CLUSTERING_FACTOR
-------------------- -----------------
ID2_IDX 1748
ID1_IDX 57642
--原来按id1列有序,现在按照id2列排序,Id1列自然变成随机,所以体现在CLUF上,是id2列的CLUF变小了
参考:https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1032431852141
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29646619/viewspace-1169417/ ,如需转载,请注明出处,否则将追究法律责任。