1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

WL#2575 - Fulltext: Parser plugin for FTS

Manual merge.


Makefile.am:
  Added new 'plugin' subdir.
configure.in:
  Added plugin related makefiles.
include/my_base.h:
  Added HA_OPEN_FROM_SQL_LAYER flag - indicates that a table was openned from the sql layer.
  Added HA_OPTION_RELIES_ON_SQL_LAYER flag - indicates that a table relies on the sql layer.
  Added HA_CREATE_RELIES_ON_SQL_LAYER flag - indicates that a table must be created with
  HA_OPTION_RELIES_ON_SQL_LAYER flag.
include/myisam.h:
  Distinct fulltext parser number added.
include/plugin.h:
  Revise comment.
sql/ha_myisam.cc:
  Pass HA_OPEN_FROM_SQL_LAYER flag to mi_open().
  Pass HA_CREATE_RELIES_ON_SQL_LAYER flag to mi_create().
sql/sql_plugin.cc:
  Reuse "unused" dynamic array elements.
  A check for plugin info interface version.
sql/sql_plugin.h:
  Added plugin_type_names[] - string plugin type names.
sql/sql_show.cc:
  Use plugin_type_names array instead of switch to find literal parser name representation.
sql/sql_table.cc:
  Fixed that ALTER TABLE ... ADD INDEX loses WITH PARSER info.
storage/myisam/ft_boolean_search.c:
  Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
  ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_nlq_search.c:
  Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
  ftparser_call_initializer(), to parser->parse().
storage/myisam/ft_parser.c:
  Added two functions:
  ftparser_call_initializer() - calls parser->init() function if specified and parser is not yet
  initialized. Returns MYSQL_FTPARSER_PARAM *.
  ftparser_call_deinitializer() - calls parser->deinit() function if specified and parser was
  initialized. Deinitializes all parsers.
  ft_parse() accepts additional param now - MYSQL_FTPARSER_PARM and passes it to parser->parse().
storage/myisam/ft_update.c:
  Call fulltext parser init() function, pass MYSQL_FTPARSER_PARAM, returned by
  ftparser_call_initializer(), to _mi_ft_parse().
  _mi_ft_parse() accepts additional param now - MYSQL_FTPARSER_PARAM and passes
  it to parser->parse().
storage/myisam/ftdefs.h:
  Prototypes for new functions were added. MYSQL_FTPARSER_PARAM was added
  to ft_parse and _mi_ft_parse().
storage/myisam/mi_close.c:
  Free ftparser_param allocated by ftparser_call_initializer().
storage/myisam/mi_create.c:
  If a table relies on the sql layer, set HA_OPTION_RELIES_ON_SQL_LAYER.
storage/myisam/mi_locking.c:
  Call deinitializer for each initialized parser.
storage/myisam/mi_open.c:
  Set default values for share->ftparser and keydef->ftparser_nr.
  If a table is openned from the non-sql layer and HA_OPTION_RELIES_ON_SQL_LAYER is set, raise
  HA_ERR_UNSUPPORTED error.
storage/myisam/myisamdef.h:
  Added number of distinct parsers to MYISAM_SHARE.
  Added ftparser_param to MI_INFO.
plugin/Makefile.am:
  New BitKeeper file ``plugin/Makefile.am''
plugin/fulltext/Makefile.am:
  New BitKeeper file ``plugin/fulltext/Makefile.am''
plugin/fulltext/plugin_example.c:
  New BitKeeper file ``plugin/fulltext/plugin_example.c''
This commit is contained in:
unknown
2005-12-28 16:05:30 +04:00
parent 5bfbfb24e5
commit 38005eae6a
23 changed files with 602 additions and 140 deletions

View File

@ -21,12 +21,31 @@
char *opt_plugin_dir_ptr;
char opt_plugin_dir[FN_REFLEN];
const char *plugin_type_names[]=
{
"UDF",
"STORAGE ENGINE",
"FTPARSER"
};
static const char *plugin_interface_version_sym=
"_mysql_plugin_interface_version_";
static const char *plugin_declarations_sym= "_mysql_plugin_declarations_";
static int min_plugin_interface_version= 0x0000;
/* Note that 'int version' must be the first field of every plugin
sub-structure (plugin->info).
*/
static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0x0000,
0x0000,
0x0000
};
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0x0000, /* UDF: not implemented */
0x0000, /* STORAGE ENGINE: not implemented */
MYSQL_FTPARSER_INTERFACE_VERSION
};
static DYNAMIC_ARRAY plugin_dl_array;
static DYNAMIC_ARRAY plugin_array;
static HASH plugin_hash[MYSQL_MAX_PLUGIN_TYPE_NUM];
@ -51,6 +70,27 @@ static struct st_plugin_dl *plugin_dl_find(LEX_STRING *dl)
}
static st_plugin_dl *plugin_dl_insert_or_reuse(struct st_plugin_dl *plugin_dl)
{
uint i;
DBUG_ENTER("plugin_dl_insert_or_reuse");
for (i= 0; i < plugin_dl_array.elements; i++)
{
struct st_plugin_dl *tmp= dynamic_element(&plugin_dl_array, i,
struct st_plugin_dl *);
if (! tmp->ref_count)
{
memcpy(tmp, plugin_dl, sizeof(struct st_plugin_dl));
DBUG_RETURN(tmp);
}
}
if (insert_dynamic(&plugin_dl_array, (gptr)plugin_dl))
DBUG_RETURN(0);
DBUG_RETURN(dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
struct st_plugin_dl *));
}
static st_plugin_dl *plugin_dl_add(LEX_STRING *dl, int report)
{
#ifdef HAVE_DLOPEN
@ -144,7 +184,7 @@ static st_plugin_dl *plugin_dl_add(LEX_STRING *dl, int report)
&dummy_errors);
plugin_dl.dl.str[plugin_dl.dl.length]= 0;
/* Add this dll to array */
if (insert_dynamic(&plugin_dl_array, (gptr)&plugin_dl))
if (! (tmp= plugin_dl_insert_or_reuse(&plugin_dl)))
{
dlclose(plugin_dl.handle);
my_free(plugin_dl.dl.str, MYF(0));
@ -154,8 +194,7 @@ static st_plugin_dl *plugin_dl_add(LEX_STRING *dl, int report)
sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_dl));
DBUG_RETURN(0);
}
DBUG_RETURN(dynamic_element(&plugin_dl_array, plugin_dl_array.elements - 1,
struct st_plugin_dl *));
DBUG_RETURN(tmp);
#else
DBUG_ENTER("plugin_dl_add");
if (report & REPORT_TO_USER)
@ -236,7 +275,7 @@ my_bool plugin_is_ready(LEX_STRING *name, int type)
struct st_plugin_int *plugin_lock(LEX_STRING *name, int type)
{
struct st_plugin_int *rc;
DBUG_ENTER("plugin_find");
DBUG_ENTER("plugin_lock");
rw_wrlock(&THR_LOCK_plugin);
if ((rc= plugin_find_internal(name, type)))
{
@ -250,6 +289,27 @@ struct st_plugin_int *plugin_lock(LEX_STRING *name, int type)
}
static st_plugin_int *plugin_insert_or_reuse(struct st_plugin_int *plugin)
{
uint i;
DBUG_ENTER("plugin_insert_or_reuse");
for (i= 0; i < plugin_array.elements; i++)
{
struct st_plugin_int *tmp= dynamic_element(&plugin_array, i,
struct st_plugin_int *);
if (tmp->state == PLUGIN_IS_FREED)
{
memcpy(tmp, plugin, sizeof(struct st_plugin_int));
DBUG_RETURN(tmp);
}
}
if (insert_dynamic(&plugin_array, (gptr)plugin))
DBUG_RETURN(0);
DBUG_RETURN(dynamic_element(&plugin_array, plugin_array.elements - 1,
struct st_plugin_int *));
}
static my_bool plugin_add(LEX_STRING *name, LEX_STRING *dl, int report)
{
struct st_plugin_int tmp;
@ -275,12 +335,28 @@ static my_bool plugin_add(LEX_STRING *name, LEX_STRING *dl, int report)
(const uchar *)plugin->name,
name_len))
{
struct st_plugin_int *tmp_plugin_ptr;
if (*(int*)plugin->info <
min_plugin_info_interface_version[plugin->type] ||
((*(int*)plugin->info) >> 8) >
(cur_plugin_info_interface_version[plugin->type] >> 8))
{
char buf[256];
strxnmov(buf, sizeof(buf) - 1, "API version for ",
plugin_type_names[plugin->type], " plugin is too different",
NullS);
if (report & REPORT_TO_USER)
my_error(ER_CANT_OPEN_LIBRARY, MYF(0), dl->str, 0, buf);
if (report & REPORT_TO_LOG)
sql_print_error(ER(ER_CANT_OPEN_LIBRARY), dl->str, 0, buf);
goto err;
}
tmp.plugin= plugin;
tmp.name.str= (char *)plugin->name;
tmp.name.length= name_len;
tmp.ref_count= 0;
tmp.state= PLUGIN_IS_UNINITIALIZED;
if (insert_dynamic(&plugin_array, (gptr)&tmp))
if (! (tmp_plugin_ptr= plugin_insert_or_reuse(&tmp)))
{
if (report & REPORT_TO_USER)
my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_int));
@ -288,14 +364,9 @@ static my_bool plugin_add(LEX_STRING *name, LEX_STRING *dl, int report)
sql_print_error(ER(ER_OUTOFMEMORY), sizeof(struct st_plugin_int));
goto err;
}
if (my_hash_insert(&plugin_hash[plugin->type],
(byte*)dynamic_element(&plugin_array,
plugin_array.elements - 1,
struct st_plugin_int *)))
if (my_hash_insert(&plugin_hash[plugin->type], (byte*)tmp_plugin_ptr))
{
struct st_plugin_int *tmp_plugin= dynamic_element(&plugin_array,
plugin_array.elements - 1, struct st_plugin_int *);
tmp_plugin->state= PLUGIN_IS_FREED;
tmp_plugin_ptr->state= PLUGIN_IS_FREED;
if (report & REPORT_TO_USER)
my_error(ER_OUTOFMEMORY, MYF(0), sizeof(struct st_plugin_int));
if (report & REPORT_TO_LOG)
@ -332,7 +403,7 @@ static void plugin_del(LEX_STRING *name)
void plugin_unlock(struct st_plugin_int *plugin)
{
DBUG_ENTER("plugin_release");
DBUG_ENTER("plugin_unlock");
rw_wrlock(&THR_LOCK_plugin);
DBUG_ASSERT(plugin && plugin->ref_count);
plugin->ref_count--;