Re: Query performance - Mailing list pgsql-performance

From Richard Huxton
Subject Re: Query performance
Date
Msg-id 40E12A5D.70007@archonet.com
Whole thread Raw
In response to Re: Query performance  ("Bill" <bill@math.uchicago.edu>)
Responses Re: Query performance
List pgsql-performance
Bill wrote:
> Ok....so here lies the output of oclh (i.e "\d oclh")
>
>                     Table "public.oclh"
>  Column |         Type          |           Modifiers
> --------+-----------------------+-------------------------------
>  symbol | character varying(10) | not null default ''
>  date   | date                  | not null default '0001-01-01'
>  open   | numeric(12,2)         | not null default '0.00'
>  close  | numeric(12,2)         | not null default '0.00'
>  low    | numeric(12,2)         | not null default '0.00'
>  high   | numeric(12,2)         | not null default '0.00'
> Indexes: symbol_2_oclh_index btree (symbol, date),
>          symbol_oclh_index btree (symbol, date)

Well, I'm not sure why the two indexes on the same columns, and I'm not
sure it makes sense to have defaults for _any_ of the columns there.

So - you want:
1. ratio = abs(closing-opening)/opening
2. average = all the ratios of each day of each stock
3. Highest average

Well, I don't know what you mean by #2, but #1 is just:

SELECT
   symbol,
   "date",
   abs(close - open)/open AS ratio
FROM
   oclh
GROUP BY
   symbol, date;

I'd probably fill in a summary table with this and use that as the basis
for your further queries. Presumably from "yesterday" back, the
ratios/averages won't change.

--
   Richard Huxton
   Archonet Ltd

pgsql-performance by date:

Previous
From: Chris Cheston
Date:
Subject: Re: postgres 7.4 at 100%
Next
From: "Harald Lau (Sector-X)"
Date:
Subject: Re: no index-usage on aggregate-functions?