Can you apply LIMIT on MySQL before LEFT JOIN another?
For example:
SELECT * FROM table_1 LIMIT 5
LEFT JOIN table_2 AS table_1.id = table_2.id
WHERE 1
Otherwise the engine takes all of table_1 b开发者_如何学JAVAefore applying the join, then limiting which can slow the query down massively (with massive tables).
You can do it by joining on a subquery instead of an actual table. Something like this should work:
SELECT * FROM
(SELECT * FROM table_1 LIMIT 5) as subq
LEFT JOIN table_2 ON subq.id = table_2.id WHERE 1
精彩评论