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 01317D1B535 for ; Thu, 18 Sep 2003 15:00:58 +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 80082-06 for ; Thu, 18 Sep 2003 12:00:26 -0300 (ADT) Received: from falcon.mail.pas.earthlink.net (falcon.mail.pas.earthlink.net [207.217.120.74]) by svr1.postgresql.org (Postfix) with ESMTP id B934DD1B52C for ; Thu, 18 Sep 2003 12:00:25 -0300 (ADT) Received: from statler.psp.pas.earthlink.net ([207.217.78.21]) by falcon.mail.pas.earthlink.net with esmtp (Exim 3.33 #1) id 1A00GB-0006dZ-00; Thu, 18 Sep 2003 07:59:55 -0700 Message-ID: <24864010.1063897195181.JavaMail.root@statler.psp.pas.earthlink.net> Date: Thu, 18 Sep 2003 07:59:54 -0700 (GMT-07:00) From: LN Cisneros Reply-To: LN Cisneros To: Manfred Koizar , Christopher Kings-Lynne Subject: Re: rewrite in to exists? Cc: LN Cisneros , pgsql-performance@postgresql.org 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-Archive-Number: 200309/267 X-Sequence-Number: 3633 On Thu, 18 Sep 2003 13:23:37 +0800, "Christopher Kings-Lynne" >To the original poster: You did not provide a lot of information, but >the following suggestions might give you an idea ... > Yes, sorry about that. But in my query for a set of dates returned from the subquery I would then like to get all records that match this set of dates (ordered). I believe this query will work and hopefully speed it up (the "IN" query is extremely slow)...I give this one a try: >SELECT t1.code, t1.id, t1.date_of_service > FROM tbl t1 INNER JOIN > (SELECT DISTINCT date_of_service > FROM tbl > WHERE xxx >= '29800' AND xxx <= '29909' > AND code = 'XX' > ) AS t2 ON (t1.date_of_service = t2.date_of_service) > WHERE t1.client_code = 'XX' > ORDER BY id, date_of_service; A question I have is is the "DISTINCT" really going to help or is it just going to throw another sort into the mix making it slower? Thanks for the help! Laurette