Will ANSI JOIN vs. non-ANSI JOIN queries perform differently?

前端 未结 7 1763
我在风中等你
我在风中等你 2020-11-22 02:25

I have my business-logic in ~7000 lines of T-SQL stored procedures, and most of them has next JOIN syntax:

SELECT A.A, B.B, C.C
FROM aaa AS A, bbb AS B, ccc          


        
7条回答
  •  盖世英雄少女心
    2020-11-22 03:18

    ANSI syntax does enforce neither predicate placement in the proper clause (be that ON or WHERE), nor the affinity of the ON clause to adjacent table reference. A developer is free to write a mess like this

    SELECT
       C.FullName,
       C.CustomerCode,
       O.OrderDate,
       O.OrderTotal,
       OD.ExtendedShippingNotes
    FROM
       Customer C
       CROSS JOIN Order O
       INNER JOIN OrderDetail OD
          ON C.CustomerID = O.CustomerID
          AND C.CustomerStatus = 'Preferred'
          AND O.OrderTotal > 1000.0
    WHERE
       O.OrderID = OD.OrderID;
    

    Speaking of query tools who "will generate ANSI-92", I'm commenting here because it generated

    SELECT 1
       FROM DEPARTMENTS C
            JOIN EMPLOYEES A
                 JOIN JOBS B
         ON C.DEPARTMENT_ID = A.DEPARTMENT_ID
         ON A.JOB_ID = B.JOB_ID
    

    The only syntax that escapes conventional "restrict-project-cartesian product" is outer join. This operation is more complicated because it is not associative (both with itself and with normal join). One have to judiciously parenthesize query with outer join, at least. However, it is an exotic operation; if you are using it too often I suggest taking relational database class.

提交回复
热议问题