为什么这个查询键查找?
Why does this query a key lookup?
我想了解为什么这个查询是键查找,即使我添加了我在索引中选择的所有列?
这是查询
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
这是它的执行计划和信息。
因为 IsCategoryFirst 列很可能不在键中。 And/or 因为 IsCategoryFirst 上有一个单独的(单列?)索引,它正在使用它。
我想了解为什么这个查询是键查找,即使我添加了我在索引中选择的所有列?
这是查询
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
这是它的执行计划和信息。
因为 IsCategoryFirst 列很可能不在键中。 And/or 因为 IsCategoryFirst 上有一个单独的(单列?)索引,它正在使用它。