Re: IN or OR? whats the diff?

2006-08-01 Thread Visolve DB Team

Hi Michael,

While using IN operator

expr IN (value,...)

Returns 1 if expr is equal to any of the values in the IN list, else returns 
0.


If all values are constants, they are evaluated according to the type of 
expr and sorted. The search for the item then is done using a binary search. 
This means IN is very quick if the IN value list consists entirely of 
constants.




Thanks,

VisolveDB Team

- Original Message - 
From: Ratheesh K J [EMAIL PROTECTED]

To: mysql@lists.mysql.com
Sent: Tuesday, August 01, 2006 10:22 AM
Subject: IN or OR? whats the diff?


Hello all,

Just wanted to know if using IN in the where clause is better than OR in 
terms of performance.


that is :

Are these both same in terms of performance

SELECT * FROM TABLE
   WHERE  ( COLUMN = 1 OR COLUMN = 2 );

SELECT * FROM TABLE
   WHERE COLUMN IN ( 1, 2 );

thanks,

Ratheesh Bhat K J


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



IN or OR? whats the diff?

2006-07-31 Thread Ratheesh K J
Hello all,

Just wanted to know if using IN in the where clause is better than OR in terms 
of performance.

that is :

Are these both same in terms of performance

SELECT * FROM TABLE
WHERE  ( COLUMN = 1 OR COLUMN = 2 );

SELECT * FROM TABLE
WHERE COLUMN IN ( 1, 2 );

thanks,

Ratheesh Bhat K J


Re: IN or OR? whats the diff?

2006-07-31 Thread Michael Stassen

Ratheesh K J wrote:

Hello all,

Just wanted to know if using IN in the where clause is better than OR in terms 
of performance.

that is :

Are these both same in terms of performance

SELECT * FROM TABLE
WHERE  ( COLUMN = 1 OR COLUMN = 2 );

SELECT * FROM TABLE
WHERE COLUMN IN ( 1, 2 );

thanks,

Ratheesh Bhat K J


They are the same.

You can verify that mysql treats them the same by putting EXPLAIN in front of 
each.  See the manual for details 
http://dev.mysql.com/doc/refman/4.1/en/explain.html.


Michael

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]