proposal: tsearch dictionary initialization hook

Started by Pavel Stehuleover 15 years ago5 messages
#1Pavel Stehule
pavel.stehule@gmail.com
1 attachment(s)

Hello,

I propose a new hook type - that helps with controlling a life cycle
of some tsearch dictionaries. This hook has minimal impact on
performance - it's called once per session for one tsearch
configuration.

Regards

Pavel Stehule

Attachments:

ts_init_dict_hook.diffapplication/octet-stream; name=ts_init_dict_hook.diffDownload
*** ./src/backend/utils/cache/ts_cache.c.orig	2010-08-05 17:25:35.000000000 +0200
--- ./src/backend/utils/cache/ts_cache.c	2010-09-05 08:25:00.958285837 +0200
***************
*** 76,81 ****
--- 76,83 ----
  
  static Oid	TSCurrentConfigCache = InvalidOid;
  
+ /* hook to preparing tseach dictionary to work */
+ init_ts_dictionary_hook_type init_ts_dictionary_hook = NULL;
  
  /*
   * We use this syscache callback to detect when a visible change to a TS
***************
*** 336,344 ****
  			else
  				dictoptions = deserialize_deflist(opt);
  
! 			entry->dictData =
! 				DatumGetPointer(OidFunctionCall1(template->tmplinit,
! 											  PointerGetDatum(dictoptions)));
  
  			MemoryContextSwitchTo(oldcontext);
  		}
--- 338,352 ----
  			else
  				dictoptions = deserialize_deflist(opt);
  
! 			if (init_ts_dictionary_hook)
! 			{
! 				entry->dictData = 
! 					(*init_ts_dictionary_hook)(template->tmplinit, dictoptions);
! 			}
! 			else
! 				entry->dictData =
! 					DatumGetPointer(OidFunctionCall1(template->tmplinit,
! 												  PointerGetDatum(dictoptions)));
  
  			MemoryContextSwitchTo(oldcontext);
  		}
*** ./src/include/tsearch/ts_cache.h.orig	2010-01-02 17:58:09.000000000 +0100
--- ./src/include/tsearch/ts_cache.h	2010-09-05 08:16:05.683832929 +0200
***************
*** 81,86 ****
--- 81,91 ----
  	ListDictionary *map;
  } TSConfigCacheEntry;
  
+ typedef void *(*init_ts_dictionary_hook_type) (Oid tmpinit,
+ 							    List *dictoptions);
+ 
+ extern PGDLLIMPORT init_ts_dictionary_hook_type init_ts_dictionary;
+ 
  
  /*
   * GUC variable for current configuration
#2Teodor Sigaev
teodor@sigaev.ru
In reply to: Pavel Stehule (#1)
Re: proposal: tsearch dictionary initialization hook

Hm, what is aim of this hook? It looks like a wrapper of dictionary init method.

I propose a new hook type - that helps with controlling a life cycle
of some tsearch dictionaries. This hook has minimal impact on
performance - it's called once per session for one tsearch
configuration.

--
Teodor Sigaev E-mail: teodor@sigaev.ru
WWW: http://www.sigaev.ru/

#3Pavel Stehule
pavel.stehule@gmail.com
In reply to: Teodor Sigaev (#2)
Re: proposal: tsearch dictionary initialization hook

Hello

2010/9/7 Teodor Sigaev <teodor@sigaev.ru>:

Hm, what is aim of this hook? It looks like a wrapper of dictionary init
method.

If I use a mmap for shared dictionary, then I have to prealloc and
maybe preread dictionary - it can be done in external module. But I
have to join preloaded dictionary to requested dictionary. This hook
allows this relation - and it's general - I don't need any special
support in ispell dictionary.

Regards

Pavel

Show quoted text

I propose a new hook type - that helps with controlling a life cycle
of some tsearch dictionaries. This hook has minimal impact on
performance - it's called once per session for one tsearch
configuration.

--
Teodor Sigaev                                   E-mail: teodor@sigaev.ru
                                                  WWW: http://www.sigaev.ru/

#4Robert Haas
robertmhaas@gmail.com
In reply to: Pavel Stehule (#3)
Re: proposal: tsearch dictionary initialization hook

On Tue, Sep 7, 2010 at 12:55 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

2010/9/7 Teodor Sigaev <teodor@sigaev.ru>:

Hm, what is aim of this hook? It looks like a wrapper of dictionary init
method.

If I use a mmap for shared dictionary, then I have to prealloc and
maybe preread dictionary - it can be done in external module. But I
have to join preloaded dictionary to requested dictionary. This hook
allows this relation - and it's general - I don't need any special
support in ispell dictionary.

Review:

1. Is this really necessary? It seems that you're inserting a hook
here when you could just as well change tmplinit to point to whatever
function you want to call, which wouldn't require a code change.

2. Our standard criteria for the inclusion of a hook is some sample
code that demonstrates how it can be usefully used. I think you need
to provide that before we can consider this further.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

#5Pavel Stehule
pavel.stehule@gmail.com
In reply to: Robert Haas (#4)
Re: proposal: tsearch dictionary initialization hook

Hello

2010/9/28 Robert Haas <robertmhaas@gmail.com>:

On Tue, Sep 7, 2010 at 12:55 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

2010/9/7 Teodor Sigaev <teodor@sigaev.ru>:

Hm, what is aim of this hook? It looks like a wrapper of dictionary init
method.

If I use a mmap for shared dictionary, then I have to prealloc and
maybe preread dictionary - it can be done in external module. But I
have to join preloaded dictionary to requested dictionary. This hook
allows this relation - and it's general - I don't need any special
support in ispell dictionary.

Review:

1. Is this really necessary?  It seems that you're inserting a hook
here when you could just as well change tmplinit to point to whatever
function you want to call, which wouldn't require a code change.

The a creating of new hacked template is second option - I didn't find
it. It good for hacking and probably I'll use it because I have not a
time to work on this problem. On second hand - it is less on more
little bit dark hack - you have to modify system tables. Using a hook
is more transparent - you can or not just load a module, that uses a
hook.

2. Our standard criteria for the inclusion of a hook is some sample
code that demonstrates how it can be usefully used.  I think you need
to provide that before we can consider this further.

yes - I understand, but I have not time to work on this subject now,
so It can be moved to rejected patches queue. Some my ideas depends on
proposed (different people) shared memory control, but I don't see any
move on this, so there isn't reason why implement a hook or some
modules uses this hook now.

Regards

Pavel Stehule

Show quoted text

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company