On Aug 18, 2009, at 5:26 PM, yaconsult wrote:
>
> My question is if it makes a difference to use parentheses when not
> logically required, as in the following example where the only  
> logical used
> is "and":
>
>            select * from log
>            where
>              (response >= 200 and response < 300)
>              and
>              (port >= 8444 and port <= 8459)
>
> Is there any difference in execution or performance if the  
> parentheses are
> present or not?  I'm guessing not, but would like confirmation.
>
>            select * from log
>            where
>              response >= 200
>              and response < 300
>              and port >= 8444
>              and port <= 8459
>

No.  Both queries are identical.  You can see this by prefixing them  
both with EXPLAIN and looking at the content of the generated prepared  
statement, and observing that the prepared statements are identical.

Using "x BETWEEN y AND z" instead of "x>=y AND x<=z" is unlikely to  
make any measurable performance difference in the case where x is a  
simple column value.  If x is an expensive subquery of some kind, it  
could make a difference since with BETWEEN x is only evaluated once,  
whereas it would be evaluated twice for "x>=y AND x<=z".  Other than  
the number of times that x is evaluated, there is no difference in  
BETWEEN and "x>=y AND x<=z".  If an index is used to evaluate the x  
expression then the two forms really are completely identical.

D. Richard Hipp
d...@hwaci.com



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to