Re: [PERFORM] Sorted group by

2010-08-11 Thread Alvaro Herrera
Excerpts from Matthew Wakeling's message of mar ago 10 11:40:16 -0400 2010: > I am trying to retrieve, for many sets of rows grouped on a couple of > fields, the value of an ungrouped field where the row has the highest > value in another ungrouped field. I think this does what you want (schema

Re: [PERFORM] Sorted group by

2010-08-11 Thread Matthew Wakeling
Original query: explain analyse select * from tracker where objectid < 120; QUERY PLAN --- Index Scan using tracker_objectid on tracker (cost=0.00..915152.62 rows=3684504 width=33) (

Re: [PERFORM] Sorted group by

2010-08-10 Thread Jonathan Blitz
ct: Re: [PERFORM] Sorted group by Matthew Wakeling 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 gro

Re: [PERFORM] Sorted group by

2010-08-10 Thread Kevin Grittner
Matthew Wakeling 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 exis

Re: [PERFORM] Sorted group by

2010-08-10 Thread Thom Brown
On 10 August 2010 17:06, Thom Brown wrote: > On 10 August 2010 17:03, Matthew Wakeling wrote: >> On Tue, 10 Aug 2010, Thomas Kellerer wrote: >>> >>> No. It's built in (8.4) and it's called Windowing functions: >>> http://www.postgresql.org/docs/8.4/static/tutorial-window.html >>> http://www.postg

Re: [PERFORM] Sorted group by

2010-08-10 Thread Thomas Kellerer
Matthew Wakeling wrote on 10.08.2010 18:03: On Tue, 10 Aug 2010, Thomas Kellerer wrote: No. It's built in (8.4) and it's called Windowing functions: http://www.postgresql.org/docs/8.4/static/tutorial-window.html http://www.postgresql.org/docs/8.4/static/functions-window.html SELECT group, last_

Re: [PERFORM] Sorted group by

2010-08-10 Thread hubert depesz lubaczewski
On Tue, Aug 10, 2010 at 04:40:16PM +0100, Matthew Wakeling wrote: > > I'm trying to eke a little bit more performance out of an > application, and I was wondering if there was a better way to do the > following: > > I am trying to retrieve, for many sets of rows grouped on a couple > of fields, t

Re: [PERFORM] Sorted group by

2010-08-10 Thread Thom Brown
On 10 August 2010 17:03, Matthew Wakeling wrote: > On Tue, 10 Aug 2010, Thomas Kellerer wrote: >> >> No. It's built in (8.4) and it's called Windowing functions: >> http://www.postgresql.org/docs/8.4/static/tutorial-window.html >> http://www.postgresql.org/docs/8.4/static/functions-window.html >>

Re: [PERFORM] Sorted group by

2010-08-10 Thread Matthew Wakeling
On Tue, 10 Aug 2010, Thomas Kellerer wrote: No. It's built in (8.4) and it's called Windowing functions: http://www.postgresql.org/docs/8.4/static/tutorial-window.html http://www.postgresql.org/docs/8.4/static/functions-window.html SELECT group, last_value(value) over(ORDER BY number) FROM table

Re: [PERFORM] Sorted group by

2010-08-10 Thread Thomas Kellerer
Matthew Wakeling wrote on 10.08.2010 17:40: Currently, I do this in my application by ordering by the number and only using the last value. I imagine that this is something that can be done in the new Postgres 9, with a sorted group by - something like this: SELECT group, LAST(value, ORDER BY nu

[PERFORM] Sorted group by

2010-08-10 Thread Matthew Wakeling
I'm trying to eke a little bit more performance out of an application, and I was wondering if there was a better way to do the following: I am trying to retrieve, for many sets of rows grouped on a couple of fields, the value of an ungrouped field where the row has the highest value in anoth