|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, June 09, 2011 10:47 AM
Points: 779,
Visits: 221
|
|
|
|
|
|
SSC Veteran
      
Group: General Forum Members
Last Login: 2 days ago @ 7:17 AM
Points: 223,
Visits: 103
|
|
One book to read is Relational Database Index Design and the Optimizers by Tapio Lahdenmaki and Mike Leach. This Book contains basics and a "little" further. Regards JT a DBA
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Thursday, May 16, 2013 2:10 PM
Points: 2,668,
Visits: 688
|
|
The only comment I'd make is that the order of columns in a covered index "just depends" , generally the most restrictive ( selective) is best placed first - but not always - so it's worth making a few tests including putting the columns in reverse order, I tend to create a number of variations for a particular query and see which the optimiser finds best ( not for simple queries or all queries obviously ) Also worth noting that changing data volumes can change the index selection process. Nice article.
The GrumpyOldDBA www.grumpyolddba.co.uk http://sqlblogcasts.com/blogs/grumpyolddba/
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, June 09, 2011 10:47 AM
Points: 779,
Visits: 221
|
|
| Colin, those are both good points that deserve mentioning! Thank you for pointing them out. It is definitely important to try changing up your high-cost queries to see how the query processor will handle them as part of the baseline/test process. Also, re-evaluating efficiency at a later date when data has changed is a good part of the full database lifecycle.
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, August 27, 2010 3:03 PM
Points: 16,
Visits: 7
|
|
Great Article! You know what would make your query even more valuable (to me, at least) is a rowcount for the table in the resultset. The indexes I would want to pay the most attention to for potentially dropping are the indexes on the largest tables. I would add that to the order by. Anyone know how to get the rowcount in 2005? The rowcnt field that was available on sysindexes doesn't appear to have made the transition from 2000 to 2005. Luke
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, June 09, 2011 10:47 AM
Points: 779,
Visits: 221
|
|
Luke- Try joining to sys.dm_db_index_physical_stats to determine rowcount... that should work.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, June 09, 2011 10:47 AM
Points: 779,
Visits: 221
|
|
(post-coffee) Wait, that's a function... try APPLY.
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 1:35 PM
Points: 301,
Visits: 473
|
|
(mid-coffee) a join seemed to worked, I think... would it have been better to use APPLY? TIA, I've never tried it. And thank you for the article! >L< SELECT o.name AS object_name, i.name AS index_name,i .type_desc, u.user_seeks, u.user_scans, u.user_lookups, u.user_updates,p .record_countFROM sys.indexes iJOIN sys.objects oON i.object_id = o.object_idLEFT JOIN sys.dm_db_index_usage_stats uON i.object_id = u.object_idAND i.index_id = u.index_idAND u.database_id = DB_ID()JOIN (SELECT object_id,record_countFROM master.sys.dm_db_index_physical_stats(DB_ID(), NULL,NULL,NULL,'DETAILED') ) pON i.object_id = p.object_idWHERE o.type <> 'S' -- No system tables!ORDER BY (ISNULL(p.record_count,0) +ISNULL(u.user_seeks, 0) + ISNULL(u.user_scans, 0) + ISNULL(u.user_lookups, 0) + ISNULL(u.user_updates, 0)), o.name, i.name
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 9:18 AM
Points: 772,
Visits: 1,825
|
|
Great article with many good tips. You said, "I once had a developer look me straight in the eye and say that there would never be a problem with adding as many indexes as possible to a table; the query processor would simply select the ones it needed and ignore the rest." That might be OK if this is a pre-built, static, never changing database. Too many indexes are going to cause a bad impact on INSERT, UPDATE, and DELETE. Remember all those indexes have to be updated when the data changes.
ATB
Charles Kincaid
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Thursday, June 09, 2011 10:47 AM
Points: 779,
Visits: 221
|
|
Yup... see my comment two lines down: Unnecessary indexes can force the query processor to evaluate more before deciding on an optimum execution plan, can slow down transactional processing and can take up a great deal of space on disk.
|
|
|
|