Re: slow "IN" clause - Mailing list pgsql-performance

From Vinko Vrsalovic
Subject Re: slow "IN" clause
Date
Msg-id 1144731748.9011.2.camel@localhost.localdomain
Whole thread Raw
In response to Re: slow "IN" clause  ("Qingqing Zhou" <zhouqq@cs.toronto.edu>)
List pgsql-performance
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.


pgsql-performance by date:

Previous
From: FavoYang@gmail.com
Date:
Subject: slow "IN" clause
Next
From: "soni de"
Date:
Subject: Re: Takes too long to fetch the data from database