X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.225.181]) by svr1.postgresql.org (Postfix) with ESMTP id D4C2ECBAE8 for ; Sun, 13 Jul 2003 21:50:27 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr5.postgresql.org [64.117.225.181]) (amavisd-new, port 10024) with ESMTP id 37706-05 for ; Sun, 13 Jul 2003 21:50:40 +0000 (GMT) Received: from noao.edu (noao.edu [140.252.1.54]) by svr1.postgresql.org (Postfix) with ESMTP id 64AE1CBAA8 for ; Sun, 13 Jul 2003 18:50:18 -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 8067408 for pgsql-sql@postgresql.org; Sun, 13 Jul 2003 14:50:42 -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 h6DLogIY018660; Sun, 13 Jul 2003 14:50:42 -0700 Received: (from swampler@localhost) by weaver.tuc.noao.edu (8.12.8/8.12.8/Submit) id h6DLogBC018658; Sun, 13 Jul 2003 14:50:42 -0700 Date: Sun, 13 Jul 2003 14:50:42 -0700 From: Steve Wampler To: pgsql-sql@postgresql.org Subject: Replacing a simple nested query? Message-ID: <20030713215042.GA18643@weaver.tuc.noao.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/155 X-Sequence-Number: 14269 I've got a simple nested query: select * from attributes where id in (select id from attributes where (name='obsid') and (value='oid00066')); that performs abysmally. I've heard this described as the 'classic WHERE IN' problem. Is there a better way to obtain the same results? The inner select identifies a set of ids (2049 of them, to be exact) that are then used to locate records that have the same id (about 30-40K of those, including the aforementioned 2049). Thanks! -Steve -- Steve Wampler -- swampler@noao.edu Quantum materiae materietur marmota monax si marmota monax materiam possit materiari?