Left Join outperforming Inner Join?

后端 未结 6 1971
不思量自难忘°
不思量自难忘° 2021-01-01 19:56

I\'ve been profiling some queries in an application I\'m working on, and I came across a query that was retrieving more rows than necessary, the result set being trimmed dow

6条回答
  •  执念已碎
    2021-01-01 20:23

    LEFT JOIN is returning more rows than INNER JOIN because these 2 are different.
    If LEFT JOIN does not find related entry in the table it is looking for, it will return NULLs for the table.
    But if INNER JOIN does not find related entry, it will not return the whole row at all.

    But to your question, do you have query_cache enabled? Try running the query with

    SELECT SQL_NO_CACHE `contacts`.*, ...
    

    Other than that, I'd populate the tables with more data, ran

    ANALYZE TABLE t1, t2;
    OPTIMIZE TABLE t1, t2;
    

    And see what happens.

提交回复
热议问题