i am attempting to run a subquery in a table:
SELECT t1.*, t2.* FROM t1
LEFT JOIN (SELECT * FROM table2 GROUP BY col1) AS t2 on t1.col1 = t2.col1
WHERE ...
My main question is, since that subquery called on it's own would pull the entire time, does it also pull the entire time while it's in a subquery, even though the WHERE condition on the parent query is only pulling just a few rows of the actual database?
I suppose I could put the where query inside the subquery, but its a pretty complex where query that involves other tables.
Best Answer
It shouldn't. It depends on what the system can simplify the query to.
You can demonstrate this very easily by considering the plan for queries such as:
The two should be identical.