Is NATURAL (JOIN) considered harmful in production environment?

后端 未结 6 1005
野性不改
野性不改 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条回答
  •  猫巷女王i
    2020-12-03 22:40

    Do you mean the syntax like this:

    SELECT * 
      FROM t1, t2, t3 ON t1.id = t2.id 
                     AND t2.id = t3.id
    

    Versus this:

             SELECT *  
               FROM t1 
    LEFT OUTER JOIN t2 ON t1.id = t2.id 
                      AND t2.id = t3.id
    

    I prefer the 2nd syntax and also format it differently:

             SELECT *
               FROM T1
    LEFT OUTER JOIN T2 ON T2.id = T1.id
    LEFT OUTER JOIN T3 ON T3.id = T2.id
    

    In this case, it is very clear what tables I am joining and what ON clause I am using to join them. By using that first syntax is just too easy to not put in the proper JOIN and get a huge result set. I do this because I am prone to typos, and this is my insurance against that. Plus, it is visually easier to debug.

提交回复
热议问题