Skip site navigation (1) Skip section navigation (2)

Re: WHERE clause OR vs IN

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
Cc: Medi Montaseri <montaseri(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: WHERE clause OR vs IN
Date: 2007-12-13 01:03:15
Message-ID: 29422.1197507795@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-admin
Richard Broersma Jr <rabroersma(at)yahoo(dot)com> writes:
> --- On Wed, 12/12/07, Medi Montaseri <montaseri(at)gmail(dot)com> wrote:
>> based on your report, run time of OR is 0.275 ms and IN is
>> 0.314
>> 
> postgres=# explain analyze select * from tellers where
>> bid in ('1','2');
 
> Two other options are:

> SELECT *
>   FROM Tellers
>  WHERE bin = ANY( '1', '2' );

Note that depending on which PG version you are testing, x IN (a,b,c)
is exactly equivalent to x=a OR x=b OR x=c (older versions), or to
x = ANY(ARRAYa,b,c]) (newer versions).

>     SELECT T.*
>       FROM Tellers AS T
> INNER JOIN ( VALUES ( '1' ), ( '2' ) ) AS B( bin )
>         ON T.bin = B.bin;

I seriously doubt that one's gonna win ...

			regards, tom lane

In response to

Responses

pgsql-admin by date

Next:From: Richard Broersma JrDate: 2007-12-13 01:17:42
Subject: Re: WHERE clause OR vs IN
Previous:From: Richard Broersma JrDate: 2007-12-13 00:37:45
Subject: Re: WHERE clause OR vs IN

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group