Re: Does PG cache results of an aggregate function, (and results of non-volatile functions)?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Allan Kamau <kamauallan(at)gmail(dot)com>, Postgres General Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Does PG cache results of an aggregate function, (and results of non-volatile functions)?
Date: 2009-09-18 14:16:03
Message-ID: 15514.1253283363@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
> On Thu, Sep 3, 2009 at 3:44 AM, Allan Kamau <kamauallan(at)gmail(dot)com> wrote:
>> I do have a query which make use of the results of an aggregate
>> function (for example bit_or) several times in the output column list
>> of the SELECT clause, does PostgreSQL simply execute the aggregate
>> function only once and provide the output to the other calls to the
>> same aggregate function.
>> How about the case of non volatile functions? Do they get executed as
>> many times as they occur in the select clause?

> I don't think so...could you provide a better example? It sounds like
> your query is one that might benefit from use of CTE...

Might be overkill --- nodeAgg.c does check for textually identical
aggregate calls and avoid computing them more than once. But looking
at the actual query and its explain plan would be necessary to be sure.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Howard Cole 2009-09-18 15:07:07 Re: pgadmin is changing pgpass.conf
Previous Message Picavet Vincent 2009-09-18 14:00:41 gap in sequence numbers