X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 88509D1D2A0 for ; Fri, 6 Feb 2004 04:00:46 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 20711-04 for ; Fri, 6 Feb 2004 00:00:42 -0400 (AST) Received: from davinci.ethosmedia.com (server228.ethosmedia.com [209.128.84.228]) by svr1.postgresql.org (Postfix) with ESMTP id 8520CD1D269 for ; Fri, 6 Feb 2004 00:00:41 -0400 (AST) Received: from [63.195.55.98] (HELO 192.168.1.29) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 4379757; Thu, 05 Feb 2004 20:01:42 -0800 From: Josh Berkus Reply-To: josh@agliodbs.com Organization: Aglio Database Solutions To: "Richard Sydney-Smith" , Subject: Re: Slow sub-selects, max and count(*) Date: Thu, 5 Feb 2004 19:59:43 -0800 User-Agent: KMail/1.5.4 References: <003b01c3ec5f$d740c3e0$76e98a90@athlon2000> In-Reply-To: <003b01c3ec5f$d740c3e0$76e98a90@athlon2000> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200402051959.43263.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/60 X-Sequence-Number: 16751 Richard, > Ian you suggested a simular problem was solved using "exists" rather than "in". I am not sure how the use differs. I have tried to include it in option 4 below. Hmmm ... this piece of advice is dated; with PG 7.4, IN() queries should be plenty fast. If you're using 7.3 or less, though watch out! > 1) delete from fsechist where hist_q in (select hist_q from fsechist, temp_shareprices where hist_tick = ticker and dte = hist_date); I can't help you with this unless you attribute column names to their tables. Please use full table.column syntax. > update fsechist set hist_tick = \'@@\' from fsechist h, temp_shareprices t where t.ticker = h.hist_tick and h.hist_date = t.dte; Put an ANALYZE fsechist here. > delete from fsechist where hist_tick = \'@@\'; Is there a reason why you are doing this in two steps? > -- does not allow insert of a single company data > delete from fsechist where hist_date in (select distinct dte from temp_shareprices); The DISTINCT is completely unnecessary. > delete from fsechist where exists(select 1 from fsechist, temp_shareprices where hist_tick = ticker and dte = hist_date); This is not the same query as #1. -- -Josh Berkus Aglio Database Solutions San Francisco