From: | Ang Chin Han <angch(at)bytecraft(dot)com(dot)my> |
---|---|
To: | Christopher Browne <cbbrowne(at)acm(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Why does adding SUM and GROUP BY destroy performance? |
Date: | 2003-09-19 07:21:35 |
Message-ID: | 3F6AAE7F.7030301@bytecraft.com.my |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Christopher Browne wrote:
> In the last exciting episode, dvlink(at)yahoo(dot)com (David Link) wrote:
>
>>Why does adding SUM and GROUP BY destroy performance?
>
>
> When you use SUM (or other aggregates), there are no short cuts to
> walking through each and every tuple specified by the WHERE clause.
Er... not in this case, if I read David's email correctly.
His first query is walking through every tuple anyway.
His second query is the one summing them up, AFTER, here's the critical
part, GROUPing them by t.tid.
I suspect 7.4 (now in beta), or rewriting the query for <7.4 would speed
thing up. 7.4's Hash Aggregate would be the winner here.
As for rewriting this, David, try:
SELECT t.tid, t.title,
(select the stuff you want from lots of tables where something = t.tid)
FROM
title t;
Doubt it'll be as fast as using 7.4 though.
--
Linux homer 2.4.18-14 #1 Wed Sep 4 13:35:50 EDT 2002 i686 i686 i386
GNU/Linux
3:00pm up 267 days, 6:26, 4 users, load average: 5.44, 5.26, 5.17
From | Date | Subject | |
---|---|---|---|
Next Message | Oleg Bartunov | 2003-09-19 07:42:26 | Re: PostgreSQL versus MySQL |
Previous Message | Gregory S. Williamson | 2003-09-19 07:06:30 | Re: PostgreSQL versus MySQL |