Commit 9c960615 authored by Alexander Barkov's avatar Alexander Barkov

Part2: MDEV-20837 Add MariaDB_FUNCTION_PLUGIN

Removing MariaDB_FUNCTION_COLLECTION_PLUGIN
parent 5a052ab6
...@@ -47,7 +47,6 @@ IF(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND RUN_ABI_CHECK) ...@@ -47,7 +47,6 @@ IF(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND RUN_ABI_CHECK)
${CMAKE_SOURCE_DIR}/include/mysql/plugin_encryption.h ${CMAKE_SOURCE_DIR}/include/mysql/plugin_encryption.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_data_type.h ${CMAKE_SOURCE_DIR}/include/mysql/plugin_data_type.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_function.h ${CMAKE_SOURCE_DIR}/include/mysql/plugin_function.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_function_collection.h
) )
ADD_CUSTOM_TARGET(abi_check ALL ADD_CUSTOM_TARGET(abi_check ALL
......
...@@ -90,14 +90,13 @@ typedef struct st_mysql_xid MYSQL_XID; ...@@ -90,14 +90,13 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_AUDIT_PLUGIN 5 #define MYSQL_AUDIT_PLUGIN 5
#define MYSQL_REPLICATION_PLUGIN 6 #define MYSQL_REPLICATION_PLUGIN 6
#define MYSQL_AUTHENTICATION_PLUGIN 7 #define MYSQL_AUTHENTICATION_PLUGIN 7
#define MYSQL_MAX_PLUGIN_TYPE_NUM 13 /* The number of plugin types */ #define MYSQL_MAX_PLUGIN_TYPE_NUM 12 /* The number of plugin types */
/* MariaDB plugin types */ /* MariaDB plugin types */
#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8 #define MariaDB_PASSWORD_VALIDATION_PLUGIN 8
#define MariaDB_ENCRYPTION_PLUGIN 9 #define MariaDB_ENCRYPTION_PLUGIN 9
#define MariaDB_DATA_TYPE_PLUGIN 10 #define MariaDB_DATA_TYPE_PLUGIN 10
#define MariaDB_FUNCTION_PLUGIN 11 #define MariaDB_FUNCTION_PLUGIN 11
#define MariaDB_FUNCTION_COLLECTION_PLUGIN 12
/* We use the following strings to define licenses for plugins */ /* We use the following strings to define licenses for plugins */
#define PLUGIN_LICENSE_PROPRIETARY 0 #define PLUGIN_LICENSE_PROPRIETARY 0
......
#ifndef MARIADB_PLUGIN_FUNCTION_COLLECTION_INCLUDED
#define MARIADB_PLUGIN_FUNCTION_COLLECTION_INCLUDED
/* Copyright (C) 2019, Alexander Barkov and MariaDB
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
/**
@file
Data Type Plugin API.
This file defines the API for server plugins that manage function collections.
*/
#ifdef __cplusplus
#include <mysql/plugin.h>
/*
API for data type plugins. (MariaDB_FUNCTION_COLLECTION_PLUGIN)
*/
#define MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
class Native_func_registry_array
{
const Native_func_registry *m_elements;
size_t m_count;
public:
Native_func_registry_array()
:m_elements(NULL),
m_count(0)
{ }
Native_func_registry_array(const Native_func_registry *elements, size_t count)
:m_elements(elements),
m_count(count)
{ }
const Native_func_registry& element(size_t i) const
{
DBUG_ASSERT(i < m_count);
return m_elements[i];
}
size_t count() const { return m_count; }
};
class Plugin_function_collection
{
int m_interface_version;
const Native_func_registry_array m_native_func_registry_array;
HASH m_hash;
public:
bool init();
void deinit()
{
my_hash_free(&m_hash);
}
static int init_plugin(st_plugin_int *plugin)
{
Plugin_function_collection *coll=
reinterpret_cast<Plugin_function_collection*>(plugin->plugin->info);
return coll->init();
}
static int deinit_plugin(st_plugin_int *plugin)
{
Plugin_function_collection *coll=
reinterpret_cast<Plugin_function_collection*>(plugin->plugin->info);
coll->deinit();
return 0;
}
public:
Plugin_function_collection(int interface_version,
const Native_func_registry_array &nfra)
:m_interface_version(interface_version),
m_native_func_registry_array(nfra)
{
bzero((void*) &m_hash, sizeof(m_hash));
}
Create_func *find_native_function_builder(THD *thd,
const LEX_CSTRING &name) const;
};
/**
Data type plugin descriptor
*/
#endif /* __cplusplus */
#endif /* MARIADB_PLUGIN_FUNCTION_COLLECTION_INCLUDED */
This diff is collapsed.
...@@ -36,7 +36,6 @@ ...@@ -36,7 +36,6 @@
#include "sql_time.h" #include "sql_time.h"
#include "sql_type_geom.h" #include "sql_type_geom.h"
#include <mysql/plugin_function.h> #include <mysql/plugin_function.h>
#include <mysql/plugin_function_collection.h>
extern "C" uchar* extern "C" uchar*
...@@ -49,80 +48,22 @@ get_native_fct_hash_key(const uchar *buff, size_t *length, ...@@ -49,80 +48,22 @@ get_native_fct_hash_key(const uchar *buff, size_t *length,
} }
bool Plugin_function_collection::init() bool Native_func_registry_array::append_to_hash(HASH *hash) const
{ {
DBUG_ENTER("Plugin_function_collection::init"); DBUG_ENTER("Native_func_registry_array::append_to_hash");
if (my_hash_init(&m_hash, for (size_t i= 0; i < count(); i++)
system_charset_info,
(ulong) m_native_func_registry_array.count(),
0,
0,
(my_hash_get_key) get_native_fct_hash_key,
NULL, /* Nothing to free */
MYF(0)))
DBUG_RETURN(true);
for (size_t i= 0; i < m_native_func_registry_array.count(); i++)
{ {
const Native_func_registry &func= m_native_func_registry_array.element(i); const Native_func_registry &func= element(i);
DBUG_ASSERT(func.builder != NULL); DBUG_ASSERT(func.builder != NULL);
if (my_hash_insert(&m_hash, (uchar*) &func)) if (my_hash_insert(hash, (uchar*) &func))
DBUG_RETURN(true); DBUG_RETURN(true);
} }
DBUG_RETURN(false); DBUG_RETURN(false);
} }
Create_func *
Plugin_function_collection::find_native_function_builder(THD *thd,
const LEX_CSTRING &name)
const
{
const Native_func_registry *func;
func= (const Native_func_registry*) my_hash_search(&m_hash,
(uchar*) name.str,
name.length);
return func ? func->builder : NULL;
}
class Plugin_find_native_func_builder_param
{
bool find_native_function_builder(THD *thd,
const Plugin_function_collection *pfc)
{
// plugin_foreach() will stop iterating when this function returns TRUE
return ((builder= pfc->find_native_function_builder(thd, name))) != NULL;
}
static my_bool find_in_plugin(THD *thd, plugin_ref plugin, void *data)
{
Plugin_find_native_func_builder_param *param=
reinterpret_cast<Plugin_find_native_func_builder_param*>(data);
const Plugin_function_collection *fc=
reinterpret_cast<Plugin_function_collection*>
(plugin_decl(plugin)->info);
return param->find_native_function_builder(thd, fc);
}
public:
LEX_CSTRING name;
Create_func *builder;
Plugin_find_native_func_builder_param(const LEX_CSTRING &name_arg)
:name(name_arg), builder(NULL)
{ }
Create_func *find(THD *thd)
{
if (!plugin_foreach(thd,
Plugin_find_native_func_builder_param::find_in_plugin,
MariaDB_FUNCTION_COLLECTION_PLUGIN, this))
return NULL;
return builder;
}
};
#ifdef HAVE_SPATIAL #ifdef HAVE_SPATIAL
extern Plugin_function_collection plugin_function_collection_geometry; extern Native_func_registry_array native_func_registry_array_geom;
#endif #endif
...@@ -5633,11 +5574,12 @@ static Native_func_registry func_array[] = ...@@ -5633,11 +5574,12 @@ static Native_func_registry func_array[] =
{ { STRING_WITH_LEN("WSREP_LAST_SEEN_GTID") }, BUILDER(Create_func_wsrep_last_seen_gtid)}, { { STRING_WITH_LEN("WSREP_LAST_SEEN_GTID") }, BUILDER(Create_func_wsrep_last_seen_gtid)},
{ { STRING_WITH_LEN("WSREP_SYNC_WAIT_UPTO_GTID") }, BUILDER(Create_func_wsrep_sync_wait_upto)}, { { STRING_WITH_LEN("WSREP_SYNC_WAIT_UPTO_GTID") }, BUILDER(Create_func_wsrep_sync_wait_upto)},
#endif /* WITH_WSREP */ #endif /* WITH_WSREP */
{ { STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)}, { { STRING_WITH_LEN("YEARWEEK") }, BUILDER(Create_func_year_week)}
{ {0, 0}, NULL}
}; };
Native_func_registry_array
native_func_registry_array(func_array, array_elements(func_array));
static HASH native_functions_hash; static HASH native_functions_hash;
/* /*
...@@ -5649,10 +5591,13 @@ static HASH native_functions_hash; ...@@ -5649,10 +5591,13 @@ static HASH native_functions_hash;
int item_create_init() int item_create_init()
{ {
DBUG_ENTER("item_create_init"); DBUG_ENTER("item_create_init");
size_t count= native_func_registry_array.count();
#ifdef HAVE_SPATIAL
count+= native_func_registry_array_geom.count();
#endif
if (my_hash_init(& native_functions_hash, if (my_hash_init(& native_functions_hash,
system_charset_info, system_charset_info,
array_elements(func_array), (ulong) count,
0, 0,
0, 0,
(my_hash_get_key) get_native_fct_hash_key, (my_hash_get_key) get_native_fct_hash_key,
...@@ -5660,17 +5605,33 @@ int item_create_init() ...@@ -5660,17 +5605,33 @@ int item_create_init()
MYF(0))) MYF(0)))
DBUG_RETURN(1); DBUG_RETURN(1);
if (item_create_append(func_array)) if (native_func_registry_array.append_to_hash(&native_functions_hash))
DBUG_RETURN(1); DBUG_RETURN(1);
#ifdef HAVE_SPATIAL #ifdef HAVE_SPATIAL
if (plugin_function_collection_geometry.init()) if (native_func_registry_array_geom.append_to_hash(&native_functions_hash))
DBUG_RETURN(1); DBUG_RETURN(1);
#endif #endif
#ifndef DBUG_OFF
for (uint i=0 ; i < native_functions_hash.records ; i++)
{
Native_func_registry *func;
func= (Native_func_registry*) my_hash_element(& native_functions_hash, i);
DBUG_PRINT("info", ("native function: %s length: %u",
func->name.str, (uint) func->name.length));
}
#endif
DBUG_RETURN(0); DBUG_RETURN(0);
} }
/*
This function is used (dangerously) by plugin/versioning/versioning.cc
TODO: MDEV-20842 Wrap SQL functions defined in
plugin/versioning/versioning.cc into MariaDB_FUNCTION_PLUGIN
*/
int item_create_append(Native_func_registry array[]) int item_create_append(Native_func_registry array[])
{ {
Native_func_registry *func; Native_func_registry *func;
...@@ -5683,15 +5644,6 @@ int item_create_append(Native_func_registry array[]) ...@@ -5683,15 +5644,6 @@ int item_create_append(Native_func_registry array[])
DBUG_RETURN(1); DBUG_RETURN(1);
} }
#ifndef DBUG_OFF
for (uint i=0 ; i < native_functions_hash.records ; i++)
{
func= (Native_func_registry*) my_hash_element(& native_functions_hash, i);
DBUG_PRINT("info", ("native function: %s length: %u",
func->name.str, (uint) func->name.length));
}
#endif
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -5705,9 +5657,6 @@ void item_create_cleanup() ...@@ -5705,9 +5657,6 @@ void item_create_cleanup()
{ {
DBUG_ENTER("item_create_cleanup"); DBUG_ENTER("item_create_cleanup");
my_hash_free(& native_functions_hash); my_hash_free(& native_functions_hash);
#ifdef HAVE_SPATIAL
plugin_function_collection_geometry.deinit();
#endif
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
} }
...@@ -5746,16 +5695,7 @@ find_native_function_builder(THD *thd, const LEX_CSTRING *name) ...@@ -5746,16 +5695,7 @@ find_native_function_builder(THD *thd, const LEX_CSTRING *name)
if ((builder= function_plugin_find_native_function_builder(thd, *name))) if ((builder= function_plugin_find_native_function_builder(thd, *name)))
return builder; return builder;
if ((builder= Plugin_find_native_func_builder_param(*name).find(thd))) return NULL;
return builder;
#ifdef HAVE_SPATIAL
if (!builder)
builder= plugin_function_collection_geometry.
find_native_function_builder(thd, *name);
#endif
return builder;
} }
Create_qfunc * Create_qfunc *
......
...@@ -315,5 +315,30 @@ Item *create_func_dyncol_get(THD *thd, Item *num, Item *str, ...@@ -315,5 +315,30 @@ Item *create_func_dyncol_get(THD *thd, Item *num, Item *str,
const char *c_len, const char *c_dec, const char *c_len, const char *c_dec,
CHARSET_INFO *cs); CHARSET_INFO *cs);
Item *create_func_dyncol_json(THD *thd, Item *str); Item *create_func_dyncol_json(THD *thd, Item *str);
class Native_func_registry_array
{
const Native_func_registry *m_elements;
size_t m_count;
public:
Native_func_registry_array()
:m_elements(NULL),
m_count(0)
{ }
Native_func_registry_array(const Native_func_registry *elements, size_t count)
:m_elements(elements),
m_count(count)
{ }
const Native_func_registry& element(size_t i) const
{
DBUG_ASSERT(i < m_count);
return m_elements[i];
}
size_t count() const { return m_count; }
bool append_to_hash(HASH *hash) const;
};
#endif #endif
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#include <m_ctype.h> #include <m_ctype.h>
#include "opt_range.h" #include "opt_range.h"
#include "item_geofunc.h" #include "item_geofunc.h"
#include <mysql/plugin_function_collection.h> #include "item_create.h"
bool Item_geometry_func::fix_length_and_dec() bool Item_geometry_func::fix_length_and_dec()
...@@ -3733,16 +3733,6 @@ Create_func_y Create_func_y::s_singleton; ...@@ -3733,16 +3733,6 @@ Create_func_y Create_func_y::s_singleton;
/*************************************************************************/ /*************************************************************************/
class FHash: public HASH
{
public:
FHash()
{
bzero((HASH *) this, sizeof(HASH));
}
};
#define GEOM_BUILDER(F) & F::s_singleton #define GEOM_BUILDER(F) & F::s_singleton
...@@ -3907,10 +3897,8 @@ static Native_func_registry func_array_geom[] = ...@@ -3907,10 +3897,8 @@ static Native_func_registry func_array_geom[] =
}; };
Plugin_function_collection Native_func_registry_array
plugin_function_collection_geometry( native_func_registry_array_geom(func_array_geom,
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION, array_elements(func_array_geom));
Native_func_registry_array(func_array_geom,
array_elements(func_array_geom)));
#endif /*HAVE_SPATIAL*/ #endif /*HAVE_SPATIAL*/
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include <mysql/plugin_encryption.h> #include <mysql/plugin_encryption.h>
#include <mysql/plugin_data_type.h> #include <mysql/plugin_data_type.h>
#include <mysql/plugin_function.h> #include <mysql/plugin_function.h>
#include <mysql/plugin_function_collection.h>
#include "sql_plugin_compat.h" #include "sql_plugin_compat.h"
#ifdef HAVE_LINK_H #ifdef HAVE_LINK_H
...@@ -95,8 +94,7 @@ const LEX_CSTRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]= ...@@ -95,8 +94,7 @@ const LEX_CSTRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ STRING_WITH_LEN("PASSWORD VALIDATION") }, { STRING_WITH_LEN("PASSWORD VALIDATION") },
{ STRING_WITH_LEN("ENCRYPTION") }, { STRING_WITH_LEN("ENCRYPTION") },
{ STRING_WITH_LEN("DATA TYPE") }, { STRING_WITH_LEN("DATA TYPE") },
{ STRING_WITH_LEN("FUNCTION") }, { STRING_WITH_LEN("FUNCTION") }
{ STRING_WITH_LEN("FUNCTION COLLECTION") }
}; };
extern int initialize_schema_table(st_plugin_int *plugin); extern int initialize_schema_table(st_plugin_int *plugin);
...@@ -117,16 +115,14 @@ plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= ...@@ -117,16 +115,14 @@ plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ {
0, ha_initialize_handlerton, 0, 0,initialize_schema_table, 0, ha_initialize_handlerton, 0, 0,initialize_schema_table,
initialize_audit_plugin, 0, 0, 0, initialize_encryption_plugin, 0, initialize_audit_plugin, 0, 0, 0, initialize_encryption_plugin, 0,
0, // FUNCTION 0 // FUNCTION
Plugin_function_collection::init_plugin
}; };
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ {
0, ha_finalize_handlerton, 0, 0, finalize_schema_table, 0, ha_finalize_handlerton, 0, 0, finalize_schema_table,
finalize_audit_plugin, 0, 0, 0, finalize_encryption_plugin, 0, finalize_audit_plugin, 0, 0, 0, finalize_encryption_plugin, 0,
0, // FUNCTION 0 // FUNCTION
Plugin_function_collection::deinit_plugin
}; };
/* /*
...@@ -140,7 +136,6 @@ static int plugin_type_initialization_order[MYSQL_MAX_PLUGIN_TYPE_NUM]= ...@@ -140,7 +136,6 @@ static int plugin_type_initialization_order[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MariaDB_ENCRYPTION_PLUGIN, MariaDB_ENCRYPTION_PLUGIN,
MariaDB_DATA_TYPE_PLUGIN, MariaDB_DATA_TYPE_PLUGIN,
MariaDB_FUNCTION_PLUGIN, MariaDB_FUNCTION_PLUGIN,
MariaDB_FUNCTION_COLLECTION_PLUGIN,
MYSQL_STORAGE_ENGINE_PLUGIN, MYSQL_STORAGE_ENGINE_PLUGIN,
MYSQL_INFORMATION_SCHEMA_PLUGIN, MYSQL_INFORMATION_SCHEMA_PLUGIN,
MYSQL_FTPARSER_PLUGIN, MYSQL_FTPARSER_PLUGIN,
...@@ -184,8 +179,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= ...@@ -184,8 +179,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION, MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION,
MariaDB_ENCRYPTION_INTERFACE_VERSION, MariaDB_ENCRYPTION_INTERFACE_VERSION,
MariaDB_DATA_TYPE_INTERFACE_VERSION, MariaDB_DATA_TYPE_INTERFACE_VERSION,
MariaDB_FUNCTION_INTERFACE_VERSION, MariaDB_FUNCTION_INTERFACE_VERSION
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION
}; };
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ {
...@@ -200,8 +194,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= ...@@ -200,8 +194,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION, MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION,
MariaDB_ENCRYPTION_INTERFACE_VERSION, MariaDB_ENCRYPTION_INTERFACE_VERSION,
MariaDB_DATA_TYPE_INTERFACE_VERSION, MariaDB_DATA_TYPE_INTERFACE_VERSION,
MariaDB_FUNCTION_INTERFACE_VERSION, MariaDB_FUNCTION_INTERFACE_VERSION
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION
}; };
static struct static struct
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment