I have an old SQL Server 2014 Express which I wanted to upgrade to SQL Server 2017 Enterprise.
I've installed it on the same machine and moved one of the databases (through a backup -> restore).
Then I ran this query on both servers:
SELECT T1.FileName, T2.BatchId
FROM Table1 AS T1
JOIN Table2 AS T2 ON T1.BatchGuid = T2.Guid
ORDER BY T2.BatchId, T1.FileName
Unexpectedly, the old server returned ~1 200 000 rows in 8-12 seconds and the new server in ~90 seconds.
I've tried to go through the same steps on my laptop and it worked perfectly (12 seconds).
Then I've tried to run the query without order by and both servers returned same 1 200 000 rows in 4 seconds.
What could be the reason of such a slow performance with an order by clause?