pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Atkins <steve@blighty.com>
To: pgsql-performance@postgresql.org
Subject: Re: optimizing large query with IN (...)
Date: Wed, 10 Mar 2004 09:11:04 -0800
Message-ID: <20040310171104.GA1666@gp.word-to-the-wise.com> (raw)
In-Reply-To: <63139.200.174.148.100.1078938143.squirrel@webmail.webnow.com.br>
References: <62371.200.174.148.100.1078889715.squirrel@webmail.webnow.com.br>
	<Pine.LNX.4.33.0403100944240.10418-100000@css120.ihs.com>
	<63139.200.174.148.100.1078938143.squirrel@webmail.webnow.com.br>

On Wed, Mar 10, 2004 at 02:02:23PM -0300, Marcus Andree S. Magalhaes wrote:

> Hmm... from the 'performance' point of view, since the data comes from
> a quite complex select statement, Isn't it better/quicker to have this
> select replaced by a select into and creating a temporary database?

Definitely - why loop the data into the application and back out again
if you don't need to?

> > The problem, as I understand it, is that 7.4 introduced massive
> > improvements in handling moderately large in() clauses, as long as they
> > can fit in sort_mem, and are provided by a subselect.
> >
> > So, creating a temp table with all the values in it and using in() on
> > the  temp table may be a win:
> >
> > begin;
> > create temp table t_ids(id int);
> > insert into t_ids(id) values (123); <- repeat a few hundred times
> > select * from maintable where id in (select id from t_ids);
> > ...

Cheers,
  Steve



view thread (10+ messages)  latest in thread

Message-ID: <20040310171104.GA1666@gp.word-to-the-wise.com>
Permalink:  ../20040310171104.GA1666@gp.word-to-the-wise.com/
Also on:    postgresql.org/message-id/20040310171104.GA1666@gp.word-to-the-wise.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-performance@postgresql.org
  Cc: steve@blighty.com
  Subject: Re: optimizing large query with IN (...)
  In-Reply-To: <20040310171104.GA1666@gp.word-to-the-wise.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