简体   繁体   中英

Recreate nonunique index for bulk load

I have simple table with foreign key (for single column) and nonunique index for column involved in a FK . I disable FK before bulk load (before bulk load I truncate table), and enable it after. I know that in Oracle when you disable a UNIQUE or PRIMARY KEY constraint an associated index is dropped. And when you enable a UNIQUE or PRIMARY KEY constraint an associated index is created. But what about disabling/enabling FK ? Should I manually drop nonunique index for FK before bulk load and also manually create nonunique index after? Or I can keep that index (I mean would this index be valid if I kept him)?

You need to first disable the INDEX

ALTER INDEX idx_fk_column UNUSABLE;

then after your DML operations re-build it.

ALTER INDEX idx_fk_column REBUILD;

If you keep the index it is still valid. But it may be an overhead during the load. So, some sites prefer to disable (using UNUSABLE) and reenable (using REBUILD) such non-unique indexes (Note : If it is a Unique index, setting UNUSABLE would prevent INSERTs, so you'd have to actually DROP and CREATE).

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