Commit 5a052ab6 authored by Alexander Barkov's avatar Alexander Barkov

Part1: MDEV-20837 Add MariaDB_FUNCTION_PLUGIN

- Defining MariaDB_FUNCTION_PLUGIN
- Changing the code in /plugins/type_inet/ and /plugins/type_test/
  to use MariaDB_FUNCTION_PLUGIN instead of MariaDB_FUNCTION_COLLECTION_PLUGIN.
- Changing maturity for the INET6 data type plugin from experimental to alpha.
parent 22b645ef
......@@ -46,6 +46,7 @@ IF(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" AND RUN_ABI_CHECK)
${CMAKE_SOURCE_DIR}/include/mysql/plugin_password_validation.h
${CMAKE_SOURCE_DIR}/include/mysql/plugin_encryption.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_collection.h
)
......
......@@ -90,13 +90,14 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_AUDIT_PLUGIN 5
#define MYSQL_REPLICATION_PLUGIN 6
#define MYSQL_AUTHENTICATION_PLUGIN 7
#define MYSQL_MAX_PLUGIN_TYPE_NUM 12 /* The number of plugin types */
#define MYSQL_MAX_PLUGIN_TYPE_NUM 13 /* The number of plugin types */
/* MariaDB plugin types */
#define MariaDB_PASSWORD_VALIDATION_PLUGIN 8
#define MariaDB_ENCRYPTION_PLUGIN 9
#define MariaDB_DATA_TYPE_PLUGIN 10
#define MariaDB_FUNCTION_COLLECTION_PLUGIN 11
#define MariaDB_FUNCTION_PLUGIN 11
#define MariaDB_FUNCTION_COLLECTION_PLUGIN 12
/* We use the following strings to define licenses for plugins */
#define PLUGIN_LICENSE_PROPRIETARY 0
......
#ifndef MARIADB_PLUGIN_FUNCTION_INCLUDED
#define MARIADB_PLUGIN_FUNCTION_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
Function Plugin API.
This file defines the API for server plugins that manage functions.
*/
#ifdef __cplusplus
#include <mysql/plugin.h>
/*
API for function plugins. (MariaDB_FUNCTION_PLUGIN)
*/
#define MariaDB_FUNCTION_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
class Plugin_function
{
int m_interface_version;
Create_func *m_builder;
public:
Plugin_function(Create_func *builder)
:m_interface_version(MariaDB_FUNCTION_INTERFACE_VERSION),
m_builder(builder)
{ }
Create_func *create_func()
{
return m_builder;
}
};
#endif /* __cplusplus */
#endif /* MARIADB_PLUGIN_FUNCTION_INCLUDED */
This diff is collapsed.
......@@ -9,14 +9,14 @@ PLUGIN_LICENSE,
PLUGIN_MATURITY,
PLUGIN_AUTH_VERSION
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_TYPE='FUNCTION COLLECTION'
AND PLUGIN_NAME='func_test';
PLUGIN_NAME func_test
WHERE PLUGIN_TYPE='FUNCTION'
AND PLUGIN_NAME='sysconst_test';
PLUGIN_NAME sysconst_test
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION COLLECTION
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function collection test
PLUGIN_DESCRIPTION Function SYSCONST_TEST()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Experimental
PLUGIN_AUTH_VERSION 1.0
......
......@@ -14,8 +14,8 @@ SELECT
PLUGIN_MATURITY,
PLUGIN_AUTH_VERSION
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_TYPE='FUNCTION COLLECTION'
AND PLUGIN_NAME='func_test';
WHERE PLUGIN_TYPE='FUNCTION'
AND PLUGIN_NAME='sysconst_test';
--horizontal_results
......
......@@ -19,7 +19,7 @@
#include <my_global.h>
#include <sql_class.h>
#include <mysql/plugin_function_collection.h>
#include <mysql/plugin_function.h>
class Item_func_sysconst_test :public Item_func_sysconst
{
......@@ -64,26 +64,18 @@ Item* Create_func_sysconst_test::create_builder(THD *thd)
#define BUILDER(F) & F::s_singleton
static Native_func_registry func_array[] =
{
{{STRING_WITH_LEN("SYSCONST_TEST")}, BUILDER(Create_func_sysconst_test)}
};
static Plugin_function_collection
plugin_descriptor_function_collection_test(
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION,
Native_func_registry_array(func_array, array_elements(func_array)));
static Plugin_function
plugin_descriptor_function_sysconst_test(BUILDER(Create_func_sysconst_test));
/*************************************************************************/
maria_declare_plugin(type_test)
{
MariaDB_FUNCTION_COLLECTION_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_function_collection_test, // pointer to type-specific plugin descriptor
"func_test", // plugin name
MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_function_sysconst_test, // pointer to type-specific plugin descriptor
"sysconst_test", // plugin name
"MariaDB Corporation", // plugin author
"Function collection test", // the plugin description
"Function SYSCONST_TEST()", // the plugin description
PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h)
0, // Pointer to plugin initialization function
0, // Pointer to plugin deinitialization function
......
......@@ -5,6 +5,7 @@
# MDEV-20768 Turn INET functions into a function collection plugin
#
SELECT
'----' AS `----`,
PLUGIN_NAME,
PLUGIN_VERSION,
PLUGIN_STATUS,
......@@ -15,16 +16,96 @@ PLUGIN_LICENSE,
PLUGIN_MATURITY,
PLUGIN_AUTH_VERSION
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_TYPE='FUNCTION COLLECTION'
AND PLUGIN_NAME='func_inet';
PLUGIN_NAME func_inet
WHERE PLUGIN_TYPE='FUNCTION'
AND PLUGIN_NAME IN
('inet_aton',
'inet_ntoa',
'inet6_aton',
'inet6_ntoa',
'is_ipv4',
'is_ipv6',
'is_ipv4_compat',
'is_ipv4_mapped')
ORDER BY PLUGIN_NAME;
---- ----
PLUGIN_NAME inet6_aton
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION COLLECTION
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function collection test
PLUGIN_DESCRIPTION Function INET6_ATON()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Experimental
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME inet6_ntoa
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function INET6_NTOA()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME inet_aton
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function INET_ATON()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME inet_ntoa
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function INET_NTOA()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME is_ipv4
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function IS_IPV4()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME is_ipv4_compat
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function IS_IPV4_COMPAT()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME is_ipv4_mapped
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function IS_IPV4_MAPPED()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
---- ----
PLUGIN_NAME is_ipv6
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function IS_IPV6()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
#
# End of 10.5 tests
......
......@@ -8,6 +8,7 @@
--vertical_results
SELECT
'----' AS `----`,
PLUGIN_NAME,
PLUGIN_VERSION,
PLUGIN_STATUS,
......@@ -18,8 +19,17 @@ SELECT
PLUGIN_MATURITY,
PLUGIN_AUTH_VERSION
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_TYPE='FUNCTION COLLECTION'
AND PLUGIN_NAME='func_inet';
WHERE PLUGIN_TYPE='FUNCTION'
AND PLUGIN_NAME IN
('inet_aton',
'inet_ntoa',
'inet6_aton',
'inet6_ntoa',
'is_ipv4',
'is_ipv6',
'is_ipv4_compat',
'is_ipv4_mapped')
ORDER BY PLUGIN_NAME;
--horizontal_results
--echo #
......
......@@ -22,9 +22,9 @@ PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE DATA TYPE
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Data type TEST_INT8
PLUGIN_DESCRIPTION Data type INET6
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Experimental
PLUGIN_MATURITY Alpha
PLUGIN_AUTH_VERSION 1.0
#
# End of 10.5 tests
......
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include "sp.h"
#include "sql_time.h"
#include "sql_type_geom.h"
#include <mysql/plugin_function.h>
#include <mysql/plugin_function_collection.h>
......@@ -5710,6 +5711,24 @@ void item_create_cleanup()
DBUG_VOID_RETURN;
}
static Create_func *
function_plugin_find_native_function_builder(THD *thd, const LEX_CSTRING &name)
{
plugin_ref plugin;
if ((plugin= my_plugin_lock_by_name(thd, &name, MariaDB_FUNCTION_PLUGIN)))
{
Create_func *builder=
reinterpret_cast<Plugin_function*>(plugin_decl(plugin)->info)->
create_func();
// TODO: MDEV-20846 Add proper unlocking for MariaDB_FUNCTION_PLUGIN
plugin_unlock(thd, plugin);
return builder;
}
return NULL;
}
Create_func *
find_native_function_builder(THD *thd, const LEX_CSTRING *name)
{
......@@ -5724,6 +5743,9 @@ find_native_function_builder(THD *thd, const LEX_CSTRING *name)
if (func && (builder= func->builder))
return builder;
if ((builder= function_plugin_find_native_function_builder(thd, *name)))
return builder;
if ((builder= Plugin_find_native_func_builder_param(*name).find(thd)))
return builder;
......
......@@ -39,6 +39,7 @@
#include <mysql/plugin_password_validation.h>
#include <mysql/plugin_encryption.h>
#include <mysql/plugin_data_type.h>
#include <mysql/plugin_function.h>
#include <mysql/plugin_function_collection.h>
#include "sql_plugin_compat.h"
......@@ -94,6 +95,7 @@ const LEX_CSTRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{ STRING_WITH_LEN("PASSWORD VALIDATION") },
{ STRING_WITH_LEN("ENCRYPTION") },
{ STRING_WITH_LEN("DATA TYPE") },
{ STRING_WITH_LEN("FUNCTION") },
{ STRING_WITH_LEN("FUNCTION COLLECTION") }
};
......@@ -115,6 +117,7 @@ plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0, ha_initialize_handlerton, 0, 0,initialize_schema_table,
initialize_audit_plugin, 0, 0, 0, initialize_encryption_plugin, 0,
0, // FUNCTION
Plugin_function_collection::init_plugin
};
......@@ -122,6 +125,7 @@ plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
0, ha_finalize_handlerton, 0, 0, finalize_schema_table,
finalize_audit_plugin, 0, 0, 0, finalize_encryption_plugin, 0,
0, // FUNCTION
Plugin_function_collection::deinit_plugin
};
......@@ -135,6 +139,7 @@ static int plugin_type_initialization_order[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MYSQL_DAEMON_PLUGIN,
MariaDB_ENCRYPTION_PLUGIN,
MariaDB_DATA_TYPE_PLUGIN,
MariaDB_FUNCTION_PLUGIN,
MariaDB_FUNCTION_COLLECTION_PLUGIN,
MYSQL_STORAGE_ENGINE_PLUGIN,
MYSQL_INFORMATION_SCHEMA_PLUGIN,
......@@ -179,6 +184,7 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION,
MariaDB_ENCRYPTION_INTERFACE_VERSION,
MariaDB_DATA_TYPE_INTERFACE_VERSION,
MariaDB_FUNCTION_INTERFACE_VERSION,
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION
};
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
......@@ -194,6 +200,7 @@ static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
MariaDB_PASSWORD_VALIDATION_INTERFACE_VERSION,
MariaDB_ENCRYPTION_INTERFACE_VERSION,
MariaDB_DATA_TYPE_INTERFACE_VERSION,
MariaDB_FUNCTION_INTERFACE_VERSION,
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION
};
......
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