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

From Qingqing Zhou
Subject Re: slow "IN" clause
Date
Msg-id e1co2g$17eh$1@news.hub.org
Whole thread Raw
Responses Re: slow "IN" clause  (Vinko Vrsalovic <el@vinko.cl>)
List pgsql-performance
<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.

Regards,
Qingqing



pgsql-performance by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: serious problems with vacuuming databases
Next
From: Brendan Duddridge
Date:
Subject: Re: OT: Data structure design question: How do they count so fast?