开发者

Insertion of data after creating index on empty table or creating unique index after inserting data on oracle?

开发者 https://www.devze.com 2022-12-14 23:57 出处:网络
Which option 开发者_StackOverflow中文版is better and faster? Insertion of data after creating index on empty table or creating unique index after inserting data. I have around 10M rows to insert. Wh

Which option 开发者_StackOverflow中文版is better and faster? Insertion of data after creating index on empty table or creating unique index after inserting data. I have around 10M rows to insert. Which option would be better so that I could have least downtime.


Insert your data first, then create your index.

Every time you do an UPDATE, INSERT or DELETE operation, any indexes on the table have to be updated as well. So if you create the index first, and then insert 10M rows, the index will have to be updated 10M times as well (unless you're doing bulk operations).


It is faster and better to insert the records and then create the index after rows have been imported. It's faster because you don't have the overhead of index maintenance as the rows are inserted and it is better from a fragmentation standpoint on your indexes.

Obviously for a unique index, be sure that the data you are importing is unique so you don't have failures when trying to create the index.


As others have said, insert first and add the index later. If the table already exists and you have to insert a pile of data like this, drop all indexes and constraints, insert the data, then re-apply first your indexes and then your constraints. You'll certainly want to do intermediate commits to help preclude the possibility that you'll run out of rollback segment space or something similar. If you're inserting this much data it might prove useful to look at using SQL*Loader to save yourself time and aggravation.

I hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消