100 likes | 231 Views
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.
E N D
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
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
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: amanda@aucklandsql.com
Website: www.aucklandsql.com Mailing list: announce@aucklandsql.com