Join vs. sub-query

前端 未结 19 2017
广开言路
广开言路 2020-11-21 05:05

I am an old-school MySQL user and have always preferred JOIN over sub-query. But nowadays everyone uses sub-query, and I hate it; I don\'t know why.

19条回答
  •  野的像风
    2020-11-21 05:28

    I just thinking about the same problem, but I am using subquery in the FROM part. I need connect and query from large tables, the "slave" table have 28 million record but the result is only 128 so small result big data! I am using MAX() function on it.

    First I am using LEFT JOIN because I think that is the correct way, the mysql can optimalize etc. Second time just for testing, I rewrite to sub-select against the JOIN.

    LEFT JOIN runtime: 1.12s SUB-SELECT runtime: 0.06s

    18 times faster the subselect than the join! Just in the chokito adv. The subselect looks terrible but the result ...

提交回复
热议问题