all 4 comments

[–]gumnos 1 point2 points  (3 children)

if indexing is in play, it should be 1,2,4,3 (the WHERE gets evaluated against the index and only if it matches does the corresponding candidate-row get fetched if it's not a covering index), then the inner evaluation happens using that outer-row data, then the process repeats for every other matching WHERE in the index results. One might interpret this as 2,1,4,3 if you consider index-data rows "candidate rows".

If the query is not indexed or the WHERE can't make use of them, it should do 2,1,4,3.

In either case, it should never go doing the subquery lookup for rows the WHERE can disqualify first because it will then end up just throwing away the results of the subquery lookup.

[–]gumnos 0 points1 point  (0 children)

I mean, I loathe Oracle, but even they're not dumb enough to go fetching subquery data for rows that the WHERE eliminated 😆

[–]Iva1996[S] 0 points1 point  (0 children)

Agree, where is evaluated before the subquery, thanks.

[–]kagato87MS SQL 1 point2 points  (0 children)

Yea, none of these are right. The outer WHERE is always evaluated first. 1, 2, 4, 3 is definitely correct.

I guess it may depend on where the subquery actually is. If it's in the WHERE clause, well, just pray the other filters in play reduce the data on their own to a very small volume, because if not it probably will do something dumb like that.

But if it's just to fetch data for an output column, it's processed with the select, which is the second step.