pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Richard Broersma Jr <rabroersma@yahoo.com>
Cc: Medi Montaseri <montaseri@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: WHERE clause OR vs IN
Date: Wed, 12 Dec 2007 20:03:15 -0500
Message-ID: <29422.1197507795@sss.pgh.pa.us> (raw)
In-Reply-To: <359993.87392.qm@web31808.mail.mud.yahoo.com>
References: <359993.87392.qm@web31808.mail.mud.yahoo.com>

Richard Broersma Jr <rabroersma@yahoo.com> writes:
> --- On Wed, 12/12/07, Medi Montaseri <montaseri@gmail.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



view thread (7+ messages)  latest in thread

Message-ID: <29422.1197507795@sss.pgh.pa.us>
Permalink:  ../29422.1197507795@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29422.1197507795@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rabroersma@yahoo.com, montaseri@gmail.com
  Subject: Re: WHERE clause OR vs IN
  In-Reply-To: <29422.1197507795@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox