Why is my SQL Server ORDER BY slow despite the ordered column being indexed?

后端 未结 5 2245
一整个雨季
一整个雨季 2020-12-29 06:13

I have an SQL query (generated by LINQ to Entities) which is roughly like the following:

SELECT * FROM [mydb].[dbo].[employees]
JOIN [mydb].[dbo].[industry]
         


        
5条回答
  •  旧时难觅i
    2020-12-29 06:45

    What order are the fields in the clustered index included in? You'll want to put the startDateTime field first in order for the ORDER BY to match it, or in this case (countryId, startDateTime) up front in that order since you want to select a single countryId (indirectly, via countryName) and then order by startDateTime.

提交回复
热议问题