Re: Aggregate Supporting Functions - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Aggregate Supporting Functions
Date
Msg-id 30851.1433860000@sss.pgh.pa.us
Whole thread Raw
In response to Re: Aggregate Supporting Functions  (Kevin Grittner <kgrittn@ymail.com>)
Responses Re: Aggregate Supporting Functions  (Kevin Grittner <kgrittn@ymail.com>)
Re: Aggregate Supporting Functions  (David Rowley <david.rowley@2ndquadrant.com>)
List pgsql-hackers
Kevin Grittner <kgrittn@ymail.com> writes:
> David Rowley <david.rowley@2ndquadrant.com> wrote:
>> [ avoid duplicate calculations for related aggregates ]

> From the information you have proposed storing, with cost factors
> associated with the functions, it seems technically possible to
> infer that you could run (for example) the avg() aggregate to
> accumulate both but only run the final functions of the aggregates
> referenced by the query.  That seems like an optimization to try
> hard to forget about until you have at least one real-world use
> case where it would yield a significant benefit.  It seems
> premature to optimize for that before having the rest working.

Actually, I would suggest that you forget about all the other aspects
and *just* do that, because it could be made to work today on existing
aggregate functions, and it would not require hundreds-to-thousands
of lines of boilerplate support code in the grammar, catalog support,
pg_dump, yadda yadda.  That is, look to see which aggregates use the
same transition function and run that just once.  We already have the
rule that the final function can't destroy the transition output,
so running two different final functions on the same transition result
should Just Work.

The rest of what David is thinking about could be done in a followon
version by allowing the same aggregate to be implemented by any of several
transition-function/final-function pairs, then teaching the planner to
prefer pairs that let the same transition function be used for several
aggregates.  But I'd see that as a later refinement that might well fail
the bang-for-buck test, and hence shouldn't be the first step.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: The Future of Aggregation
Next
From: Kevin Grittner
Date:
Subject: Re: The Future of Aggregation