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

后端 未结 5 2260
一整个雨季
一整个雨季 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:26

    Indexing a column doesn't help make the sort faster.

    If you want to make your query a lot faster, then reverse the order of your tables. Specifically, list table country first in your joined tables.

    The reason why this helps is that the where clause can filter rows from the first table instead of having to make all those joins, then filtering the rows.

提交回复
热议问题