Download - Effective Indexes
Effective Indexes For Beginners
Performance is slow
Let’s add another index!
Ineffective Indexes
• Insert, Update and Delete operations will be slower if you have too many indexes on your table
• Indexes are stored on the disk, the more indexes you have, the more disk space you use
sys.dm_db_index_usage_stats
• Counts of different types of index operations
• Time each type of operation last performed.
• Requires VIEW SERVER STATE permission
• Counters reset to empty when SQL Server Service is restarted
• If the database is detached or shutdown, all rows associated with that DB are removed
• Information gathered is real-time
sys.dm_db_index_usage_stats
Column Name Column Name
database_id last_user_update
object_id system_seeks
index_id system_scans
user_seeks system_lookups
user_scans system_updates
user_lookups last_system_seek
user_updates last_system_scan
last_user_seek last_system_lookup
last_user_scan last_system_update
last_user_lookup
On to the code…
• Pick a table and view its indexes• Take a look at the current usage • Run code that targets each index and
see when the index was last used• Recheck the usage• View index usage for entire database• How to disable an index• How to enable an index• How to drop an index
Demo...
Conclusion• Use sys.dm_db_index_usage_stats
DMV to easily identify real-time index usage stats
• Identify indexes that are rarely or never used
• Disable for a time before dropping
• If disabled indexes aren’t missed – drop them to save disk space
Resources• Click 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/c6y6a3
• BOL sys.dm_db_index_usage_stats information page: http://tinyurl.com/qpfa4d
• Useful blog article on managing indexes at a more detailed level: http://tinyurl.com/38fb5v
• Blog: http://nzgirlgeek.blogspot.com• Web: www.aucklandsql.com
www.girlgeekdinners.co.nz• Email: [email protected]
Microsoft Office Word Document
Website:www.aucklandsql.com
Mailing list:[email protected]