我正在尝试微调以下查询以删除表假脱机。它有1000万条记录。我在下面给出了我的执行计划。
查询:
SELECT
ATT.EMPCODE
,ATT.EMPNAME
,ATT.FROMDATE
,ISNULL(EMPPER.FIRST_NAME.'')
,ISNULL(EMPPER.MIDDLE_NAME.'')
,ISNULL(EMPPER.LAST_NAME.'')
,DET.[SUPERVISOR]
,ATT.[DEPARTMENT]
,SHI. [SHIFT TIME]
,DET.IN_TIME
,LAT.UT_TIME
,SHI.SHIFT_NAME
,PRO.[ACTUAL_TIME]
,LAT.[LATE]
FROM
Attendance ATT
INNER JOIN [172.241.2.147].HIST_DATT.DBO.EMPLOYEE EMP
ON ATT.N_ID=ATT.EMPID
LEFT JOIN
(SELECT *
FROM [172.241.2.147].HIST_DATT.DBO.VIEW_ATTENDANCE_DETAILS
WHERE TODATE BETWEEN 'NOV 01 2016' AND 'NOV 15 2016'
) DET
ON ATT.N_ID=DET.N_ID AND ATT.FROMDATE=DET.TODATE
LEFT JOIN
(SELECT *
FROM [172.241.2.147].HIST_DATT.DBO.VIEW_EMPLOYEE_SHIFT
WHERE TODATE BETWEEN 'NOV 01 2016' AND 'NOV 15 2016'
) SHI
ON ATT.N_ID=SHI.N_ID
AND ATT.FROMDATE=SHI.TODATE
LEFT JOIN
(SELECT *
FROM [172.241.2.147].HIST_DATT.DBO.PROCESSDETAILS
WHERE TODATE BETWEEN 'NOV 01 2016' AND 'NOV 15 2016'
) PRO
ON ATT.N_ID = D.N_ID
AND ATT.FROMDATE=D.TODATE
LEFT JOIN
(SELECT *
FROM [172.241.2.147].HIST_DATT.DBO.LATETIME
WHERE TODATE BETWEEN 'NOV 01 2016' AND 'NOV 15 2016'
) LAT
ON ATT.N_ID=E.N_ID AND ATT.FROMDATE=E.FROMDATE
LEFT OUTER JOIN [172.241.2.147].HIST_DATT.DBO.VIEW_LEAVE_STATUS LEV
ON LEV.N_ID=ATT.N_ID AND ATT.FROMDATE=LEV.FROMDATE
LEFT OUTER JOIN [172.241.2.147].HIST_DATT.DBO.REPORTS RPT
ON ATT.N_ID=R.N_ID
LEFT JOIN [172.241.2.147].HIST_DATT.DBO.EMPLOYEE_DETAIL EDTS H
ON R.RM_ID=H.N_ID
LEFT JOIN [172.241.2.147].HIST_DATT.DBO.EMPLOYEE_PERSONAL EMPPER Z ON ATT.N_ID=Z.N_ID AND ATT.FROMDATE =Z.FROMDATE
WHERE 1=1
ORDER BY
ATT.N_ID
,ATT.FROMDATE
OPTION (QUERYTRACEON 8690)
执行计划: