pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vinko Vrsalovic <el@vinko.cl>
To: Qingqing Zhou <zhouqq@cs.toronto.edu>
Cc: pgsql-performance@postgresql.org
Subject: Re: slow "IN" clause
Date: Tue, 11 Apr 2006 01:02:28 -0400
Message-ID: <1144731748.9011.2.camel@localhost.localdomain> (raw)
In-Reply-To: <e1co2g$17eh$1@news.hub.org>
References: <1144640620.925899.274170@z34g2000cwc.googlegroups.com>
	<e1co2g$17eh$1@news.hub.org>

On lun, 2006-04-10 at 12:44 +0800, Qingqing Zhou wrote: 
> <FavoYang@gmail.com> wrote
> > I have a slow sql:
> > SELECT * FROM mytable WHERE id IN (1,3,5,7,....3k here...);
> > mytable is about 10k rows.
> >
> > if don't use the "IN" clause, it will cost 0,11 second, otherwise it
> > will cost 2.x second
> > I guess pg use linear search to deal with IN clause, is there any way
> > to let pg use other search method with IN clause? (ex.Binary Search or
> > hash Search)
> >
> 
> If you can put (1, 3, .., 3k) in a table, PG may choose a hash join.

And maybe using

SELECT * FROM yourtable WHERE id < 6002 AND id % 2 = 1;

turns out to be faster, if we are allowed to extrapolate from the
example. 

V.




view thread (3+ messages)

Message-ID: <1144731748.9011.2.camel@localhost.localdomain>
Permalink:  ../1144731748.9011.2.camel@localhost.localdomain/
Also on:    postgresql.org/message-id/1144731748.9011.2.camel@localhost.localdomain

 · 

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-performance@postgresql.org
  Cc: el@vinko.cl, zhouqq@cs.toronto.edu
  Subject: Re: slow "IN" clause
  In-Reply-To: <1144731748.9011.2.camel@localhost.localdomain>

* 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