简体   繁体   中英

Programatically drop and recreate Oracle indexes for bulk update

Since Oracle does not support disabling normal indexes, I would like to programatically drop all indexes on a table before a bulk update and recreate them once the update is complete. I imagine this would require some custom PL/SQL. Can anyone offer a solution to this? Maybe someone here has already written such a script.

For reference, here is a solution for SQL Server: Automatically Drop and Recreate current indexes .

set head off
set echo off
set pages 1000
set lines 300
set feedback off
spool index_unusable.sql
select 'alter index ' || index_name || ' unusable;' from user_indexes where table_name='MY_TABLE';
spool off
@index_unusable.sql

do you bulk import setting this in your session before:

alter session set skip_unusable_indexes=true;

after the import:

set head off
set echo off
set pages 1000
set lines 300
set feedback off
spool index_rebuild.sql
select 'alter index ' || index_name || ' rebuild;' from user_indexes where table_name='MY_TABLE';
spool off
@index_rebuild.sql

If you have constraints you will need to disable them as well using:

 alter table mytable modify constraint constraint_name DISABLE keep index;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM