Why isn't SQL ANSI-92 standard better adopted over ANSI-89?

后端 未结 16 1760
日久生厌
日久生厌 2020-11-22 10:59

At every company I have worked at, I have found that people are still writing their SQL queries in the ANSI-89 standard:

select a.id, b.id, b.address_1
from          


        
16条回答
  •  花落未央
    2020-11-22 11:08

    1) Standard way to write OUTER JOIN, versus *= or (+)=

    2) NATURAL JOIN

    3) Depend in the database engine, ANSI-92 trends to be more optimal.

    4) Manual optimization :

    Let's say that we have the next syntax (ANSI-89):

    (1)select * from TABLE_OFFICES to,BIG_TABLE_USERS btu
    where to.iduser=tbu.iduser and to.idoffice=1
    

    It could be written as:

    (2)select * from TABLE_OFFICES to
    inner join BIG_TABLE_USERS btu on to.iduser=tbu.iduser
    where to.idoffice=1
    

    But also as :

    (3)select * from TABLE_OFFICES to
    inner join BIG_TABLE_USERS btu on to.iduser=tbu.iduser and to.idoffice=1
    

    All of them (1),(2),(3) return the same result, however they are optimized differently, it depends in the database engine but most of them do :

    • (1) its up to the database engine decide the optimization.
    • (2) it joins both tables then do the filter per office.
    • (3) it filters the BIG_TABLE_USERS using the idoffice then join both tables.

    5) Longer queries are less messy.

提交回复
热议问题