Subqueries vs joins

前端 未结 14 1892
闹比i
闹比i 2020-11-22 16:10

I refactored a slow section of an application we inherited from another company to use an inner join instead of a subquery like:

WHERE id IN (SELECT id FROM          


        
14条回答
  •  失恋的感觉
    2020-11-22 16:34

    This question is somewhat general, so here's a general answer:

    Basically, queries take longer when MySQL has tons of rows to sort through.

    Do this:

    Run an EXPLAIN on each of the queries (the JOIN'ed one, then the Subqueried one), and post the results here.

    I think seeing the difference in MySQL's interpretation of those queries would be a learning experience for everyone.

提交回复
热议问题