Oracle 11g 新特性 -- Invisible Indexes(不可見的索引) 說明

來源:互聯網
上載者:User

一.Invisible Indexes 說明

Oracle 從版本11g 開始,可以建立不可見的索引。最佳化程式會忽略不可見的索引,除非在會話或系統層級上將 OPTIMIZER_USE_INVISIBLE_INDEXES  初始化參數顯式設定為TRUE。此參數的預設值是FALSE。

使索引不可見是使索引不可用或刪除索引的一種替代辦法。使用不可見的索引,可完成以下操作:

(1)  在刪除索引之前測試對索引的刪除。

(2)  對應用程式的特定操作或模組使用臨時索引結構,這樣就不會影響整個應用程式。

注意:

與停用索引不同,不可見的索引在使用DML 語句期間仍會得到維護。

當索引不可見時,最佳化程式產生的計劃不會使用該索引。如果未發現效能下降,則可以刪除該索引。還可以建立最初不可見的索引,執行測試,然後確定是否使該索引可見。

可以查詢*_INDEXES 資料字典視圖的VISIBILITY 列來確定該索引是VISIBLE 還是INVISIBLE。

SQL> select visibility from dba_indexes where index_name='IDX_ID';

VISIBILIT

---------

VISIBLE

 

 

--建立不可見索引:

CREATE INDEX index_name ONtable_name(column_name) INVISIBLE;

 

--修改索引是否可見:

ALTER INDEX index_name INVISIBLE;

ALTER INDEX index_name VISIBLE;

 

 

二.樣本
 

--建立表,索引,並收集統計資訊:

 

SQL> create table dave(id number);

 

Table created.

 

SQL> begin

 2    for I in 1 .. 10000 loop

 3      insert into DAVE values(I);

 4    end loop;

 5    commit;

 6  end;

 7  /

 

PL/SQL procedure successfully completed.

 

SQL> create index idx_id on dave(id)invisible;

 

Index created.

 

SQL> execdbms_stats.gather_table_stats(ownname =>'&owner',tabname=>'&tablename',estimate_percent => &est_per ,method_opt =>'forall columns size 1',degree=>&degree,cascade => true);

Enter value for owner: sys

Enter value for tablename: dave

Enter value for est_per: 50

Enter value for degree: 2

 

PL/SQL procedure successfully completed.

 

SQL>

  • 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.