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

前端 未结 7 1773
我在风中等你
我在风中等你 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:09

    In my mind the FROM clause is where I decide what columns I need in the rows for my SELECT clause to work on. It is where a business rule is expressed that will bring onto the same row, values needed in calculations. The business rule can be customers who have invoices, resulting in rows of invoices including the customer responsible. It could also be venues in the same postcode as clients, resulting in a list of venues and clients that are close together.

    It is where I work out the centricity of the rows in my result set. After all, we are simply shown the metaphor of a list in RDBMSs, each list having a topic (the entity) and each row being an instance of the entity. If the row centricity is understood, the entity of the result set is understood.

    The WHERE clause, which conceptually executes after the rows are defined in the from clause, culls rows not required (or includes rows that are required) for the SELECT clause to work on.

    Because join logic can be expressed in both the FROM clause and the WHERE clause, and because the clauses exist to divide and conquer complex logic, I choose to put join logic that involves values in columns in the FROM clause because that is essentially expressing a business rule that is supported by matching values in columns.

    i.e. I won't write a WHERE clause like this:

     WHERE Column1 = Column2
    

    I will put that in the FROM clause like this:

     ON Column1 = Column2
    

    Likewise, if a column is to be compared to external values (values that may or may not be in a column) such as comparing a postcode to a specific postcode, I will put that in the WHERE clause because I am essentially saying I only want rows like this.

    i.e. I won't write a FROM clause like this:

     ON PostCode = '1234'
    

    I will put that in the WHERE clause like this:

     WHERE PostCode = '1234'
    

提交回复
热议问题