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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-admin by date

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