October 6, 2013 at 7:31 am
We are loading large number of records in table and i am trying to find the best approach.
i) Disable all indices including cluster and non-cluster.
ii) Load all the data
iii) Re-enable all indices.
I came across mixed responses online. Since we are enabling the indices anyway, why even disable them? I am guessing it will take the same amount of time to enable them back compared to have it enabled when we are loading the data. If we do not disable the index , we will need to update the stats which will also take some time.
Also, wouldn't i just need to re-enable clustered index and that should also take care of nc indices?
If there is a better way to do this please let me know.
October 6, 2013 at 7:36 am
If you disable the clustered index, the entire table is inaccessible (can't be read or modified), so you can't do that before a load or the load will fail.
As for disable NC indexes before and enable afterwards, maybe. There's no hard answer that works everywhere. It depends on the overhead the indexes would put on the insert and on how long it takes to rebuild them. You have to test and see what works in your situation
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 6, 2013 at 8:20 am
GilaMonster (10/6/2013)
If you disable the clustered index, the entire table is inaccessible (can't be read or modified), so you can't do that before a load or the load will fail.As for disable NC indexes before and enable afterwards, maybe. There's no hard answer that works everywhere. It depends on the overhead the indexes would put on the insert and on how long it takes to rebuild them. You have to test and see what works in your situation
what happens if i drop the clustered index and re-create the clustered index after the load? Would that speed up the process?
October 6, 2013 at 9:31 am
Drop the clustered index = recreate the entire table and rebuild all nonclustered indexes
Create the clustered index = recreate the entire table (again) and rebuild all nonclustered indexes (again)
Given that, what do you think?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
October 6, 2013 at 8:07 pm
GilaMonster (10/6/2013)
Drop the clustered index = recreate the entire table and rebuild all nonclustered indexesCreate the clustered index = recreate the entire table (again) and rebuild all nonclustered indexes (again)
Given that, what do you think?
Got it, what if PK is not a clustered index, so basically PK is a non-clustered index. Can we disable PK which is nc index?thanks
October 7, 2013 at 4:17 am
curious_sqldba (10/6/2013)
Can we disable PK which is nc index?thanks
you cant disable PK infact you can drop the constraint and think how would you maintain the uniqueness
because
if duplicate records get inserted and it will need extra and useless attention to remove duplicacy and create PK
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
October 7, 2013 at 5:04 am
curious_sqldba (10/6/2013)
Can we disable PK which is nc index?thanks
Do you want to disable data integrity constraints in your table? Do you want to potentially allow bad data in and have it so that the constraints can't be recreated?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply