Re: Slow sub-selects, max and count(*) - Mailing list pgsql-sql

From Josh Berkus
Subject Re: Slow sub-selects, max and count(*)
Date
Msg-id 200402051959.43263.josh@agliodbs.com
Whole thread Raw
In response to Re: Slow sub-selects, max and count(*)  ("Richard Sydney-Smith" <richard@ibisaustralia.com>)
List pgsql-sql
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 BerkusAglio Database SolutionsSan Francisco



pgsql-sql by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Slow sub-selects, max and count(*)
Next
From: "Mona H. Kapadia"
Date:
Subject: unsubscribe