加online这个参数,这个参数加上以后,除了create过程中index 保持online状态,Oracle还会在create index之前等待所有DML操作结束,然后得到DDL锁,
开始create.
SQL> create index t1 on test(id) online;
————————————————————————————————
一、重建索引的前提
1、表上频繁发生update,delete操作;
2、表上发生了alter table ..move操作(move操作导致了rowid变化)。
二、重建索引的标准
1、索引重建是否有必要,一般看索引是否倾斜的严重,是否浪费了空间, 那应该如何才可以判断索引是否倾斜的严重,是否浪费了空间, 对索引进行结构分析(如下):
SQL>Analyze index index_name validate structure;
2、在执行步骤1的session中查询index_stats表,不要到别的session去查询。
SQL>select height,DEL_LF_ROWS/LF_ROWS from index_stats;
说明:当 查询出来的 height>=4 或者 DEL_LF_ROWS/LF_ROWS>0.2 的场合 , 该索引考虑重建 。
举例: (t_gl_assistbalance 26 万多条信息 )
SQL> select count(*) from t_gl_assistbalance ;
输出结果:
COUNT(*)
----------
265788
SQL> Analyze index IX_GL_ASSTBAL_1 validate structure;
Index analyzed
SQL> select height,DEL_LF_ROWS/LF_ROWS from index_stats;
输出结果:
HEIGHT DEL_LF_ROWS/LF_ROWS
---------- -------------------
4 1
————————————----、2 、直接重建:
举例:
alter index indexname rebuild; 或alter index indexname rebuild online;