oracle 重建索引

1.跟據索引是否傾斜的嚴重,是否浪費了空間斷定是否須要重建sql

Analyze index 索引名稱 validate structure;

select height,DEL_LF_ROWS,LF_ROWS,DEL_LF_ROWS/LF_ROWS from index_stats where name='索引名稱';

height>=4 或者 DEL_LF_ROWS/LF_ROWS>0.2  則須要重建索引ui

2.重建索引方式code

刪除原來的索引,重建創建索引

刪除索引:drop index 索引名;

建立索引:create index 索引名 on 表名(列名);

這種方法是最慢的,最耗時的。不建議使用。it

直接重建io

alter index 索引名稱 rebuild; 
或
alter index 索引名稱 rebuild online;

快速重建索引的一種有效的辦法,由於使用現有索引項來重建新索引,若是客戶操做時有其餘用戶在對這個表操做,儘可能使用帶online參數來最大限度的減小索引重建時將會出現的任何加鎖問題。建議使用table

alter index 索引名稱 coalesce

使用帶有coalesce參數時重建期間不須要額外空間,它只是在重建索引時將處於同一個索引分支內的葉塊拼合起來,這最大限度的減小了與查詢過程當中相關的潛在的加鎖問題,可是,coalesce選項不能用來將一個索引轉移到其餘表空間。class

3.查詢索引date

//表上有哪些索引,狀態如何
select status,i.* from user_indexes i where table_name=upper('表名');
//查詢某個索引的狀態
select status,index_name from user_indexes s where index_name=upper('索引名稱');
//查詢分區索引
select status,index_name from user_ind_partitions s where index_name=upper('索引名稱');
相關文章
相關標籤/搜索