我试图理解为什么这会查询键查找,即使我添加了我在索引中选择的所有列?
这是查询
SELECT TOP 1
ART.Id,
ART.Title,
ART.InitialTitle,
ART.Summary,
ART.IsCategoryFirst,
ART.RootCategoryId,
CAT.Name,
ART.OldFacebookCommentsUrl,
ICO.CssClass,
ART.TopicName,
ART.MainArticlePhoto,
ART.FrontPagePhoto,
ART.PublishDate
FROM Articles ART WITH (NOLOCK)
INNER JOIN Categories CAT WITH (NOLOCK) ON CAT.Id = ART.RootCategoryId
LEFT JOIN ArticleIcons ICO WITH (NOLOCK) ON ICO.Id = ART.IconId
WHERE ART.RootCategoryId = 3
AND ART.PublishDate < GETDATE()
AND ART.Active = 1
AND IsCategoryFirst = 1
这是应该涵盖的索引
CREATE NONCLUSTERED INDEX [SmallArticleResponse] ON [dbo].[Articles]
(
[RootCategoryId] ASC,
[Active] ASC,
[PublishDate] DESC,
[Coefficient] DESC
)
INCLUDE ( [Id],
[Title],
[InitialTitle],
[OldFacebookCommentsUrl],
[Summary],
[IconId],
[TopicName],
[FrontPagePhoto],
[MainArticlePhoto],
[FacebookPhoto],
[IsCategoryFirst]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
答案 0 :(得分:1)
因为IsCategoryFirst列不在密钥中,所以很有可能。和/或因为IsCategoryFirst上有一个单独的(单列?)索引而且它正在使用它。