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

后端 未结 5 2246
一整个雨季
一整个雨季 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条回答
  •  再見小時候
    2020-12-29 06:39

    You should try below code also

    Insert the records into temporary table Without using the Order by clause

    SELECT * into #temp FROM [mydb].[dbo].[employees]
    JOIN [mydb].[dbo].[industry]
      ON jobs.industryId = industry.id
    JOIN [mydb].[dbo].[state]
      ON jobs.stateId = state.id
    JOIN [mydb].[dbo].[positionType]
      ON jobs.positionTypeId = positionType.id
    JOIN [mydb].[dbo].[payPer]
      ON jobs.salaryPerId = payPer.id
    JOIN [mydb].[dbo].[country]
      ON jobs.countryId = country.id
    WHERE countryName = 'US'
    

    Now run the statement using Order By Clause

    Select * from #temp ORDER BY startDatetime
    

提交回复
热议问题