Re: Traffic jams in fn_extra - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Traffic jams in fn_extra
Date
Msg-id 13164.1385340153@sss.pgh.pa.us
Whole thread Raw
In response to Re: Traffic jams in fn_extra  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: Traffic jams in fn_extra  (Paul Ramsey <pramsey@cleverelephant.ca>)
List pgsql-hackers
Simon Riggs <simon@2ndQuadrant.com> writes:
> On 24 November 2013 16:02, Paul Ramsey <pramsey@cleverelephant.ca> wrote:
>> We do the dance because it�s how we always have and don�t know any other way, any better way. :) The usual
explanation.Is there any place you can point to that demonstrates your technique?
 

> src/backend/utils/mmgr/README

> You can create memory contexts as children of other contexts, so for
> example you might create "PostGIS Cache Context" as a sub-context of
> TopTransactionContext. So it can be created dynamically as needed and
> will automatically go away at end of xact.

The real question of course is whether transaction-level caching is
appropriate for what they're storing.  If they want only statement-level
caching then using fn_extra is often the right thing.

Also note that having the cache go away is the easy part.  The hard part
is knowing whether you've created it yet in the current transaction, and
finding it if you have.  The usual method is to keep a static variable
pointing to it, and plugging into the transaction cleanup callback
mechanism with a routine that'll reset the pointer to NULL at transaction
end.  For examples, look for callers of RegisterXactCallback().
        regards, tom lane



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Re[2]: [HACKERS] Connect from background worker thread to database
Next
From: Peter Eisentraut
Date:
Subject: Re: Building on S390