Received: from grynet.passagen.se (grynet.passagen.se [195.163.107.36]) by hub.org (8.9.3/8.9.3) with ESMTP id PAA92148 for ; Mon, 1 Nov 1999 15:09:48 -0500 (EST) (envelope-from osk@hem.passagen.se) Received: from oskar (d212-151-61-72.swipnet.se [212.151.61.72]) by grynet.passagen.se (8.8.6/8.8.6) with ESMTP id VAA16972 for ; Mon, 1 Nov 1999 21:09:46 +0100 (MET) Received: from usel by oskar with local (Exim 3.03 #1 (Debian)) id 11iNmg-00027U-00 for ; Mon, 01 Nov 1999 21:10:30 +0100 Date: Mon, 1 Nov 1999 21:10:30 +0100 From: Oskar Liljeblad To: pgsql-sql@postgresql.org Subject: Re: [SQL] query with subquery abnormally slow? Message-ID: <19991101211030.A8132@oskar> References: <19991101194707.A7034@oskar> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii User-Agent: Mutt/1.0pre4i In-Reply-To: <19991101194707.A7034@oskar>; from osk@hem.passagen.se on Mon, Nov 01, 1999 at 07:47:07PM +0100 On Mon, Nov 01, 1999 at 07:47:07PM +0100, Oskar Liljeblad wrote: > I'm doing a SELECT query with a subquery on a table with 12K rows > but it is very slow (10 seconds+). The query looks like this: > > select * > from items > where package in > (select package > from items > where ...blah... > group by package) I could do it much faster with this query: select distinct i2.package, i1.* from items i1, items i2 where i1.package = i2.package and ...blah... but it is still at least three times slower than doing the subquery first, and for each row in the result another query. Any ideas? Oskar Liljeblad (osk@hem.passagen.se)