From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | "Mark Cave-Ayland" <m(dot)cave-ayland(at)webbased(dot)co(dot)uk> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Any advice about function caching? |
Date: | 2005-11-07 23:05:58 |
Message-ID: | 29337.1131404758@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
"Mark Cave-Ayland" <m(dot)cave-ayland(at)webbased(dot)co(dot)uk> writes:
> My current code works by using MemoryContextCreate() to create a child
> context to MessageContext and using the Init()/Delete() functions to
> initialise and destroy a cache in the local backend. However, this doesn't
> really work particularly well when using cursors and prepared queries since
> it appears what I should be doing is using a cache per portal rather than a
> cache per backend.
If you want per-query state, keep it in a data structure linked from the
fcinfo->flinfo->fn_extra field (physically, store it in
fcinfo->flinfo->fn_mcxt, or create a subcontext of that if you wish).
If you need to get control at query shutdown to free non-palloc'd
resources, RegisterExprContextCallback may help. (I think such
callbacks are only called during *successful* query shutdown, though,
so if you have external library state you need to clean up anyway,
you'll need some other approach to keeping track of it ... maybe a
permanent data structure instead of a per-query one.)
src/backend/utils/fmgr/funcapi.c and src/backend/executor/functions.c
might be useful examples.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2005-11-07 23:09:41 | Re: broken comment justification logic in new pgindent |
Previous Message | Bruce Momjian | 2005-11-07 23:01:12 | Re: broken comment justification logic in new pgindent |