Oracle索引管理

來源:互聯網
上載者:User
基礎知識:create table test01(   enno number(3),   enname varchar(20),   sex  varchar(2),   age  number(3))1、建立索引     文法:create index 索引名稱 on 表名稱(列名稱1,列名稱2,.......) tablespace 資料表空間名稱;    例子:create index  ind_enno on test01(enno) tablespace system;    建立唯一索引:create unique index 索引名稱 on 表名稱(列名稱1,列名稱2,......) tablespace 資料表空間名稱   例子:create unique index ind_age  on test01(age) tablespace system   建立函數索引:create index 索引名稱 on 表名稱(函數)   例子:create index ind_sex on test01 (upper(sex))2、查詢索引     select  index_name,table_name     from dba_indexes     where table_name='TEST01';3、刪除索引      文法:drop index 索引名稱       例子:drop index ind_enno; 4、重新命名索引      文法:alter index 舊索引名稱 rename to 新索引名稱       例子:alter  index ind_enno rename to ind_enno1 5、監控索引的使用  開啟監控:   alter index  索引名稱  monitoring usage  查詢使用方式:select * from v$object_usage;  關閉監控:alter index 索引名 nomonitoring usage例子:    alter index ind_enno monitoring usage;    對test01表進行查詢:select * from  test01 where enno='1';   alter index ind_enno nomonitoring usage;   select * from v$object_usage;INDEX_NAME        TABLE_NAME      MON USE    START_MONITORING
  END_MONITORING------------------------------ ---------------------------  ---    --- --- ------------------- -------------------IND_ENNO        TEST01      YES     YES   02/27/2013 05:42:41備忘:use代表使用方式,yes表示使用,no表示未使用6、重建索引   文法:alter index 索引名稱 rebuild    例子:alter index ind_enno rebuild;   文法:alter index 索引名稱 rebuild  online    例子:alter index  ind_enno rebuild online;===================以下內容是引用他人文章===============================

出處:http://blog.csdn.net/hailang99/article/details/1827129

目的:為了讀者更好理解作者寫的內容

alter index ... rebuild online的機制

當我們對索引進行rebuild時,如果不加online選項,oracle則直接讀取原索引的資料;當我們添加online選項時,oracle是直接掃描表中的資料,那如何維護索引段資料的一致性呢?就是從引開始建立到索引建立完成這段時間的資料改變...

從索引開始rebuild online開始的那一刻起,oracle會先建立一個SYS_JOURNAL_xxx的系統臨時日誌表,結構類似於mlog$_表,通過內部觸發器,記錄了開始rebuild索引時表上所發生的改變的記錄,當索引已經建立好之後,新資料將直接寫入索引,只需要把SYS_JOURNAL_xxx日誌表中的改變維護到索引中即可.

1。drop & create 的話,當前Table 無法使用該index ,可能會嚴重影響應用,只能在應用不需用到該 Index時使用 , 而 alter index .. rebuild online 則沒有這個限制,只是會消耗DB資源,不至於嚴重影響應用

2。Drop & create 只需佔用一份index的space , 不像alter index .. rebuild online ,會在建立過程中需要佔用新老兩個index的space, 在free space不足的環境中,也許只能選用Drop & create 

3. 至於 alter index .. rebuild ,或者alter index .. rebuild online 是否會使用 INDEX SCAN 代替 TABLE SCAN ,似乎不同環境有不同的結果。(RBO狀態下)
我的一套環境中,alter index .. rebuild ==> INDEX FAST FULL SCAN 
alter index .. rebuild online==> TABLE FULL SCAN 
而另一套,則是alter index .. rebuild /alter index .. rebuild online 都採用了TABLE FULL SCAN

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.