Does the order of tables in a join matter, when LEFT (outer) joins are used?

前端 未结 3 1149
情书的邮戳
情书的邮戳 2020-12-18 01:54

I would like to confirm that the SQL query

SELECT ....
  FROM apples,
       oranges
       LEFT JOIN kiwis ON kiwis.orange_id = oranges.id,
       bananas
          


        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-18 02:25

    The situation is summarized at Controlling the Planner with Explicit JOIN Clauses. Outer joins don't get reordered, inner ones can be. And you can force a particular optimizer order by dropping *join_collapse_limit* before running the query, and just putting things in the order you want them it. That's how you "hint" at the database in this area.

    In general, you want to use EXPLAIN to confirm what order you're getting, and that can sometimes be used to visually confirm that two queries are getting the same plan.

提交回复
热议问题