BETWEEN clause versus <= AND >=

前端 未结 8 1331
無奈伤痛
無奈伤痛 2020-12-14 05:54

Is there a performance difference between using a BETWEEN clause or using <= AND >= comparisons?

i.e. these two queries:

SELECT *  
  FROM table           


        
8条回答
  •  死守一世寂寞
    2020-12-14 06:53

    It may be worth considering the SQL standard for this (although this might not correspond to all implementations, even if it should):

    Format
    
     ::=
       [ NOT ] BETWEEN
         AND 
    
    Syntax Rules
    
    [...]
    
    6) "X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z".
    

    Having said so, there is no difference in behaviour, although for complex X, there may be a difference in parsing time, as mentioned by Benoit here

    Found in http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt

提交回复
热议问题