我正在对一个运行很长时间的进程进行故障排除,这个选择语句运行了 30 多分钟,当我注释掉它的各个部分时,它运行得非常快。我在似乎导致问题的表旁边放了一个 *,带有两个 ** 的表在 Empid 和 ChangeDate 上有一个聚集索引(这些列不相邻)不确定这是否重要,也没有这些表有 3000 多行。我希望需要做一些简单的调整。我应该在源表中查看什么?任何建议,将不胜感激。我用谷歌搜索了“单个语句中的多个连接”,但没有运气。出于故障排除的目的,我将 with(nolock) 放入。
select
je.EmpID,
max(med.ChangeDate) as Max_Medical_ChangeDate,
max(den.ChangeDate) as Max_Dental_ChangeDate,
max(k.ChangeDate) as Max_401K_ChangeDate,
max(ltd.ChangeDate) as Max_LTD_ChangeDate,
max(std.ChangeDate) as Max_STD_ChangeDate,
max(life.ChangeDate) as Max_Life_ChangeDate,
max(sal.ChangeDate) as Max_Salary_ChangeDate,
max(ltdexe.ChangeDate) as Max_LTDEXE_ChangeDate
max(accid.ChangeDate) as Max_Accid_ChangeDate,
max(cancr.ChangeDate) as Max_Cancr_ChangeDate,
max(hosp.ChangeDate) as Max_Hosp_ChangeDate
from Judge_Emp je WITH(NOLOCK)
left join Medical med on je.EmpID = med.EmpID
left join Dental den on med.EmpID = den.EmpID
left join R401K k on den.EmpID = k.EmpID
left join STDIns std on k.EmpID = std.EmpID
left join LTDIns ltd on std.EmpID = ltd.EmpID
* left join LTDEXEIns ltdexe on ltd.EmpID = ltdexe.EmpID
** left join LifeIns life on ltdexe.EmpID = life.EmpID
* left join Salary sal on life.EmpID = sal.EmpID
left join AF_Accid accid on accid.EmpID=sal.EmpID
left join AF_Cancr cancr on cancr.EmpID=accid.EmpID
left join AF_Hosp hosp on hosp.EmpID=cancr.EmpID
group by je.EmpID
谢谢