sql server ,查询数据很快,但是加上 order by后,很慢很慢。不加“order by CreatedTime DESC”时,查询是0.6S,加上后查询是19S。(关联表code,有几百万条数据,主表只有二十多条数据 )请指教怎么优化这条sql?加了索引也不起任何作用。sql如下:
select LinesNo, PointNo, EmployeeNo, sioos.TraceCodeChar, BadContent, sioos.CreatedTime, svcc.Color, silb.Name,
case when State=0 then 'NG' when State=1 then 'OK' end as State,
case when State=1 then '否'
when State=0 and CheckState = 2 then '否'
when State=0 and CheckState = 0 then '否'
when State=0 and CheckState = 1 then '是'
end as IsOverKill
from station as sioos
left join code as svcc on sioos.TraceCodeChar = svcc.QrCodeChar
left join trace as sitr on sioos.TraceCodeChar = sitr.TraceCodeChar and sitr.StationNo = 'OQC'
left join linebody as silb on sitr.LineBodyNo = silb.LineBodyNo
where sioos.CreatedTime BETWEEN '2022/8/8 0:00:00' AND '2022/8/12 0:00:00'
order by sioos.CreatedTime DESC
sql加order by后变慢
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-