Effective Indexes For Beginners
Performance is slowLet’s add another index!
Ineffective IndexesInsert, Update and Delete operations will be slower if you have too many indexes on your tableIndexes are stored on the disk, the more indexes you have, the more disk space you use
sys.dm_db_index_usage_statsCounts of different types of index operationsTime each type of operation last performed.Requires VIEW SERVER STATE permissionCounters reset to empty when SQL Server Service is restartedIf the database is detached or shutdown, all rows associated with that DB are removedInformation gathered is real-time
sys.dm_db_index_usage_stats
On to the code…Pick a table and view its indexesTake a look at the current usage Run code that targets each index and see when the index was last usedRecheck the usageView index usage for entire databaseHow to disable an indexHow to enable an indexHow to drop an index
Demo...
ConclusionUse sys.dm_db_index_usage_stats DMV to easily identify real-time index usage statsIdentify indexes that are rarely or never usedDisable for a time before droppingIf disabled indexes aren’t missed – drop them to save disk space
ResourcesClick on the Word icon to the right to access the SQL code used in the practical element of this session. Download AdventureWorks2008 DBs for free here: http://tinyurl.com/c6y6a3BOL sys.dm_db_index_usage_stats information page: http://tinyurl.com/qpfa4dUseful blog article on managing indexes at a more detailed level: http://tinyurl.com/38fb5vBlog:   	http://nzgirlgeek.blogspot.comWeb:   	www.aucklandsql.comwww.girlgeekdinners.co.nzEmail: 	amanda@aucklandsql.com
Website:www.aucklandsql.comMailing list:announce@aucklandsql.com

More Related Content

PPT
SQL Server 2008 Certifications
DOCX
Cronograma
PPTX
Simplifying Architecture Design
PPTX
PPT
The Ever So Slighty Geeky Quiz With Maybe
PPTX
PPTX
PPTX
California
SQL Server 2008 Certifications
Cronograma
Simplifying Architecture Design
The Ever So Slighty Geeky Quiz With Maybe
California

Viewers also liked (6)

PDF
Freebase API @ HackTO 2
PPTX
Learn the Colors in Spanish
PDF
Panama & Los Angeles
PPTX
RE-Introduction to Workflow
PPTX
Practical Information Architecture
PPTX
Top Ten Non-SharePoint Technical Issues that Can Doom Your Implementation
Freebase API @ HackTO 2
Learn the Colors in Spanish
Panama & Los Angeles
RE-Introduction to Workflow
Practical Information Architecture
Top Ten Non-SharePoint Technical Issues that Can Doom Your Implementation
Ad

Similar to Effective Indexes (20)

PPTX
Are Indexes Unnecessary in Exadata
PPTX
Advanced Index Tuning
PPTX
dotnetMALAGA - Sql query tuning guidelines
PDF
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
PDF
SQL Server 2014 Monitoring and Profiling
PPTX
Dev Sql Indexing Strategies
PDF
Expert Performance Indexing in Azure SQL and SQL Server 2022 Fourth Edition E...
ODP
Database index by Reema Gajjar
PPTX
Understanding indices
PDF
PPTX
Database Performance
PPT
Optimizing Data Accessin Sq Lserver2005
PDF
The dr overnight dba
PPS
07 qmds2005 session10
PPT
Module08
PPT
Module08
PPT
Managing SQLserver
PDF
3 indexes
PPT
Indexing Strategies
PPT
Performance Tuning And Optimization Microsoft SQL Database
Are Indexes Unnecessary in Exadata
Advanced Index Tuning
dotnetMALAGA - Sql query tuning guidelines
SQLDay2013_Denny Cherry - Table indexing for the .NET Developer
SQL Server 2014 Monitoring and Profiling
Dev Sql Indexing Strategies
Expert Performance Indexing in Azure SQL and SQL Server 2022 Fourth Edition E...
Database index by Reema Gajjar
Understanding indices
Database Performance
Optimizing Data Accessin Sq Lserver2005
The dr overnight dba
07 qmds2005 session10
Module08
Module08
Managing SQLserver
3 indexes
Indexing Strategies
Performance Tuning And Optimization Microsoft SQL Database
Ad

Effective Indexes

  • 2. Performance is slowLet’s add another index!
  • 3. Ineffective IndexesInsert, Update and Delete operations will be slower if you have too many indexes on your tableIndexes are stored on the disk, the more indexes you have, the more disk space you use
  • 4. sys.dm_db_index_usage_statsCounts of different types of index operationsTime each type of operation last performed.Requires VIEW SERVER STATE permissionCounters reset to empty when SQL Server Service is restartedIf the database is detached or shutdown, all rows associated with that DB are removedInformation gathered is real-time
  • 6. On to the code…Pick a table and view its indexesTake a look at the current usage Run code that targets each index and see when the index was last usedRecheck the usageView index usage for entire databaseHow to disable an indexHow to enable an indexHow to drop an index
  • 8. ConclusionUse sys.dm_db_index_usage_stats DMV to easily identify real-time index usage statsIdentify indexes that are rarely or never usedDisable for a time before droppingIf disabled indexes aren’t missed – drop them to save disk space
  • 9. ResourcesClick on the Word icon to the right to access the SQL code used in the practical element of this session. Download AdventureWorks2008 DBs for free here: http://tinyurl.com/c6y6a3BOL sys.dm_db_index_usage_stats information page: http://tinyurl.com/qpfa4dUseful blog article on managing indexes at a more detailed level: http://tinyurl.com/38fb5vBlog: http://nzgirlgeek.blogspot.comWeb: www.aucklandsql.comwww.girlgeekdinners.co.nzEmail: amanda@aucklandsql.com

Editor's Notes

  • #2: From SQL Server 2005 onwards, we have been able to use DMVs to identify which of our indexes are effective and which of our indexes can be disabled.  This short talk will cover, at a very high level, how and why you should be checking the effectiveness of your indexes.
  • #3: When fixingperformance issues on a database there are quite a few DBAs and developers out there whose first thought is – ‘let’s add another index’. We need to stop and think before adding another index; surely we should check to see if the indexes we’ve already got are doing their job correctly and make sure they’re being effectively used and maybe we could also get rid of any indexes that are a waste of disk space and aren’t doing anything constructive. I’ve worked with developers in the past who were of the impression that the more indexes you stick on a table the better, and even when performance was bad they continued to add more indexes as if they were some sort of database sticky plaster. So what happens if we’ve got too many indexes on a table?
  • #4: If you have too many indexes on a table then you run the risk of causing performance issues with the very thing you are using to try and fix the performance issues. As index size on the disk is dependent up on the table size, number of columns and type of columns,toomany indexes may = slower performance. What we need to do is find out which indexes are useful and which are not, then we get rid of the useless ones, free up some disk space and also make ongoing maintenance much less of a headache. But how can we do this? From SQL Server 2005 onwards this task is much simpler as you can use DMVs to help investigate index usage stats. We’re going to look at one of these DMVs in this presentation.
  • #5: The DMV we’re going to be using in the demonstration is sys.dm_db_index_usage_stats. I’ve provided a link at then end of this talk for the relevant MSDN page. This DMV returns a lot of information – user and system seeks, scans, lookups and updates along with the times these occurred. You can evaluate at table or database level.
  • #6: What information does this DMV return? These are the columns returned by the DMV.Data types and descriptions of each of these items can be found on the MSDN page for this DMV – details at the end.
  • #7: We’ll be using the AdventureWorks2008 DB for during the code example stage – this is free to download from codeplex and there is a link provided at the end of this presentation. What I’m going to do is show you the information returned by sys.dm_db_index_usage_stats, we will then run some select statements so that you can see how the results change. You will also be able to see when the index was last used. You can use this information to find indexes that are sitting around using up disk space but not being used, however, don’t drop indexes willynilly – they may not have been used for a while but what if one of those indexes that aren’t being used are only triggered when Joe Bloggs updates some data in an obscure table once a fortnight. The best option is to disable the index for a period to see what effect this has on the database. If after a set period of time (perhaps base this on the last used value – if it was a month ago, wait a month) you see no degradation in performance, then you should be able to safely drop the index.
  • #9: Using sys.dm_db_index_usage_stats DMV you can identify indexes which are used often by queries and also indexes which are rarely used. Any indexes that are rarely or never used, disable the indexes for some time and see is there is any performance degradation.If there is no performance degradation then you can go ahead and drop the index there by saving disk space and improving performance during Insert, Update and Delete operations.