3 ms·
Ironically, I have seen mysql installs up to at least 2012 produce faster results for multiple round trips than trying to get them to do the same thing using a
by mst 5y ago
Ironically, I have seen mysql installs up to at least 2012 produce faster results for multiple round trips than trying to get them to do the same thing using a JOIN.
Certainly I've seen code where
SELECT x.*, y.* FROM x LEFT JOIN y ON y.x_id = x.id
was actually slower than
SELECT x.* FROM x
then collecting the x.id values on the client side and running
SELECT y.* FROM y WHERE y.x_id IN (<list of x.id values>)
then putting the two sets of results together with a for loop.
(and all the y rows were per-x, this isn't about getting fewer results, just about query planning fun and mysql being -extremely- good at selecting things by a specific unique key but less so at anything even slightly more complicated - in some cases using a semantically pointless subselect in FROM to force the initial results to be materialised as a temp table worked out rather well too)
So far as I'm aware this has long since ceased to be an issue, but the world of performance optimisation can be a fun place sometimes.