I would use explicit JOIN
syntax, but reduce the noise:
SELECT * -- really? *all* columns?
FROM t1
JOIN t2 ON t1.id = t2.col
JOIN t3 ON t1.id = t3.col
JOIN t4 ON t1.id = t4.col
-- ... more tables
WHERE ...
Place conditions linking two tables in the JOIN
clause.
Place other conditions in the WHERE
clause.
INNER
is a noise word. Parentheses are not required around join conditions.
To answer your question:
Are implicit joins as efficient as explicit joins in Postgres?
Yes. There is no difference in efficiency. Postgres is typically free to rearrange the order of join operations and apply JOIN
and WHERE
conditions in any order it sees fit. The manual:
Explicit inner join syntax (INNER JOIN
, CROSS JOIN
, or unadorned JOIN
)
is semantically the same as listing the input relations in FROM
, so it
does not constrain the join order.
There are special considerations for OUTER
joins that do not apply here.
And be aware of some limitations:
Since you mentioned:
+many more tables
... you probably need to consider how to optimize planning time and query execution time by carefully choosing the order of explicit joins and placement of conditions. You may want to use subqueries, CTEs, mix explicit and implicit joins, use parentheses among groups of FROM
clause items or play with configuration settings to get best results.
Related: