Re: C language context - Mailing list pgsql-hackers

From Tom Lane
Subject Re: C language context
Date
Msg-id 26441.1062804375@sss.pgh.pa.us
Whole thread Raw
In response to C language context  (Andrew Dunstan <andrew@dunslane.net>)
List pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
> Just how transient is the memory context created for a C language 
> function call?

Fairly.  IIRC, you'll normally be running in a context that will be
reset at the start of the next tuple cycle for the plan node your
function is evaluated by.  If you've got a heavily recursive routine,
it might need to do its own cleanup per-call, but most of the time you
need not bother with pfree.

> I'm still trying to get to the bottom of it, but I want to know if I'm 
> safe in relying on the context cleanup to handle things for me. It's an 
> immutable text function returning text, and is intended for use in a 
> functional index.

You might wanna check the code, but I think we force a context reset
after each tuple for functional index evaluations as well.

AFAIR, the only case where we really still require user-provided
functions to avoid leaking memory is support functions and operators for
indexes (for example, the comparison functions used by btrees).  The
internal memory usage in the index AMs is hairy enough to make it
hard to fix that, though I'd like to do so someday.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Rod Taylor
Date:
Subject: Re: [PATCHES] Warning for missing createlang
Next
From: Tom Lane
Date:
Subject: Re: Examining the output of: ldd `which postgres`