pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Qingqing Zhou <zhouqq@cs.toronto.edu>
To: pgsql-performance@postgresql.org
Subject: Re: slow "IN" clause
Date: Mon, 10 Apr 2006 12:44:46 +0800
Message-ID: <e1co2g$17eh$1@news.hub.org> (raw)
References: <1144640620.925899.274170@z34g2000cwc.googlegroups.com>


<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





view thread (3+ messages)  latest in thread

Message-ID: <e1co2g$17eh$1@news.hub.org>
Permalink:  ../e1co2g$17eh$1@news.hub.org/
Also on:    postgresql.org/message-id/e1co2g$17eh$1@news.hub.org

 · 

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: zhouqq@cs.toronto.edu
  Subject: Re: slow "IN" clause
  In-Reply-To: <e1co2g$17eh$1@news.hub.org>

* 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