От: Bill
Тема: Re: Query performance
Дата: ,
Msg-id: 200406301346.i5UDktfL013134@math.uchicago.edu
(см: обсуждение, исходный текст)
Ответ на: Re: Query performance  (Bruno Wolff III)
Ответы: Re: Query performance  (Rod Taylor)
Список: pgsql-performance

Скрыть дерево обсуждения

Query performance  ("Bill", )
 Re: Query performance  (Richard Huxton, )
  Re: Query performance  ("Bill", )
   Re: Query performance  (Richard Huxton, )
    Re: Query performance  ("Bill", )
     Re: Query performance  (Richard Huxton, )
     Re: Query performance  (Bruno Wolff III, )
      Re: Query performance  ("Bill", )
       Re: Query performance  (Rod Taylor, )
 Re: Query performance  ("Mischa Sandberg", )

Thanks this query works for what I want.  So here is an output of the
explain analyze:
 Limit  (cost=2421582.59..2421582.65 rows=25 width=29) (actual
time=1985800.32..1985800.44 rows=25 loops=1)
   ->  Sort  (cost=2421582.59..2424251.12 rows=1067414 width=29) (actual
time=1985800.31..1985800.35 rows=26 loops=1)
         Sort Key: avg(((open - "close") / (open + 1::numeric)))
         ->  Aggregate  (cost=2200163.04..2280219.09 rows=1067414 width=29)
(actual time=910291.94..1984972.93 rows=22362 loops=1)
               ->  Group  (cost=2200163.04..2253533.74 rows=10674140
width=29) (actual time=910085.96..1105064.28 rows=10674140 loops=1)
                     ->  Sort  (cost=2200163.04..2226848.39 rows=10674140
width=29) (actual time=910085.93..988909.94 rows=10674140 loops=1)
                           Sort Key: symbol
                           ->  Seq Scan on oclh  (cost=0.00..228404.40
rows=10674140 width=29) (actual time=20.00..137720.61 rows=10674140 loops=1)
 Total runtime: 1986748.44 msec
(9 rows)

Can I get any better performance?


-----Original Message-----
From: Bruno Wolff III [mailto:]
Sent: Tuesday, June 29, 2004 2:52 PM
To: Bill
Subject: Re: [PERFORM] Query performance

On Tue, Jun 29, 2004 at 12:33:51 -0500,
  Bill <> wrote:
> Ok, thanks.  So let me explain the query number 2 as this is the more
> difficult to write.  So I have a list of stocks, this table contains the
> price of all of the stocks at the open and close date.  Ok, now we have a
> ratio from query (1) that returns at least a very rough index of the daily
> performance of a given stock, with each ratio representing the stock's
> performance in one day.  Now we need to average this with the same stock's
> ratio every day, to get a total average for each stock contained in the
> database.  Now I would simply like to find a ratio like this that
> the average of every stock in the table and simply find the greatest
> Sorry about the lousy explanation before, is this a bit better?

You can do something like:

SELECT symbol, avg((open-close)/open) GROUP BY symbol
  ORDER BY avg((open-close)/open) DESC LIMIT 1;

If you aren't interested in the variance of the daily change, it seems like
you would be best off using the opening price for the first day you have
recorded for the stock and the closing price on the last day and looking
at the relative change.

В списке pgsql-performance по дате сообщения:

От: Tom Lane
Сообщение: Re: reindex and copy - deadlock?
От: Roger Ging
Сообщение: Re: How can one see what queries are running withing a