Re: Optimizing aggregates - Mailing list pgsql-hackers

From Andres Freund
Subject Re: Optimizing aggregates
Date
Msg-id 20160831155153.5tnt4z5lzjhsjzlw@alap3.anarazel.de
Whole thread Raw
In response to Optimizing aggregates  (Heikki Linnakangas <hlinnaka@iki.fi>)
Responses Re: Optimizing aggregates  (Heikki Linnakangas <hlinnaka@iki.fi>)
List pgsql-hackers
Hi,

On 2016-08-31 17:47:18 +0300, Heikki Linnakangas wrote:
> # ........  ........  ..........  .................
> ........................................
> #
>     25.70%     0.00%  postmaster  [unknown]          [k] 0000000000000000
>     14.23%    13.75%  postmaster  postgres           [.] ExecProject

> ExecProject stands out. I find that pretty surprising.
>
> We're using ExecProject to extract the arguments from the input tuples, to
> pass to the aggregate transition functions. It looks like that's a pretty
> expensive way of doing it, for a typical aggregate that takes only one
> argument.
>
> We actually used to call ExecEvalExpr() directly for each argument, but that
> was changed by the patch that added support for ordered set aggregates. It
> looks like that was a bad idea, from a performance point of view.

I complained about that as well
http://archives.postgresql.org/message-id/20160519175727.ymv2y5tye4qgcmqx%40alap3.anarazel.de


> I propose that we go back to calling ExecEvalExpr() directly, for
> non-ordered aggregates, per the attached patch. That makes that example
> query about 10% faster on my laptop, which is in line with the fact that
> ExecProject() accounted for about 13% of the CPU time.

My approach is a bit different.

I've first combined the projection for all the aggregates, ordered set,
or not, into one projetion. That got rid of a fair amount of overhead
when you have multiple aggregates.  I attached an, probably out of date,
WIP version of that patch.

Secondly, I'm working on overhauling expression evaluation to be
faster. Even without the ExecProject overhead, the computations very
quickly become the bottleneck. During that I pretty much merged
ExecProject and ExecEvalExpr into one - they're really not that
different, and the distinction serves no purpose, except to increase the
number of function calls. The reason I'm working on getting rid of
targetlist SRFs is precisely that. A proof of concept of that is
attached to
http://archives.postgresql.org/message-id/20160714011850.bd5zhu35szle3n3c%40alap3.anarazel.de

Greetings,

Andres Freund

Attachment

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: pg_sequence catalog
Next
From: Alvaro Herrera
Date:
Subject: Re: pg_sequence catalog