Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
871 views
in Technique[技术] by (71.8m points)

sql server - Database Tuning Advisor recommends to create an existing index

When I run SQL Server 2005 Database Tuning Advisor, it gives a recommendation to create an index, but it will recommends to index a column which already has an index on it. Why does it give a recommendation to create the same index again?

Here is my SQL:

SELECT t.name AS 'affected_table'
  , 'Create NonClustered Index IX_' + t.name + '_' 
   + CAST(ddmid.index_handle AS VARCHAR(10))
   + ' On ' + ddmid.STATEMENT 
   + ' (' + IsNull(ddmid.equality_columns,'') 
   + CASE 
     WHEN ddmid.equality_columns IS NOT NULL 
          AND ddmid.inequality_columns IS NOT NULL
     THEN ',' 
     ELSE '' 
     END 
   + ISNULL(ddmid.inequality_columns, '')
   + ')' 
   + ISNULL(' Include (' + ddmid.included_columns + ');', ';') 
  AS sql_statement
  , ddmigs.user_seeks
  , ddmigs.user_scans
  , CAST((ddmigs.user_seeks + ddmigs.user_scans) 
    * ddmigs.avg_user_impact AS INT) AS 'est_impact'
  , ddmigs.last_user_seek
FROM 
  sys.dm_db_missing_index_groups AS ddmig
  INNER JOIN sys.dm_db_missing_index_group_stats AS ddmigs
    ON ddmigs.group_handle = ddmig.index_group_handle
  INNER JOIN sys.dm_db_missing_index_details AS ddmid 
    ON ddmig.index_handle = ddmid.index_handle
  INNER Join sys.tables AS t
    ON ddmid.OBJECT_ID = t.OBJECT_ID
WHERE 
  ddmid.database_id = DB_ID()
  AND CAST((ddmigs.user_seeks + ddmigs.user_scans) 
  * ddmigs.avg_user_impact AS INT) > 100
ORDER BY 
  CAST((ddmigs.user_seeks + ddmigs.user_scans) 
  * ddmigs.avg_user_impact AS INT) DESC;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Perhaps try "DESC" to order a different way?

This worked in another similar SO question... Why does SQL Server 2005 Dynamic Management View report a missing index when it is not?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...