Which clause performs first in a SELECT statement?
I have a doubt in select query on this basis.
consider the below example
SELECT * 
FROM #temp A 
INNER JOIN #temp B ON A.id = B.id 
INNER JOIN #temp C ON B.id = C.id 
WHERE A.Name = 'Acb' AND B.Name = C.Name
Whether, First it checks
WHEREclause and then performsINNER JOINFirst
JOINand then checks condition?
If it first performs JOIN and then WHERE condition; how can it perform more where conditions for different JOINs?
                        
The conceptual order of query processing is:
But this is just a conceptual order. In fact the engine may decide to rearrange clauses. Here is proof. Let's make 2 tables with 1000000 rows each:
Now run 2 queries:
Notice that the first query will filter most rows out in the
joincondition, but the second query filters in thewherecondition. Look at the produced plans:This means that in the first query optimized, the engine decided first to evaluate the
joincondition to filter out rows. In the second query, it evaluated thewhereclause first.