pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedslow "IN" clause
3+ messages / 3 participants
[nested] [flat]
* slow "IN" clause
@ 2006-04-10 03:43 FavoYang@gmail.com
2006-04-10 04:44 ` Re: slow "IN" clause Qingqing Zhou <zhouqq@cs.toronto.edu>
0 siblings, 1 reply; 3+ messages in thread
From: FavoYang@gmail.com @ 2006-04-10 03:43 UTC (permalink / raw)
To: pgsql-performance
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] 3+ messages in thread
* Re: slow "IN" clause
2006-04-10 03:43 slow "IN" clause FavoYang@gmail.com
@ 2006-04-10 04:44 ` Qingqing Zhou <zhouqq@cs.toronto.edu>
2006-04-11 05:02 ` Re: slow "IN" clause Vinko Vrsalovic <el@vinko.cl>
0 siblings, 1 reply; 3+ messages in thread
From: Qingqing Zhou @ 2006-04-10 04:44 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: slow "IN" clause
2006-04-10 03:43 slow "IN" clause FavoYang@gmail.com
2006-04-10 04:44 ` Re: slow "IN" clause Qingqing Zhou <zhouqq@cs.toronto.edu>
@ 2006-04-11 05:02 ` Vinko Vrsalovic <el@vinko.cl>
0 siblings, 0 replies; 3+ messages in thread
From: Vinko Vrsalovic @ 2006-04-11 05:02 UTC (permalink / raw)
To: Qingqing Zhou <zhouqq@cs.toronto.edu>; +Cc: 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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2006-04-11 05:02 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-04-10 03:43 slow "IN" clause FavoYang@gmail.com
2006-04-10 04:44 ` Qingqing Zhou <zhouqq@cs.toronto.edu>
2006-04-11 05:02 ` Vinko Vrsalovic <el@vinko.cl>
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