选择带覆盖​​索引的查询求助于索引扫描

时间:2015-01-20 06:51:33

标签: sql-server

我的桌子里面有大约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服务器会选择一个搜索

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

enter image description here

1 个答案:

答案 0 :(得分:0)

由于Ordering by ID,您可能会得到这样的结果。 尝试删除order by id。除此之外,您还可以在订购时获得非关系结果。委托您的客户端应用程序订购。

您可以使用HINTS强制选择使用索引,如:

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