索引在重建时,查询仍然可以使用旧索引。实际上,oracle在rebuild时,在创建新索引过程中,并不会删除旧索引,直到新索引rebuild成功。
从这点可以知道rebuild比删除重建的一个好处是不会影响原有的SQL查询,但也正由于此,用rebuild方式建立索引需要相应表空间的空闲空间是删除重建方式的2倍。
结论:
1、rebuild会阻塞对基表的DML操作,但不会影响rebuild期间查询对原有索引的使用。
2、rebuild的数据源可能是基表,也可能是原索引。取决于基表和原索引的大小,哪个小,rebuild时就会用那个作为数据源。这也说明了网上盛传的rebuild以原索引作为数据库的说法是不完全正确的。
3、rebuild online运行用户在索引重建期间执行DML操作。
4、rebuild online的数据源是基表。
索引是否需要重建脚本:
col owner format a15 truncate;
col table_name format a30 truncate;
col index_name format a30 truncate;
select
idx.owner owner,
idx.table_name tablename,
idx.index_name index_name,
idx.blocks idx_blocks,
tbl.blocks tbl_blocks,
trunc(idx.blocks/tbl.blocks*100)/100 pct
from
(select i.owner owner ,i.index_name index_name,
SUM(S1.blocks) blocks,i.table_owner table_owner,
i.table_name table_name
from dba_segments s1,dba_indexes i
where
s1.owner=i.owner and
s1.segment_name=i.index_name and
i.owner not in
('SYS', 'OUTLN', 'SYSTEM','MGMT_VIEW','SYSMAN','DBSNMP','WMSYS','XDB',
'DIP','GOLDENGATE','CTXSYS' )
GROUP BY i.owner ,i.index_name ,i.table_owner , i.table_name ) idx,
(select t.owner owner ,t.table_name table_name,SUM(s2.blocks) blocks
from dba_segments s2,dba_tables t
where
s2.owner=t.owner and
s2.segment_name=t.table_name and
t.owner
not in
('SYS', 'OUTLN','SYSTEM','MGMT_VIEW','SYSMAN','DBSNMP','WMSYS','XDB',
'DIP','GOLDENGATE','CTXSYS' )
GROUP BY T.OWNER,T.TABLE_NAME
) tbl
where
idx.table_owner=tbl.owner and
idx.table_name=tbl.table_name and
(idx.blocks/tbl.blocks)>0.5 and
idx.blocks>200
order by 4;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/23891491/viewspace-2847845/ ,如需转载,请注明出处,否则将追究法律责任。