Database Tuning Advisor建议创建现有索引

时间:2009-07-11 14:15:33

标签: sql-server sql-server-2005 indexing

当我运行SQL Server 2005数据库调优顾问时,它建议创建索引,但它会建议索引已经有索引的列。为什么它建议再次创建相同的索引?

这是我的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;

4 个答案:

答案 0 :(得分:7)

也许尝试“DESC”以不同的方式订购?

这在另一个类似的SO问题中起作用...... Why does SQL Server 2005 Dynamic Management View report a missing index when it is not?

答案 1 :(得分:0)

您可能需要运行查询并建议已存在的索引。

SELECT * FROM table WITH INDEX(IX_INDEX_SHOULD_BE_USED) WHERE x = y

可能没有认为SQL Server中的索引有用。运行建议需要索引的查询,并在SQL Server中查看执行路径,然后构建所需的其他索引。

答案 2 :(得分:0)

请列出完整的索引缺失警告消息?一般来说,它要求在表上创建索引但是只返回某些字段,而不是表上的索引,默认情况下将返回所有字段。

答案 3 :(得分:0)

继续编写当前索引结构的详细信息,然后将其与DTA的建议进行比较。

我怀疑你会发现结果存在结构差异。