From: | "David Bennett" <davidb(at)pfxcorp(dot)com> |
---|---|
To: | <pgsql-general-owner+M220495=david=andl(dot)org(at)postgresql(dot)org>, <pgsql-general(at)postgresql(dot)org> |
Cc: | <david(at)andl(dot)org>, <pgsql-general-owner+M220489=david=andl(dot)org(at)postgresql(dot)org> |
Subject: | Re: Does a call to a language handler provide a context/session, and somewhere to keep session data? |
Date: | 2016-03-07 23:27:14 |
Message-ID: | 000401d178c8$e17ec930$a47c5b90$@pfxcorp.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Jan de Visser
One thing that's probably key here is that pgsql isn't multi-threaded.
Individual connections are handled by forked backends, which share a shared- memory cache that's not accessible by SQL-land code (which includes language handlers). So I think your problem goes away once you realize that all the data you have is tied to a single connection anyway.
[dmb>]
[dmb>] Thanks. Yes, I knew that. My problem is a strategy to start up the language engine once (per session), load stuff from the database once, and then keep the per-call cost as low as possible. I know that palloc() memory goes away; that it has a lifetime longer than a function invocation and should span a recursive function call, but definitely not longer than a transaction. So I need to get some memory per session and keep a pointer to it per session (which it seems is per process).
You cannot use multi-threaded code (which touches the database) in language handlers or other "plug-in" code.
[dmb>] That's good -- I hate threads. I've never been able to figure out how to test them adequately. No loss there.
Also, trying to outsmart the db engine's cache by building your own is usually an exercise in futility and often counter-productive. I speak from experience :-P
[dmb>] Isn't cache invalidation the second hardest thing in computing (after naming things)?
[dmb>] Seems like DLL static memory with allocation from process memory (or even malloc()) is "the simplest thing that could possibly work".
Regards
David M Bennett FACS
Andl - A New Database Language - andl.org
From | Date | Subject | |
---|---|---|---|
Next Message | david | 2016-03-07 23:28:00 | Re: Does a call to a language handler provide a context/session, and somewhere to keep session data? |
Previous Message | Geoff Winkless | 2016-03-07 21:23:36 | Re: index problems (again) |