X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 705B9D1BCB2 for ; Wed, 10 Mar 2004 17:18:21 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 69518-03 for ; Wed, 10 Mar 2004 13:18:14 -0400 (AST) Received: from gp.word-to-the-wise.com (gp.word-to-the-wise.com [64.71.176.18]) by svr1.postgresql.org (Postfix) with ESMTP id DC115D1B80C for ; Wed, 10 Mar 2004 13:18:13 -0400 (AST) Received: by gp.word-to-the-wise.com (Postfix, from userid 500) id 6D892900015; Wed, 10 Mar 2004 09:11:04 -0800 (PST) Date: Wed, 10 Mar 2004 09:11:04 -0800 From: Steve Atkins To: pgsql-performance@postgresql.org Subject: Re: optimizing large query with IN (...) Message-ID: <20040310171104.GA1666@gp.word-to-the-wise.com> References: <62371.200.174.148.100.1078889715.squirrel@webmail.webnow.com.br> <63139.200.174.148.100.1078938143.squirrel@webmail.webnow.com.br> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <63139.200.174.148.100.1078938143.squirrel@webmail.webnow.com.br> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/138 X-Sequence-Number: 5994 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