我在select子句和外部apply中测试相关子查询的性能。为什么select子句中的相关子查询的执行效果优于OUTER APPLY
- 选择---
中的相关子查询SELECT
(SELECT TOP 1
L.LineNum
FROM RDR1 L
WHERE T1.Docentry = L.DocEntry
ORDER BY L.Linenum DESC) as LineNum,
T1.Docentry, T1.Docdate, T1.CardCode, *
FROM
ORDR T1
--36 sec--
- 外部申请 -
SELECT
L.LineNum,T1.Docentry,T1.Docdate,T1.CardCode,*
FROM
ORDR T1
OUTER APPLY
(SELECT TOP 1
T2.LineNum
FROM RDR1 T2
WHERE T1.Docentry = T2.DocEntry
ORDER BY T2.Linenum DESC) as L
--42sec--
答案 0 :(得分:0)
您是否查看了查询计划
Select max(T2.LineNum), T1.Docentry, T1.Docdate, T1.CardCode
FROM ORDR T1
join RDR1 t2
on T1.Docentry = T2.DocEntry
group by T1.Docentry, T1.Docdate, T1.CardCode