关于为什么向此查询添加排序的任何想法比没有 order by 的返回速度要快得多?我希望相反,那么什么会导致这种情况发生?
SELECT TOP (500) r.cID,r.aField,a.Description
FROM dbo.tblR r
inner join dbo.tblA a on r.aID = a.ID
left join dbo.tblX x on x.cID = r.cID
WHERE (ISNULL(x.anotherField,'') <> r.anotherField or x.field3 is null)
and (r.ID=(select max(ID) from tblR where cID = r.cID and
ISNULL(aField,'') <> ''))
and r.cID in (select ID from tblC)
ORDER BY r.cID ASC -- when I comment this line out it runs much slower
Run Code Online (Sandbox Code Playgroud)
执行计划没有多大帮助。