Assume i have a query like:
(SELECT a FROM t1)UNION ALL(SELECT a FROM t2)ORDER BY a LIMIT 10;
Will MySQL be so clever and execute it in the same way (and time) as:
(SELECT a FROM t1 LIMIT 10)UNION ALL(SELECT a FROM t2 LIMIT 10)ORDER BY a LIMIT 10;
In other words:
will the limit clause from the outer UNION statement be applied to the inner SELECT queries automatically? Otherwise the inner queries might return a lot (millions) of rows, although only the first 10 rows have a chance to appear in the final result.