oracle重建index
一:考慮重建索引的場合
1:表上頻繁發(fā)生update,delete操作
2:表上發(fā)生了alter table ..move操作(move操作導(dǎo)致了rowid變化)
二:判斷重建索引的標(biāo)準(zhǔn)
1,
Analyze index indexname validate structure;
2, 在執(zhí)行步驟1的session中查詢index_stats表,不要到別的session去查詢
3, 在步驟2查詢出來的height>=4或者DEL_LF_ROWS/LF_ROWS>0.2的場合,該索引考慮重建;
Example:
----------
SQL> analyze index pk_t_test validate structure;
Index analyzed
---------- -------------------
SQL> delete from test_index where rownum<250000;
---------- -------------------
SQL> select height,DEL_LF_ROWS/LF_ROWS from index_stats;
---------- -------------------
三:重建索引的方式
四:alter index rebuid內(nèi)部過程和注意點
(1)
Rebuild以index fast full scan(or table full scan)方式讀取原索引中的數(shù)據(jù)來構(gòu)建一個新的索引,有排序的操作; rebuild online 執(zhí)行表掃描獲取數(shù)據(jù),有排序的操作;
Rebuild
Eg1:
SQL> explain plan for alter index idx_policy_id2 rebuild;
Explained
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------
| Id
---------------------------------------------------------------------
|
|
|
|
---------------------------------------------------------------------
Eg2:
SQL>
Explained
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------
| Id
---------------------------------------------------------------------
|
|
|
|
Eg3: (注意和Eg1比較)
Rebuil online 方式:
SQL> explain plan for alter index idx_policy_id2 rebuild online;
Explained
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
---------------------------------------------------------------------
| Id