Sql server 通过索引扫描选择包含索引的查询

Sql server 通过索引扫描选择包含索引的查询,sql-server,Sql Server,我有一个表,其中大约有31列,大约有1000万行 给出以下查询 Select top (1000) [CallType], [AttributedCallType], [Extension], [CallDurationBacking], [AnswerTimeBacking], [AccountCode], [AuthorisationCode], [RequestedRoute], [SelectedRoute], [SelectedTrunk], [ConditionCode], [Cal

我有一个表,其中大约有31列,大约有1000万行

给出以下查询

Select top (1000)
[CallType],
[AttributedCallType],
[Extension],
[CallDurationBacking],
[AnswerTimeBacking],
[AccountCode],
[AuthorisationCode],
[RequestedRoute],
[SelectedRoute],
[SelectedTrunk],
[ConditionCode],
[CalibratedTime],
[StoredDialledNumber],
[AttributedSiteNumber],
[AttributedExtension],
[Cost],
[AttributedCountry],
[PlanName],
[ClassificationName]
from CallRecords 
where ClientId = 15 and 
      Reported = 0 and 
      ResultCodeId > 1 
order by id
以及以下涵盖指数

CREATE NONCLUSTERED INDEX [_dta_index_CallRecords_5_565577053__K2_K37_K31_1_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_25_26_28_32_33_34_35_36_38_39] ON [dbo].[CallRecords]
(
    [ClientId] ASC,
    [Reported] ASC,
    [ResultCodeId] ASC
)
INCLUDE (   [Id],
    [CallType],
    [AttributedCallType],
    [Extension],
    [CallDurationBacking],
    [AnswerTimeBacking],
    [AccountCode],
    [AuthorisationCode],
    [RequestedRoute],
    [SelectedRoute],
    [SelectedTrunk],
    [ConditionCode],
    [CalibratedTime],
    [StoredDialledNumber],
    [AttributedSiteNumber],
    [AttributedExtension],
    [Cost],
    [AttributedCountry],
    [PlanName],
    [ClassificationName]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
为什么执行计划要使用聚集索引扫描

我原以为SQL server会选择seek

如何强制使用索引查找/键查找


您可能会得到这样的结果,因为
按ID排序。
尝试按id删除订单
。除此之外,排序时会得到非关系结果。将订购委托给您的客户应用程序

您可以使用以下提示强制选择使用索引:

from CallRecords WITH (INDEX(_dta_index_CallRecords_5_565577053__K2_K37_K31_1_3_4_5.....)) 

您在包含列列表中遗漏了“[AttributedCallType]”列?将该列添加到索引中,它仍在扫描确保您的索引已启用并受信任:查询:从sys.check\u约束中选择*@sdrzymala在系统中不返回任何内容。请检查约束,不要假设计划是错误的。如果条件不是很有选择性或者表统计信息过时,查询优化器将求助于扫描。尝试使用索引提示执行查询,并比较两个查询的执行计划。此查询返回多少行?排序肯定是造成问题的原因