索引查询未充分优化

时间:2017-09-29 14:58:15

标签: sql sql-server

我正在尝试优化以下查询,并且只能进行10秒的筹码。我试图在连接中涉及的外键表列上应用非聚簇索引。 有人能让我知道我能做些什么来加快查询速度吗?

select
    c.companyId, 
    c.companyName, 
    c.city, 
    cst.companyStatusTypeName,
    ct.companyTypeName,
    sc.simpleIndustryDescription,
    c.officeFaxValue, 
    c.officePhoneValue, 
    c.streetAddress,
    c.streetAddress2, 
    c.yearFounded,
    c.zipCode,
    c.webpage,
    rep.templateTypeName, 
    rcg.isoCountry2,
    rs.abbreviation
from ciqCompany c
    inner join ciqCompanyStatusType cst on cst.companystatustypeid = c.companystatustypeid
    inner join ciqCompanyType ct on ct.companyTypeId = c.companyTypeId
    inner join refReportingTemplateType rep on rep.templateTypeId = c.reportingtemplateTypeId
    inner join refCountryGeo rcg on c.countryId = rcg.countryId
    inner join refState rs on rs.stateId = c.stateId
    inner join ciqSimpleIndustry sc on sc.simpleIndustryId = c.simpleIndustryId

执行计划

enter image description here

表格定义

enter image description here

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

查看执行计划,我发现密钥查找占用的时间最多 尝试使用该查询中的所有列创建索引 或者尝试在索引中使用包含的列。

一些有用的阅读:https://www.red-gate.com/simple-talk/sql/learn-sql-server/using-covering-indexes-to-improve-query-performance/