oracle的clustering_factor
CLUSTERING_FACTOR表示表上資料的儲存順序和索引欄位的順序符合的程度,clustering_factor主要影響index range scan
1、表中資料的存放順序按object_id存放,索引也建在object_id列上。
預測:因為資料在表中存放順序和索引順序一致,,clustering_factor和表資料塊個數應該相近。
SQL> drop table test;
Table dropped.
SQL> create table test as select * from dba_objects order by object_id;
Table created.
SQL> create index idx_test_object_id on test(object_id);
Index created.
SQL> analyze table test compute statistics for table for all indexes for all indexed columns;
Table analyzed.
SQL> select table_name,blocks,num_rows from user_tables where table_name='TEST';
TABLE_NAME BLOCKS NUM_ROWS
------------------------------ ---------- ----------
TEST 705 49842
SQL> select clustering_factor from user_indexes where index_name='IDX_TEST_OBJECT_ID';
CLUSTERING_FACTOR
-----------------
685
表資料塊數是705,索引聚簇因子是685,接近。發現聚簇因子比資料塊數還要少,這是為什麼?其實只要稍加註意就會了解到,資料塊中不只包含資料還包含一些其他控制資訊,而clustering_factor只包含有資料。
2、表中資料按object_name順序存放,索引建在object_id列上。
預測:表中資料存放順序和索引排序順序不一定一致,所以聚簇因子會遠遠大於資料塊數。
SQL> drop table test;
Table dropped.
SQL> create table test as select * from dba_objects order by object_name;
Table created.
SQL> create index idx_test_object_id on test(object_id);
Index created.
SQL> analyze table test compute statistics for table for all indexes for all indexed columns;
Table analyzed.
SQL> select table_name,blocks,num_rows from user_tables where table_name='TEST';
TABLE_NAME BLOCKS NUM_ROWS
------------------------------ ---------- ----------
TEST 705 49842
SQL> select clustering_factor from user_indexes where index_name='IDX_TEST_OBJECT_ID';
CLUSTERING_FACTOR
-----------------
36531
表中資料塊數705,資料行49842,聚簇因子36531.聚簇因子遠遠大於表中資料塊數,更接近於表中資料行數。
關於clustering_factor的計算方法:
因為索引是排序的,所以oracle會先找到表中物理儲存的第一行,該行的clustering_factor=1;
再看物理儲存的第二行,如果該行與第一行在同一個資料塊,聚簇因子clustering_factor還是1不會增加,否則加1;
依次類推,直到表中所有行都計算完。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24496749/viewspace-723294/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 索引掃描可能不如全表掃描的場景的理解__純粹資料量而言,不涉及CLUSTERING_FACTOR索引
- oracle的比率:Oracle
- oracle的索引Oracle索引
- oracle的表Oracle
- oracle的鎖Oracle
- 【RECO_ORACLE】Oracle閃回PDB的方法Oracle
- Oracle的快照standbyOracle
- oracle comment on的用法Oracle
- oracle樹的裁剪Oracle
- oracle OMF的使用Oracle
- Oracle的壓測Oracle
- Oracle:DG 的 switchoverOracle
- ORACLE的HINT詳解Oracle
- oracle的exit、return、continueOracle
- relink oracle的結果Oracle
- oracle的一個bugOracle
- 坑爹的Oracle 11.2.0.3Oracle
- oracle 中的事務Oracle
- 查殺oracle的阻塞Oracle
- Oracle 中的exception——(Raise)OracleExceptionAI
- Oracle中的sql hintOracleSQL
- oracle的並行世界Oracle並行
- Oracle優化的方法Oracle優化
- oracle的adr清理incidentOracleIDE
- oracle的redo和undoOracle
- Oracle的特性分頁Oracle
- Oracle的全文索引Oracle索引
- Oracle DBA的職責Oracle
- oracle的scn及sequenceOracle
- oracle 的表壓縮Oracle
- oracle_ray.sh 常用的oracle sql功能指令碼OracleSQL指令碼
- oracle truncate table recover(oracle 如何拯救誤操作truncate的表)Oracle
- TLS 1.3已反向移植到的Oracle JDK8 - OracleTLSOracleJDK
- python連線Oracle的外掛cx_Oracle安裝PythonOracle
- 【ASK_ORACLE】重灌Oracle資料泵(Datapump)工具的方法Oracle
- Oracle 的Lgwr Worker的工作原理Oracle
- Oracle Tuning (Oracle 效能調整)的一些總結(轉)Oracle
- 【ASK_ORACLE】關於Oracle索引分裂你需要知道的Oracle索引
- 【BUILD_ORACLE】在Oracle cloud資料庫“插拔”PDB的方法UIOracleCloud資料庫