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 ««12

Disabling Indexes Expand / Collapse
Author
Message
Posted Tuesday, July 22, 2008 8:58 AM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: Moderators
Last Login: Yesterday @ 9:08 AM
Points: 6,800, Visits: 1,916
Have to find the tipping point. Drop/create may or may not be faster, for example if you are adding 1 million rows to a 100 million row table. The other portion of the trade off is fragmentation, by rebuilding at the end you correct any fragmentation created during load. Either way you should update column based stats (those that dont match to an index) post load.

Andy
SQLAndy - My Blog!
Connect with me on LinkedIn
Follow me on Twitter
Post #538536
Posted Tuesday, July 22, 2008 10:49 AM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Yesterday @ 3:14 PM
Points: 4,363, Visits: 9,545
Andy Warren (7/22/2008)
Have to find the tipping point. Drop/create may or may not be faster, for example if you are adding 1 million rows to a 100 million row table. The other portion of the trade off is fragmentation, by rebuilding at the end you correct any fragmentation created during load. Either way you should update column based stats (those that dont match to an index) post load.


Definitely have to find the tipping point - and determine what is best for your process. However, dropping and recreating the indexes is actually a lot more work than disabling/rebuilding.

As another poster pointed out - it is very easy to build a procedure that loops through all non-clustered indexes and disable them. This allows for adding new indexes, dropping existing indexes, etc... as you need them without having to modify your code at all.

To rebuild the indexes at the end of the process, you issue a single command for the table:

ALTER INDEX ALL ON table REBUILD;

This rebuilds all indexes for the table, including the clustered index. I have a table on my report server with well over 120 million rows and multiple indexes. The rebuild of all indexes on this one table takes no more than 30 minutes, which is far less time than the increased processing time if I leave the indexes enabled.


Jeffrey Williams
Problems are opportunites brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs
Post #538631
Posted Tuesday, July 22, 2008 11:25 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Wednesday, October 22, 2014 4:55 AM
Points: 41, Visits: 164
I have tested and used this feature a lot. Some advantages to me were, I did not have to script out every index on a table before dropping it. This made database maintenance much easier. If during monitoring missing indexes, I deemed it necessary to add a new index, It would not be lost because index creation were stored in other processes. In testing, I found that disabling all non clustered indexes and leaving the cluster index enabled, then bulk loading data (100's of millions of rows), then re-enabling to rebuild the index, took approx. the same about of time to script and save all indexes, drop all indexes, bulk load data, reapply the indexes. So, for me, this allowed for reduced scripts to maintain.

I also created a stored procedure that would accept a table name and an option to enable\disable indexes. I also added an option to truncate\delete rows.

Post #538666
Posted Tuesday, July 22, 2008 12:25 PM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Friday, October 24, 2014 4:29 PM
Points: 872, Visits: 954
Andy Warren (7/22/2008)
Have to find the tipping point. Drop/create may or may not be faster, for example if you are adding 1 million rows to a 100 million row table. The other portion of the trade off is fragmentation, by rebuilding at the end you correct any fragmentation created during load. Either way you should update column based stats (those that dont match to an index) post load.


I agree, you have to find tipping point for your system.

What I have seen in our Data Warehouse is that the Fact tables with few indexes and thus having index space smaller than data space load faster with drop/recreate during the ETL.

On the other hand for Fact tables with lot of indexes and thus having index space greater than data space, ETL is faster if indexes are not dropped. We do rebuild these indexes monthly though to take care of fragmentation.

So sometimes you have to use both strategies in your system; drop/recreate and leaving the indexes alone during ETL. Keeping track of it does adds to maintenance list though!
Post #538737
Posted Tuesday, July 22, 2008 3:58 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Sunday, November 23, 2014 2:05 PM
Points: 188, Visits: 1,568
Very interesting article and discussion. Thank you!

Nicole Bowman

Nothing is forever.
Post #538880
Posted Friday, September 19, 2008 9:01 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, November 5, 2014 9:59 AM
Points: 257, Visits: 181
I know this is an old article, but I figured I'd give a reason why you should disable indexes.

Not all organizations have the ability to have dbs for applications and others for reporting. So, for EOM or EOY reporting, transactional indicies might cause these reports to take forever especially if there are rollups or aggregations. It's best practice to not have indexes that you don't need, but rather than drop and recreate for EOM or EOY reporting, you can disable. That way, the maintenance hit is not a constant.

Yes, I know.. This is not best practice period . But sometimes, the customer has their limitations.
Post #572618
Posted Thursday, June 18, 2009 10:11 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 11:32 PM
Points: 1,295, Visits: 2,993
hello,

the article is really interesting. We have log shipping set up on one of the dbs and there is also huge bulk inserts gng on, bcoz of that the size of log backups is increasing. We were following the process of dropping the indices, bulk-insert the data and then recreate the indices. if i go the other way around by disabling the indices, bulk-insert data and then re-enable, will this decrese the size of log backups? I think so yes bcoz then there is less activity than re-created the indices from scratch. Please suggest me . thanks in advance
Post #737731
Posted Wednesday, May 26, 2010 2:54 PM


Old Hand

Old HandOld HandOld HandOld HandOld HandOld HandOld HandOld Hand

Group: General Forum Members
Last Login: 2 days ago @ 6:29 PM
Points: 380, Visits: 625
I guess you could say I'm a little late to the party. But thanks, Andy! And thanks to those who have commented.

You all helped me find a solution to a problem I had with bulk inserts, the bulk-logged recovery model, and minimal logging.


Dave Mason
Orange County, FL
Post #928630
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse