X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 35AE6CBADE for ; Sun, 13 Jul 2003 20:45:49 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 80384-05 for ; Sun, 13 Jul 2003 20:46:09 +0000 (GMT) Received: from noao.edu (noao.edu [140.252.1.54]) by svr1.postgresql.org (Postfix) with ESMTP id E1805CBAD4 for ; Sun, 13 Jul 2003 17:45:46 -0300 (ADT) Received: from weaver.tuc.noao.edu ([140.252.38.8] verified) by noao.edu (CommuniGate Pro SMTP 4.1b9) with ESMTP-TLS id 8067177 for pgsql-performance@postgresql.org; Sun, 13 Jul 2003 13:46:10 -0700 Received: from weaver.tuc.noao.edu (localhost.localdomain [127.0.0.1]) by weaver.tuc.noao.edu (8.12.8/8.12.5) with ESMTP id h6DKkAIY018150; Sun, 13 Jul 2003 13:46:10 -0700 Received: (from swampler@localhost) by weaver.tuc.noao.edu (8.12.8/8.12.8/Submit) id h6DKkA9g018148; Sun, 13 Jul 2003 13:46:10 -0700 Date: Sun, 13 Jul 2003 13:46:10 -0700 From: Steve Wampler To: pgsql-performance@postgresql.org Subject: Re: Improving a simple query? Message-ID: <20030713204610.GA18123@weaver.tuc.noao.edu> References: <1058119515.23012.114.camel@weaver.tuc.noao.edu> <49293.192.168.1.32.1058123357.squirrel@mainbox.archonet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <49293.192.168.1.32.1058123357.squirrel@mainbox.archonet.com> User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/205 X-Sequence-Number: 2498 On Sun, Jul 13, 2003 at 08:09:17PM +0100, Richard Huxton wrote: > > I'm not an SQL or PostgreSQL expert. > > > > I'm getting abysmal performance on a nested query and > > need some help on finding ways to improve the performance: > [snip] > > select * from attributes_table where id in (select id from > > attributes where (name='obsid') and (value='oid00066')); > > This is the classic IN problem (much improved in 7.4 dev I believe). The > recommended approach is to rewrite the query as an EXISTS form if > possible. See the mailing list archives for plenty of examples. > > Could you not rewrite this as a simple join though? Hmmm, I don't see how. Then again, I'm pretty much the village idiot w.r.t. SQL... The inner select is locating a set of (2049) ids (actually from the same table, since 'attributes' is just a view into 'attributes_table'). The outer select is then locating all records (~30-40K) that have any of those ids. Is that really something a JOIN could be used for? -Steve -- Steve Wampler -- swampler@noao.edu Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?