pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
slow 'IN' clause
2+ messages / 2 participants
[nested] [flat]

* slow 'IN' clause
@ 2006-04-10 03:44  FavoYang@gmail.com
  0 siblings, 1 reply; 2+ messages in thread

From: FavoYang@gmail.com @ 2006-04-10 03:44 UTC (permalink / raw)
  To: pgsql-sql

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)




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: slow 'IN' clause
@ 2006-04-11 20:21  Bruno Wolff III <bruno@wolff.to>
  parent: FavoYang@gmail.com
  0 siblings, 0 replies; 2+ messages in thread

From: Bruno Wolff III @ 2006-04-11 20:21 UTC (permalink / raw)
  To: FavoYang@gmail.com; +Cc: pgsql-sql

On Sun, Apr 09, 2006 at 20:44:34 -0700,
  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)

It would help if you told us what version of Postgres you are running
and showed EXPLAIN ANALYZE results for the two queries.

I have heard of people getting better speed by loading the constant list
into a temp table and then doing a join.

Some older versions of Postgres also had problems with large constant lists,
so if you are using an old version of Postgres upgrading might help.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-04-11 20:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-10 03:44 slow 'IN' clause FavoYang@gmail.com
2006-04-11 20:21 ` Bruno Wolff III <bruno@wolff.to>

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