question

Mark avatar image
Mark asked

Detecting bad Indexes

How can indexes, which need to be recreated, be detected? Of course a query taking a long time to run can signal trouble with an index, but how do you detect them before that happens?
sql-server-2005indexfragmentation
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Håkan Winther avatar image
Håkan Winther answered
Do you mean an index that is fragmented? Or do you mean an index that is not used becaues it's not "good enough" If you need to see indexes that are fragmented you can use sys.dm_db_index_physical_stats Read more at : [ http://msdn.microsoft.com/en-us/library/ms188917.aspx][1] I also recommend you to take a look at Ola Hallengrens "maintenance solution", that contains an excellent index maintenance solution. [ http://ola.hallengren.com/][2] If you mean un-used indexes take a look at sys.dm_db_index_usage_stats Read more at :[ http://msdn.microsoft.com/en-us/library/ms188755.aspx][3] [1]: http://msdn.microsoft.com/en-us/library/ms188917.aspx [2]: http://ola.hallengren.com/ [3]: http://msdn.microsoft.com/en-us/library/ms188755.aspx
6 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Håkan Winther avatar image Håkan Winther commented ·
Keep in mind that sometimes that performance issues are caused by statistics that is out of date. The first thing you can try when queries suddenly takes long time is to update the statistics. The statistics should be updated automatically, unless turned off, but only if more than 20% of the data has been modified.
1 Like 1 ·
Håkan Winther avatar image Håkan Winther commented ·
You will get different results depending on the parameters you specify. Can't remember right now, but I think it is database Id, table Id, index id, partition number and mode. If you use null in any of the three first parameters you will get records for more then one table.
1 Like 1 ·
Mark avatar image Mark commented ·
@Hakan, I'll look into these links - thank you. I'm primarily interested in fragmentation. But I know of one query that was stuck for a long time, implying to me that maybe more than fragmentation was an issue too. (Recreating the index resolved the issue.)
0 Likes 0 ·
WilliamD avatar image WilliamD commented ·
Ola rules! Get his scripts for defragging.
0 Likes 0 ·
Mark avatar image Mark commented ·
If I'm runnging this sys.dm_db_index_physical_stats right, I'm getting over 500 rows after letting it run 5 minutes on one table. I don't understand that. The table has 3 indexes.
0 Likes 0 ·
Mark avatar image Mark commented ·
@Håkan, thank you and Kev for the answers, I wish I could accept both answers. Now I have a lot of reading to do. In FoxPro, I had an easy rule that worked most of the time: if the index file became bigger than the table file, that was usually a sign to reindex.
0 Likes 0 ·
Kev Riley avatar image
Kev Riley answered
I have the same questions as Håkan..... But to add to those useful links: - Michelle Ufford's fantastic [index defrag scripts][1] - plenty of scripts over on SSC for finding [unused indexes][2] - Paul Neilsen's [duplicate index script][3] - and finally for good measure, Jesse Roberge's [missing index finder script][4] [1]: http://sqlfool.com/2010/04/index-defrag-script-v4-0/ [2]: http://www.sqlservercentral.com/search/?q=unused+indexes&t=s [3]: http://sqlblog.com/blogs/paul_nielsen/archive/2008/06/25/find-duplicate-indexes.aspx [4]: http://www.sqlservercentral.com/scripts/Index+Management/63937/
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.