From: | T E Schmitz <mailreg(at)numerixtechnology(dot)de> |
---|---|
To: | |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: triple self-join crawling |
Date: | 2007-03-19 08:22:32 |
Message-ID: | 45FE4848.5040407@numerixtechnology.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
T E Schmitz wrote:
> The following self join of a table containing 5800 records is crawling:
>
> 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
Things improved hugely when I changed the JOIN clauses:
LEFT OUTER JOIN history AS past_month ON (past_month.stock =
history.stock AND past_month.day >= (history.day - 30) AND
past_month.day < history.day)
LEFT OUTER JOIN history AS past_week ON (past_week.stock =
past_month.stock AND past_week.day =past_month.day AND past_week.day
>= (history.day - 7))
--
Regards,
Tarlika Elisabeth Schmitz
From | Date | Subject | |
---|---|---|---|
Next Message | Ezequias R. da Rocha | 2007-03-19 12:21:30 | Encode |
Previous Message | Andrew Sullivan | 2007-03-19 08:12:28 | Re: triple self-join crawling |