IT tutorials
 
Technology
 

SQL Server 2008 R2 : Query Versus Update Performance , Identifying Missing Indexes

8/24/2013 9:32:43 AM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
Each index on a table adds additional overhead for data modifications because the indexes also need to be maintained as changes are made to index key columns. In an OLTP environment, excessive indexes on your tables can be almost as much of a performance issue as missing indexes. To improve OLTP performance, you should limit the number of indexes on your tables to only those absolutely needed; you definitely should eliminate any unnecessary and unused indexes that may be defined on your tables to eliminate the overhead they introduce.

Fortunately, SQL Server provides a DMV that you can use to identify which indexes in your database are not being used: sys.dm_db_index_usage_stats. The columns in the sys.dm_db_index_usage_stats are shown in Table 1.

Table 1. Columns in the sys.dm_db_index_usage_stats DMV
Column NameDescription
database_idID of the database on which the table or view is defined
object_idID of the table or view on which the index is defined
index_idID of the index
user_seeksNumber of seeks by user queries
user_scansNumber of scans by user queries
user_lookupsNumber of bookmark lookups by user queries
user_updatesNumber of updates by user queries
last_user_seekTime of last user seek
last_user_scanTime of last user scan
last_user_lookupTime of last user lookup
last_user_updateTime of last user update
system_seeksNumber of seeks by system queries
system_scansNumber of scans by system queries
system_lookupsNumber of lookups by system queries
system_updatesNumber of updates by system queries
last_system_seekTime of last system seek
last_system_scanTime of last system scan
last_system_lookupTime of last system lookup
last_system_updateTime of last system update

Every individual seek, scan, lookup, or update on an index by a query execution is counted as a use of that index, and the corresponding counter in the view is incremented. Thus, you can run a query against this DMV to see whether there are any indexes that your queries are not using, that is, indexes that either have no rows in the DMV or have 0 values in the user_seeks, user_scans, or user_lookups columns (or the time values of the last_user_* columns are significantly in the past). You especially need to focus on any indexes that don’t show any user query activity but do have a high value in the last_user_update column. This indicates an index that’s adding significant update overhead but not being used by any queries for locating data rows.

For example, the query shown in Listing 1 returns all indexes in the current database that have never been accessed; that is, they would have no records at all in the sys.dm_db_index_usage_stats table.

Listing 1. A Query for Unused Indexes
SELECT  convert(varchar(12), OBJECT_SCHEMA_NAME(I.OBJECT_ID)) AS SchemaName,
convert(varchar(20), OBJECT_NAME(I.OBJECT_ID)) AS ObjectName,
convert(varchar(30), I.NAME) AS IndexName
FROM sys.indexes I
WHERE -- only get indexes for user created tables
OBJECTPROPERTY(I.OBJECT_ID, 'IsUserTable') = 1
-- ignore heaps
and I.index_id > 0
-- find all indexes that exist but are NOT used
AND NOT EXISTS (
SELECT index_id
FROM sys.dm_db_index_usage_stats
WHERE OBJECT_ID = I.OBJECT_ID
AND I.index_id = index_id
AND database_id = DB_ID())
ORDER BY SchemaName, ObjectName, IndexName



Also, you should be aware that that the information is reported in the DMV both for operations caused by user-submitted queries and for operations caused by internally generated queries, such as scans for gathering statistics. If you run UPDATE STATISTICS on a table, the sys.dm_db_index_usage_stats table will have a row for each index for the system scan performed by the UPDATE STATISTICS command. However, the index may still be unused by any queries in your applications. Consequently, you might want to modify the previous query to look for indexes with 0 values in the last_user_* columns instead of indexes with no row at all in the DMV. Listing 2 provides an alternative query.

Listing 2. A Query for Indexes Unused by Appliation Queries
SELECT  convert(varchar(12), OBJECT_SCHEMA_NAME(I.OBJECT_ID)) AS SchemaName,
convert(varchar(20), OBJECT_NAME(I.OBJECT_ID)) AS ObjectName,
convert(varchar(30), I.NAME) AS IndexName
FROM sys.indexes I
LEFT OUTER JOIN
sys.dm_db_index_usage_stats u
on I.index_id = u.index_id
and u.database_id = DB_ID()
WHERE -- only get indexes for user created tables
OBJECTPROPERTY(I.OBJECT_ID, 'IsUserTable') = 1
-- ignore heaps
and I.index_id > 0
-- find all indexes that exist but are NOT used
and isnull(u.last_user_seek, 0) = 0
and isnull(u.last_user_scan, 0) = 0
and isnull(u.last_user_lookup, 0) = 0
ORDER BY SchemaName, ObjectName, IndexName



Note that the information returned by sys.dm_db_index_usage_stats is useful only if your server has been running long enough and has processed a sufficient amount of your standard and peak workflow. Also, you should be aware that the data in the DMV is cleared each time SQL Server is restarted, or if a database is detached and reattached. To prevent losing useful information, you might want to create a scheduled job that periodically queries the DMVs and saves the information to your own tables so you can track the information over time for more thorough and complete analysis.

 
Others
 
- SQL Server 2008 R2 : Query Versus Update Performance , Identifying Missing Indexes
- Windows Server 2008 : Creating Basic Visual Basic Scripts - Using if Statements, Checking for a Value with a Message Box
- Windows Server 2008 : Creating Basic Visual Basic Scripts - Displaying a Message Box with a Visual Basic Script
- Windows Server 2008 : Creating Basic Visual Basic Scripts - Working with filesystemobject
- Windows 7 : Installing and Upgrading Programs - Common Installation Prompts (part 2) - Type of Installation
- Windows 7 : Installing and Upgrading Programs - Common Installation Prompts (part 1) - Compliance check , The End User License Agreement
- Windows 7 : Installing and Upgrading Programs - Installing and Upgrading from a Disk
- Windows Server 2012 : Using Capacity-Analysis Tools - Other Microsoft Assessment and Planning Tools, Third-Party Toolset
- Windows Server 2012 : Using Capacity-Analysis Tools - Windows Performance Monitor
- Windows Server 2012 : Using Capacity-Analysis Tools - Network Monitor (part 2) - Capturing Network Traffic Between Computers , Parsing Captured Network Traffic Data
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us