Is NATURAL (JOIN) considered harmful in production environment?

后端 未结 6 996
野性不改
野性不改 2020-12-03 21:39

I am reading about NATURAL shorthand form for SQL joins and I see some traps:

  • it just takes automatically all same named column-pairs (use USI
6条回答
  •  渐次进展
    2020-12-03 22:24

    NATURAL JOIN syntax is anti-pattern:

    • The purpose of the query is less obvious;
      • the columns used by the application is not clear
      • the columns used can change "unexpectedly"
    • The syntax goes against the modularity rule, about using strict typing whenever possible. Explicit is almost universally better.

    Because of this, I don't recommend the syntax in any environment.
    I also don't recommend mixing syntax (IE: using both NATURAL JOIN and explicit INNER/OUTER JOIN syntax) - keep a consistent codebase format.

提交回复
热议问题