I have this query:
;WITH My_CTE AS
(
SELECT
col1,
col2
FROM
My_Table
)
SELECT TOP(10)
col1,
col2
FROM
My_CTE
WHERE
col1 > 10
ORDER BY
col2
Will SQL Server load all records from My_Table
first and then filter out records not satisfying where clause or it will manage to optimize select within CTE ?
Notice that TOP, ORDER BY and WHERE clauses are only in outer query.