pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andrew Sullivan <ajs@crankycanuck.ca>
To: pgsql-sql@postgresql.org
Subject: Re: triple self-join crawling
Date: Mon, 19 Mar 2007 04:12:28 -0400
Message-ID: <20070319081228.GA21894@phlogiston.dyndns.org> (raw)
In-Reply-To: <45FD9840.4040305@numerixtechnology.de>
References: <45FD9840.4040305@numerixtechnology.de>

Define "crawling".  Also, please post EXPLAIN and, if feasible,
EXPLAIN ANALYSE output for your case.

A

On Sun, Mar 18, 2007 at 07:51:28PM +0000, T E Schmitz wrote:
> The following self join of a table containing 5800 records is crawling:
> 
> CREATE TABLE history
> (
>     stock VARCHAR(30) NOT NULL,
>     day date NOT NULL,
>     open NUMERIC (6,1) NOT NULL,
>     high NUMERIC (6,1) NOT NULL,
>     low NUMERIC (6,1) NOT NULL,
>     close NUMERIC (6,1) NOT NULL,
>     volume NUMERIC (12) NOT NULL,
>     PRIMARY KEY (stock,day)
> );
> 
> 
> SELECT
>     history.stock, history.day, history.high, history.low,
>     MAX(past_week.high) AS week_high,
>     MAX(past_month.high) AS month_high
> FROM history
> INNER JOIN history AS past_month ON (past_month.stock = history.stock 
> AND past_month.day < history.day AND past_month.day >= (history.day - 30))
> INNER JOIN history AS past_week  ON (past_week.stock   = 
> past_month.stock AND past_week.day < history.day AND past_week.day >= 
> (history.day - 7))
> GROUP BY  history.stock, history.day, history.high, history.low
> ORDER BY history.stock, history.day DESC
> 
> 
> How can I speed this up?
> 
> 
> -- 
> 
> 
> Regards,
> 
> Tarlika Elisabeth Schmitz
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
> 
>               http://www.postgresql.org/docs/faq

-- 
Andrew Sullivan  | ajs@crankycanuck.ca
Unfortunately reformatting the Internet is a little more painful 
than reformatting your hard drive when it gets out of whack.
		--Scott Morris



view thread (6+ messages)  latest in thread

Message-ID: <20070319081228.GA21894@phlogiston.dyndns.org>
Permalink:  ../20070319081228.GA21894@phlogiston.dyndns.org/
Also on:    postgresql.org/message-id/20070319081228.GA21894@phlogiston.dyndns.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ajs@crankycanuck.ca
  Subject: Re: triple self-join crawling
  In-Reply-To: <20070319081228.GA21894@phlogiston.dyndns.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox