I have 2 Sql Server instances, and one query:
SELECT
[DetailDescription],
[SubTotal]
FROM [dbo].[CRR] WITH (INDEX (IX_CORM_CORMId))
WHERE CORM_CORMId >= 5933168 AND CORM_CORMId <= 5955843
This leads to 2 query execution plans:
One with Sort gets 301740 rows and takes 48s, other gets 286743 rows without Sort takes 5s. One db is a bit outdated copy of other. Order of rows number in table is 98 419 368.
My questions are:
- I don't understand why Sort is needed for Nested Loops join? I've tried to disable it with 'OPTION (QUERYTRACEON 2340)'. The option makes no difference at all.
- Why is such big differnce in execution time? How to avoid this?
I use Sql Server 2014.
Update:
With STATISTICS IO:
Table 'CynergyResidualRecord'. Scan count 1, logical reads 1226357, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0. Table 'Worktable'. Scan count 0, logical reads 0, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.