Platform - SQL Server 2008 R2 This is part of a complex stored procedure that took more than 5 minutes to complete, and I was asked to help troubleshoot
;WITH FilteredOrders AS
(
),
PagedOrders AS
(
SELECT * FROM
(
SELECT ROW_NUMBER() OVER ( order by OrderNumber asc ) AS Row,
FROM FilteredOrders
) AS NumberedOrders
WHERE NumberedOrders.Row BETWEEN 1 AND 500
)
SELECT * FROM PagedOrders
I removed the subquery in the second CTE and recommended this
;WITH FilteredOrders AS
(
)
SELECT ROW_NUMBER() OVER ( order by OrderNumber asc ) AS Row,
INTO
FROM FilteredOrders
SELECT *
FROM
WHERE
Now the request is executed after 2 seconds. Although I do not want to admit this, the fact is that I do not quite understand the massive increase in productivity that the second request gave. Why do I see such a big difference?
source
share