Re: Slow sub-selects, max and count(*)

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: "Richard Sydney-Smith" <richard(at)ibisaustralia(dot)com>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Slow sub-selects, max and count(*)
Date: 2004-02-06 03:59:43
Message-ID: 200402051959.43263.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Octavio Alvarez 2004-02-06 07:19:04 Seq scan on zero-parameters function
Previous Message Bruno Wolff III 2004-02-06 03:39:41 Re: Slow sub-selects, max and count(*)