1.跟据索引是否倾斜的严重,是否浪费了空间判定是否需要重建
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 则需要重建索引
2.重建索引方式
删除原来的索引,重建建立
删除索引:drop index 索引名;
创建索引:create index 索引名 on 表名(列名);
这种方法是最慢的,最耗时的。不建议使用。
直接重建
alter index 索引名称 rebuild;
或
alter index 索引名称 rebuild online;
快速重建索引的一种有效的办法,因为使用现有索引项来重建新索引,如果客户操作时有其他用户在对这个表操作,尽量使用带online参数来最大限度的减少索引重建时将会出现的任何加锁问题。建议使用
alter index 索引名称 coalesce
使用带有coalesce参数时重建期间不需要额外空间,它只是在重建索引时将处于同一个索引分支内的叶块拼合起来,这最大限度的减少了与查询过程中相关的潜在的加锁问题,但是,coalesce选项不能用来将一个索引转移到其他表空间。
3.查询索引
//表上有哪些索引,状态如何
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('索引名称');