pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Joe Conway <mail@joeconway.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Richard Jones <rich@annexia.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: Very large IN-clause is slow, but how to rewrite it?
Date: Sun, 25 Feb 2007 10:27:08 -0800
Message-ID: <45E1D4FC.4050901@joeconway.com> (raw)
In-Reply-To: <7794.1172422591@sss.pgh.pa.us>
References: <20070225123913.GA17124@furbychan.cocan.org>
	<7794.1172422591@sss.pgh.pa.us>

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




view thread (6+ messages)  latest in thread

Message-ID: <45E1D4FC.4050901@joeconway.com>
Permalink:  ../45E1D4FC.4050901@joeconway.com/
Also on:    postgresql.org/message-id/45E1D4FC.4050901@joeconway.com

 · 

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-sql@postgresql.org
  Cc: mail@joeconway.com, tgl@sss.pgh.pa.us, rich@annexia.org
  Subject: Re: Very large IN-clause is slow, but how to rewrite it?
  In-Reply-To: <45E1D4FC.4050901@joeconway.com>

* 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