Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Indexing Rule of Thumb ?

Author  Topic 

homebrew
Posting Yak Master

114 Posts

Posted - 2009-12-16 : 21:16:16
Maybe this is too general, but here goes. I'm looking at an older application written by previous employees, and they created all kinds of crazy indexes, many duplicating each other, or indexing columns that are not used in JOIN or WHERE or ORDER BY. I think they went crazy with the tuning advisor, so I want to clean them up.

In general if I have fairly simple queries, joining a few tables, and Table_A is frequently joining other tables on Column_A, with a WHERE condition on Column_B, I assume it makes sense to have an index on Column_A, and another on Column_B. But is there a point to having 1 index on Column_A and Column_B together ?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-16 : 21:25:50
Yes there's a point to the composite index of Column_A, Column_B. What if you had a WHERE clause with WHERE Column_A = 1 AND Column_B = 2? The query would be most efficient with the composite index since it can't use two indexes to satisfy the WHERE clause.

Here's what I use to determine if any indexes can be removed: http://sqlserverpedia.com/wiki/Find_Indexes_Not_In_Use

I only remove indexes with a value of zero for reads.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2009-12-17 : 07:25:03
If there's a filter on Column B and a join on ColumnA then the best index there would be either (A, B) or (B,A) Test both and see which is used.

It's not very useful to have 2 separate indexes. While SQL can do what's called an index intersection, it's very uncommon for it to do so. Far more often it will pick one of the indexes, use that, fetch the rest of the columns from the cluster/heap and then do the additional filters

--
Gail Shaw
SQL Server MVP
Go to Top of Page

homebrew
Posting Yak Master

114 Posts

Posted - 2009-12-17 : 09:04:59
Thanks for the replies and that link.
Go to Top of Page

jagoodie
Starting Member

4 Posts

Posted - 2009-12-17 : 13:37:29
Thanks for the post tkizer, great link. Is their any reason to not drop any index that has a less than say 5% reads per write?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-17 : 19:57:47
I caused massive performance degradation a few months ago when I dropped an index that had very low reads. The process that used the index apparently only runs once a week, but when it does run it needs that index otherwise it's going to scan. Unfortunately it scanned a table with a few hundred million rows which caused CPU utilization to be constant over 90%. This caused all queries to slow down on this mission critical system. We have a performance requirement that queries should take no more than 300 milliseconds, so this was hugely noticed by our customers.

Due to this, I never will drop any indexes unless the reads are zero and also the SQL Server needs to remain up for a while in order for that data to be good. Had I restarted SQL Server the day after the weekly process ran and then ran the DMV report, it would have said zero for reads which is not true since it's a weekly process.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

homebrew
Posting Yak Master

114 Posts

Posted - 2009-12-18 : 09:53:34
And make sure to script out the indexes before dropping them so you can easily recreate them if needed.
Go to Top of Page

jagoodie
Starting Member

4 Posts

Posted - 2009-12-18 : 11:17:24
Both excellent points. Thank you!!!
Go to Top of Page
   

- Advertisement -