Custom cache implemented in a postgresql C function

Поиск
Список
Период
Сортировка
От Gabi Julien
Тема Custom cache implemented in a postgresql C function
Дата
Msg-id 201010201944.12855.gabi.julien@broadsign.com
обсуждение исходный текст
Ответы Re: Custom cache implemented in a postgresql C function  (Rob Sargent <robjsargent@gmail.com>)
Re: Custom cache implemented in a postgresql C function  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Custom cache implemented in a postgresql C function  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: Custom cache implemented in a postgresql C function  ("A.M." <agentm@themactionfaction.com>)
Список pgsql-general
Hi,

Here is my problem: I have a postgresql C function that looks like this:

Datum filter(PG_FUNCTION_ARGS);

It takes identifiers and queries a bunch of tables and ends up returning true or false. So far nothing difficult except
thatwe want better performance. The function was already optimized to the best of my abilities and changing the
structureof the database would not help. However, having a cache would be the perfect solution. I could implement this
cacheoutside of postgresql if need be but nothing could beat implementing this directly in a postgresql C function. 

So this is what I want, a custom cache built into a postgresql C function. Since postgresql uses different processes,
itwould be best to use the shared memory. Can this be done safely? At its core, the cache could be considered as simple
asa map protected by a mutex. With postgresql, I first need to initialized some shared memory. This is explained at the
endof this link: 

http://www.postgresql.org/docs/8.2/static/xfunc-c.html

However, it sounds like I need to reserve the shared memory in advance using:

void RequestAddinShmemSpace(int size)

In my case, I do not know how big my cache will be. I would preferably allocate the memory dynamically. Is this
possible?In any case, am I trying to reinvent the wheel here? Is there already a shared map or a shared hash structure
availablein postgresql? 

If shared memory turns out too difficult to use, I could create separate caches for each postgresql processes. This
wouldbe a waste of space but it might be better then nothing. In this case, do I need to make my code thread safe? In
otherwords, is postgresql using more then one thread per processes? 

Any insights would be more then welcome!
Thank you,
Gabi Julien

В списке pgsql-general по дате отправления:

Предыдущее
От: DM
Дата:
Сообщение: Re: Composite Index question
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: Composite Index question