Commit 6afb2a37 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-20768 Turn INET functions into a function collection plugin

parent e0117f11
......@@ -116,9 +116,7 @@ SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc
../sql/sql_mode.cc
../sql/sql_type_json.cc
../sql/sql_type_geom.cc
../sql/sql_type_inet.cc
../sql/table_cache.cc ../sql/mf_iocache_encr.cc
../sql/item_inetfunc.cc
../sql/wsrep_dummy.cc ../sql/encryption.cc
../sql/item_windowfunc.cc ../sql/sql_window.cc
../sql/sql_cte.cc
......
......@@ -203,6 +203,7 @@ my @DEFAULT_SUITES= qw(
rpl-
sys_vars-
sql_sequence-
type_inet-
unit-
vcol-
versioning-
......
# Copyright (c) 2016-2019, MariaDB corporation. All rights reserved.
#
# 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 Street, Fifth Floor, Boston, MA 02110-1335 USA
MYSQL_ADD_PLUGIN(type_inet
plugin.cc item_inetfunc.cc sql_type_inet.cc
MANDATORY RECOMPILE_FOR_EMBEDDED)
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014 MariaDB Foundation
Copyright (c) 2019 MariaDB Corporation
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
......@@ -14,6 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#define MYSQL_SERVER
#include "mariadb.h"
#include "item_inetfunc.h"
#include "sql_type_inet.h"
......
......@@ -3,6 +3,7 @@
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014 MariaDB Foundation
Copyright (c) 2019 MariaDB Corporation
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
......
#
# Start of 10.5 tests
#
#
# MDEV-20768 Turn INET functions into a function collection plugin
#
SELECT
PLUGIN_NAME,
PLUGIN_VERSION,
PLUGIN_STATUS,
PLUGIN_TYPE,
PLUGIN_AUTHOR,
PLUGIN_DESCRIPTION,
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
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION COLLECTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function collection test
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Experimental
PLUGIN_AUTH_VERSION 1.0
#
# End of 10.5 tests
#
--echo #
--echo # Start of 10.5 tests
--echo #
--echo #
--echo # MDEV-20768 Turn INET functions into a function collection plugin
--echo #
--vertical_results
SELECT
PLUGIN_NAME,
PLUGIN_VERSION,
PLUGIN_STATUS,
PLUGIN_TYPE,
PLUGIN_AUTHOR,
PLUGIN_DESCRIPTION,
PLUGIN_LICENSE,
PLUGIN_MATURITY,
PLUGIN_AUTH_VERSION
FROM INFORMATION_SCHEMA.PLUGINS
WHERE PLUGIN_TYPE='FUNCTION COLLECTION'
AND PLUGIN_NAME='func_inet';
--horizontal_results
--echo #
--echo # End of 10.5 tests
--echo #
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014 MariaDB Foundation
Copyright (c) 2019 MariaDB Corporation
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 */
#define MYSQL_SERVER
#include "mariadb.h"
#include "sql_class.h"
#include "sql_type_inet.h"
#include "item_inetfunc.h"
#include <mysql/plugin_data_type.h>
#include <mysql/plugin_function_collection.h>
/*************************************************************************/
class Create_func_inet_ntoa : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_inet_ntoa(thd, arg1);
}
static Create_func_inet_ntoa s_singleton;
protected:
Create_func_inet_ntoa() {}
virtual ~Create_func_inet_ntoa() {}
};
class Create_func_inet_aton : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_inet_aton(thd, arg1);
}
static Create_func_inet_aton s_singleton;
protected:
Create_func_inet_aton() {}
virtual ~Create_func_inet_aton() {}
};
class Create_func_inet6_aton : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_inet6_aton(thd, arg1);
}
static Create_func_inet6_aton s_singleton;
protected:
Create_func_inet6_aton() {}
virtual ~Create_func_inet6_aton() {}
};
class Create_func_inet6_ntoa : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_inet6_ntoa(thd, arg1);
}
static Create_func_inet6_ntoa s_singleton;
protected:
Create_func_inet6_ntoa() {}
virtual ~Create_func_inet6_ntoa() {}
};
class Create_func_is_ipv4 : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_is_ipv4(thd, arg1);
}
static Create_func_is_ipv4 s_singleton;
protected:
Create_func_is_ipv4() {}
virtual ~Create_func_is_ipv4() {}
};
class Create_func_is_ipv6 : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_is_ipv6(thd, arg1);
}
static Create_func_is_ipv6 s_singleton;
protected:
Create_func_is_ipv6() {}
virtual ~Create_func_is_ipv6() {}
};
class Create_func_is_ipv4_compat : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_is_ipv4_compat(thd, arg1);
}
static Create_func_is_ipv4_compat s_singleton;
protected:
Create_func_is_ipv4_compat() {}
virtual ~Create_func_is_ipv4_compat() {}
};
class Create_func_is_ipv4_mapped : public Create_func_arg1
{
public:
Item *create_1_arg(THD *thd, Item *arg1) override
{
return new (thd->mem_root) Item_func_is_ipv4_mapped(thd, arg1);
}
static Create_func_is_ipv4_mapped s_singleton;
protected:
Create_func_is_ipv4_mapped() {}
virtual ~Create_func_is_ipv4_mapped() {}
};
Create_func_inet_ntoa Create_func_inet_ntoa::s_singleton;
Create_func_inet6_aton Create_func_inet6_aton::s_singleton;
Create_func_inet6_ntoa Create_func_inet6_ntoa::s_singleton;
Create_func_inet_aton Create_func_inet_aton::s_singleton;
Create_func_is_ipv4 Create_func_is_ipv4::s_singleton;
Create_func_is_ipv6 Create_func_is_ipv6::s_singleton;
Create_func_is_ipv4_compat Create_func_is_ipv4_compat::s_singleton;
Create_func_is_ipv4_mapped Create_func_is_ipv4_mapped::s_singleton;
#define BUILDER(F) & F::s_singleton
static Native_func_registry func_array[] =
{
{{STRING_WITH_LEN("INET_ATON")}, BUILDER(Create_func_inet_aton)},
{{STRING_WITH_LEN("INET_NTOA")}, BUILDER(Create_func_inet_ntoa)},
{{STRING_WITH_LEN("INET6_ATON")}, BUILDER(Create_func_inet6_aton)},
{{STRING_WITH_LEN("INET6_NTOA")}, BUILDER(Create_func_inet6_ntoa)},
{{STRING_WITH_LEN("IS_IPV4")}, BUILDER(Create_func_is_ipv4)},
{{STRING_WITH_LEN("IS_IPV6")}, BUILDER(Create_func_is_ipv6)},
{{STRING_WITH_LEN("IS_IPV4_COMPAT")}, BUILDER(Create_func_is_ipv4_compat)},
{{STRING_WITH_LEN("IS_IPV4_MAPPED")}, BUILDER(Create_func_is_ipv4_mapped)}
};
static Plugin_function_collection
plugin_descriptor_function_collection_inet(
MariaDB_FUNCTION_COLLECTION_INTERFACE_VERSION,
Native_func_registry_array(func_array, array_elements(func_array)));
/*************************************************************************/
maria_declare_plugin(type_inet)
{
MariaDB_FUNCTION_COLLECTION_PLUGIN, // the plugin type (see include/mysql/plugin.h)
&plugin_descriptor_function_collection_inet, // pointer to type-specific plugin descriptor
"func_inet", // plugin name
"MariaDB Corporation", // plugin author
"Function collection 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
0x0100, // Numeric version 0xAABB means AA.BB veriosn
NULL, // Status variables
NULL, // System variables
"1.0", // String version representation
MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity(see include/mysql/plugin.h)*/
}
maria_declare_plugin_end;
/* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
Copyright (c) 2014 MariaDB Foundation
Copyright (c) 2019 MariaDB Corporation
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
......@@ -14,6 +15,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
#define MYSQL_SERVER
#include "mariadb.h"
#include "my_net.h"
#include "sql_class.h" // THD, SORT_FIELD_ATTR
......
......@@ -119,7 +119,7 @@ SET (SQL_SOURCE
sql_profile.cc event_parse_data.cc sql_alter.cc
sql_signal.cc mdl.cc sql_admin.cc
transaction.cc sys_vars.cc sql_truncate.cc datadict.cc
sql_reload.cc item_inetfunc.cc
sql_reload.cc
# added in MariaDB:
sql_explain.cc
......@@ -137,7 +137,6 @@ SET (SQL_SOURCE
semisync_master_ack_receiver.cc
sql_type.cc sql_mode.cc sql_type_json.cc
sql_type_geom.cc
sql_type_inet.cc
item_windowfunc.cc sql_window.cc
sql_cte.cc
item_vers.cc
......
......@@ -33,7 +33,6 @@
#include "set_var.h"
#include "sp_head.h"
#include "sp.h"
#include "item_inetfunc.h"
#include "sql_time.h"
#include "sql_type_geom.h"
#include <mysql/plugin_function_collection.h>
......@@ -92,7 +91,8 @@ class Plugin_find_native_func_builder_param
bool find_native_function_builder(THD *thd,
const Plugin_function_collection *pfc)
{
return ((builder= pfc->find_native_function_builder(thd, name))) == NULL;
// 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)
{
......@@ -111,9 +111,9 @@ class Plugin_find_native_func_builder_param
{ }
Create_func *find(THD *thd)
{
if (plugin_foreach(thd,
Plugin_find_native_func_builder_param::find_in_plugin,
MariaDB_FUNCTION_COLLECTION_PLUGIN, this))
if (!plugin_foreach(thd,
Plugin_find_native_func_builder_param::find_in_plugin,
MariaDB_FUNCTION_COLLECTION_PLUGIN, this))
return NULL;
return builder;
}
......@@ -907,110 +907,6 @@ class Create_func_ifnull : public Create_func_arg2
};
class Create_func_inet_ntoa : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_inet_ntoa s_singleton;
protected:
Create_func_inet_ntoa() {}
virtual ~Create_func_inet_ntoa() {}
};
class Create_func_inet_aton : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_inet_aton s_singleton;
protected:
Create_func_inet_aton() {}
virtual ~Create_func_inet_aton() {}
};
class Create_func_inet6_aton : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_inet6_aton s_singleton;
protected:
Create_func_inet6_aton() {}
virtual ~Create_func_inet6_aton() {}
};
class Create_func_inet6_ntoa : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_inet6_ntoa s_singleton;
protected:
Create_func_inet6_ntoa() {}
virtual ~Create_func_inet6_ntoa() {}
};
class Create_func_is_ipv4 : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_is_ipv4 s_singleton;
protected:
Create_func_is_ipv4() {}
virtual ~Create_func_is_ipv4() {}
};
class Create_func_is_ipv6 : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_is_ipv6 s_singleton;
protected:
Create_func_is_ipv6() {}
virtual ~Create_func_is_ipv6() {}
};
class Create_func_is_ipv4_compat : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_is_ipv4_compat s_singleton;
protected:
Create_func_is_ipv4_compat() {}
virtual ~Create_func_is_ipv4_compat() {}
};
class Create_func_is_ipv4_mapped : public Create_func_arg1
{
public:
virtual Item *create_1_arg(THD *thd, Item *arg1);
static Create_func_is_ipv4_mapped s_singleton;
protected:
Create_func_is_ipv4_mapped() {}
virtual ~Create_func_is_ipv4_mapped() {}
};
class Create_func_instr : public Create_func_arg2
{
public:
......@@ -3685,78 +3581,6 @@ Create_func_ifnull::create_2_arg(THD *thd, Item *arg1, Item *arg2)
}
Create_func_inet_ntoa Create_func_inet_ntoa::s_singleton;
Item*
Create_func_inet_ntoa::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_inet_ntoa(thd, arg1);
}
Create_func_inet6_aton Create_func_inet6_aton::s_singleton;
Item*
Create_func_inet6_aton::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_inet6_aton(thd, arg1);
}
Create_func_inet6_ntoa Create_func_inet6_ntoa::s_singleton;
Item*
Create_func_inet6_ntoa::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_inet6_ntoa(thd, arg1);
}
Create_func_inet_aton Create_func_inet_aton::s_singleton;
Item*
Create_func_inet_aton::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_inet_aton(thd, arg1);
}
Create_func_is_ipv4 Create_func_is_ipv4::s_singleton;
Item*
Create_func_is_ipv4::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_is_ipv4(thd, arg1);
}
Create_func_is_ipv6 Create_func_is_ipv6::s_singleton;
Item*
Create_func_is_ipv6::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_is_ipv6(thd, arg1);
}
Create_func_is_ipv4_compat Create_func_is_ipv4_compat::s_singleton;
Item*
Create_func_is_ipv4_compat::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_is_ipv4_compat(thd, arg1);
}
Create_func_is_ipv4_mapped Create_func_is_ipv4_mapped::s_singleton;
Item*
Create_func_is_ipv4_mapped::create_1_arg(THD *thd, Item *arg1)
{
return new (thd->mem_root) Item_func_is_ipv4_mapped(thd, arg1);
}
Create_func_instr Create_func_instr::s_singleton;
Item*
......@@ -5681,14 +5505,6 @@ static Native_func_registry func_array[] =
{ { STRING_WITH_LEN("GREATEST") }, BUILDER(Create_func_greatest)},
{ { STRING_WITH_LEN("HEX") }, BUILDER(Create_func_hex)},
{ { STRING_WITH_LEN("IFNULL") }, BUILDER(Create_func_ifnull)},
{ { STRING_WITH_LEN("INET_ATON") }, BUILDER(Create_func_inet_aton)},
{ { STRING_WITH_LEN("INET_NTOA") }, BUILDER(Create_func_inet_ntoa)},
{ { STRING_WITH_LEN("INET6_ATON") }, BUILDER(Create_func_inet6_aton)},
{ { STRING_WITH_LEN("INET6_NTOA") }, BUILDER(Create_func_inet6_ntoa)},
{ { STRING_WITH_LEN("IS_IPV4") }, BUILDER(Create_func_is_ipv4)},
{ { STRING_WITH_LEN("IS_IPV6") }, BUILDER(Create_func_is_ipv6)},
{ { STRING_WITH_LEN("IS_IPV4_COMPAT") }, BUILDER(Create_func_is_ipv4_compat)},
{ { STRING_WITH_LEN("IS_IPV4_MAPPED") }, BUILDER(Create_func_is_ipv4_mapped)},
{ { STRING_WITH_LEN("INSTR") }, BUILDER(Create_func_instr)},
{ { STRING_WITH_LEN("ISNULL") }, BUILDER(Create_func_isnull)},
{ { STRING_WITH_LEN("IS_FREE_LOCK") }, BUILDER(Create_func_is_free_lock)},
......
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