qq_37033096 2022-08-16 16:36 采纳率: 0%
浏览 305

sql加order by后变慢

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

  • 写回答

4条回答 默认 最新

  • .魚肉 2022-08-16 16:42
    关注

    explain的结果是什么

    评论

报告相同问题?

问题事件

  • 修改了问题 8月16日
  • 修改了问题 8月16日
  • 创建了问题 8月16日