Lou*_*ise 1 sql optimization sql-server-2005
我需要优化以下查询,有人可以帮忙吗?我知道这是导致问题的不存在部分,因为它正在进行大规模的表扫描,但我是新手,有人可以给出任何建议吗?
select count(*)
from Job j
where company = 'A'
and branch = 'Branch123'
and engineerNumber = '000123'
and ID > 60473
and not exists(
select JobNumber, Company, Branch
from OutboundEvents o
where o.JobNumber = j.JobNumber
and o.branch = j.branch
and o.company = j.company
and o.Formtype = 'CompleteJob')
Run Code Online (Sandbox Code Playgroud)
create index [<indexname>] on [Job] (
[company], [branch], [engineerNumber], [ID]) include ([JobNumber]);
create index [<indexname>] on [OutboundEvents] (
[company], [branch], [JobNumber], [Formtype]);
Run Code Online (Sandbox Code Playgroud)
您优化的查询不是您优化的数据模型.首先阅读设计索引.