Make indexes unusable before big insert

Make indexes unusable before doing a big insert, then rebuild them at the end, is faster than insert with indexes in place and no risk of forgetting to recreate a dropped index:

create table af ( mycol varchar2(100) ) ;
create index af1 on af ( mycol ) ;
alter index af1 unusable ;
insert into af (mycol) select * from big_table ;
select status from dba_indexes where index_name = 'AF1' ;
alter index af1 rebuild ;
select status from dba_indexes where index_name = 'AF1' ;

Code to make a lot of indexes unusable in one go is:

select 'alter index '||owner||'.'||index_name||' unusable ;'
from dba_indexes
where owner = 'MYSCHEMA' ;
This entry was posted in Scripts. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>