Sql-server – SQL Server order of execution and query plan

execution-planorder-bysql server

I am aware that the order of execution of a query in SQL Server is (excluding TOP, etc):

FROM, JOIN
WHERE
GROUP BY
HAVING
SELECT
ORDER BY

However, I cannot understand how in the query plan the sort (which corresponds to the order by) is done before the select (given that they are read from right to left) if the order of execution is per above => SELECT before ORDER BY.

An simple example is as follows:

enter image description here

I excluded a JOIN on purpose as to avoid the case of having that sort corresponding to the JOIN.

Best Answer

The order of execution you have quoted is a version of the Logical Processing Order of the SELECT statement - as the documentation states. The actual physical execution of the statement is determined by the query processor and the order may vary from this list. Also the SELECT node in the plan isn't an execution plan operator at all. This root node just labels the type of statement.

I.e., the DBMS is free to do it any way it wants, as long at it returns the same result as if it had used the logical execution order.