Oracle的聚簇因子對於查詢IO的影響

來源:互聯網
上載者:User
Oracle中,對於同一個查詢語句,有時候會很快的完成,有時候卻很慢,但是表結構什麼的完全一致,表中的資料也完全一致,這個具體是什麼原因呢,就要從Index中的細節說起了。

在Oracle中的一個特殊的視圖user_indexes中有一個特殊的列,名字是clustering_factor,這個值的內容就是如果訪問表的整個表資料,會造成多少次資料庫IO。我們可以通過下面的SQL語句來查看。

SELECT
        A.INDEX_NAME,
        B.NUM_ROWS,
        B.BLOCKS,
        A.CLUSTERING_FACTOR
FROM
        USER_INDEXES A,
        USER_TABLES B
WHERE
        A.INDEX_NAME = ?
        AND A.TABLE_NAME = B.TABLE_NAME

在這個SQL語句中,?代表的就是我們要檢索的Index的名稱。在表中資料有時候屬於無序狀態,這個時候的CLUSTERING_FACTOR比較接近NUM_ROWS,說明如果掃描整個表,每次都要根據Index來讀取相應行的RowID,這個時候的IO操作很多,自然檢索時間會比較長。如果資料有序的話,CLUSTERING_FACTOR比較接近BLOCKS,說明相鄰的資料在一個塊中,減少了IO運算元量,自然檢索時間會大大降低。

 

下面這一段是Oracle 手冊中關於CLUSTERING_FACTOR的說明:

Indicates the amount of order of the rows in the table based on the values of the index.

  • If the value is near the number of blocks, then the table is very well ordered. In this case, the index entries in a single leaf block tend to point to rows in the same data blocks.

  • If the value is near the number of rows, then the table is very randomly ordered. In this case, it is unlikely that index entries in the same leaf block point to rows in the same data blocks.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.