为什么Sql Server建议在已存在的情况下创建索引?

时间:2010-03-15 18:31:57

标签: sql-server-2008 indexing query-analyzer

我对我们的一个表运行了一个非常基本的查询,我注意到执行计划查询处理器建议我们在列上创建一个索引

查询

SELECT SUM(DATALENGTH(Data))
FROM Item
WHERE Namespace = 'http://some_url/some_namespace/'

运行后,我收到以下消息

// The Query Processor estimates that implementing the following index could improve the query cost by 96.7211%.
CREATE NONCLUSTERED INDEX [<Name of Missing Index, sysname,>]
ON [dbo].[Item] ([Namespace])

我的问题是我已经在该列上有这样的索引:

CREATE NONCLUSTERED INDEX [IX_ItemNamespace] ON [dbo].[Item] 
(
    [Namespace] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

为什么Sql Server建议我在已经存在时创建这样的索引?

1 个答案:

答案 0 :(得分:0)

索引列和排序顺序有所不同......

上一页SO 1SO 2

然而,对于这个简单的尝试,尝试添加INCLUDE clause以覆盖它。

CREATE NONCLUSTERED INDEX [IX_ItemNamespace] ON [dbo].[Item] ([Namespace]) INCLUDE ([Data])