Re: Aggregate Supporting Functions

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Kevin Grittner <kgrittn(at)ymail(dot)com>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Aggregate Supporting Functions
Date: 2015-06-09 14:26:40
Message-ID: 30851.1433860000@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Kevin Grittner <kgrittn(at)ymail(dot)com> writes:
> David Rowley <david(dot)rowley(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2015-06-09 14:52:51 Re: The Future of Aggregation
Previous Message Tomas Vondra 2015-06-09 14:10:29 Re: The Future of Aggregation