X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id BA17FD1B4F6 for ; Thu, 18 Sep 2003 05:00:01 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 73906-10 for ; Thu, 18 Sep 2003 01:59:30 -0300 (ADT) Received: from swan.mail.pas.earthlink.net (swan.mail.pas.earthlink.net [207.217.120.123]) by svr1.postgresql.org (Postfix) with ESMTP id C5DEFD1B4F0 for ; Thu, 18 Sep 2003 01:59:29 -0300 (ADT) Received: from rowlf.psp.pas.earthlink.net ([207.217.78.187]) by swan.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 19zqt7-0000Wo-00 for pgsql-performance@postgresql.org; Wed, 17 Sep 2003 21:59:29 -0700 Message-ID: <20399973.1063861169740.JavaMail.root@rowlf.psp.pas.earthlink.net> Date: Wed, 17 Sep 2003 21:59:29 -0700 (GMT-07:00) From: LN Cisneros Reply-To: LN Cisneros To: pgsql-performance@postgresql.org Subject: rewrite in to exists? Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Earthlink Zoo Mail 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests=BAYES_30, LARGE_COLLECTION, RCVD_IN_OSIRUSOFT_COM X-Spam-Level: X-Archive-Number: 200309/256 X-Sequence-Number: 3622 I'm on 7.3.4 and this query gets horrible performance. Is there a way to rewrite it with an exists or some way to get better performance? select code, id, name, date_of_service from tbl where date_of_service in (select date_of_service from tbl where xxx >= '29800' and xxx <= '29909' and code = 'XX') and client_code = 'XX' order by id, date_of_service; Thanks!