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

From Joe Conway
Subject Re: Very large IN-clause is slow, but how to rewrite it?
Date
Msg-id 45E1D4FC.4050901@joeconway.com
Whole thread Raw
In response to Re: Very large IN-clause is slow, but how to rewrite it?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Very large IN-clause is slow, but how to rewrite it?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Tom Lane wrote:
> Richard Jones <rich@annexia.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



pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Very large IN-clause is slow, but how to rewrite it?
Next
From: Tom Lane
Date:
Subject: Re: Very large IN-clause is slow, but how to rewrite it?