Re: Sorted group by

From: Jonathan Blitz <jblitz(at)013(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Sorted group by
Date: 2010-08-10 17:38:02
Message-ID: 80C83A54DDD9410F87FC9DDC78967ED0@jblaptop
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


Another couple of possible ways:

Select groupfield,value
>From tbl x1
Where number = (select max(number) from tbl x2 where x2.groupfield=
x1.groupfield)

Select groupfield,value
>From tbl x1
Where (groupfield,number) in (select groupfield,max(number) from tbl group
by groupfield)

Which is quickest?
Probably best to try out and see.

-----Original Message-----
From: pgsql-performance-owner(at)postgresql(dot)org
[mailto:pgsql-performance-owner(at)postgresql(dot)org] On Behalf Of Kevin Grittner
Sent: Tuesday, August 10, 2010 7:38 PM
To: Matthew Wakeling; pgsql-performance(at)postgresql(dot)org
Subject: Re: [PERFORM] Sorted group by

Matthew Wakeling <matthew(at)flymine(dot)org> wrote:

> I'm trying to eke a little bit more performance out of an application

In addition to the suggestion from Thomas Kellerer, it would be interesting
to try the following and see how performance compares using real data.

select group, value from tbl x
where not exists
(select * from tbl y
where y.group = x.group and y.number > x.number);

We have a lot of code using this general technique, and I'm curious whether
there are big gains to be had by moving to the windowing functions. (I
suspect there are.)

-Kevin

--
Sent via pgsql-performance mailing list (pgsql-performance(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance
No virus found in this incoming message.
Checked by AVG - www.avg.com
Version: 9.0.851 / Virus Database: 271.1.1/3061 - Release Date: 08/09/10
21:35:00

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Brad Nicholson 2010-08-10 17:57:20 Re: Completely un-tuned Postgresql benchmark results: SSD vs desktop HDD
Previous Message Kevin Grittner 2010-08-10 16:37:40 Re: Sorted group by