Re: ffunc called multiple for same value - Mailing list pgsql-hackers

From Ian Burrell
Subject Re: ffunc called multiple for same value
Date
Msg-id 410179A7.90102@rentrak.com
Whole thread Raw
In response to Re: ffunc called multiple for same value  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ffunc called multiple for same value  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Tom Lane wrote:
> 
> So I'm rather inclined to define this behavior as "not a bug".  The fact
> that you're complaining seems to indicate that your ffunc scribbles on
> its input, which is bad programming practice in any case.  Ordinarily
> I would not think that an ffunc should have any problem with being
> executed repeatedly on the same final transvalue.  (If you really want
> to do things that way, maybe your code should take responsibility for
> keeping a flag to execute just once, rather than pushing the cost onto
> everybody.)
> 

We are doing things in the aggregates that make them troublesome when 
called the ffunc is called multiple times.  The state structure uses a 
lot of memory for intermediate work.  The memory needs to be freed as 
soon as possible otherwise there is a danger of running of out memory. 
It is possible to store the resuts on the first ffunc call, free the 
intermediate state, return the results on later calls, and make sure the 
free only happens once.

The docs didn't make clear that calling ffunc multiple times could 
happens so we did not code to allow it.
 - Ian




pgsql-hackers by date:

Previous
From: Mike Mascari
Date:
Subject: Re: ffunc called multiple for same value
Next
From: Thomas F.O'Connell
Date:
Subject: psql listTables