Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

disable /enable indices? Is it worth it? Expand / Collapse
Author
Message
Posted Sunday, October 6, 2013 7:31 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 21, 2014 10:33 AM
Points: 1,283, Visits: 2,959

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.
Post #1501919
Posted Sunday, October 6, 2013 7:36 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 42,805, Visits: 35,925
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1501920
Posted Sunday, October 6, 2013 8:20 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 21, 2014 10:33 AM
Points: 1,283, Visits: 2,959
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?
Post #1501923
Posted Sunday, October 6, 2013 9:31 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 42,805, Visits: 35,925
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1501925
Posted Sunday, October 6, 2013 8:07 PM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 21, 2014 10:33 AM
Points: 1,283, Visits: 2,959
GilaMonster (10/6/2013)
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?


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
Post #1501981
Posted Monday, October 7, 2013 4:17 AM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 12:26 AM
Points: 2,840, Visits: 3,963
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
Post #1502067
Posted Monday, October 7, 2013 5:04 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 8:47 AM
Points: 42,805, Visits: 35,925
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 2008, MVP
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass

Post #1502080
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse