Re: big distinct clause vs. group by - Mailing list pgsql-performance

From Robert Haas
Subject Re: big distinct clause vs. group by
Date
Msg-id 4B594466-0554-4AF8-A8BC-8FDA9C393DF9@gmail.com
Whole thread Raw
In response to Re: big distinct clause vs. group by  (Uwe Bartels <uwe.bartels@gmail.com>)
Responses Re: big distinct clause vs. group by
Re: big distinct clause vs. group by
List pgsql-performance
On Apr 18, 2011, at 1:13 PM, Uwe Bartels <uwe.bartels@gmail.com> wrote:
> Hi Robert,
>
> thanks for your answer.
> the aggregate function I was talking about is the function I need to use for the non-group by columns like min() in
myexample. 
> There are of course several function to choose from, and I wanted to know which causes as less as possible resources.

Oh, I see. min() is probably as good as anything. You could also create a custom aggregate that just always returns its
firstinput. I've occasionally wished we had such a thing as a built-in. 

Another option is to try to rewrite the query with a subselect so that you do the aggregation first and then add the
extracolumns by joining against the output of the aggregate. If this can be done without joining the same table twice,
it'soften much faster, but it isn't always possible.  :-( 

...Robert

pgsql-performance by date:

Previous
From: Robert Haas
Date:
Subject: Re: oom_killer
Next
From: Robert Haas
Date:
Subject: Re: REINDEX takes half a day (and still not complete!)