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('索引名称');
相关文章
相关标签/搜索