Re: Very large IN-clause is slow, but how to rewrite it?

From: Joe Conway <mail(at)joeconway(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Richard Jones <rich(at)annexia(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Very large IN-clause is slow, but how to rewrite it?
Date: 2007-02-25 18:27:08
Message-ID: 45E1D4FC.4050901@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tom Lane wrote:
> Richard Jones <rich(at)annexia(dot)org> writes:
>> I've been profiling a PG database / mix of applications and found that
>> one statement which takes a very long time to execute is:
>
> PG 8.2 does better with long IN-lists ... although if the list is so
> long as to be fetching a significant fraction of the table, you'll still
> have problems. In that case I'd advise putting the values into a temp
> table, ANALYZEing same, and doing "WHERE foo IN (SELECT x FROM tmp_table)".

If 8.2, what about
... WHERE foo IN (select x from (values (1$),(2$),...,(N$)) as t(x))
?

It would be interesting to see how that compares performance-wise.

Joe

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2007-02-25 18:34:44 Re: Very large IN-clause is slow, but how to rewrite it?
Previous Message Tom Lane 2007-02-25 16:56:31 Re: Very large IN-clause is slow, but how to rewrite it?