Re: big distinct clause vs. group by

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Apr 18, 2011, at 1:13 PM, Uwe Bartels <uwe.bartels@xxxxxxxxx> 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 my example.
> 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 first input. 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 extra columns by joining against the output of the aggregate. If this can be done without joining the same table twice, it's often much faster, but it isn't always possible.  :-(

...Robert
-- 
Sent via pgsql-performance mailing list (pgsql-performance@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance



[Postgresql General]     [Postgresql PHP]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Yosemite]

  Powered by Linux