Skip site navigation (1) Skip section navigation (2)

Re: Query performance

From: Richard Huxton <dev(at)archonet(dot)com>
To: Bill <bill(at)math(dot)uchicago(dot)edu>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Query performance
Date: 2004-06-29 08:37:49
Message-ID: 40E12A5D.70007@archonet.com (view raw or flat)
Thread:
Lists: 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

In response to

Responses

pgsql-performance by date

Next:From: Harald Lau (Sector-X)Date: 2004-06-29 08:46:27
Subject: Re: no index-usage on aggregate-functions?
Previous:From: Chris ChestonDate: 2004-06-29 08:37:30
Subject: Re: postgres 7.4 at 100%

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group