Missing Indexes in SQL Server 2005
2011-04-02 12:45
387 查看
There are several new features in SQL Server 2005. There are a few features to help find missing indexes, which are some of the very good ones. How great it will be if you know what indexes you need to create based on your workload? In SQL Server 2000, we had to use SQL Profiler trace files and Index tuning wizard. But with SQL Server 2005 DMVs, we can easily figure out what indexes we need to create which would benefit our application.
The following are the missing index DMVs ( From SQL Server 2005 BOL)
Let’s see what indexes are there for table [Person.Address] table in AdventureWorks database by running this code:
Fig:1
Zoom in | Open in new window
I don’t see an index for ModifiedDate column for [Person.Address] table. So, to get a entry in the “sys.dm_db_missing_index_details” DMV, lets run a query like this:
Query: 1
You may not see any results for the query above, but SQL Server internally recorded that a query was run and a index on “ModifiedDate” column would have been very useful.
Query: 2
Fig: 2
Zoom in | Open in new window
In Fig: 2, see the “equality_columns” field, which implies that a index on the [Modified Date] column is missing ( or might be helpful)
Query: 3:
Run Query 1 several times. Now, run Query: 3,
Fig: 3
In Fig 3, notice the “user_seeks” column. So every time a query is run, for which an index might be useful, SQL Server keeps updating the missing index DMVs. This is very valuable information, based on this you can create indexes to support those queries. Isn’t this cool! Yes, SQL Server 2005 rocks!
The DMVs for missing indexes are great new features. I work with a Siebel CRM database where queries are built dynamically. So it is hard to design indexes in advance. The missing index feature helps to me create indexes for those queries that have high “user_seeks” for a particular column in a table.
For more information see “About the Missing Indexes Feature” in SQL Server 2005 Books Online.
from:http://www.sqlservercentral.com/articles/Indexing/64134/
The following are the missing index DMVs ( From SQL Server 2005 BOL)
sys.dm_db_missing_index_group_stats | Returns summary information about missing index groups, for example, the performance improvements that could be gained by implementing a specific group of missing indexes. |
sys.dm_db_missing_index_groups | Returns information about a specific group of missing indexes, such as the group identifier and the identifiers of all missing indexes that are contained in that group. |
sys.dm_db_missing_index_details | Returns detailed information about a missing index; for example, it returns the name and identifier of the table where the index is missing, and the columns and column types that should make up the missing index. |
sys.dm_db_missing_index_columns | Returns information about the database table columns that are missing an index. |
use AdventureWorks; exec sp_helpindex [Person.Address]
Fig:1
Zoom in | Open in new window
I don’t see an index for ModifiedDate column for [Person.Address] table. So, to get a entry in the “sys.dm_db_missing_index_details” DMV, lets run a query like this:
Query: 1
select * from Person.Address where ModifiedDate = '01/01/2008'
You may not see any results for the query above, but SQL Server internally recorded that a query was run and a index on “ModifiedDate” column would have been very useful.
Query: 2
select * from sys.dm_db_missing_index_details:
Fig: 2
Zoom in | Open in new window
In Fig: 2, see the “equality_columns” field, which implies that a index on the [Modified Date] column is missing ( or might be helpful)
Query: 3:
select db_name(d.database_id) dbname, object_name(d.object_id) tablename, d.index_handle, d.equality_columns, d.inequality_columns, d.included_columns, d.statement as fully_qualified_object, gs.* from sys.dm_db_missing_index_groups g join sys.dm_db_missing_index_group_stats gs on gs.group_handle = g.index_group_handle join sys.dm_db_missing_index_details d on g.index_handle = d.index_handle where d.database_id = d.database_id and d.object_id = d.object_id and object_name(d.object_id) = 'Address'
Run Query 1 several times. Now, run Query: 3,
Fig: 3
In Fig 3, notice the “user_seeks” column. So every time a query is run, for which an index might be useful, SQL Server keeps updating the missing index DMVs. This is very valuable information, based on this you can create indexes to support those queries. Isn’t this cool! Yes, SQL Server 2005 rocks!
The DMVs for missing indexes are great new features. I work with a Siebel CRM database where queries are built dynamically. So it is hard to design indexes in advance. The missing index feature helps to me create indexes for those queries that have high “user_seeks” for a particular column in a table.
For more information see “About the Missing Indexes Feature” in SQL Server 2005 Books Online.
from:http://www.sqlservercentral.com/articles/Indexing/64134/
相关文章推荐
- Partitioned Tables and Indexes in SQL Server 2005
- Partitioned Tables and Indexes in SQL Server 2005
- Partitioned Tables and Indexes in SQL Server 2005
- 检查SQL Server2005中的重叠索引(Detecting Overlapping Indexes in SQL Server 2005)
- Partitioned Tables and Indexes in SQL Server 2005 (EN原版)
- Partitioned Tables and Indexes in SQL Server 2005
- How to check if a date is a valid date in Sql Server 2005
- Using DDL Triggers in SQL Server 2005 to Capture Schema Changes
- XML Enhancement in SQL Server 2005
- How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005
- [转载]官方视频教学《XML Support in SQL Server 2005》
- Index Fragmentation Report in SQL Server 2005 and 2008
- OPENXML In SQL Server 2005
- 安装完SQL Server 2005 Express后安装SQL Server Management Studio Express提示:Setup is missing prerequisites:- MSXML6
- Enabling xp_cmdshell in SQL server 2005
- Enable CLR in SQL Server 2005/2008
- SQL语句执行顺序 in SQL Server 2005
- Problem in connecting VS 2005 to SQL Server 2008
- Built-In Performance Reports in SQL Server 2005 -ZT
- How to Alter a Replicated Article in SQL Server 2005