[转载]oracle重建索引
一:考虑重建索引的场合
1:表上频繁发生update,delete操作
2:表上发生了alter table ..move操作(move操作导致了rowid变化)
二:判断重建索引的标准
1,
Analyze index indexname validate structure;
2, 在执行步骤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内部过程和注意点
(1)
Rebuild以index fast full scan(or table full
scan)方式读取原索引中的数据来构建一个新的索引,有排序的操作; rebuild online
执行表扫描获取数据,有排序的操作;
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