11g新特性_索引的可見與不可見,11g新特性索引可見

來源:互聯網
上載者:User

11g新特性_索引的可見與不可見,11g新特性索引可見

當你想評估一個索引對你SQL查詢語句的影響時,恰巧你的資料庫是11g時候,可以快速將索引設定成VISIBLE或INVISIBLE。值得稱讚的時,當索引被設定成INVISIBLE時候,DML語句發生時候照常會維護索引,也就是說處於INVISIBLE狀態下的索引並不失效,只是最佳化器不選擇索引路徑而已。

 

下面通過實驗來驗證一下:

 

SQL> select * from v$version;BANNER--------------------------------------------------------------------------------Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit ProductionPL/SQL Release 11.2.0.4.0 - ProductionCORE11.2.0.4.0ProductionTNS for Linux: Version 11.2.0.4.0 - ProductionNLSRTL Version 11.2.0.4.0 - ProductionSQL> select * from t;ID---------- 21122 133SQL> select count(id) from t; COUNT(ID)---------- 5Execution Plan----------------------------------------------------------Plan hash value: 2966233522---------------------------------------------------------------------------| Id  | Operation   | Name | Rows  | Bytes | Cost (%CPU)| Time  |---------------------------------------------------------------------------|   0 | SELECT STATEMENT   |  |1 |3 |2   (0)| 00:00:01 ||   1 |  SORT AGGREGATE    |  |1 |3 |       |  ||   2 |   <strong>TABLE ACCESS FULL</strong>| T  |5 |    15 |2   (0)| 00:00:01 |--可以看到此時是全表掃描


在T表ID列建立唯一索引

 

<p>SQL> create unique index idx_t_id on t(id) invisible;</p><p>Index created.</p>SQL> select count(id) from t;       COUNT(ID)---------- 5Execution Plan----------------------------------------------------------Plan hash value: 4168287108-----------------------------------------------------------------------------| Id  | Operation | Name     | Rows  | Bytes | Cost (%CPU)| Time     |-----------------------------------------------------------------------------|   0 | SELECT STATEMENT |    |  1 |  3 |  1   (0)| 00:00:01 ||   1 |  SORT AGGREGATE  |    |  1 |  3 | |    ||   2 |   <strong>INDEX FULL SCAN</strong>| IDX_T_ID |  5 | 15 |  1   (0)| 00:00:01 |-----------------------------------------------------------------------------  --發生索引全掃描


將索引設定成INVISIBLE

SQL> alter index idx_t_id invisible; Index altered<p>SQL> select index_name,status,visibility from dba_indexes where table_name='T'; INDEX_NAME                     STATUS   VISIBILITY------------------------------ -------- ----------IDX_T_ID                       <span style="color:#ff0000;"><strong>VALID</strong></span>    <strong>INVISIBLE</strong></p><p>SQL> select count(id) from t;</p><p> COUNT(ID)----------  5</p><p>Execution Plan----------------------------------------------------------Plan hash value: 2966233522</p><p>---------------------------------------------------------------------------| Id  | Operation    | Name | Rows  | Bytes | Cost (%CPU)| Time   |---------------------------------------------------------------------------|   0 | SELECT STATEMENT   |   | 1 | 3 | 2   (0)| 00:00:01 ||   1 |  SORT AGGREGATE    |   | 1 | 3 |        |   ||   2 |   <strong>TABLE ACCESS FULL</strong>| T   | 5 |    15 | 2   (0)| 00:00:01 |      --此時執行計畫裡又是走全表掃描路徑---------------------------------------------------------------------------</p><p>SQL> alter index idx_t_id visible; Index altered</p>


索引的不可見可以避免了索引重建,尤其是大表的索引,這個新特性更有利於資料庫的最佳化

 

-------------------------------------------------------------------------------------------------

本文來自於我的技術部落格 http://blog.csdn.net/robo23

轉載請標註源文連結,否則追究法律責任!

 


怎讓ORACLE索引不起作用(不可見)

  OK,從上面我們可以看到索引很正常。那現在假設我們不再需要這個索引了,因此想刪除它,但又不知道會不會有本文開頭所說的風險。如果可以刪除前先把索引不可見,確認沒問題後再刪除,這樣就沒問題了,為此,Oracle11g推出新的功能,設定索引是否可見,樣本如下:
 
怎刪除word中的小點點,索引作錯了,全篇都是

小點點是灰色的吧,列印不出來的,這是用來區分空格與其他不可見字元用的。點擊工具,選項,視圖,把格式標記下的空格與全部前的勾去掉就行了。做目錄只要把要加入目錄的內容格式設定成標題1,標題2。。。。。。,看你要做幾級目錄。然後點擊插入,索引與目錄,目錄。
 

相關文章

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.