diff options
Diffstat (limited to 'plugin')
103 files changed, 14056 insertions, 287 deletions
diff --git a/plugin/auth_gssapi/CMakeLists.txt b/plugin/auth_gssapi/CMakeLists.txt index 3ac89404302..1bf727ddf2e 100644 --- a/plugin/auth_gssapi/CMakeLists.txt +++ b/plugin/auth_gssapi/CMakeLists.txt @@ -32,6 +32,7 @@ ELSE() ENDIF() SET(CMAKE_REQUIRED_INCLUDES ${GSSAPI_INCS}) SET(CMAKE_REQUIRED_LIBRARIES ${GSSAPI_LIBS}) + SET(CMAKE_REQUIRED_FLAGS "-Werror -Wall") INCLUDE(CheckCXXSymbolExists) CHECK_CXX_SYMBOL_EXISTS(krb5_xfree "krb5.h" HAVE_KRB5_XFREE) IF(HAVE_KRB5_XFREE) diff --git a/plugin/auth_gssapi/cmake/FindGSSAPI.cmake b/plugin/auth_gssapi/cmake/FindGSSAPI.cmake index 67309eed1ee..78d1ec8409b 100644 --- a/plugin/auth_gssapi/cmake/FindGSSAPI.cmake +++ b/plugin/auth_gssapi/cmake/FindGSSAPI.cmake @@ -58,7 +58,11 @@ else(GSSAPI_LIBS AND GSSAPI_FLAVOR) message(STATUS "GSSAPI configure check failed.") set(HAVE_KRB5_GSSAPI FALSE) endif(_return_VALUE) - + IF(CMAKE_SYSTEM_NAME MATCHES AIX) + string(REGEX REPLACE "-Wl[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}") + string(REGEX REPLACE "-L[A-Za-z0-9_/,:-]*[ $]?" "" GSSAPI_LIBS "${GSSAPI_LIBS}") + ENDIF() + exec_program(${KRB5_CONFIG} ARGS --cflags gssapi RETURN_VALUE _return_VALUE OUTPUT_VARIABLE GSSAPI_INCS) string(REGEX REPLACE "(\r?\n)+$" "" GSSAPI_INCS "${GSSAPI_INCS}") string(REGEX REPLACE " *-I" ";" GSSAPI_INCS "${GSSAPI_INCS}") diff --git a/plugin/auth_gssapi/gssapi_server.cc b/plugin/auth_gssapi/gssapi_server.cc index 1d3cbb7a130..db7bda9a6b4 100644 --- a/plugin/auth_gssapi/gssapi_server.cc +++ b/plugin/auth_gssapi/gssapi_server.cc @@ -158,8 +158,8 @@ int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) gss_buffer_desc client_name_buf, input, output; char *client_name_str; const char *user= 0; - size_t userlen; - int use_full_name; + size_t userlen= 0; + int use_full_name= 0; /* server acquires credential */ major= gss_acquire_cred(&minor, service_name, GSS_C_INDEFINITE, @@ -244,7 +244,7 @@ int auth_server(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *auth_info) && userlen < client_name_buf.length && client_name_str[userlen] == '@')) { - if (strncmp(client_name_str, user, userlen) == 0) + if (user && strncmp(client_name_str, user, userlen) == 0) { rc= CR_OK; } diff --git a/plugin/auth_gssapi/server_plugin.cc b/plugin/auth_gssapi/server_plugin.cc index bce6a812d12..4fdad2de4b8 100644 --- a/plugin/auth_gssapi/server_plugin.cc +++ b/plugin/auth_gssapi/server_plugin.cc @@ -90,6 +90,7 @@ static int deinitialize_plugin(void *unused) return plugin_deinit(); } +#ifdef PLUGIN_GSSAPI /* system variable */ static MYSQL_SYSVAR_STR(keytab_path, srv_keytab_path, PLUGIN_VAR_RQCMDARG|PLUGIN_VAR_READONLY, @@ -97,6 +98,8 @@ static MYSQL_SYSVAR_STR(keytab_path, srv_keytab_path, NULL, NULL, ""); +#endif + static MYSQL_SYSVAR_STR(principal_name, srv_principal_name, PLUGIN_VAR_RQCMDARG|PLUGIN_VAR_READONLY, "GSSAPI target name - service principal name for Kerberos authentication.", diff --git a/plugin/auth_pam/testing/pam_mariadb_mtr.c b/plugin/auth_pam/testing/pam_mariadb_mtr.c index 2075d5fdbf3..f61a8da7682 100644 --- a/plugin/auth_pam/testing/pam_mariadb_mtr.c +++ b/plugin/auth_pam/testing/pam_mariadb_mtr.c @@ -22,9 +22,9 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags __attribute__((unused)), struct pam_response *resp = 0; int pam_err, retval = PAM_SYSTEM_ERR; struct pam_message msg[N] = { - { PAM_TEXT_INFO, "Challenge input first." }, - { PAM_PROMPT_ECHO_OFF, "Enter:" }, - { PAM_ERROR_MSG, "Now, the magic number!" } + { PAM_TEXT_INFO, (char*)"Challenge input first." }, + { PAM_PROMPT_ECHO_OFF, (char*)"Enter:" }, + { PAM_ERROR_MSG, (char*)"Now, the magic number!" } }; const struct pam_message *msgp[N] = { msg, msg+1, msg+2 }; char *r1 = 0, *r2 = 0; @@ -46,7 +46,7 @@ int pam_sm_authenticate(pam_handle_t *pamh, int flags __attribute__((unused)), { free(resp); msg[0].msg_style = PAM_PROMPT_ECHO_ON; - msg[0].msg = "PIN:"; + msg[0].msg = (char*)"PIN:"; pam_err = (*conv->conv)(1, msgp, &resp, conv->appdata_ptr); if (pam_err != PAM_SUCCESS || !resp || !((r2= resp[0].resp))) diff --git a/plugin/auth_socket/CMakeLists.txt b/plugin/auth_socket/CMakeLists.txt index 5a59520a3e4..a3f42d416a7 100644 --- a/plugin/auth_socket/CMakeLists.txt +++ b/plugin/auth_socket/CMakeLists.txt @@ -57,12 +57,53 @@ IF (HAVE_XUCRED) SET(ok 1) ELSE() +# illumos, is that you? +CHECK_CXX_SOURCE_COMPILES( +"#include <ucred.h> +int main() { + ucred_t *cred = NULL; + getpeerucred(0, &cred); + }" HAVE_GETPEERUCRED) + +# Depending on the flags set in the compilation environment, illumos will have +# either the POSIX.1c draft 6 or POSIX.1c final implementation of getpwuid_r() +# Check that defining _POSIX_PTHREAD_SEMANTICS provides the final standard +# version. + +CHECK_CXX_SOURCE_COMPILES( +"#define _POSIX_PTHREAD_SEMANTICS +#include <pwd.h> +int main() { + getpwuid_r(0, NULL, NULL, 0, NULL); + }" HAVE_GETPWUID_POSIX_FINAL) + +IF (HAVE_GETPEERUCRED AND HAVE_GETPWUID_POSIX_FINAL) + ADD_DEFINITIONS(-DHAVE_GETPEERUCRED) + ADD_DEFINITIONS(-D_POSIX_PTHREAD_SEMANTICS) + SET(ok 1) +ELSE() + +# AIX also! +CHECK_CXX_SOURCE_COMPILES( +"#include <sys/socket.h> +int main() { + struct peercred_struct cred; + getsockopt(0, SOL_SOCKET, SO_PEERID, &cred, 0); + }" HAVE_PEERCRED_STRUCT) + +IF (HAVE_PEERCRED_STRUCT) + ADD_DEFINITIONS(-DHAVE_PEERCRED_STRUCT) + SET(ok 1) +ELSE() + # Who else? Anyone? # C'mon, show your creativity, be different! ifdef's are fun, aren't they? ENDIF() ENDIF() ENDIF() +ENDIF() +ENDIF() IF(ok) MYSQL_ADD_PLUGIN(auth_socket auth_socket.c DEFAULT) diff --git a/plugin/auth_socket/auth_socket.c b/plugin/auth_socket/auth_socket.c index 46eae517cb8..c20defed872 100644 --- a/plugin/auth_socket/auth_socket.c +++ b/plugin/auth_socket/auth_socket.c @@ -47,6 +47,15 @@ #define uid cr_uid #define ucred xucred +#elif defined HAVE_GETPEERUCRED +#include <ucred.h> + +#elif defined HAVE_PEERCRED_STRUCT +#define level SOL_SOCKET +#define SO_PEERCRED SO_PEERID +#define uid euid +#define ucred peercred_struct + #else #error impossible #endif @@ -64,10 +73,15 @@ static int socket_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) { unsigned char *pkt; MYSQL_PLUGIN_VIO_INFO vio_info; +#ifdef HAVE_GETPEERUCRED + ucred_t *cred = NULL; +#else struct ucred cred; socklen_t cred_len= sizeof(cred); +#endif struct passwd pwd_buf, *pwd; char buf[1024]; + uid_t u; /* no user name yet ? read the client handshake packet with the user name */ if (info->user_name == 0) @@ -83,14 +97,23 @@ static int socket_auth(MYSQL_PLUGIN_VIO *vio, MYSQL_SERVER_AUTH_INFO *info) return CR_ERROR; /* get the UID of the client process */ +#ifdef HAVE_GETPEERUCRED + if (getpeerucred(vio_info.socket, &cred) != 0) + return CR_ERROR; + u = ucred_geteuid(cred); + ucred_free(cred); +#else if (getsockopt(vio_info.socket, level, SO_PEERCRED, &cred, &cred_len)) return CR_ERROR; if (cred_len != sizeof(cred)) return CR_ERROR; + u = cred.uid; +#endif + /* and find the username for this uid */ - getpwuid_r(cred.uid, &pwd_buf, buf, sizeof(buf), &pwd); + getpwuid_r(u, &pwd_buf, buf, sizeof(buf), &pwd); if (pwd == NULL) return CR_ERROR; diff --git a/plugin/aws_key_management/aws_key_management_plugin.cc b/plugin/aws_key_management/aws_key_management_plugin.cc index e2182336aa6..7740c2eae60 100644 --- a/plugin/aws_key_management/aws_key_management_plugin.cc +++ b/plugin/aws_key_management/aws_key_management_plugin.cc @@ -81,6 +81,7 @@ static unsigned long key_spec; static unsigned long log_level; static int rotate_key; static int request_timeout; +static char* endpoint_url; #ifndef DBUG_OFF #define WITH_AWS_MOCK 1 @@ -233,6 +234,10 @@ static int aws_init() { clientConfiguration.region = region; } + if (endpoint_url && endpoint_url[0]) + { + clientConfiguration.endpointOverride = endpoint_url; + } if (request_timeout) { clientConfiguration.requestTimeoutMs= request_timeout; @@ -715,6 +720,11 @@ static MYSQL_SYSVAR_STR(region, region, "AWS region. For example us-east-1, or eu-central-1. If no value provided, SDK default is used.", NULL, NULL, ""); +static MYSQL_SYSVAR_STR(endpoint_url, endpoint_url, + PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, + "Used to override the default AWS API endpoint. If not set, the default will be used", + NULL, NULL, ""); + #if WITH_AWS_MOCK static MYSQL_SYSVAR_BOOL(mock, mock, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, @@ -729,6 +739,7 @@ static struct st_mysql_sys_var* settings[]= { MYSQL_SYSVAR(log_level), MYSQL_SYSVAR(request_timeout), MYSQL_SYSVAR(region), + MYSQL_SYSVAR(endpoint_url), #if WITH_AWS_MOCK MYSQL_SYSVAR(mock), #endif diff --git a/plugin/daemon_example/daemon_example.cc b/plugin/daemon_example/daemon_example.cc index 87f48a1fa69..50026e92be1 100644 --- a/plugin/daemon_example/daemon_example.cc +++ b/plugin/daemon_example/daemon_example.cc @@ -98,7 +98,7 @@ static int daemon_example_plugin_init(void *p __attribute__ ((unused))) struct st_plugin_int *plugin= (struct st_plugin_int *)p; con= (struct mysql_heartbeat_context *) - my_malloc(sizeof(struct mysql_heartbeat_context), MYF(0)); + my_malloc(PSI_NOT_INSTRUMENTED, sizeof(struct mysql_heartbeat_context), MYF(0)); fn_format(heartbeat_filename, "mysql-heartbeat", "", ".log", MY_REPLACE_EXT | MY_UNPACK_FILENAME); diff --git a/plugin/disks/information_schema_disks.cc b/plugin/disks/information_schema_disks.cc index bfae81eceac..15e26dad12a 100644 --- a/plugin/disks/information_schema_disks.cc +++ b/plugin/disks/information_schema_disks.cc @@ -30,7 +30,7 @@ #define HAVE_GETMNTENT #endif #include <sql_class.h> -#include <table.h> +#include <sql_i_s.h> #include <sql_acl.h> /* check_global_access() */ /* @@ -58,21 +58,23 @@ typedef struct statfs st_info; bool schema_table_store_record(THD *thd, TABLE *table); -namespace -{ struct st_mysql_information_schema disks_table_info = { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + +namespace Show { + ST_FIELD_INFO disks_table_fields[]= { - { "Disk", PATH_MAX, MYSQL_TYPE_STRING, 0, 0 ,0, 0 }, - { "Path", PATH_MAX, MYSQL_TYPE_STRING, 0, 0 ,0, 0 }, - { "Total", 32, MYSQL_TYPE_LONGLONG, 0, 0 ,0 ,0 }, // Total amount available - { "Used", 32, MYSQL_TYPE_LONGLONG, 0, 0 ,0 ,0 }, // Amount of space used - { "Available", 32, MYSQL_TYPE_LONGLONG, 0, 0 ,0 ,0 }, // Amount available to users other than root. - { 0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0 } + Column("Disk", Varchar(PATH_MAX), NOT_NULL), + Column("Path", Varchar(PATH_MAX), NOT_NULL), + Column("Total", SLonglong(32), NOT_NULL), // Total amount available + Column("Used", SLonglong(32), NOT_NULL), // Amount of space used + Column("Available", SLonglong(32), NOT_NULL), // Amount available to users other than root. + CEnd() }; + static int disks_table_add_row_stat( THD* pThd, TABLE* pTable, @@ -262,7 +264,7 @@ static int disks_table_deinit(void *ptr __attribute__((unused))) return 0; } -} +} // namespace Show extern "C" { @@ -275,8 +277,8 @@ maria_declare_plugin(disks) "Johan Wikman, Daniel Black", /* author */ "Disk space information", /* description */ PLUGIN_LICENSE_GPL, /* license type */ - disks_table_init, /* init function */ - disks_table_deinit, /* deinit function */ + Show::disks_table_init, /* init function */ + Show::disks_table_deinit, /* deinit function */ 0x0102, /* version = 1.2 */ NULL, /* no status variables */ NULL, /* no system variables */ diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index a7bc1d3d60e..3b2e95f1e13 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -67,9 +67,9 @@ ST_SCHEMA_TABLE *i_s_feedback; ///< table descriptor for our I_S table */ static ST_FIELD_INFO feedback_fields[] = { - {"VARIABLE_NAME", 255, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"VARIABLE_VALUE", 1024, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0} + Show::Column("VARIABLE_NAME", Show::Varchar(255), NOT_NULL), + Show::Column("VARIABLE_VALUE", Show::Varchar(1024), NOT_NULL), + Show::CEnd() }; static COND * const OOM= (COND*)1; @@ -94,8 +94,9 @@ static COND* make_cond(THD *thd, TABLE_LIST *tables, LEX_STRING *filter) Item_cond_or *res= NULL; /* A reference to this context will be stored in Item_field */ Name_resolution_context *nrc= new (thd->mem_root) Name_resolution_context; - const char *db= tables->db.str, *table= tables->alias.str; - LEX_CSTRING *field= &tables->table->field[0]->field_name; + LEX_CSTRING &db= tables->db; + LEX_CSTRING &table= tables->alias; + LEX_CSTRING &field= tables->table->field[0]->field_name; CHARSET_INFO *cs= &my_charset_latin1; if (!filter->str || !nrc) @@ -179,13 +180,12 @@ static LEX_STRING vars_filter[]= { {C_STRING_WITH_LEN("secure_auth")}, {C_STRING_WITH_LEN("slow_launch_time")}, {C_STRING_WITH_LEN("sql%")}, - {C_STRING_WITH_LEN("storage_engine")}, + {C_STRING_WITH_LEN("default_storage_engine")}, {C_STRING_WITH_LEN("sync_binlog")}, {C_STRING_WITH_LEN("table_definition_cache")}, {C_STRING_WITH_LEN("table_open_cache")}, {C_STRING_WITH_LEN("thread_handling")}, {C_STRING_WITH_LEN("time_zone")}, - {C_STRING_WITH_LEN("timed_mutexes")}, {C_STRING_WITH_LEN("version%")}, {0, 0} }; @@ -282,7 +282,7 @@ static int init(void *p) if (*s == ' ') url_count++; - urls= (Url **)my_malloc(url_count*sizeof(Url*), MYF(MY_WME)); + urls= (Url **)my_malloc(PSI_INSTRUMENT_ME, url_count*sizeof(Url*), MYF(MY_WME)); if (!urls) return 1; @@ -411,24 +411,6 @@ static struct st_mysql_information_schema feedback = } // namespace feedback -mysql_declare_plugin(feedback) -{ - MYSQL_INFORMATION_SCHEMA_PLUGIN, - &feedback::feedback, - "FEEDBACK", - "Sergei Golubchik", - "MariaDB User Feedback Plugin", - PLUGIN_LICENSE_GPL, - feedback::init, - feedback::free, - 0x0101, - NULL, - feedback::settings, - NULL, - 0 -} -mysql_declare_plugin_end; -#ifdef MARIA_PLUGIN_INTERFACE_VERSION maria_declare_plugin(feedback) { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -446,4 +428,3 @@ maria_declare_plugin(feedback) MariaDB_PLUGIN_MATURITY_STABLE } maria_declare_plugin_end; -#endif diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 3976c950541..73b1bc67e79 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -92,8 +92,7 @@ static int prepare_for_fill(TABLE_LIST *tables) thd->variables.pseudo_thread_id= thd->thread_id; server_threads.insert(thd); thd->thread_stack= (char*) &tables; - if (thd->store_globals()) - return 1; + thd->store_globals(); thd->mysys_var->current_cond= &sleep_condition; thd->mysys_var->current_mutex= &sleep_mutex; @@ -106,7 +105,7 @@ static int prepare_for_fill(TABLE_LIST *tables) thd->db= null_clex_str; thd->security_ctx->host_or_ip= ""; thd->security_ctx->db_access= DB_ACLS; - thd->security_ctx->master_access= ~NO_ACCESS; + thd->security_ctx->master_access= ALL_KNOWN_ACL; bzero((char*) &thd->net, sizeof(thd->net)); lex_start(thd); mysql_init_select(thd->lex); diff --git a/plugin/feedback/url_base.cc b/plugin/feedback/url_base.cc index 21661079c98..1ba21306bdf 100644 --- a/plugin/feedback/url_base.cc +++ b/plugin/feedback/url_base.cc @@ -27,7 +27,7 @@ Url* http_create(const char *url, size_t url_length); */ Url* Url::create(const char *url, size_t url_length) { - url= my_strndup(url, url_length, MYF(MY_WME)); + url= my_strndup(PSI_INSTRUMENT_ME, url, url_length, MYF(MY_WME)); if (!url) return NULL; @@ -88,8 +88,8 @@ int Url::parse_proxy_server(const char *proxy_server, size_t proxy_length, port->length= 2; } - host->str= my_strndup(host->str, host->length, MYF(MY_WME)); - port->str= my_strndup(port->str, port->length, MYF(MY_WME)); + host->str= my_strndup(PSI_INSTRUMENT_ME, host->str, host->length, MYF(MY_WME)); + port->str= my_strndup(PSI_INSTRUMENT_ME, port->str, port->length, MYF(MY_WME)); return 0; } diff --git a/plugin/feedback/url_http.cc b/plugin/feedback/url_http.cc index db05adebdd2..98116dd04f1 100644 --- a/plugin/feedback/url_http.cc +++ b/plugin/feedback/url_http.cc @@ -143,9 +143,9 @@ Url* http_create(const char *url, size_t url_length) if (!host.length || !port.length || path.str[0] != '/') return NULL; - host.str= my_strndup(host.str, host.length, MYF(MY_WME)); - port.str= my_strndup(port.str, port.length, MYF(MY_WME)); - path.str= my_strndup(path.str, path.length, MYF(MY_WME)); + host.str= my_strndup(PSI_INSTRUMENT_ME, host.str, host.length, MYF(MY_WME)); + port.str= my_strndup(PSI_INSTRUMENT_ME, port.str, port.length, MYF(MY_WME)); + path.str= my_strndup(PSI_INSTRUMENT_ME, path.str, path.length, MYF(MY_WME)); if (!host.str || !port.str || !path.str) { diff --git a/plugin/func_test/CMakeLists.txt b/plugin/func_test/CMakeLists.txt new file mode 100644 index 00000000000..38ce82d36e4 --- /dev/null +++ b/plugin/func_test/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) 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(func_test plugin.cc RECOMPILE_FOR_EMBEDDED + MODULE_ONLY COMPONENT Test) diff --git a/plugin/func_test/mysql-test/func_test/func_test.result b/plugin/func_test/mysql-test/func_test/func_test.result new file mode 100644 index 00000000000..92d03fbddf0 --- /dev/null +++ b/plugin/func_test/mysql-test/func_test/func_test.result @@ -0,0 +1,28 @@ +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' + AND PLUGIN_NAME='sysconst_test'; +PLUGIN_NAME sysconst_test +PLUGIN_VERSION 1.0 +PLUGIN_STATUS ACTIVE +PLUGIN_TYPE FUNCTION +PLUGIN_AUTHOR MariaDB Corporation +PLUGIN_DESCRIPTION Function SYSCONST_TEST() +PLUGIN_LICENSE GPL +PLUGIN_MATURITY Experimental +PLUGIN_AUTH_VERSION 1.0 +SELECT sysconst_test(); +sysconst_test() +sysconst_test +SELECT sysconst_test(); +sysconst_test() +sysconst_test diff --git a/plugin/func_test/mysql-test/func_test/func_test.test b/plugin/func_test/mysql-test/func_test/func_test.test new file mode 100644 index 00000000000..d5e6a6044fe --- /dev/null +++ b/plugin/func_test/mysql-test/func_test/func_test.test @@ -0,0 +1,23 @@ +#--echo # +#--echo # +#--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' + AND PLUGIN_NAME='sysconst_test'; +--horizontal_results + + +SELECT sysconst_test(); +SELECT sysconst_test(); diff --git a/plugin/func_test/mysql-test/func_test/suite.opt b/plugin/func_test/mysql-test/func_test/suite.opt new file mode 100644 index 00000000000..8c8bfe0f4e6 --- /dev/null +++ b/plugin/func_test/mysql-test/func_test/suite.opt @@ -0,0 +1 @@ +--plugin-load-add=$FUNC_TEST_SO diff --git a/plugin/func_test/mysql-test/func_test/suite.pm b/plugin/func_test/mysql-test/func_test/suite.pm new file mode 100644 index 00000000000..ddaa6b55df2 --- /dev/null +++ b/plugin/func_test/mysql-test/func_test/suite.pm @@ -0,0 +1,9 @@ +package My::Suite::Func_test; + +@ISA = qw(My::Suite); + +return "No FUNC_TEST plugin" unless $ENV{FUNC_TEST_SO}; + +sub is_default { 1 } + +bless { }; diff --git a/plugin/func_test/plugin.cc b/plugin/func_test/plugin.cc new file mode 100644 index 00000000000..811189773f1 --- /dev/null +++ b/plugin/func_test/plugin.cc @@ -0,0 +1,87 @@ +/* + 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-1301 USA */ + +#define MYSQL_SERVER + +#include <my_global.h> +#include <sql_class.h> +#include <mysql/plugin_function.h> + +class Item_func_sysconst_test :public Item_func_sysconst +{ +public: + Item_func_sysconst_test(THD *thd): Item_func_sysconst(thd) {} + String *val_str(String *str) + { + null_value= str->copy(STRING_WITH_LEN("sysconst_test"), system_charset_info); + return null_value ? NULL : str; + } + bool fix_length_and_dec() + { + max_length= MAX_FIELD_NAME * system_charset_info->mbmaxlen; + maybe_null= true; + return false; + } + const char *func_name() const { return "sysconst_test"; } + const char *fully_qualified_func_name() const { return "sysconst_test()"; } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_sysconst_test>(thd, this); } +}; + + +class Create_func_sysconst_test : public Create_func_arg0 +{ +public: + Item *create_builder(THD *thd) override; + static Create_func_sysconst_test s_singleton; +protected: + Create_func_sysconst_test() {} +}; + + +Create_func_sysconst_test Create_func_sysconst_test::s_singleton; + +Item* Create_func_sysconst_test::create_builder(THD *thd) +{ + return new (thd->mem_root) Item_func_sysconst_test(thd); +} + + +#define BUILDER(F) & F::s_singleton + + +static Plugin_function + plugin_descriptor_function_sysconst_test(BUILDER(Create_func_sysconst_test)); + +/*************************************************************************/ + +maria_declare_plugin(type_test) +{ + 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 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 + 0x0100, // Numeric version 0xAABB means AA.BB version + 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; diff --git a/plugin/handler_socket/client/hspool_test.pl b/plugin/handler_socket/client/hspool_test.pl index 973913d4ee9..03227e31b56 100755 --- a/plugin/handler_socket/client/hspool_test.pl +++ b/plugin/handler_socket/client/hspool_test.pl @@ -31,8 +31,8 @@ my $moreflds_prefix = get_conf("moreflds_prefix", "f"); my $mysql_user = 'root'; my $mysql_password = ''; -my $dsn = "DBI:mysql:database=;host=$host;port=$mysqlport" - . ";mysql_server_prepare=$ssps"; +my $dsn = "DBI:MariaDB:database=;host=$host;port=$mysqlport" + . ";mariadb_server_prepare=$ssps"; my $dbh = DBI->connect($dsn, $mysql_user, $mysql_password, { RaiseError => 1 }); my $hsargs = { 'host' => $host, 'port' => $hsport_rd }; diff --git a/plugin/handler_socket/client/hstest.pl b/plugin/handler_socket/client/hstest.pl index 7651dddbc63..1363e153c44 100755 --- a/plugin/handler_socket/client/hstest.pl +++ b/plugin/handler_socket/client/hstest.pl @@ -33,8 +33,8 @@ my $moreflds_prefix = get_conf("moreflds_prefix", "column0123456789_"); my $keytype = get_conf("keytype", "varchar(32)"); my $file = get_conf("file", undef); -my $dsn = "DBI:mysql:database=;host=$host;port=$mysqlport" - . ";mysql_server_prepare=$ssps"; +my $dsn = "DBI:MariaDB:database=;host=$host;port=$mysqlport" + . ";mariadb_server_prepare=$ssps"; my $dbh = DBI->connect($dsn, $mysqluser, $mysqlpass, { RaiseError => 1 }); my $hsargs = { 'host' => $host, 'port' => $hsport }; my $cli = new Net::HandlerSocket($hsargs); diff --git a/plugin/handler_socket/handlersocket/database.cpp b/plugin/handler_socket/handlersocket/database.cpp index 9c0a2d81b98..937b1177ae4 100644 --- a/plugin/handler_socket/handlersocket/database.cpp +++ b/plugin/handler_socket/handlersocket/database.cpp @@ -298,11 +298,11 @@ dbcontext::init_thread(const void *stack_bottom, volatile int& shutdown_flag) thd->options |= OPTION_BIN_LOG; #endif safeFree((char*) thd->db.str); - thd->db.str= my_strdup("handlersocket", MYF(0)); + thd->db.str= my_strdup(PSI_NOT_INSTRUMENTED, "handlersocket", MYF(0)); thd->db.length= sizeof("handlersocket")-1; } thd->variables.option_bits |= OPTION_TABLE_LOCK; - my_pthread_setspecific_ptr(THR_THD, thd); + set_current_thd(thd); DBG_THR(fprintf(stderr, "HNDSOCK x0 %p\n", thd)); } { @@ -339,7 +339,7 @@ dbcontext::term_thread() { DBG_THR(fprintf(stderr, "HNDSOCK thread end %p\n", thd)); close_tables_if(); - my_pthread_setspecific_ptr(THR_THD, 0); + set_current_thd(nullptr); { delete thd; thd = 0; @@ -1004,7 +1004,7 @@ dbcontext::cmd_open(dbcallback_i& cb, const cmd_open_args& arg) LEX_CSTRING db_name= { arg.dbn, strlen(arg.dbn) }; LEX_CSTRING tbl_name= { arg.tbl, strlen(arg.tbl) }; tables.init_one_table(&db_name, &tbl_name, 0, lock_type); - tables.mdl_request.init(MDL_key::TABLE, arg.dbn, arg.tbl, + MDL_REQUEST_INIT(&tables.mdl_request, MDL_key::TABLE, arg.dbn, arg.tbl, for_write_flag ? MDL_SHARED_WRITE : MDL_SHARED_READ, MDL_TRANSACTION); Open_table_context ot_act(thd, 0); if (!open_table(thd, &tables, &ot_act)) { diff --git a/plugin/handler_socket/regtest/common/hstest.pm b/plugin/handler_socket/regtest/common/hstest.pm index 348242b027f..89f273c9786 100644 --- a/plugin/handler_socket/regtest/common/hstest.pm +++ b/plugin/handler_socket/regtest/common/hstest.pm @@ -29,10 +29,10 @@ sub get_dbi_connection { = ($conf{dbname}, $conf{host}, $conf{myport}, $conf{ssps}, $conf{user}, $conf{pass}); my $mycnf = "binary_my.cnf"; - my $dsn = "DBI:mysql:database=;host=$host;port=$myport" - . ";mysql_server_prepare=$ssps" - . ";mysql_read_default_group=perl" - . ";mysql_read_default_file=../common/$mycnf"; + my $dsn = "DBI:MariaDB:database=;host=$host;port=$myport" + . ";mariadb_server_prepare=$ssps" + . ";mariadb_read_default_group=perl" + . ";mariadb_read_default_file=../common/$mycnf"; my $dbh = DBI->connect($dsn, $user, $pass, { RaiseError => 1 }); return $dbh; } diff --git a/plugin/locale_info/locale_info.cc b/plugin/locale_info/locale_info.cc index e444b4fade0..dd0ca303dc8 100644 --- a/plugin/locale_info/locale_info.cc +++ b/plugin/locale_info/locale_info.cc @@ -28,27 +28,31 @@ #include <my_global.h> #include <sql_class.h> // THD -#include <table.h> // ST_SCHEMA_TABLE +#include <sql_i_s.h> // ST_SCHEMA_TABLE #include <mysql/plugin.h> #include <m_ctype.h> #include "sql_locale.h" -bool schema_table_store_record(THD *thd, TABLE *table); static MY_LOCALE **locale_list; +namespace Show { + /* LOCALES */ static ST_FIELD_INFO locale_info_locale_fields_info[]= { - {"ID", 4, MYSQL_TYPE_LONGLONG, 0, 0, "Id", 0}, - {"NAME", 255, MYSQL_TYPE_STRING, 0, 0, "Name", 0}, - {"DESCRIPTION", 255, MYSQL_TYPE_STRING, 0, 0, "Description", 0}, - {"MAX_MONTH_NAME_LENGTH", 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"MAX_DAY_NAME_LENGTH", 4, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"DECIMAL_POINT", 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"THOUSAND_SEP", 2, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"ERROR_MESSAGE_LANGUAGE", 64, MYSQL_TYPE_STRING, 0, 0, "Error_Message_Language", 0}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("ID", SLonglong(4), NOT_NULL, "Id"), + Column("NAME", Varchar(255), NOT_NULL, "Name"), + Column("DESCRIPTION", Varchar(255), NOT_NULL, "Description"), + Column("MAX_MONTH_NAME_LENGTH", SLonglong(4), NOT_NULL), + Column("MAX_DAY_NAME_LENGTH", SLonglong(4), NOT_NULL), + Column("DECIMAL_POINT", Varchar(2), NOT_NULL), + Column("THOUSAND_SEP", Varchar(2), NOT_NULL), + Column("ERROR_MESSAGE_LANGUAGE", Varchar(64), NOT_NULL, "Error_Message_Language"), + CEnd() }; + +} // namespace Show + static int locale_info_fill_table_locale(THD* thd, TABLE_LIST* tables, COND* cond) { TABLE *table= tables->table; @@ -84,16 +88,10 @@ static int locale_info_fill_table_locale(THD* thd, TABLE_LIST* tables, COND* con static int locale_info_plugin_init_locales(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= locale_info_locale_fields_info; + schema->fields_info= Show::locale_info_locale_fields_info; schema->fill_table= locale_info_fill_table_locale; -#if defined(_WIN64) - locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPEAVMY_LOCALE@@A"); -#elif defined(_WIN32) - locale_list = (MY_LOCALE **)GetProcAddress(GetModuleHandle(NULL), "?my_locales@@3PAPAVMY_LOCALE@@A"); -#else locale_list = my_locales; -#endif return 0; } @@ -114,7 +112,7 @@ maria_declare_plugin(locales) PLUGIN_LICENSE_BSD, /* the plugin license (see include/mysql/plugin.h) */ locale_info_plugin_init_locales, /* Pointer to plugin initialization function */ 0, /* Pointer to plugin deinitialization function */ - 0x0100, /* Numeric version 0xAABB means AA.BB veriosn */ + 0x0100, /* Numeric version 0xAABB means AA.BB version */ NULL, /* Status variables */ NULL, /* System variables */ "1.0", /* String version representation */ diff --git a/plugin/metadata_lock_info/metadata_lock_info.cc b/plugin/metadata_lock_info/metadata_lock_info.cc index a4c1d8ef205..a85048de47f 100644 --- a/plugin/metadata_lock_info/metadata_lock_info.cc +++ b/plugin/metadata_lock_info/metadata_lock_info.cc @@ -18,7 +18,7 @@ #include "mysql_version.h" #include "mysql/plugin.h" #include "sql_class.h" -#include "sql_show.h" +#include "sql_i_s.h" static const LEX_STRING metadata_lock_info_lock_name[] = { { C_STRING_WITH_LEN("Backup lock") }, @@ -32,23 +32,22 @@ static const LEX_STRING metadata_lock_info_lock_name[] = { { C_STRING_WITH_LEN("User lock") }, }; +namespace Show { + static ST_FIELD_INFO i_s_metadata_lock_info_fields_info[] = { - {"THREAD_ID", 20, MYSQL_TYPE_LONGLONG, 0, - MY_I_S_UNSIGNED, "thread_id", SKIP_OPEN_TABLE}, - {"LOCK_MODE", 24, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, "lock_mode", SKIP_OPEN_TABLE}, - {"LOCK_DURATION", 30, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, "lock_duration", SKIP_OPEN_TABLE}, - {"LOCK_TYPE", 33, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, "lock_type", SKIP_OPEN_TABLE}, - {"TABLE_SCHEMA", 64, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, "table_schema", SKIP_OPEN_TABLE}, - {"TABLE_NAME", 64, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, "table_name", SKIP_OPEN_TABLE}, - {NULL, 0, MYSQL_TYPE_STRING, 0, 0, NULL, 0} + Column("THREAD_ID", ULonglong(20), NOT_NULL, "thread_id"), + Column("LOCK_MODE", Varchar(24), NULLABLE, "lock_mode"), + Column("LOCK_DURATION", Varchar(30), NULLABLE, "lock_duration"), + Column("LOCK_TYPE", Varchar(33), NULLABLE, "lock_type"), + Column("TABLE_SCHEMA", Name(), NULLABLE, "table_schema"), + Column("TABLE_NAME", Name(), NULLABLE, "table_name"), + CEnd() }; +} // namespace Show + + struct st_i_s_metadata_param { THD *thd; @@ -110,7 +109,7 @@ static int i_s_metadata_lock_info_init( ST_SCHEMA_TABLE *schema = (ST_SCHEMA_TABLE *) p; DBUG_ENTER("i_s_metadata_lock_info_init"); - schema->fields_info = i_s_metadata_lock_info_fields_info; + schema->fields_info = Show::i_s_metadata_lock_info_fields_info; schema->fill_table = i_s_metadata_lock_info_fill_table; schema->idx_field1 = 0; DBUG_RETURN(0); @@ -126,7 +125,6 @@ static int i_s_metadata_lock_info_deinit( static struct st_mysql_information_schema i_s_metadata_lock_info_plugin = { MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; -#ifdef MARIADB_BASE_VERSION maria_declare_plugin(metadata_lock_info) { MYSQL_INFORMATION_SCHEMA_PLUGIN, @@ -144,24 +142,3 @@ maria_declare_plugin(metadata_lock_info) MariaDB_PLUGIN_MATURITY_STABLE } maria_declare_plugin_end; -#else -mysql_declare_plugin(metadata_lock_info) -{ - MYSQL_INFORMATION_SCHEMA_PLUGIN, - &i_s_metadata_lock_info_plugin, - "METADATA_LOCK_INFO", - "Kentoku Shiba", - "Metadata locking viewer", - PLUGIN_LICENSE_GPL, - i_s_metadata_lock_info_init, - i_s_metadata_lock_info_deinit, - 0x0001, - NULL, - NULL, - NULL, -#if MYSQL_VERSION_ID >= 50600 - 0, -#endif -} -mysql_declare_plugin_end; -#endif diff --git a/plugin/qc_info/qc_info.cc b/plugin/qc_info/qc_info.cc index c01207571d2..e97f547550f 100644 --- a/plugin/qc_info/qc_info.cc +++ b/plugin/qc_info/qc_info.cc @@ -37,7 +37,7 @@ #include <sql_acl.h> // PROCESS_ACL #include <sql_class.h> // THD #include <sql_cache.h> -#include <table.h> // ST_SCHEMA_TABLE +#include <sql_i_s.h> // ST_SCHEMA_TABLE #include <set_var.h> // sql_mode_string_representation #include <tztime.h> #include <mysql/plugin.h> @@ -72,43 +72,50 @@ bool schema_table_store_record(THD *thd, TABLE *table); #define COLUMN_CLIENT_LONG_FLAG 16 #define COLUMN_CLIENT_PROTOCOL_41 17 -#define COLUMN_PROTOCOL_TYPE 18 -#define COLUMN_MORE_RESULTS_EXISTS 19 -#define COLUMN_IN_TRANS 20 -#define COLUMN_AUTOCOMMIT 21 -#define COLUMN_PKT_NR 22 -#define COLUMN_HITS 23 +#define COLUMN_CLIENT_EXTENDED_METADATA 18 +#define COLUMN_PROTOCOL_TYPE 19 +#define COLUMN_MORE_RESULTS_EXISTS 20 +#define COLUMN_IN_TRANS 21 +#define COLUMN_AUTOCOMMIT 22 +#define COLUMN_PKT_NR 23 +#define COLUMN_HITS 24 + + +namespace Show { /* ST_FIELD_INFO is defined in table.h */ static ST_FIELD_INFO qc_info_fields[]= { - {"STATEMENT_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"STATEMENT_TEXT", MAX_STATEMENT_TEXT_LENGTH, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"RESULT_BLOCKS_COUNT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, - {"RESULT_BLOCKS_SIZE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"RESULT_BLOCKS_SIZE_USED", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"LIMIT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"MAX_SORT_LENGTH", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"GROUP_CONCAT_MAX_LENGTH", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, 0, 0}, - {"CHARACTER_SET_CLIENT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"CHARACTER_SET_RESULT", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"COLLATION", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"TIMEZONE", 50, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"DEFAULT_WEEK_FORMAT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, - {"DIV_PRECISION_INCREMENT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, 0, 0}, - {"SQL_MODE", 250, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"LC_TIME_NAMES", 100, MYSQL_TYPE_STRING, 0, 0, 0, 0}, - {"CLIENT_LONG_FLAG", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"CLIENT_PROTOCOL_41", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"PROTOCOL_TYPE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"MORE_RESULTS_EXISTS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"IN_TRANS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"AUTOCOMMIT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"PACKET_NUMBER", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_TINY, 0, 0, 0, 0}, - {"HITS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, 0, 0}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("STATEMENT_SCHEMA", Varchar(NAME_LEN), NOT_NULL), + Column("STATEMENT_TEXT", Longtext(MAX_STATEMENT_TEXT_LENGTH),NOT_NULL), + Column("RESULT_BLOCKS_COUNT", SLong(), NOT_NULL), + Column("RESULT_BLOCKS_SIZE", SLonglong(MY_INT32_NUM_DECIMAL_DIGITS),NOT_NULL), + Column("RESULT_BLOCKS_SIZE_USED",SLonglong(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("LIMIT", SLonglong(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("MAX_SORT_LENGTH", SLonglong(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("GROUP_CONCAT_MAX_LENGTH",SLonglong(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("CHARACTER_SET_CLIENT", CSName(), NOT_NULL), + Column("CHARACTER_SET_RESULT", CSName(), NOT_NULL), + Column("COLLATION", CSName(), NOT_NULL), + Column("TIMEZONE", Varchar(50), NOT_NULL), + Column("DEFAULT_WEEK_FORMAT", SLong(), NOT_NULL), + Column("DIV_PRECISION_INCREMENT",SLong(), NOT_NULL), + Column("SQL_MODE", Varchar(250), NOT_NULL), + Column("LC_TIME_NAMES", Varchar(100), NOT_NULL), + Column("CLIENT_LONG_FLAG", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("CLIENT_PROTOCOL_41", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("CLIENT_EXTENDED_METADATA",STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("PROTOCOL_TYPE", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("MORE_RESULTS_EXISTS", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("IN_TRANS", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("AUTOCOMMIT", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("PACKET_NUMBER", STiny(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + Column("HITS", SLonglong(MY_INT32_NUM_DECIMAL_DIGITS), NOT_NULL), + CEnd() }; +} // namespace Show + static const char unknown[]= "#UNKNOWN#"; @@ -213,6 +220,8 @@ static int qc_info_fill_table(THD *thd, TABLE_LIST *tables, table->field[COLUMN_CLIENT_LONG_FLAG]->store(flags.client_long_flag, 0); table->field[COLUMN_CLIENT_PROTOCOL_41]->store(flags.client_protocol_41, 0); + table->field[COLUMN_CLIENT_EXTENDED_METADATA]-> + store(flags.client_extended_metadata, 0); table->field[COLUMN_PROTOCOL_TYPE]->store(flags.protocol_type, 0); table->field[COLUMN_MORE_RESULTS_EXISTS]->store(flags.more_results_exists, 0); table->field[COLUMN_IN_TRANS]->store(flags.in_trans, 0); @@ -276,15 +285,9 @@ static int qc_info_plugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= qc_info_fields; + schema->fields_info= Show::qc_info_fields; schema->fill_table= qc_info_fill_table; - -#ifdef _WIN32 - qc = (Accessible_Query_Cache *) - GetProcAddress(GetModuleHandle(NULL), "?query_cache@@3VQuery_cache@@A"); -#else qc = (Accessible_Query_Cache *)&query_cache; -#endif return qc == 0; } diff --git a/plugin/query_response_time/plugin.cc b/plugin/query_response_time/plugin.cc index c337424039c..0362c6e2792 100644 --- a/plugin/query_response_time/plugin.cc +++ b/plugin/query_response_time/plugin.cc @@ -16,7 +16,7 @@ #define MYSQL_SERVER #include <my_global.h> #include <sql_class.h> -#include <table.h> +#include <sql_i_s.h> #include <sql_show.h> #include <mysql/plugin_audit.h> #include "query_response_time.h" @@ -71,19 +71,22 @@ static struct st_mysql_sys_var *query_response_time_info_vars[]= }; +namespace Show { + ST_FIELD_INFO query_response_time_fields_info[] = { - { "TIME", QRT_TIME_STRING_LENGTH, MYSQL_TYPE_STRING, 0, 0, "Time", 0 }, - { "COUNT", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, MY_I_S_UNSIGNED, "Count", 0 }, - { "TOTAL", QRT_TIME_STRING_LENGTH, MYSQL_TYPE_STRING, 0, 0, "Total", 0 }, - { 0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0 } + Column("TIME", Varchar(QRT_TIME_STRING_LENGTH), NOT_NULL, "Time"), + Column("COUNT", ULong(), NOT_NULL, "Count"), + Column("TOTAL", Varchar(QRT_TIME_STRING_LENGTH), NOT_NULL, "Total"), + CEnd() }; +} // namespace Show static int query_response_time_info_init(void *p) { ST_SCHEMA_TABLE *i_s_query_response_time= (ST_SCHEMA_TABLE *) p; - i_s_query_response_time->fields_info= query_response_time_fields_info; + i_s_query_response_time->fields_info= Show::query_response_time_fields_info; i_s_query_response_time->fill_table= query_response_time_fill; i_s_query_response_time->reset_table= query_response_time_flush; query_response_time_init(); diff --git a/plugin/server_audit/server_audit.c b/plugin/server_audit/server_audit.c index 86f38edf724..a63531bcbf1 100644 --- a/plugin/server_audit/server_audit.c +++ b/plugin/server_audit/server_audit.c @@ -124,7 +124,7 @@ static char *default_home= (char *)"."; #define my_rename(A, B, C) loc_rename(A, B) #define my_tell(A, B) loc_tell(A) #define my_write(A, B, C, D) loc_write(A, B, C) -#define my_malloc(A, B) malloc(A) +#define my_malloc(A, B, C) malloc(B) #define my_free(A) free(A) #ifdef my_errno #undef my_errno @@ -277,7 +277,7 @@ static my_off_t loc_tell(File fd) #endif /*WIN32*/ -extern char server_version[]; +extern MYSQL_PLUGIN_IMPORT char server_version[]; static const char *serv_ver= NULL; static int started_mysql= 0; static int mysql_57_started= 0; @@ -2443,7 +2443,6 @@ typedef struct loc_system_variables ulong max_tmp_tables; ulong max_insert_delayed_threads; ulong min_examined_row_limit; - ulong multi_range_count; ulong net_buffer_length; ulong net_interactive_timeout; ulong net_read_timeout; @@ -2483,31 +2482,37 @@ typedef struct loc_system_variables static int init_done= 0; +static void* find_sym(const char *sym) +{ +#ifdef _WIN32 + return GetProcAddress(GetModuleHandle("server.dll"),sym); +#else + return dlsym(RTLD_DEFAULT, sym); +#endif +} + static int server_audit_init(void *p __attribute__((unused))) { if (!serv_ver) { -#ifdef _WIN32 - serv_ver= (const char *) GetProcAddress(0, "server_version"); -#else - serv_ver= server_version; -#endif /*_WIN32*/ + serv_ver= find_sym("server_version"); } + if (!mysql_57_started) { - const void *my_hash_init_ptr= dlsym(RTLD_DEFAULT, "_my_hash_init"); + const void *my_hash_init_ptr= find_sym("_my_hash_init"); if (!my_hash_init_ptr) { maria_above_5= 1; - my_hash_init_ptr= dlsym(RTLD_DEFAULT, "my_hash_init2"); + my_hash_init_ptr= find_sym("my_hash_init2"); } if (!my_hash_init_ptr) return 1; } - if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "mysql_data_home"))) + if(!(int_mysql_data_home= find_sym("mysql_data_home"))) { - if(!(int_mysql_data_home= dlsym(RTLD_DEFAULT, "?mysql_data_home@@3PADA"))) + if(!(int_mysql_data_home= find_sym("?mysql_data_home@@3PADA"))) int_mysql_data_home= &default_home; } @@ -3036,7 +3041,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) if (fdwReason != DLL_PROCESS_ATTACH) return 1; - serv_ver= (const char *) GetProcAddress(0, "server_version"); + serv_ver= server_version; #else void __attribute__ ((constructor)) audit_plugin_so_init(void) { diff --git a/plugin/test_sql_service/CMakeLists.txt b/plugin/test_sql_service/CMakeLists.txt new file mode 100644 index 00000000000..aa9ecfe685e --- /dev/null +++ b/plugin/test_sql_service/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (C) 2013 Alexey Botchkov and SkySQL Ab +# +# 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 + +SET(SOURCES test_sql_service.c) + +MYSQL_ADD_PLUGIN(test_sql_service ${SOURCES} MODULE_ONLY RECOMPILE_FOR_EMBEDDED) diff --git a/plugin/test_sql_service/COPYING b/plugin/test_sql_service/COPYING new file mode 100644 index 00000000000..6e475df5526 --- /dev/null +++ b/plugin/test_sql_service/COPYING @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + 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; either version 2 of the License, or + (at your option) any later version. + + 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. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/plugin/test_sql_service/test_sql_service.c b/plugin/test_sql_service/test_sql_service.c new file mode 100644 index 00000000000..062f10fce58 --- /dev/null +++ b/plugin/test_sql_service/test_sql_service.c @@ -0,0 +1,145 @@ +/* Copyright (C) 2019, Alexey Botchkov and 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 Street, Fifth Floor, Boston, MA 02110-1335 USA */ + + +#define PLUGIN_VERSION 0x100 +#define PLUGIN_STR_VERSION "1.0.0" + +#define _my_thread_var loc_thread_var + +#include <my_config.h> +#include <assert.h> +#include <my_global.h> +#include <my_base.h> +#include <typelib.h> +//#include <mysql_com.h> /* for enum enum_server_command */ +#include <mysql/plugin.h> +#include <mysql/plugin_audit.h> +//#include <string.h> + + +LEX_STRING * thd_query_string (MYSQL_THD thd); +unsigned long long thd_query_id(const MYSQL_THD thd); +size_t thd_query_safe(MYSQL_THD thd, char *buf, size_t buflen); +const char *thd_user_name(MYSQL_THD thd); +const char *thd_client_host(MYSQL_THD thd); +const char *thd_client_ip(MYSQL_THD thd); +LEX_CSTRING *thd_current_db(MYSQL_THD thd); +int thd_current_status(MYSQL_THD thd); +enum enum_server_command thd_current_command(MYSQL_THD thd); + +int maria_compare_hostname(const char *wild_host, long wild_ip, long ip_mask, + const char *host, const char *ip); +void maria_update_hostname(const char **wild_host, long *wild_ip, long *ip_mask, + const char *host); + +/* Status variables for SHOW STATUS */ +static long test_passed= 0; +static struct st_mysql_show_var test_sql_status[]= +{ + {"test_sql_service_passed", (char *)&test_passed, SHOW_LONG}, + {0,0,0} +}; + +static my_bool do_test= TRUE; +static void run_test(MYSQL_THD thd, struct st_mysql_sys_var *var, + void *var_ptr, const void *save); +static MYSQL_SYSVAR_BOOL(run_test, do_test, PLUGIN_VAR_OPCMDARG, + "Perform the test now.", NULL, run_test, FALSE); +static struct st_mysql_sys_var* test_sql_vars[]= +{ + MYSQL_SYSVAR(run_test), + NULL +}; + + +extern int execute_sql_command(const char *command, + char *hosts, char *names, char *filters); + + + +static int do_tests() +{ + char plugins[1024]; + char names[1024]; + char dl[2048]; + int result; + + result= execute_sql_command("select 'plugin', name, dl from mysql.plugin", + plugins, names, dl); + + return result; +} + + +void auditing(MYSQL_THD thd, unsigned int event_class, const void *ev) +{ +} + + +static void run_test(MYSQL_THD thd __attribute__((unused)), + struct st_mysql_sys_var *var __attribute__((unused)), + void *var_ptr __attribute__((unused)), + const void *save __attribute__((unused))) +{ + test_passed= do_tests(); +} + + +static int init_done= 0; + +static int test_sql_service_plugin_init(void *p __attribute__((unused))) +{ + init_done= 1; + return 0; +} + + +static int test_sql_service_plugin_deinit(void *p __attribute__((unused))) +{ + if (!init_done) + return 0; + + return 0; +} + + +static struct st_mysql_audit maria_descriptor = +{ + MYSQL_AUDIT_INTERFACE_VERSION, + NULL, + auditing, + { MYSQL_AUDIT_GENERAL_CLASSMASK | + MYSQL_AUDIT_TABLE_CLASSMASK | + MYSQL_AUDIT_CONNECTION_CLASSMASK } +}; +maria_declare_plugin(test_sql_service) +{ + MYSQL_AUDIT_PLUGIN, + &maria_descriptor, + "TEST_SQL_SERVICE", + "Alexey Botchkov (MariaDB Corporation)", + "Test SQL service", + PLUGIN_LICENSE_GPL, + test_sql_service_plugin_init, + test_sql_service_plugin_deinit, + PLUGIN_VERSION, + test_sql_status, + test_sql_vars, + PLUGIN_STR_VERSION, + MariaDB_PLUGIN_MATURITY_STABLE +} +maria_declare_plugin_end; + diff --git a/plugin/type_geom/CMakeLists.txt b/plugin/type_geom/CMakeLists.txt new file mode 100644 index 00000000000..2b0c84f6fa0 --- /dev/null +++ b/plugin/type_geom/CMakeLists.txt @@ -0,0 +1,3 @@ +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql) + +MYSQL_ADD_PLUGIN(TYPE_GEOM plugin.cc MANDATORY RECOMPILE_FOR_EMBEDDED) diff --git a/plugin/type_geom/plugin.cc b/plugin/type_geom/plugin.cc new file mode 100644 index 00000000000..b462a34cef9 --- /dev/null +++ b/plugin/type_geom/plugin.cc @@ -0,0 +1,254 @@ +/* + Copyright (c) 2000, 2015, Oracle and/or its affiliates. + Copyright (c) 2009, 2019, 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-1301 USA */ + +#include <my_global.h> +#include <sql_class.h> // THD +#include <sql_i_s.h> // ST_SCHEMA_TABLE +#include <mysql/plugin.h> +#include "sql_show.h" // get_all_tables() +#include "sql_error.h" // convert_error_to_warning() +#include "sql_type_geom.h" + + +/*********** INFORMATION_SCHEMA.SPATIEL_REF_SYS *******************/ + +namespace Show { + +static ST_FIELD_INFO spatial_ref_sys_fields_info[]= +{ + Column("SRID", SShort(5), NOT_NULL), + Column("AUTH_NAME", Varchar(FN_REFLEN), NOT_NULL), + Column("AUTH_SRID", SLong(5), NOT_NULL), + Column("SRTEXT", Varchar(2048), NOT_NULL), + CEnd() +}; + + +static int spatial_ref_sys_fill(THD *thd, TABLE_LIST *tables, COND *cond) +{ + DBUG_ENTER("fill_spatial_ref_sys"); + TABLE *table= tables->table; + CHARSET_INFO *cs= system_charset_info; + int result= 1; + + restore_record(table, s->default_values); + + table->field[0]->store(-1, FALSE); /*SRID*/ + table->field[1]->store(STRING_WITH_LEN("Not defined"), cs); /*AUTH_NAME*/ + table->field[2]->store(-1, FALSE); /*AUTH_SRID*/ + table->field[3]->store(STRING_WITH_LEN( + "LOCAL_CS[\"Spatial reference wasn't specified\"," + "LOCAL_DATUM[\"Unknown\",0]," "UNIT[\"m\",1.0]," "AXIS[\"x\",EAST]," + "AXIS[\"y\",NORTH]]"), cs);/*SRTEXT*/ + if (schema_table_store_record(thd, table)) + goto exit; + + table->field[0]->store(0, TRUE); /*SRID*/ + table->field[1]->store(STRING_WITH_LEN("EPSG"), cs); /*AUTH_NAME*/ + table->field[2]->store(404000, TRUE); /*AUTH_SRID*/ + table->field[3]->store(STRING_WITH_LEN( + "LOCAL_CS[\"Wildcard 2D cartesian plane in metric unit\"," + "LOCAL_DATUM[\"Unknown\",0]," "UNIT[\"m\",1.0]," + "AXIS[\"x\",EAST]," "AXIS[\"y\",NORTH]," + "AUTHORITY[\"EPSG\",\"404000\"]]"), cs);/*SRTEXT*/ + if (schema_table_store_record(thd, table)) + goto exit; + + result= 0; + +exit: + DBUG_RETURN(result); +} + + +static int plugin_init_spatial_ref_sys(void *p) +{ + ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; + schema->fields_info= spatial_ref_sys_fields_info; + schema->fill_table= spatial_ref_sys_fill; + return 0; +} + + +static struct st_mysql_information_schema spatial_ref_sys_plugin= +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + + +} // namespace Show + +/*********** INFORMATION_SCHEMA.GEOMETRY_COLUMNS *******************/ + + +namespace Show { + +static ST_FIELD_INFO geometry_columns_fields_info[]= +{ + Column("F_TABLE_CATALOG", Catalog(), NOT_NULL, OPEN_FRM_ONLY), + Column("F_TABLE_SCHEMA", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("F_TABLE_NAME", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("F_GEOMETRY_COLUMN", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("G_TABLE_CATALOG", Catalog(), NOT_NULL, OPEN_FRM_ONLY), + Column("G_TABLE_SCHEMA", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("G_TABLE_NAME", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("G_GEOMETRY_COLUMN", Name(), NOT_NULL, OPEN_FRM_ONLY), + Column("STORAGE_TYPE", STiny(2), NOT_NULL, OPEN_FRM_ONLY), + Column("GEOMETRY_TYPE", SLong(7), NOT_NULL, OPEN_FRM_ONLY), + Column("COORD_DIMENSION", STiny(2), NOT_NULL, OPEN_FRM_ONLY), + Column("MAX_PPR", STiny(2), NOT_NULL, OPEN_FRM_ONLY), + Column("SRID", SShort(5), NOT_NULL, OPEN_FRM_ONLY), + CEnd() +}; + + +static void geometry_columns_fill_record(TABLE *table, + const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name, + const Field_geom *field) +{ + static const LEX_CSTRING catalog= {STRING_WITH_LEN("def")}; + const CHARSET_INFO *cs= system_charset_info; + const Type_handler_geometry *gth= field->type_handler_geom(); + /*F_TABLE_CATALOG*/ + table->field[0]->store(catalog, cs); + /*F_TABLE_SCHEMA*/ + table->field[1]->store(db_name, cs); + /*F_TABLE_NAME*/ + table->field[2]->store(table_name, cs); + /*G_TABLE_CATALOG*/ + table->field[4]->store(catalog, cs); + /*G_TABLE_SCHEMA*/ + table->field[5]->store(db_name, cs); + /*G_TABLE_NAME*/ + table->field[6]->store(table_name, cs); + /*G_GEOMETRY_COLUMN*/ + table->field[7]->store(field->field_name, cs); + /*STORAGE_TYPE*/ + table->field[8]->store(1LL, true); /*Always 1 (binary implementation)*/ + /*GEOMETRY_TYPE*/ + table->field[9]->store((longlong) (gth->geometry_type()), true); + /*COORD_DIMENSION*/ + table->field[10]->store(2LL, true); + /*MAX_PPR*/ + table->field[11]->set_null(); + /*SRID*/ + table->field[12]->store((longlong) (field->get_srid()), true); +} + + +static int get_geometry_column_record(THD *thd, TABLE_LIST *tables, + TABLE *table, bool res, + const LEX_CSTRING *db_name, + const LEX_CSTRING *table_name) +{ + TABLE *show_table; + Field **ptr, *field; + DBUG_ENTER("get_geometry_column_record"); + + if (res) + { + /* + open_table() failed with an error. + Convert the error to a warning and let the caller + continue with the next table. + */ + convert_error_to_warning(thd); + DBUG_RETURN(0); + } + + // Skip INFORMATION_SCHEMA tables. They don't have geometry columns. + if (tables->schema_table) + DBUG_RETURN(0); + + show_table= tables->table; + ptr= show_table->field; + show_table->use_all_columns(); // Required for default + restore_record(show_table, s->default_values); + + for (; (field= *ptr) ; ptr++) + { + const Field_geom *fg; + if (field->type() == MYSQL_TYPE_GEOMETRY && + (fg= dynamic_cast<const Field_geom*>(field))) + { + DEBUG_SYNC(thd, "get_schema_column"); + /* Get default row, with all NULL fields set to NULL */ + restore_record(table, s->default_values); + geometry_columns_fill_record(table, db_name, table_name, fg); + if (schema_table_store_record(thd, table)) + DBUG_RETURN(1); + } + } + + DBUG_RETURN(0); +} + + +static int plugin_init_geometry_columns(void *p) +{ + ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; + schema->fields_info= geometry_columns_fields_info; + schema->fill_table= get_all_tables; + schema->process_table= get_geometry_column_record; + schema->idx_field1= 1; + schema->idx_field2= 2; + schema->i_s_requested_object= OPTIMIZE_I_S_TABLE | OPEN_VIEW_FULL; + return 0; +} + + +static struct st_mysql_information_schema geometry_columns_plugin= +{ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; + + +} // namespace Show + + +/********************* Plugin library descriptors ************************/ + + +maria_declare_plugin(type_geom) +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &Show::spatial_ref_sys_plugin, // pointer to type-specific plugin descriptor + "SPATIAL_REF_SYS", // plugin name + "MariaDB", // plugin author + "Lists all geometry columns", // the plugin description + PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h) + Show::plugin_init_spatial_ref_sys, // Pointer to plugin initialization function + 0, // Pointer to plugin deinitialization function + 0x0100, // Numeric version 0xAABB means AA.BB version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE // Maturity (see include/mysql/plugin.h)*/ +}, +{ + MYSQL_INFORMATION_SCHEMA_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &Show::geometry_columns_plugin, // pointer to type-specific plugin descriptor + "GEOMETRY_COLUMNS", // plugin name + "MariaDB", // plugin author + "Lists all geometry columns", // the plugin description + PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h) + Show::plugin_init_geometry_columns,// Pointer to plugin initialization function + 0, // Pointer to plugin deinitialization function + 0x0100, // Numeric version 0xAABB means AA.BB version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE // Maturity (see include/mysql/plugin.h) +} +maria_declare_plugin_end; diff --git a/plugin/type_inet/CMakeLists.txt b/plugin/type_inet/CMakeLists.txt new file mode 100644 index 00000000000..0040ceec256 --- /dev/null +++ b/plugin/type_inet/CMakeLists.txt @@ -0,0 +1,18 @@ +# 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 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) diff --git a/plugin/type_inet/item_inetfunc.cc b/plugin/type_inet/item_inetfunc.cc new file mode 100644 index 00000000000..50bd82817e0 --- /dev/null +++ b/plugin/type_inet/item_inetfunc.cc @@ -0,0 +1,256 @@ +/* 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 "item_inetfunc.h" +#include "sql_type_inet.h" + +/////////////////////////////////////////////////////////////////////////// + +longlong Item_func_inet_aton::val_int() +{ + DBUG_ASSERT(fixed); + + uint byte_result= 0; + ulonglong result= 0; // We are ready for 64 bit addresses + const char *p,* end; + char c= '.'; // we mark c to indicate invalid IP in case length is 0 + int dot_count= 0; + + StringBuffer<36> tmp; + String *s= args[0]->val_str_ascii(&tmp); + + if (!s) // If null value + goto err; + + null_value= 0; + + end= (p = s->ptr()) + s->length(); + while (p < end) + { + c= *p++; + int digit= (int) (c - '0'); + if (digit >= 0 && digit <= 9) + { + if ((byte_result= byte_result * 10 + digit) > 255) + goto err; // Wrong address + } + else if (c == '.') + { + dot_count++; + result= (result << 8) + (ulonglong) byte_result; + byte_result= 0; + } + else + goto err; // Invalid character + } + if (c != '.') // IP number can't end on '.' + { + /* + Attempt to support short forms of IP-addresses. It's however pretty + basic one comparing to the BSD support. + Examples: + 127 -> 0.0.0.127 + 127.255 -> 127.0.0.255 + 127.256 -> NULL (should have been 127.0.1.0) + 127.2.1 -> 127.2.0.1 + */ + switch (dot_count) { + case 1: result<<= 8; /* Fall through */ + case 2: result<<= 8; /* Fall through */ + } + return (result << 8) + (ulonglong) byte_result; + } + +err: + null_value=1; + return 0; +} + + +String* Item_func_inet_ntoa::val_str(String* str) +{ + DBUG_ASSERT(fixed); + + ulonglong n= (ulonglong) args[0]->val_int(); + + /* + We do not know if args[0] is NULL until we have called + some val function on it if args[0] is not a constant! + + Also return null if n > 255.255.255.255 + */ + if ((null_value= (args[0]->null_value || n > 0xffffffff))) + return 0; // Null value + + str->set_charset(collation.collation); + str->length(0); + + uchar buf[8]; + int4store(buf, n); + + /* Now we can assume little endian. */ + + char num[4]; + num[3]= '.'; + + for (uchar *p= buf + 4; p-- > buf;) + { + uint c= *p; + uint n1, n2; // Try to avoid divisions + n1= c / 100; // 100 digits + c-= n1 * 100; + n2= c / 10; // 10 digits + c-= n2 * 10; // last digit + num[0]= (char) n1 + '0'; + num[1]= (char) n2 + '0'; + num[2]= (char) c + '0'; + uint length= (n1 ? 4 : n2 ? 3 : 2); // Remove pre-zero + uint dot_length= (p <= buf) ? 1 : 0; + (void) str->append(num + 4 - length, length - dot_length, + &my_charset_latin1); + } + + return str; +} + + +/////////////////////////////////////////////////////////////////////////// + +/** + Converts IP-address-string to IP-address-data. + + ipv4-string -> varbinary(4) + ipv6-string -> varbinary(16) + + @return Completion status. + @retval NULL Given string does not represent an IP-address. + @retval !NULL The string has been converted sucessfully. +*/ + +String *Item_func_inet6_aton::val_str(String *buffer) +{ + DBUG_ASSERT(fixed); + + Ascii_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); + if ((null_value= tmp.is_null())) + return NULL; + + Inet4_null ipv4(*tmp.string()); + if (!ipv4.is_null()) + { + ipv4.to_binary(buffer); + return buffer; + } + + Inet6_null ipv6(*tmp.string()); + if (!ipv6.is_null()) + { + ipv6.to_binary(buffer); + return buffer; + } + + null_value= true; + return NULL; +} + + +/** + Converts IP-address-data to IP-address-string. +*/ + +String *Item_func_inet6_ntoa::val_str_ascii(String *buffer) +{ + DBUG_ASSERT(fixed); + + // Binary string argument expected + if (unlikely(args[0]->result_type() != STRING_RESULT || + args[0]->collation.collation != &my_charset_bin)) + { + null_value= true; + return NULL; + } + + String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); + if ((null_value= tmp.is_null())) + return NULL; + + Inet4_null ipv4(static_cast<const Binary_string&>(*tmp.string())); + if (!ipv4.is_null()) + { + ipv4.to_string(buffer); + return buffer; + } + + Inet6_null ipv6(static_cast<const Binary_string&>(*tmp.string())); + if (!ipv6.is_null()) + { + ipv6.to_string(buffer); + return buffer; + } + + DBUG_PRINT("info", ("INET6_NTOA(): varbinary(4) or varbinary(16) expected.")); + null_value= true; + return NULL; +} + + +/** + Checks if the passed string represents an IPv4-address. +*/ + +longlong Item_func_is_ipv4::val_int() +{ + DBUG_ASSERT(fixed); + String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); + return !tmp.is_null() && !Inet4_null(*tmp.string()).is_null(); +} + + +/** + Checks if the passed string represents an IPv6-address. +*/ + +longlong Item_func_is_ipv6::val_int() +{ + DBUG_ASSERT(fixed); + String_ptr_and_buffer<STRING_BUFFER_USUAL_SIZE> tmp(args[0]); + return !tmp.is_null() && !Inet6_null(*tmp.string()).is_null(); +} + + +/** + Checks if the passed IPv6-address is an IPv4-compat IPv6-address. +*/ + +longlong Item_func_is_ipv4_compat::val_int() +{ + Inet6_null ip6(args[0]); + return !ip6.is_null() && ip6.is_v4compat(); +} + + +/** + Checks if the passed IPv6-address is an IPv4-mapped IPv6-address. +*/ + +longlong Item_func_is_ipv4_mapped::val_int() +{ + Inet6_null ip6(args[0]); + return !ip6.is_null() && ip6.is_v4mapped(); +} diff --git a/plugin/type_inet/item_inetfunc.h b/plugin/type_inet/item_inetfunc.h new file mode 100644 index 00000000000..94255426f68 --- /dev/null +++ b/plugin/type_inet/item_inetfunc.h @@ -0,0 +1,227 @@ +#ifndef ITEM_INETFUNC_INCLUDED +#define ITEM_INETFUNC_INCLUDED + +/* 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 */ + + +#include "item.h" + +/************************************************************************* + Item_func_inet_aton implements INET_ATON() SQL-function. +*************************************************************************/ + +class Item_func_inet_aton : public Item_longlong_func +{ + bool check_arguments() const + { return check_argument_types_can_return_text(0, arg_count); } +public: + Item_func_inet_aton(THD *thd, Item *a): Item_longlong_func(thd, a) {} + longlong val_int(); + const char *func_name() const { return "inet_aton"; } + bool fix_length_and_dec() + { + decimals= 0; + max_length= 21; + maybe_null= 1; + unsigned_flag= 1; + return FALSE; + } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_inet_aton>(thd, this); } +}; + + +/************************************************************************* + Item_func_inet_ntoa implements INET_NTOA() SQL-function. +*************************************************************************/ + +class Item_func_inet_ntoa : public Item_str_func +{ +public: + Item_func_inet_ntoa(THD *thd, Item *a): Item_str_func(thd, a) + { } + String* val_str(String* str); + const char *func_name() const { return "inet_ntoa"; } + bool fix_length_and_dec() + { + decimals= 0; + fix_length_and_charset(3 * 8 + 7, default_charset()); + maybe_null= 1; + return FALSE; + } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_inet_ntoa>(thd, this); } +}; + + +/************************************************************************* + Item_func_inet_bool_base implements common code for INET6/IP-related + functions returning boolean value. +*************************************************************************/ + +class Item_func_inet_bool_base : public Item_bool_func +{ +public: + inline Item_func_inet_bool_base(THD *thd, Item *ip_addr): + Item_bool_func(thd, ip_addr) + { + null_value= false; + } + bool need_parentheses_in_default() { return false; } +}; + + +/************************************************************************* + Item_func_inet6_aton implements INET6_ATON() SQL-function. +*************************************************************************/ + +class Item_func_inet6_aton : public Item_str_func +{ +public: + inline Item_func_inet6_aton(THD *thd, Item *ip_addr): + Item_str_func(thd, ip_addr) + { } + +public: + virtual const char *func_name() const + { return "inet6_aton"; } + + virtual bool fix_length_and_dec() + { + decimals= 0; + fix_length_and_charset(16, &my_charset_bin); + maybe_null= 1; + return FALSE; + } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_inet6_aton>(thd, this); } + + String *val_str(String *to); +}; + + +/************************************************************************* + Item_func_inet6_ntoa implements INET6_NTOA() SQL-function. +*************************************************************************/ + +class Item_func_inet6_ntoa : public Item_str_ascii_func +{ +public: + inline Item_func_inet6_ntoa(THD *thd, Item *ip_addr): + Item_str_ascii_func(thd, ip_addr) + { } + +public: + virtual const char *func_name() const + { return "inet6_ntoa"; } + + virtual bool fix_length_and_dec() + { + decimals= 0; + + // max length: IPv6-address -- 16 bytes + // 16 bytes / 2 bytes per group == 8 groups => 7 delimiter + // 4 symbols per group + fix_length_and_charset(8 * 4 + 7, default_charset()); + + maybe_null= 1; + return FALSE; + } + String *val_str_ascii(String *to); + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_inet6_ntoa>(thd, this); } +}; + + +/************************************************************************* + Item_func_is_ipv4 implements IS_IPV4() SQL-function. +*************************************************************************/ + +class Item_func_is_ipv4 : public Item_func_inet_bool_base +{ +public: + inline Item_func_is_ipv4(THD *thd, Item *ip_addr): + Item_func_inet_bool_base(thd, ip_addr) + { } + +public: + virtual const char *func_name() const + { return "is_ipv4"; } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_is_ipv4>(thd, this); } + + longlong val_int(); +}; + + +/************************************************************************* + Item_func_is_ipv6 implements IS_IPV6() SQL-function. +*************************************************************************/ + +class Item_func_is_ipv6 : public Item_func_inet_bool_base +{ +public: + inline Item_func_is_ipv6(THD *thd, Item *ip_addr): + Item_func_inet_bool_base(thd, ip_addr) + { } + + virtual const char *func_name() const + { return "is_ipv6"; } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_is_ipv6>(thd, this); } + + longlong val_int(); +}; + + +/************************************************************************* + Item_func_is_ipv4_compat implements IS_IPV4_COMPAT() SQL-function. +*************************************************************************/ + +class Item_func_is_ipv4_compat : public Item_func_inet_bool_base +{ +public: + inline Item_func_is_ipv4_compat(THD *thd, Item *ip_addr): + Item_func_inet_bool_base(thd, ip_addr) + { } + virtual const char *func_name() const + { return "is_ipv4_compat"; } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_is_ipv4_compat>(thd, this); } + longlong val_int(); +}; + + +/************************************************************************* + Item_func_is_ipv4_mapped implements IS_IPV4_MAPPED() SQL-function. +*************************************************************************/ + +class Item_func_is_ipv4_mapped : public Item_func_inet_bool_base +{ +public: + inline Item_func_is_ipv4_mapped(THD *thd, Item *ip_addr): + Item_func_inet_bool_base(thd, ip_addr) + { } + virtual const char *func_name() const + { return "is_ipv4_mapped"; } + Item *get_copy(THD *thd) + { return get_item_copy<Item_func_is_ipv4_mapped>(thd, this); } + longlong val_int(); +}; + +#endif // ITEM_INETFUNC_INCLUDED diff --git a/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.result b/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.result new file mode 100644 index 00000000000..e09b1021651 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.result @@ -0,0 +1,34 @@ +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('ffff::ffff'); +PREPARE stmt FROM 'INSERT INTO t1 VALUES (?)'; +EXECUTE stmt USING CAST('::1' AS INET6); +EXECUTE stmt USING CAST(CONCAT(REPEAT(0x00,15), 0x02) AS INET6); +DEALLOCATE PREPARE stmt; +BEGIN NOT ATOMIC +DECLARE a INET6 DEFAULT '::3'; +INSERT INTO t1 VALUES (a); +END; +$$ +DROP TABLE t1; +include/show_binlog_events.inc +Log_name Pos Event_type Server_id End_log_pos Info +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; CREATE TABLE t1 (a INET6) +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('::') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('ffff::ffff') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('::1') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('::2') +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # BEGIN GTID #-#-# +master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a','::3')) +master-bin.000001 # Query # # COMMIT +master-bin.000001 # Gtid # # GTID #-#-# +master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */ diff --git a/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.test b/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.test new file mode 100644 index 00000000000..d51448090c4 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/binlog_stm_type_inet6.test @@ -0,0 +1,28 @@ +--source include/not_embedded.inc +--source include/have_binlog_format_statement.inc + +--disable_query_log +reset master; # get rid of previous tests binlog +--enable_query_log + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('ffff::ffff'); + +PREPARE stmt FROM 'INSERT INTO t1 VALUES (?)'; +EXECUTE stmt USING CAST('::1' AS INET6); +EXECUTE stmt USING CAST(CONCAT(REPEAT(0x00,15), 0x02) AS INET6); +DEALLOCATE PREPARE stmt; + +DELIMITER $$; +BEGIN NOT ATOMIC + DECLARE a INET6 DEFAULT '::3'; + INSERT INTO t1 VALUES (a); +END; +$$ +DELIMITER ;$$ + +DROP TABLE t1; + +--let $binlog_file = LAST +source include/show_binlog_events.inc; diff --git a/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result new file mode 100644 index 00000000000..7911407b8f7 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.result @@ -0,0 +1,60 @@ +# +# Start of 10.5 tests +# +# +# MDEV-20822 INET6 crashes in combination with RBR extended metadata +# +# Using DEFAULT_CHARSET format +RESET MASTER; +SET GLOBAL binlog_row_metadata = NO_LOG; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +# Columns(BINARY(16)) +DROP TABLE t1; +RESET MASTER; +RESET MASTER; +SET GLOBAL binlog_row_metadata = MINIMAL; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +# Columns(BINARY(16)) +DROP TABLE t1; +RESET MASTER; +RESET MASTER; +SET GLOBAL binlog_row_metadata = FULL; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +# Columns(`a` BINARY(16)) +DROP TABLE t1; +RESET MASTER; +# Using COLUMN_CHARSET format +RESET MASTER; +SET GLOBAL binlog_row_metadata = NO_LOG; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +# Columns(BINARY(16), +# BINARY(16), +# BINARY(48)) +DROP TABLE t1; +RESET MASTER; +RESET MASTER; +SET GLOBAL binlog_row_metadata = MINIMAL; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +# Columns(BINARY(16), +# CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci, +# CHAR(16) CHARSET utf8 COLLATE utf8_general_ci) +DROP TABLE t1; +RESET MASTER; +RESET MASTER; +SET GLOBAL binlog_row_metadata = FULL; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +# Columns(`a` BINARY(16), +# `b` CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci, +# `c` CHAR(16) CHARSET utf8 COLLATE utf8_general_ci) +DROP TABLE t1; +RESET MASTER; +SET GLOBAL binlog_row_metadata = DEFAULT; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.test b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.test new file mode 100644 index 00000000000..63672f065a8 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/binlog_table_map_optional_metadata_type_inet6.test @@ -0,0 +1,72 @@ +--source include/have_debug.inc +--source include/have_binlog_format_row.inc + +--let $MYSQLD_DATADIR= `select @@datadir` +--let $binlog_file= $MYSQLD_DATADIR/master-bin.000001 + + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20822 INET6 crashes in combination with RBR extended metadata +--echo # + +--echo # Using DEFAULT_CHARSET format + +RESET MASTER; +SET GLOBAL binlog_row_metadata = NO_LOG; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +RESET MASTER; +SET GLOBAL binlog_row_metadata = MINIMAL; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +RESET MASTER; +SET GLOBAL binlog_row_metadata = FULL; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES('::'); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +--echo # Using COLUMN_CHARSET format + +RESET MASTER; +SET GLOBAL binlog_row_metadata = NO_LOG; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +RESET MASTER; +SET GLOBAL binlog_row_metadata = MINIMAL; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +RESET MASTER; +SET GLOBAL binlog_row_metadata = FULL; +CREATE TABLE t1 (a INET6, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8); +INSERT INTO t1 VALUES('::','',''); +--source suite/binlog/include/print_optional_metadata.inc +DROP TABLE t1; +RESET MASTER; + +SET GLOBAL binlog_row_metadata = DEFAULT; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.result b/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.result new file mode 100644 index 00000000000..9ee1a0202b0 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.result @@ -0,0 +1,112 @@ +# +# Start of 10.5 tests +# +# +# MDEV-20768 Turn INET functions into a function collection plugin +# +SELECT +'----' AS `----`, +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' + 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 +PLUGIN_AUTHOR MariaDB Corporation +PLUGIN_DESCRIPTION Function INET6_ATON() +PLUGIN_LICENSE GPL +PLUGIN_MATURITY Stable +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 Stable +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 Stable +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 Stable +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 Stable +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 Stable +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 Stable +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 Stable +PLUGIN_AUTH_VERSION 1.0 +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.test b/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.test new file mode 100644 index 00000000000..45b462e8e82 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/func_inet_plugin.test @@ -0,0 +1,37 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20768 Turn INET functions into a function collection plugin +--echo # + +--vertical_results +SELECT + '----' AS `----`, + 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' + 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 # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.result b/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.result new file mode 100644 index 00000000000..7b69217f548 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.result @@ -0,0 +1,35 @@ +include/master-slave.inc +[connection master] +# +# Start of 10.5 tests +# +# +# MDEV-20844 RBR from binary(16) to inet6 fails with error 171: The event was corrupt, leading to illegal data being read +# +CREATE TABLE t1 (a BINARY(16)); +connection slave; +ALTER TABLE t1 MODIFY a INET6; +connection master; +INSERT INTO t1 VALUES (INET6_ATON('::')); +INSERT INTO t1 VALUES (INET6_ATON('::192.168.0.1')); +INSERT INTO t1 VALUES (INET6_ATON('ffff::')); +INSERT INTO t1 VALUES (INET6_ATON('ffff::192.168.0.1')); +SELECT INET6_NTOA(a) FROM t1 ORDER BY a; +INET6_NTOA(a) +:: +::192.168.0.1 +ffff:: +ffff::c0a8:1 +connection slave; +SELECT * FROM t1 ORDER BY a; +a +:: +::192.168.0.1 +ffff:: +ffff::c0a8:1 +connection master; +DROP TABLE t1; +# +# End of 10.5 tests +# +include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.test b/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.test new file mode 100644 index 00000000000..f48b1c49d48 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_row_binary_to_inet6.test @@ -0,0 +1,33 @@ +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20844 RBR from binary(16) to inet6 fails with error 171: The event was corrupt, leading to illegal data being read +--echo # + +CREATE TABLE t1 (a BINARY(16)); + +--sync_slave_with_master +ALTER TABLE t1 MODIFY a INET6; + +--connection master +INSERT INTO t1 VALUES (INET6_ATON('::')); +INSERT INTO t1 VALUES (INET6_ATON('::192.168.0.1')); +INSERT INTO t1 VALUES (INET6_ATON('ffff::')); +INSERT INTO t1 VALUES (INET6_ATON('ffff::192.168.0.1')); +SELECT INET6_NTOA(a) FROM t1 ORDER BY a; +--sync_slave_with_master +SELECT * FROM t1 ORDER BY a; + +--connection master +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # + +--source include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.result b/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.result new file mode 100644 index 00000000000..932043a92b4 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.result @@ -0,0 +1,35 @@ +include/master-slave.inc +[connection master] +# +# Start of 10.5 tests +# +# +# MDEV-20844 RBR from binary(16) to inet6 fails with error 171: The event was corrupt, leading to illegal data being read +# +CREATE TABLE t1 (a INET6); +connection slave; +ALTER TABLE t1 MODIFY a BINARY(16); +connection master; +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('::192.168.0.1'); +INSERT INTO t1 VALUES ('ffff::'); +INSERT INTO t1 VALUES ('ffff::192.168.0.1'); +SELECT a FROM t1 ORDER BY a; +a +:: +::192.168.0.1 +ffff:: +ffff::c0a8:1 +connection slave; +SELECT INET6_NTOA(a) FROM t1 ORDER BY a; +INET6_NTOA(a) +:: +::192.168.0.1 +ffff:: +ffff::c0a8:1 +connection master; +DROP TABLE t1; +# +# End of 10.5 tests +# +include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.test b/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.test new file mode 100644 index 00000000000..7abb4f6ffd9 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_row_inet6_to_binary.test @@ -0,0 +1,33 @@ +--source include/have_binlog_format_row.inc +--source include/master-slave.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20844 RBR from binary(16) to inet6 fails with error 171: The event was corrupt, leading to illegal data being read +--echo # + +CREATE TABLE t1 (a INET6); + +--sync_slave_with_master +ALTER TABLE t1 MODIFY a BINARY(16); + +--connection master +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('::192.168.0.1'); +INSERT INTO t1 VALUES ('ffff::'); +INSERT INTO t1 VALUES ('ffff::192.168.0.1'); +SELECT a FROM t1 ORDER BY a; +--sync_slave_with_master +SELECT INET6_NTOA(a) FROM t1 ORDER BY a; + +--connection master +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # + +--source include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.result b/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.result new file mode 100644 index 00000000000..5bda0b079a5 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.result @@ -0,0 +1,17 @@ +include/master-slave.inc +[connection master] +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +connection master; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +connection slave; +SELECT HEX(a), a FROM t1; +HEX(a) a +00000000000000000000000000000000 :: +FFFF000000000000000000000000FFFF ffff::ffff +connection master; +DROP TABLE t1; +connection slave; +include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.test b/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.test new file mode 100644 index 00000000000..91c092b6e20 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/rpl_type_inet6.test @@ -0,0 +1,16 @@ +--source include/master-slave.inc + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + +connection master; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +sync_slave_with_master; +SELECT HEX(a), a FROM t1; +connection master; +DROP TABLE t1; +sync_slave_with_master; + +--source include/rpl_end.inc diff --git a/plugin/type_inet/mysql-test/type_inet/suite.pm b/plugin/type_inet/mysql-test/type_inet/suite.pm new file mode 100644 index 00000000000..5893fcb78cc --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/suite.pm @@ -0,0 +1,9 @@ +package My::Suite::Type_inet; + +@ISA = qw(My::Suite); + +#return "No inet6 plugin" unless $::mysqld_variables{'inet6'} eq "ON"; + +sub is_default { 1 } + +bless { }; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.result b/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.result new file mode 100644 index 00000000000..2be7aca4107 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.result @@ -0,0 +1,18 @@ +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +SET @old_debug_dbug=@@debug_dbug; +SET debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (c01 INET6, c02 INET6); +Warnings: +Note 1105 build_frm_image: Field data type info length: 14 +Note 1105 DBUG: [0] name='c01' type_info='inet6' +Note 1105 DBUG: [1] name='c02' type_info='inet6' +SET debug_dbug=@old_debug_dbug; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c01` inet6 DEFAULT NULL, + `c02` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.test b/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.test new file mode 100644 index 00000000000..ef5ea8363f2 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6-debug.test @@ -0,0 +1,14 @@ +--source include/have_debug.inc + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + +SET @old_debug_dbug=@@debug_dbug; + +SET debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (c01 INET6, c02 INET6); +SET debug_dbug=@old_debug_dbug; + +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.result b/plugin/type_inet/mysql-test/type_inet/type_inet6.result new file mode 100644 index 00000000000..dd21c6abaf2 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.result @@ -0,0 +1,2231 @@ +# +# Basic CREATE functionality, defaults, metadata +# +CREATE TABLE t1 (a INET6 AUTO_INCREMENT); +ERROR 42000: Incorrect column specifier for column 'a' +CREATE TABLE t1 (a INET6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DESCRIBE t1; +Field Type Null Key Default Extra +a inet6 YES NULL +SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='test' AND table_name='t1'; +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME a +ORDINAL_POSITION 1 +COLUMN_DEFAULT NULL +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'); +SELECT * FROM t1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t1 t1 a a 254 (type=inet6) 39 3 Y 160 0 8 +a +::1 +SELECT CAST('::' AS INET6) AS a; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def a 254 (type=inet6) 39 2 N 33 0 8 +a +:: +DROP TABLE t1; +CREATE TABLE t1 ( +c1 INET6 DEFAULT 0x00000000000000000000000000000000, +c2 INET6 DEFAULT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, +c3 INET6 DEFAULT '::', +c4 INET6 DEFAULT 'FFFF::ffff', +c5 INET6 DEFAULT CAST(X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' AS INET6) +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c1` inet6 DEFAULT '::', + `c2` inet6 DEFAULT 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff', + `c3` inet6 DEFAULT '::', + `c4` inet6 DEFAULT 'ffff::ffff', + `c5` inet6 DEFAULT cast(X'ffffffffffffffffffffffffffffffff' as inet6) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DESCRIBE t1; +Field Type Null Key Default Extra +c1 inet6 YES :: +c2 inet6 YES ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff +c3 inet6 YES :: +c4 inet6 YES ffff::ffff +c5 inet6 YES cast(X'ffffffffffffffffffffffffffffffff' as inet6) +SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='test' AND table_name='t1'; +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME c1 +ORDINAL_POSITION 1 +COLUMN_DEFAULT '::' +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME c2 +ORDINAL_POSITION 2 +COLUMN_DEFAULT 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME c3 +ORDINAL_POSITION 3 +COLUMN_DEFAULT '::' +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME c4 +ORDINAL_POSITION 4 +COLUMN_DEFAULT 'ffff::ffff' +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME c5 +ORDINAL_POSITION 5 +COLUMN_DEFAULT cast(X'ffffffffffffffffffffffffffffffff' as inet6) +IS_NULLABLE YES +DATA_TYPE inet6 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION NULL +NUMERIC_SCALE NULL +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE inet6 +COLUMN_KEY +EXTRA +PRIVILEGES # +COLUMN_COMMENT +IS_GENERATED NEVER +GENERATION_EXPRESSION NULL +DROP TABLE t1; +CREATE TABLE t1 (c1 INET6 DEFAULT 0x00); +ERROR 42000: Invalid default value for 'c1' +CREATE TABLE t1 (c1 INET6 DEFAULT ''); +ERROR 42000: Invalid default value for 'c1' +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('x'); +ERROR 22007: Incorrect inet6 value: 'x' for column `test`.`t1`.`a` at row 1 +INSERT INTO t1 VALUES (1); +ERROR 22007: Incorrect inet6 value: '1' for column `test`.`t1`.`a` at row 1 +INSERT INTO t1 VALUES (TIME'10:20:30'); +ERROR 22007: Incorrect inet6 value: '10:20:30' for column `test`.`t1`.`a` at row 1 +INSERT INTO t1 VALUES (0x00); +ERROR 22007: Incorrect inet6 value: '\x00' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +# +# CAST +# +SELECT CAST('garbage' AS INET6); +CAST('garbage' AS INET6) +NULL +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT CAST(0x01 AS INET6); +CAST(0x01 AS INET6) +NULL +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +SELECT CAST(REPEAT(0x00,16) AS INET6); +CAST(REPEAT(0x00,16) AS INET6) +:: +SELECT CAST(REPEAT(0x11,16) AS INET6); +CAST(REPEAT(0x11,16) AS INET6) +1111:1111:1111:1111:1111:1111:1111:1111 +CREATE TABLE t1 AS SELECT CAST('::' AS INET6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `CAST('::' AS INET6)` inet6 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +# +# Text and binary formats, comparison operators +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xFFFF0000000000000000000000000001); +INSERT INTO t1 VALUES (0xFFFF0000000000000000000000000002); +SELECT * FROM t1 ORDER BY a; +a +:: +::1 +ffff::1 +ffff::2 +SELECT * FROM t1 ORDER BY a DESC; +a +ffff::2 +ffff::1 +::1 +:: +SELECT HEX(a),a FROM t1 ORDER BY a; +HEX(a) a +00000000000000000000000000000000 :: +00000000000000000000000000000001 ::1 +FFFF0000000000000000000000000001 ffff::1 +FFFF0000000000000000000000000002 ffff::2 +SELECT * FROM t1 WHERE a='::'; +a +:: +SELECT * FROM t1 WHERE a='::1'; +a +::1 +SELECT * FROM t1 WHERE a='ffff::1'; +a +ffff::1 +SELECT * FROM t1 WHERE a='ffff::2'; +a +ffff::2 +SELECT * FROM t1 WHERE a=0x00000000000000000000000000000000; +a +:: +SELECT * FROM t1 WHERE a=0x00000000000000000000000000000001; +a +::1 +SELECT * FROM t1 WHERE a=0xffff0000000000000000000000000001; +a +ffff::1 +SELECT * FROM t1 WHERE a=0xffff0000000000000000000000000002; +a +ffff::2 +SELECT * FROM t1 WHERE a<'::'; +a +SELECT * FROM t1 WHERE a<='::'; +a +:: +SELECT * FROM t1 WHERE a>='ffff::2'; +a +ffff::2 +SELECT * FROM t1 WHERE a>'ffff::2'; +a +SELECT * FROM t1 WHERE a IN ('::', 'ffff::1') ORDER BY a; +a +:: +ffff::1 +SELECT * FROM t1 WHERE a IN ('::', 0xffff0000000000000000000000000002) ORDER BY a; +a +:: +ffff::2 +SELECT * FROM t1 WHERE a<'garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a<='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a>='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a>'garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a<0x01; +a +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +SELECT * FROM t1 WHERE a<=0x01; +a +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +SELECT * FROM t1 WHERE a=0x01; +a +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +Warning 1292 Incorrect inet6 value: '\x01' +SELECT * FROM t1 WHERE a>=0x01; +a +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +SELECT * FROM t1 WHERE a>0x01; +a +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +SELECT * FROM t1 WHERE a='0::0'; +a +:: +SELECT * FROM t1 WHERE a='0::00'; +a +:: +SELECT * FROM t1 WHERE a='0::000'; +a +:: +SELECT * FROM t1 WHERE a='0::0000'; +a +:: +SELECT * FROM t1 WHERE a=0; +ERROR HY000: Illegal parameter data types inet6 and int for operation '=' +SELECT * FROM t1 WHERE a=0.0; +ERROR HY000: Illegal parameter data types inet6 and decimal for operation '=' +SELECT * FROM t1 WHERE a=0e0; +ERROR HY000: Illegal parameter data types inet6 and double for operation '=' +SELECT * FROM t1 WHERE a=TIME'10:20:30'; +ERROR HY000: Illegal parameter data types inet6 and time for operation '=' +SELECT * FROM t1 WHERE a IN ('::', 10); +ERROR HY000: Illegal parameter data types inet6 and int for operation 'in' +DROP TABLE t1; +# +# cmp_item_inet6: IN for non-constants +# +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('::1', '::2'); +SELECT * FROM t1 WHERE '::' IN (a, b); +a b +SELECT * FROM t1 WHERE '::1' IN (a, b); +a b +::1 ::2 +SELECT * FROM t1 WHERE '::01' IN (a, b); +a b +::1 ::2 +SELECT * FROM t1 WHERE '00::01' IN (a, b); +a b +::1 ::2 +DROP TABLE t1; +# +# cmp_item_inet6: DECODE_ORACLE +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (NULL),('::01'),('::02'); +SELECT a, DECODE_ORACLE(a, '::01', '01') AS d FROM t1; +a d +NULL NULL +::1 01 +::2 NULL +SELECT +a, +DECODE_ORACLE(a, '::01', '01') AS d0, +DECODE_ORACLE(a, NULL, '<NULL>', '::01', '01') AS d1, +DECODE_ORACLE(a, 'garbage', '<NULL>', '::01', '01') AS d2 +FROM t1; +a d0 d1 d2 +NULL NULL <NULL> <NULL> +::1 01 01 01 +::2 NULL NULL NULL +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +DROP TABLE t1; +# +# CASE abbreviations +# +CREATE TABLE t1 ( +c INET6, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext TEXT, +c_longtext LONGTEXT +); +CREATE TABLE t2 AS SELECT +COALESCE(c, c_char), +COALESCE(c, c_varchar), +COALESCE(c, c_tinytext), +COALESCE(c, c_text), +COALESCE(c, c_mediumtext), +COALESCE(c, c_longtext) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(c, c_char)` inet6 DEFAULT NULL, + `COALESCE(c, c_varchar)` inet6 DEFAULT NULL, + `COALESCE(c, c_tinytext)` inet6 DEFAULT NULL, + `COALESCE(c, c_text)` inet6 DEFAULT NULL, + `COALESCE(c, c_mediumtext)` inet6 DEFAULT NULL, + `COALESCE(c, c_longtext)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT +LEAST(c, c_char), +LEAST(c, c_varchar), +LEAST(c, c_tinytext), +LEAST(c, c_text), +LEAST(c, c_mediumtext), +LEAST(c, c_longtext) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `LEAST(c, c_char)` inet6 DEFAULT NULL, + `LEAST(c, c_varchar)` inet6 DEFAULT NULL, + `LEAST(c, c_tinytext)` inet6 DEFAULT NULL, + `LEAST(c, c_text)` inet6 DEFAULT NULL, + `LEAST(c, c_mediumtext)` inet6 DEFAULT NULL, + `LEAST(c, c_longtext)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (NULL),('::1'),('::2'); +SELECT COALESCE(a, '::') FROM t1 ORDER BY a; +COALESCE(a, '::') +:: +::1 +::2 +SELECT a, LEAST(a,'::0'), LEAST(a,'::f') FROM t1 ORDER BY a; +a LEAST(a,'::0') LEAST(a,'::f') +NULL NULL NULL +::1 :: ::1 +::2 :: ::2 +SELECT a, GREATEST(a,'::0'), GREATEST(a,'::f') FROM t1 ORDER BY a; +a GREATEST(a,'::0') GREATEST(a,'::f') +NULL NULL NULL +::1 ::1 ::f +::2 ::2 ::f +CREATE TABLE t2 AS SELECT +COALESCE(a, '::'), +LEAST(a,'::'), +GREATEST(a,'::') +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a, '::')` inet6 DEFAULT NULL, + `LEAST(a,'::')` inet6 DEFAULT NULL, + `GREATEST(a,'::')` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +SELECT COALESCE(a, 0x00000000000000000000000000000000) FROM t1 ORDER BY a; +COALESCE(a, 0x00000000000000000000000000000000) +:: +::1 +::2 +SELECT a, +LEAST(a, 0x00000000000000000000000000000000), +LEAST(a, 0x0000000000000000000000000000000f) +FROM t1 ORDER BY a; +a LEAST(a, 0x00000000000000000000000000000000) LEAST(a, 0x0000000000000000000000000000000f) +NULL NULL NULL +::1 :: ::1 +::2 :: ::2 +SELECT a, +GREATEST(a, 0x00000000000000000000000000000000), +GREATEST(a, 0x0000000000000000000000000000000f) +FROM t1 ORDER BY a; +a GREATEST(a, 0x00000000000000000000000000000000) GREATEST(a, 0x0000000000000000000000000000000f) +NULL NULL NULL +::1 ::1 ::f +::2 ::2 ::f +CREATE TABLE t2 AS SELECT +COALESCE(a, 0x00000000000000000000000000000000), +LEAST(a,0x00000000000000000000000000000000), +GREATEST(a,0x00000000000000000000000000000000) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a, 0x00000000000000000000000000000000)` inet6 DEFAULT NULL, + `LEAST(a,0x00000000000000000000000000000000)` inet6 DEFAULT NULL, + `GREATEST(a,0x00000000000000000000000000000000)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +SELECT COALESCE(a, 10) FROM t1; +ERROR HY000: Illegal parameter data types inet6 and int for operation 'coalesce' +SELECT LEAST(a, 10) FROM t1; +ERROR HY000: Illegal parameter data types inet6 and int for operation 'least' +SELECT GREATEST(a, 10) FROM t1; +ERROR HY000: Illegal parameter data types inet6 and int for operation 'greatest' +DROP TABLE t1; +SELECT COALESCE('garbage', CAST('::1' AS INET6)); +COALESCE('garbage', CAST('::1' AS INET6)) +::1 +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT COALESCE(0x01, CAST('::1' AS INET6)); +COALESCE(0x01, CAST('::1' AS INET6)) +::1 +Warnings: +Warning 1292 Incorrect inet6 value: '\x01' +# +# Uniqueness +# +CREATE TABLE t1 (a INET6 NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES ('41::1'),('61::1'); +INSERT INTO t1 VALUES ('41::1'); +ERROR 23000: Duplicate entry '41::1' for key 'PRIMARY' +SELECT * FROM t1; +a +41::1 +61::1 +DROP TABLE t1; +# +# Indexes +# +CREATE TABLE t1 (a INET6, KEY(a(1))); +ERROR HY000: Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys +# +# Explicit CAST on INSERT +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (CAST('1::1' AS INET6)); +INSERT INTO t1 VALUES (CAST('1::2' AS INET6)); +INSERT INTO t1 VALUES (CAST('1::3' AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::1') AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::2') AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::3') AS INET6)); +SELECT * FROM t1 ORDER BY a; +a +1::1 +1::2 +1::3 +2::1 +2::2 +2::3 +DROP TABLE t1; +# +# Explicit CAST and implicit CAST on ALTER +# +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('garbage'),('::'),('::1'),('ffff::1'),('ffff::2'); +SELECT a, CAST(a AS INET6) FROM t1 ORDER BY a; +a CAST(a AS INET6) +:: :: +::1 ::1 +ffff::1 ffff::1 +ffff::2 ffff::2 +garbage NULL +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT a, CAST(a AS INET6) FROM t1 ORDER BY CAST(a AS INET6); +a CAST(a AS INET6) +garbage NULL +:: :: +::1 ::1 +ffff::1 ffff::1 +ffff::2 ffff::2 +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +ALTER TABLE t1 MODIFY a INET6; +ERROR 22007: Incorrect inet6 value: 'garbage' for column `test`.`t1`.`a` at row 1 +SET sql_mode=''; +ALTER TABLE t1 MODIFY a INET6; +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' for column `test`.`t1`.`a` at row 1 +SET sql_mode=DEFAULT; +SELECT * FROM t1 ORDER BY a; +a +NULL +:: +::1 +ffff::1 +ffff::2 +DROP TABLE t1; +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000002); +SELECT HEX(a), CAST(a AS INET6) FROM t1 ORDER BY a; +HEX(a) CAST(a AS INET6) +00000000000000000000000000000000 :: +00000000000000000000000000000001 ::1 +FFFF0000000000000000000000000001 ffff::1 +FFFF0000000000000000000000000002 ffff::2 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1 ORDER BY a; +a +:: +::1 +ffff::1 +ffff::2 +DROP TABLE t1; +# +# INSERT..SELECT, same data types +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +CREATE TABLE t2 (a INET6); +INSERT INTO t2 SELECT a FROM t1; +SELECT * FROM t2; +a +:: +::1 +::2 +DROP TABLE t1,t2; +# +# Implicit CAST on INSERT..SELECT, text format +# +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('garbage'),('::'),('::1'),('ffff::1'),('ffff::2'); +CREATE TABLE t2 (a INET6); +INSERT INTO t2 SELECT a FROM t1; +ERROR 22007: Incorrect inet6 value: 'garbage' for column `test`.`t2`.`a` at row 1 +SET sql_mode=''; +INSERT INTO t2 SELECT a FROM t1; +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' for column `test`.`t2`.`a` at row 1 +SELECT * FROM t2 ORDER BY a; +a +NULL +:: +::1 +ffff::1 +ffff::2 +SET sql_mode=DEFAULT; +DROP TABLE t2; +CREATE TABLE t2 (a INET6 NOT NULL); +INSERT INTO t2 SELECT a FROM t1; +ERROR 22007: Incorrect inet6 value: 'garbage' for column `test`.`t2`.`a` at row 1 +SET sql_mode=''; +INSERT INTO t2 SELECT a FROM t1; +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' for column `test`.`t2`.`a` at row 1 +SELECT * FROM t2 ORDER BY a; +a +:: +:: +::1 +ffff::1 +ffff::2 +SET sql_mode=DEFAULT; +DROP TABLE t2; +DROP TABLE t1; +# +# Implicit CAST on INSERT..SELECT, binary format +# +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000002); +CREATE TABLE t2 (a INET6); +INSERT INTO t2 SELECT a FROM t1; +SELECT a FROM t2 ORDER BY a; +a +:: +::1 +ffff::1 +ffff::2 +DROP TABLE t1,t2; +# +# CAST to other data types +# +SELECT CAST(CAST('::' AS INET6) AS DOUBLE); +ERROR HY000: Illegal parameter data type inet6 for operation 'double_typecast' +SELECT CAST(CAST('::' AS INET6) AS FLOAT); +ERROR HY000: Illegal parameter data type inet6 for operation 'float_typecast' +SELECT CAST(CAST('::' AS INET6) AS DECIMAL); +ERROR HY000: Illegal parameter data type inet6 for operation 'decimal_typecast' +SELECT CAST(CAST('::' AS INET6) AS SIGNED); +ERROR HY000: Illegal parameter data type inet6 for operation 'cast_as_signed' +SELECT CAST(CAST('::' AS INET6) AS UNSIGNED); +ERROR HY000: Illegal parameter data type inet6 for operation 'cast_as_unsigned' +SELECT CAST(CAST('::' AS INET6) AS TIME); +ERROR HY000: Illegal parameter data type inet6 for operation 'cast_as_time' +SELECT CAST(CAST('::' AS INET6) AS DATE); +ERROR HY000: Illegal parameter data type inet6 for operation 'cast_as_date' +SELECT CAST(CAST('::' AS INET6) AS DATETIME); +ERROR HY000: Illegal parameter data type inet6 for operation 'cast_as_datetime' +SELECT CAST(CAST('::' AS INET6) AS CHAR); +CAST(CAST('::' AS INET6) AS CHAR) +:: +CREATE TABLE t1 AS SELECT CAST(CAST('::' AS INET6) AS CHAR) AS a; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` varchar(39) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('ffff::ffff'); +CREATE TABLE t2 AS SELECT +CAST(a AS CHAR), +CAST(a AS CHAR(39)), +CAST(a AS CHAR(530)), +CAST(a AS CHAR(65535)), +CAST(a AS CHAR(66000)), +CAST(a AS CHAR(16777215)), +CAST(a AS CHAR(16777216)) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `CAST(a AS CHAR)` varchar(39) DEFAULT NULL, + `CAST(a AS CHAR(39))` varchar(39) DEFAULT NULL, + `CAST(a AS CHAR(530))` text DEFAULT NULL, + `CAST(a AS CHAR(65535))` text DEFAULT NULL, + `CAST(a AS CHAR(66000))` mediumtext DEFAULT NULL, + `CAST(a AS CHAR(16777215))` mediumtext DEFAULT NULL, + `CAST(a AS CHAR(16777216))` longtext DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2; +CAST(a AS CHAR) ffff::ffff +CAST(a AS CHAR(39)) ffff::ffff +CAST(a AS CHAR(530)) ffff::ffff +CAST(a AS CHAR(65535)) ffff::ffff +CAST(a AS CHAR(66000)) ffff::ffff +CAST(a AS CHAR(16777215)) ffff::ffff +CAST(a AS CHAR(16777216)) ffff::ffff +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('ffff::ffff'); +CREATE TABLE t2 AS SELECT +CAST(a AS BINARY(4)) AS cb4, +CAST(a AS BINARY) AS cb, +CAST(a AS BINARY(16)) AS cb16, +CAST(a AS BINARY(32)) AS cb32, +CAST(a AS BINARY(530)) AS cb530, +CAST(a AS BINARY(65535)) AS cb65535, +CAST(a AS BINARY(66000)) AS cb66000, +CAST(a AS BINARY(16777215)) AS cb16777215, +CAST(a AS BINARY(16777216)) AS cb16777216 +FROM t1 LIMIT 0; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cb4` binary(4) DEFAULT NULL, + `cb` binary(16) DEFAULT NULL, + `cb16` binary(16) DEFAULT NULL, + `cb32` binary(32) DEFAULT NULL, + `cb530` varbinary(530) DEFAULT NULL, + `cb65535` blob DEFAULT NULL, + `cb66000` mediumblob DEFAULT NULL, + `cb16777215` mediumblob DEFAULT NULL, + `cb16777216` longblob DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT +CAST(a AS BINARY(4)) AS cb4, +CAST(a AS BINARY) AS cb, +CAST(a AS BINARY(16)) AS cb16, +CAST(a AS BINARY(32)) AS cb32, +CAST(a AS BINARY(530)) AS cb530, +CAST(a AS BINARY(65535)) AS cb65535 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cb4` binary(4) DEFAULT NULL, + `cb` binary(16) DEFAULT NULL, + `cb16` binary(16) DEFAULT NULL, + `cb32` binary(32) DEFAULT NULL, + `cb530` varbinary(530) DEFAULT NULL, + `cb65535` blob DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT +HEX(cb4), +HEX(cb), +HEX(cb16), +HEX(cb32), +LENGTH(cb530), +LENGTH(cb65535) +FROM t2; +HEX(cb4) FFFF0000 +HEX(cb) FFFF000000000000000000000000FFFF +HEX(cb16) FFFF000000000000000000000000FFFF +HEX(cb32) FFFF000000000000000000000000FFFF00000000000000000000000000000000 +LENGTH(cb530) 530 +LENGTH(cb65535) 65535 +DROP TABLE t2; +DROP TABLE t1; +# +# Implicit conversion to other types in INSERT +# +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +ERROR 22007: Incorrect integer value: '::' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a DOUBLE); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +ERROR 22007: Incorrect double value: '::' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL(32,0)); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +ERROR 22007: Incorrect decimal value: '::' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; +CREATE TABLE t1 (a TEXT); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; +# +# Boolean context +# +SELECT +CAST('::' AS INET6) IS TRUE, +CAST('::' AS INET6) IS FALSE, +CAST('::1' AS INET6) IS TRUE, +CAST('::1' AS INET6) IS FALSE; +CAST('::' AS INET6) IS TRUE CAST('::' AS INET6) IS FALSE CAST('::1' AS INET6) IS TRUE CAST('::1' AS INET6) IS FALSE +0 1 1 0 +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'); +SELECT a, a IS TRUE, a IS FALSE FROM t1 ORDER BY a; +a a IS TRUE a IS FALSE +:: 0 1 +::1 1 0 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1 WHERE a; +ERROR HY000: Illegal parameter data types inet6 and bigint for operation '<>' +DROP TABLE t1; +# +# GROUP BY +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +INSERT INTO t1 VALUES ('::1'),('::01'),('::0001'); +INSERT INTO t1 VALUES ('::2'),('::2'),('::2'),('::2'); +SELECT a, COUNT(*) FROM t1 GROUP BY a; +a COUNT(*) +:: 2 +::1 3 +::2 4 +DROP TABLE t1; +# +# Aggregate functions +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +INSERT INTO t1 VALUES ('::1'),('::01'),('::0001'); +INSERT INTO t1 VALUES ('::2'),('::2'),('::2'),('::2'); +SELECT MIN(a),MAX(a) FROM t1; +MIN(a) MAX(a) +:: ::2 +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `MIN(a)` inet6 DEFAULT NULL, + `MAX(a)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +SELECT AVG(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'avg(' +SELECT AVG(DISTINCT a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'avg(distinct ' +SELECT SUM(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'sum(' +SELECT SUM(DISTINCT a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'sum(distinct ' +SELECT STDDEV(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'std(' +SELECT GROUP_CONCAT(a ORDER BY a) FROM t1; +GROUP_CONCAT(a ORDER BY a) +::,::,::1,::1,::1,::2,::2,::2,::2 +SELECT a, GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a; +a GROUP_CONCAT(a ORDER BY a) +:: ::,:: +::1 ::1,::1,::1 +::2 ::2,::2,::2,::2 +DROP TABLE t1; +# +# MDEV-21765 Possibly inconsistent behavior of BIT_xx functions with INET6 field +# +CREATE TABLE t1 (a INET6); +SELECT BIT_AND(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'bit_and(' +SELECT BIT_OR(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'bit_or(' +SELECT BIT_XOR(a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'bit_xor(' +DROP TABLE t1; +# +# Window functions +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'),('::2'),('::3'),('::4'); +SELECT +a, +LAG(a) OVER (ORDER BY a), +LEAD(a) OVER (ORDER BY a) +FROM t1 ORDER BY a; +a LAG(a) OVER (ORDER BY a) LEAD(a) OVER (ORDER BY a) +::1 NULL ::2 +::2 ::1 ::3 +::3 ::2 ::4 +::4 ::3 NULL +SELECT +a, +FIRST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING), +LAST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +FROM t1 ORDER BY a; +a FIRST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) LAST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +::1 ::1 ::2 +::2 ::1 ::3 +::3 ::2 ::4 +::4 ::3 ::4 +DROP TABLE t1; +# +# Prepared statements +# +EXECUTE IMMEDIATE 'CREATE TABLE t1 AS SELECT ? AS a' USING CAST('::' AS INET6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING '::1'; +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING CAST('::2' AS INET6); +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING 0x00000000000000000000000000000003; +SELECT a FROM t1 ORDER BY a; +a +:: +::1 +::2 +::3 +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING '::1'; +a +::1 +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING CAST('::2' AS INET6); +a +::2 +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING 0x00000000000000000000000000000003; +a +::3 +DROP TABLE t1; +# +# Character set and collation aggregation +# +CREATE TABLE t1 (a INET6); +CREATE TABLE t2 AS SELECT +CONCAT(a) AS c1, +CONCAT(CAST('::' AS INET6)) AS c2 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` varchar(39) DEFAULT NULL, + `c2` varchar(39) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT +CONCAT(_utf8'1', a) AS c1, +CONCAT(_utf8'1', CAST('::1' AS INET6)) AS c2, +CONCAT(_utf8'1', COALESCE(a)) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL, + `c2` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL, + `c3` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT +CONCAT(_latin1'1', a) AS c1, +CONCAT(_latin1'1', CAST('::1' AS INET6)) AS c2, +CONCAT(_latin1'1', COALESCE(a)) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` varchar(40) DEFAULT NULL, + `c2` varchar(40) DEFAULT NULL, + `c3` varchar(40) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# +# UNION +# +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT CAST('::1' AS INET6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` inet6 NOT NULL DEFAULT '::' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT '::1'; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` inet6 NOT NULL DEFAULT '::' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 AS SELECT '::' AS c UNION SELECT CAST('::1' AS INET6); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `c` inet6 NOT NULL DEFAULT '::' +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT 0x00000000000000000000000000000001; +SELECT * FROM t1; +c +:: +::1 +DROP TABLE t1; +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation 'UNION' +# +# Unary operators +# +SELECT -CAST('::' AS INET6); +ERROR HY000: Illegal parameter data type inet6 for operation '-' +SELECT ABS(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'abs' +SELECT ROUND(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'round' +SELECT CEILING(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'ceiling' +SELECT FLOOR(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'floor' +# +# Arithmetic operators +# +SELECT CAST('::' AS INET6) + 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation '+' +SELECT CAST('::' AS INET6) - 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation '-' +SELECT CAST('::' AS INET6) * 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation '*' +SELECT CAST('::' AS INET6) / 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation '/' +SELECT CAST('::' AS INET6) MOD 1; +ERROR HY000: Illegal parameter data types inet6 and int for operation 'MOD' +# +# Misc +# +SELECT RAND(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'rand' +SELECT FROM_UNIXTIME(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'from_unixtime' +SELECT HOUR(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'hour' +SELECT YEAR(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'year' +SELECT RELEASE_LOCK(CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'release_lock' +SELECT JSON_LENGTH(CAST('::' AS INET6)); +JSON_LENGTH(CAST('::' AS INET6)) +NULL +Warnings: +Warning 4038 Syntax error in JSON text in argument 1 to function 'json_length' at position 1 +# +# Virtual columns +# +CREATE TABLE t1 ( +a INT, +b INET6 GENERATED ALWAYS AS (CAST(CONCAT(RAND(),a) AS INET6)), INDEX(b) +); +ERROR HY000: Function or expression 'rand()' cannot be used in the GENERATED ALWAYS AS clause of `b` +CREATE TABLE t1 ( +a INT, +b INET6 GENERATED ALWAYS AS (CAST(CONCAT('::',HEX(a)) AS INET6)), INDEX(b) +); +INSERT INTO t1 (a) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15); +SELECT * FROM t1; +a b +0 :: +1 ::1 +2 ::2 +3 ::3 +4 ::4 +5 ::5 +6 ::6 +7 ::7 +8 ::8 +9 ::9 +10 ::a +11 ::b +12 ::c +13 ::d +14 ::e +15 ::f +DROP TABLE t1; +# +# VIEW +# +CREATE TABLE t1 (a INT DEFAULT 0); +INSERT INTO t1 (a) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15); +SELECT * FROM t1 ORDER BY a; +a +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +CREATE VIEW v1 AS SELECT (CAST(CONCAT('::',HEX(a)) AS INET6)) AS c FROM t1; +SELECT * FROM v1 ORDER BY c; +c +:: +::1 +::2 +::3 +::4 +::5 +::6 +::7 +::8 +::9 +::a +::b +::c +::d +::e +::f +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INET6 DEFAULT '::'); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci +DESCRIBE v1; +Field Type Null Key Default Extra +a inet6 YES :: +INSERT INTO v1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1; +a +:: +::1 +::2 +DROP VIEW v1; +DROP TABLE t1; +CREATE TABLE t1 (a INET6 DEFAULT CAST('::' AS INET6)); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +View Create View character_set_client collation_connection +v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` latin1 latin1_swedish_ci +DESCRIBE v1; +Field Type Null Key Default Extra +a inet6 YES cast('::' as inet6) +INSERT INTO v1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1; +a +:: +::1 +::2 +DROP VIEW v1; +DROP TABLE t1; +# +# Subqueries +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1 WHERE a=(SELECT MIN(a) FROM t1) ORDER BY a; +a +:: +SELECT * FROM t1 WHERE a=(SELECT MAX(a) FROM t1) ORDER BY a; +a +::2 +SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a>'::') ORDER BY a; +a +::1 +::2 +DROP TABLE t1; +# +# Stored routines +# +CREATE PROCEDURE p1(a INET6) +BEGIN +DECLARE b INET6 DEFAULT CONCAT('1', a); +SELECT a, b; +END; +$$ +CALL p1('::1'); +a b +::1 1::1 +CALL p1(CAST('::2' AS INET6)); +a b +::2 1::2 +DROP PROCEDURE p1; +CREATE FUNCTION f1(a INET6) RETURNS INET6 +BEGIN +RETURN CONCAT('1',a); +END; +$$ +SELECT f1('::1'); +f1('::1') +1::1 +SELECT f1(CAST('::1' AS INET6)); +f1(CAST('::1' AS INET6)) +1::1 +DROP FUNCTION f1; +# +# Anchored data types in SP variables +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'); +CREATE PROCEDURE p1() +BEGIN +DECLARE va TYPE OF t1.a; +SELECT MAX(a) INTO va FROM t1; +SELECT va; +END; +$$ +CALL p1; +va +::1 +DROP PROCEDURE p1; +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('::a', '::b'); +CREATE PROCEDURE p1() +BEGIN +DECLARE va ROW TYPE OF t1; +SELECT MAX(a), MAX(b) INTO va FROM t1; +SELECT va.a, va.b; +END; +$$ +CALL p1; +va.a va.b +::a ::b +DROP PROCEDURE p1; +DROP TABLE t1; +# +# Optimizer: make_const_item_for_comparison +# +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=COALESCE(CAST('::1' AS INET6)) AND id>0; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::1' and `test`.`t1`.`id` > 0 +DROP TABLE t1; +# +# Optimizer: equal field propagation +# +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE a=COALESCE(CAST('::1' AS INET6)) +AND LENGTH(CONCAT(a,RAND()))>1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::1' and octet_length(concat(INET6'::1',rand())) > 1 +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE a=COALESCE(CAST('::1' AS INET6)) +AND LENGTH(a)>1; +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::1' +DROP TABLE t1; +# +# Optimizer: equal expression propagation +# +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE COALESCE(a)='::1' AND COALESCE(a)=CONCAT(a); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ALL NULL NULL NULL NULL 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`id` AS `id`,`test`.`t1`.`a` AS `a` from `test`.`t1` where coalesce(`test`.`t1`.`a`) = '::1' and concat(`test`.`t1`.`a`) = '::1' +DROP TABLE t1; +# +# Subquery materialization +# +CREATE TABLE t1 (a INET6, b VARCHAR(32), KEY (a), KEY(b)) ; +INSERT INTO t1 VALUES ('::a','::a'),('::a','::b'); +SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off'; +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 MATERIALIZED t1 index NULL a 17 NULL 2 Using index +EXPLAIN SELECT * FROM t1 WHERE b IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 2 Using where +2 DEPENDENT SUBQUERY t1 index_subquery a a 17 func 2 Using index; Using where +SET @@optimizer_switch=DEFAULT; +DROP TABLE t1; +# +# IS_IPV4_MAPPED(), IS_IPV4_COMPAT() now understand text notation +# +CREATE TABLE t1 (id SERIAL, a VARCHAR(32)); +INSERT INTO t1 (a) VALUES ('::192.168.0.1'),('::192.168.10.111'),('::ffff:10.10.0.1'),('::ffff:192.168.0.1'); +# This is a text notation +SELECT id, length(a), a, IS_IPV4_MAPPED(a) FROM t1 ORDER BY id; +id length(a) a IS_IPV4_MAPPED(a) +1 13 ::192.168.0.1 0 +2 16 ::192.168.10.111 0 +3 16 ::ffff:10.10.0.1 1 +4 18 ::ffff:192.168.0.1 1 +SELECT id, length(a), a, IS_IPV4_COMPAT(a) FROM t1 ORDER BY id; +id length(a) a IS_IPV4_COMPAT(a) +1 13 ::192.168.0.1 1 +2 16 ::192.168.10.111 1 +3 16 ::ffff:10.10.0.1 0 +4 18 ::ffff:192.168.0.1 0 +# This is not a text notation: it is a binary input only looking like text notation +SELECT id, length(a), a, IS_IPV4_MAPPED(BINARY a) FROM t1 ORDER BY id; +id length(a) a IS_IPV4_MAPPED(BINARY a) +1 13 ::192.168.0.1 0 +2 16 ::192.168.10.111 0 +3 16 ::ffff:10.10.0.1 0 +4 18 ::ffff:192.168.0.1 0 +Warnings: +Warning 1292 Incorrect inet6 value: '::192.168.0.1' +Warning 1292 Incorrect inet6 value: '::ffff:192.168.0.1' +SELECT id, length(a), a, IS_IPV4_COMPAT(BINARY a) FROM t1 ORDER BY id; +id length(a) a IS_IPV4_COMPAT(BINARY a) +1 13 ::192.168.0.1 0 +2 16 ::192.168.10.111 0 +3 16 ::ffff:10.10.0.1 0 +4 18 ::ffff:192.168.0.1 0 +Warnings: +Warning 1292 Incorrect inet6 value: '::192.168.0.1' +Warning 1292 Incorrect inet6 value: '::ffff:192.168.0.1' +DROP TABLE t1; +# +# ALTER from INET6 to INET6 +# +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329', 1); +ALTER TABLE t1 MODIFY b DECIMAL(10,2); +SELECT * FROM t1; +a b +2001:db8::ff00:42:8329 1.00 +DROP TABLE t1; +# +# ALTER to character string data types +# +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS CHAR(39)) FROM t1; +CAST(a AS CHAR(39)) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a CHAR(39); +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a VARCHAR(39); +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TINYTEXT; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TEXT; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a MEDIUMTEXT; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a LONGTEXT; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +# +# ALTER from character string data types +# +CREATE OR REPLACE TABLE t1 (a CHAR(64)); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a TINYTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a TEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a MEDIUMTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a LONGTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +CAST(a AS INET6) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +# +# ALTER to binary string data types +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(16); +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(17); +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF000042832900 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(15); +ERROR 22001: Data too long for column 'a' at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TINYBLOB; +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BLOB; +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a MEDIUMBLOB; +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a LONGBLOB; +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +# +# ALTER from binary string data types +# +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE TABLE t1 (a BINARY(17)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF000042832900'); +ALTER TABLE t1 MODIFY a INET6; +ERROR 22007: Incorrect inet6 value: ' \x01\x0D\xB8\x00\x00\x00\x00\x00\x00\xFF\x00\x00B\x83)\x00' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a BINARY(15)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF00004283'); +ALTER TABLE t1 MODIFY a INET6; +ERROR 22007: Incorrect inet6 value: ' \x01\x0D\xB8\x00\x00\x00\x00\x00\x00\xFF\x00\x00B\x83' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +CREATE TABLE t1 (a TINYBLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE TABLE t1 (a MEDIUMBLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +# +# SET from INET6 to INET6 +# +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +# +# SET from INET6 to numeric +# +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect integer value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b DOUBLE); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect double value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b DECIMAL(32,0)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect decimal value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b YEAR); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect integer value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +# +# SET from numeric to INET6 +# +CREATE TABLE t1 (a INT, b INET6); +INSERT INTO t1 VALUES (1, NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '1' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a DOUBLE, b INET6); +INSERT INTO t1 VALUES (1, NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '1' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a DECIMAL(32,0), b INET6); +INSERT INTO t1 VALUES (1, NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '1' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a YEAR, b INET6); +INSERT INTO t1 VALUES (1, NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '2001' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +# +# SET from INET6 to temporal +# +CREATE TABLE t1 (a INET6, b TIME); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect time value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b DATE); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect date value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b DATETIME); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect datetime value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b TIMESTAMP NULL DEFAULT NULL); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect datetime value: 'ffff::ffff' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +# +# SET from temporal to INET6 +# +CREATE TABLE t1 (a TIME, b INET6); +INSERT INTO t1 VALUES ('00:00:00', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '00:00:00' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a DATE, b INET6); +INSERT INTO t1 VALUES ('2001-01:01', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '2001-01-01' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a DATETIME, b INET6); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '2001-01-01 10:20:30' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +CREATE TABLE t1 (a TIMESTAMP, b INET6); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect inet6 value: '2001-01-01 10:20:30' for column `test`.`t1`.`b` at row 1 +SELECT b FROM t1; +b +NULL +DROP TABLE t1; +# +# SET from INET6 to character string +# +CREATE TABLE t1 (a INET6, b CHAR(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b VARCHAR(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b TEXT); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b ENUM('ffff::ffff')); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b SET('ffff::ffff')); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +# +# SET from character string to INET6 +# +CREATE TABLE t1 (a CHAR(39), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a VARCHAR(39), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a TEXT, b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a ENUM('ffff::ffff'), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a SET('ffff::ffff'), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +# +# SET from INET6 to binary +# +CREATE TABLE t1 (a INET6, b BINARY(16)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +HEX(b) +FFFF000000000000000000000000FFFF +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b VARBINARY(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +HEX(b) +FFFF000000000000000000000000FFFF +DROP TABLE t1; +CREATE TABLE t1 (a INET6, b BLOB); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +HEX(b) +FFFF000000000000000000000000FFFF +DROP TABLE t1; +# +# SET from binary to INET6 +# +CREATE TABLE t1 (a BINARY(16), b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a VARBINARY(16), b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +CREATE TABLE t1 (a BLOB, b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +b +ffff::ffff +DROP TABLE t1; +# +# Limit clause parameter +# TODO: this should fail. +# The test for a valid data type should be moved +# from parse time to fix_fields() time, and performed +# for both Item_splocal and Item_param. +# +EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6); +1 +# +# MDEV-20785 Converting INET6 to CHAR(39) produces garbage without a warning +# +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS CHAR(39)) FROM t1; +CAST(a AS CHAR(39)) +2001:db8::ff00:42:8329 +ALTER TABLE t1 MODIFY a CHAR(39); +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +# +# MDEV-20783 INET6 cannot be converted to BINARY(16) (requires clarification in documentation) +# +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(16); +SELECT HEX(a) FROM t1; +HEX(a) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +# +# MDEV-20795 CAST(inet6 AS BINARY) returns wrong result +# +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT HEX(CAST(a AS BINARY)) FROM t1; +HEX(CAST(a AS BINARY)) +20010DB8000000000000FF0000428329 +SELECT HEX(CAST(a AS BINARY(16))) FROM t1; +HEX(CAST(a AS BINARY(16))) +20010DB8000000000000FF0000428329 +DROP TABLE t1; +# +# MDEV-20808 CAST from INET6 to FLOAT does not produce an error +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'); +SELECT CAST(a AS FLOAT) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'float_typecast' +DROP TABLE t1; +# +# MDEV-20798 Conversion from INET6 to other types performed without errors or warnings +# +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 (a) VALUES ('::'); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect integer value: '::' for column `test`.`t1`.`b` at row 1 +SELECT * FROM t1; +a b +:: NULL +DROP TABLE t1; +SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30'); +CREATE TABLE t1 (a INET6, b TIMESTAMP); +INSERT INTO t1 (a) VALUES ('::'); +UPDATE t1 SET b=a; +ERROR 22007: Incorrect datetime value: '::' for column `test`.`t1`.`b` at row 1 +SELECT * FROM t1; +a b +:: 2001-01-01 10:20:30 +DROP TABLE t1; +SET timestamp=DEFAULT; +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 (a) VALUES ('::'); +ALTER TABLE t1 MODIFY a DATE; +ERROR 22007: Incorrect date value: '::' for column `test`.`t1`.`a` at row 1 +DROP TABLE t1; +# +# MDEV-20818 ER_CRASHED_ON_USAGE or Assertion `length <= column->length' failed in write_block_record on temporary table +# +CREATE TABLE t1 (a INET6); +SELECT +CAST(a AS BINARY(0)), +CAST(a AS BINARY(1)), +CAST(a AS BINARY(16)), +CAST(a AS BINARY(255)), +CAST(a AS BINARY(256)), +CAST(a AS BINARY(512)), +CAST(a AS BINARY(513)), +CAST(a AS BINARY(65532)), +CAST(a AS BINARY(65533)), +CAST(a AS BINARY(65534)), +CAST(a AS BINARY(65535)), +CAST(a AS BINARY(65536)), +CAST(a AS BINARY(16777215)), +CAST(a AS BINARY(16777216)) +FROM t1; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def CAST(a AS BINARY(0)) 254 0 0 Y 128 0 63 +def CAST(a AS BINARY(1)) 254 1 0 Y 128 0 63 +def CAST(a AS BINARY(16)) 254 16 0 Y 128 0 63 +def CAST(a AS BINARY(255)) 254 255 0 Y 128 0 63 +def CAST(a AS BINARY(256)) 253 256 0 Y 128 0 63 +def CAST(a AS BINARY(512)) 253 512 0 Y 128 0 63 +def CAST(a AS BINARY(513)) 253 513 0 Y 128 0 63 +def CAST(a AS BINARY(65532)) 253 65532 0 Y 128 0 63 +def CAST(a AS BINARY(65533)) 252 65533 0 Y 128 0 63 +def CAST(a AS BINARY(65534)) 252 65534 0 Y 128 0 63 +def CAST(a AS BINARY(65535)) 252 65535 0 Y 128 0 63 +def CAST(a AS BINARY(65536)) 250 65536 0 Y 128 0 63 +def CAST(a AS BINARY(16777215)) 250 16777215 0 Y 128 0 63 +def CAST(a AS BINARY(16777216)) 251 16777216 0 Y 128 0 63 +CAST(a AS BINARY(0)) CAST(a AS BINARY(1)) CAST(a AS BINARY(16)) CAST(a AS BINARY(255)) CAST(a AS BINARY(256)) CAST(a AS BINARY(512)) CAST(a AS BINARY(513)) CAST(a AS BINARY(65532)) CAST(a AS BINARY(65533)) CAST(a AS BINARY(65534)) CAST(a AS BINARY(65535)) CAST(a AS BINARY(65536)) CAST(a AS BINARY(16777215)) CAST(a AS BINARY(16777216)) +DROP TABLE t1; +# +# MDEV-20826 Wrong result of MIN(inet6) with GROUP BY +# +CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::'); +SELECT MIN(a), MAX(a) FROM t1 GROUP BY id; +MIN(a) MAX(a) +fff:: 8888:: +DROP TABLE t1; +# +# MDEV-20809 EXTRACT from INET6 value does not produce any warnings +# +CREATE TABLE t1 (a INET6); +SELECT EXTRACT(DAY FROM a) FROM t1; +ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)' +DROP TABLE t1; +SELECT EXTRACT(DAY FROM CAST('::' AS INET6)); +ERROR HY000: Illegal parameter data type inet6 for operation 'extract(day)' +# +# MDEV-22764 Crash with a stored aggregate function returning INET6 +# +CREATE OR REPLACE AGGREGATE FUNCTION aggregate_min_inet6(x INET6) RETURNS INET6 +BEGIN +DECLARE res INET6 DEFAULT NULL; +DECLARE CONTINUE HANDLER FOR NOT FOUND +RETURN res; +LOOP +FETCH GROUP NEXT ROW; +IF (res IS NULL) OR (res > x) THEN +SET res= x; +END IF; +END LOOP; +END; +$$ +CREATE OR REPLACE TABLE t1 (name CHAR(30), val INET6); +INSERT INTO t1 VALUES ('a', '::05'); +INSERT INTO t1 VALUES ('a', '::03'); +INSERT INTO t1 VALUES ('b', '::01'); +INSERT INTO t1 VALUES ('b', '::02'); +INSERT INTO t1 VALUES ('b', '::05'); +SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name; +name pc +a ::3 +b ::1 +CREATE OR REPLACE TABLE t2 (name CHAR(30), val INET6); +INSERT INTO t2 SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name; +SELECT * FROM t2; +name val +a ::3 +b ::1 +DROP TABLE t2; +DROP TABLE t1; +DROP FUNCTION aggregate_min_inet6; +# +# MDEV-20280 PERCENTILE_DISC() rejects temporal and string input +# +CREATE TABLE t1 (name CHAR(30), star_rating INET6); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::5'); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::3'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::1'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::2'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::5'); +SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +name pc +Lady of the Flies ::2 +Lady of the Flies ::2 +Lady of the Flies ::2 +Lord of the Ladybirds ::3 +Lord of the Ladybirds ::3 +SELECT name, PERCENTILE_DISC(0) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +name pc +Lady of the Flies ::1 +Lady of the Flies ::1 +Lady of the Flies ::1 +Lord of the Ladybirds ::3 +Lord of the Ladybirds ::3 +SELECT name, PERCENTILE_DISC(1) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +name pc +Lady of the Flies ::5 +Lady of the Flies ::5 +Lady of the Flies ::5 +Lord of the Ladybirds ::5 +Lord of the Ladybirds ::5 +DROP TABLE t1; +# +# MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part +# +CREATE TABLE t1 (a VARCHAR(8) NOT NULL, b INET6 NOT NULL); +INSERT INTO t1 VALUES ('foo','::'),('bar','1::1'); +SELECT * FROM t1 ORDER BY CASE WHEN a THEN b ELSE a END; +a b +foo :: +bar 1::1 +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'foo' +Warning 1292 Incorrect inet6 value: 'foo' +Warning 1292 Truncated incorrect DOUBLE value: 'bar' +Warning 1292 Incorrect inet6 value: 'bar' +DROP TABLE t1; +CREATE OR REPLACE TABLE t1 (a VARCHAR(8) NOT NULL); +INSERT INTO t1 VALUES ('foo'),('bar'); +SELECT * FROM t1 ORDER BY CAST(a AS INET6); +a +foo +bar +Warnings: +Warning 1292 Incorrect inet6 value: 'foo' +Warning 1292 Incorrect inet6 value: 'bar' +DROP TABLE t1; +CREATE TABLE t1 (a INET6 NOT NULL, b VARCHAR(32) NOT NULL); +CREATE TABLE t2 AS SELECT CAST(a AS INET6) AS ca, CAST(b AS INET6) AS cb FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `ca` inet6 NOT NULL, + `cb` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT COALESCE(a,a), COALESCE(a,b) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a,a)` inet6 NOT NULL, + `COALESCE(a,b)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +CREATE TABLE t2 AS SELECT a AS ca,a AS cb FROM t1 UNION SELECT a,b FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `ca` inet6 NOT NULL DEFAULT '::', + `cb` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# +# MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part +# +CREATE TABLE t1 (c INET6); +INSERT INTO t1 VALUES ('::'),(NULL); +SELECT * FROM t1 ORDER BY IFNULL(c, 'foo'); +c +NULL +:: +Warnings: +Warning 1292 Incorrect inet6 value: 'foo' +DROP TABLE t1; +CREATE TABLE t1 (c INET6); +INSERT INTO t1 VALUES ('::'),(NULL); +CREATE TABLE t2 AS SELECT IFNULL(c, 'foo') FROM t1; +Warnings: +Warning 1292 Incorrect inet6 value: 'foo' +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `IFNULL(c, 'foo')` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2; +IFNULL(c, 'foo') +:: +NULL +DROP TABLE t2; +CREATE TABLE t2 AS SELECT IFNULL(c, '::1') FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `IFNULL(c, '::1')` inet6 NOT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2; +IFNULL(c, '::1') +:: +::1 +DROP TABLE t2; +DROP TABLE t1; +# +# MDEV-26732 Assertion `0' failed in Item::val_native +# +SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop('x') FROM dual HAVING f > ''; +f var_pop('x') +Warnings: +Warning 1292 Truncated incorrect DOUBLE value: 'x' +Warning 1292 Incorrect inet6 value: '' +SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop(1) FROM dual HAVING f >= '::'; +f var_pop(1) +:: 0.0000 +CREATE TABLE t1(id INET6 NOT NULL PRIMARY KEY, dsc INET6); +INSERT INTO t1 VALUES ('::1', '1::1'),('::3', '1::3'),('::4', NULL); +CREATE TABLE t2 SELECT COALESCE(t1.dsc), COUNT(*) FROM t1 GROUP BY t1.id; +SELECT * FROM t2 ORDER BY 1,2; +COALESCE(t1.dsc) COUNT(*) +NULL 1 +1::1 1 +1::3 1 +DROP TABLE t1, t2; +# +# MDEV-24619 Wrong result or Assertion `0' in Item::val_native / Type_handler_inet6::Item_val_native_with_conversion +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != ''; +f +Warnings: +Warning 1292 Incorrect inet6 value: '' +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::'; +f +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::1'; +f +:: +DROP TABLE t1; +# +# MDEV-28491 Uuid. "UPDATE/DELETE" not working "WHERE id IN (SELECT id FROM ..)" +# +CREATE TABLE companies (id INET6, name varchar(10)); +INSERT INTO companies (id) values ('00::01'); +CREATE TABLE divisions (company_id INET6); +INSERT INTO divisions (company_id) values ('00::01'); +SELECT * FROM companies WHERE id IN (SELECT company_id FROM divisions); +id name +::1 NULL +UPDATE companies SET name = 'value' WHERE id IN (SELECT company_id FROM divisions); +SELECT * FROM companies; +id name +::1 value +DELETE FROM companies WHERE id IN (SELECT company_id FROM divisions); +SELECT * FROM companies; +id name +DROP TABLE divisions; +DROP TABLE companies; +# +# MDEV-27099 Subquery using the ALL keyword on INET6 columns produces a wrong result +# +CREATE TABLE t1 (d INET6); +INSERT INTO t1 VALUES ('1::0'), ('12::0'); +SELECT * FROM t1 ORDER BY d; +d +1:: +12:: +SELECT * FROM t1 WHERE d <= ALL (SELECT * FROM t1); +d +1:: +SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1); +d +12:: +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6.test b/plugin/type_inet/mysql-test/type_inet/type_inet6.test new file mode 100644 index 00000000000..becc063ddc9 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6.test @@ -0,0 +1,1643 @@ + +--echo # +--echo # Basic CREATE functionality, defaults, metadata +--echo # + +--error ER_WRONG_FIELD_SPEC +CREATE TABLE t1 (a INET6 AUTO_INCREMENT); + +CREATE TABLE t1 (a INET6); +SHOW CREATE TABLE t1; +DESCRIBE t1; +--vertical_results +--replace_column 19 # +SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='test' AND table_name='t1'; +--horizontal_results +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'); +--enable_metadata +SELECT * FROM t1; +SELECT CAST('::' AS INET6) AS a; +--disable_metadata +DROP TABLE t1; + + +CREATE TABLE t1 ( + c1 INET6 DEFAULT 0x00000000000000000000000000000000, + c2 INET6 DEFAULT 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, + c3 INET6 DEFAULT '::', + c4 INET6 DEFAULT 'FFFF::ffff', + c5 INET6 DEFAULT CAST(X'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF' AS INET6) +); +SHOW CREATE TABLE t1; +DESCRIBE t1; +--vertical_results +--replace_column 19 # +SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE table_schema='test' AND table_name='t1'; +--horizontal_results +DROP TABLE t1; + +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (c1 INET6 DEFAULT 0x00); +--error ER_INVALID_DEFAULT +CREATE TABLE t1 (c1 INET6 DEFAULT ''); + + +CREATE TABLE t1 (a INET6); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t1 VALUES ('x'); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t1 VALUES (1); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t1 VALUES (TIME'10:20:30'); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t1 VALUES (0x00); +DROP TABLE t1; + +--echo # +--echo # CAST +--echo # + +SELECT CAST('garbage' AS INET6); +SELECT CAST(0x01 AS INET6); +SELECT CAST(REPEAT(0x00,16) AS INET6); +SELECT CAST(REPEAT(0x11,16) AS INET6); + +CREATE TABLE t1 AS SELECT CAST('::' AS INET6); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--echo # +--echo # Text and binary formats, comparison operators +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xFFFF0000000000000000000000000001); +INSERT INTO t1 VALUES (0xFFFF0000000000000000000000000002); +SELECT * FROM t1 ORDER BY a; +SELECT * FROM t1 ORDER BY a DESC; +SELECT HEX(a),a FROM t1 ORDER BY a; +SELECT * FROM t1 WHERE a='::'; +SELECT * FROM t1 WHERE a='::1'; +SELECT * FROM t1 WHERE a='ffff::1'; +SELECT * FROM t1 WHERE a='ffff::2'; +SELECT * FROM t1 WHERE a=0x00000000000000000000000000000000; +SELECT * FROM t1 WHERE a=0x00000000000000000000000000000001; +SELECT * FROM t1 WHERE a=0xffff0000000000000000000000000001; +SELECT * FROM t1 WHERE a=0xffff0000000000000000000000000002; +SELECT * FROM t1 WHERE a<'::'; +SELECT * FROM t1 WHERE a<='::'; +SELECT * FROM t1 WHERE a>='ffff::2'; +SELECT * FROM t1 WHERE a>'ffff::2'; +SELECT * FROM t1 WHERE a IN ('::', 'ffff::1') ORDER BY a; +SELECT * FROM t1 WHERE a IN ('::', 0xffff0000000000000000000000000002) ORDER BY a; + +SELECT * FROM t1 WHERE a<'garbage'; +SELECT * FROM t1 WHERE a<='garbage'; +SELECT * FROM t1 WHERE a='garbage'; +SELECT * FROM t1 WHERE a>='garbage'; +SELECT * FROM t1 WHERE a>'garbage'; + +SELECT * FROM t1 WHERE a<0x01; +SELECT * FROM t1 WHERE a<=0x01; +SELECT * FROM t1 WHERE a=0x01; +SELECT * FROM t1 WHERE a>=0x01; +SELECT * FROM t1 WHERE a>0x01; + +SELECT * FROM t1 WHERE a='0::0'; +SELECT * FROM t1 WHERE a='0::00'; +SELECT * FROM t1 WHERE a='0::000'; +SELECT * FROM t1 WHERE a='0::0000'; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a=0; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a=0.0; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a=0e0; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a=TIME'10:20:30'; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a IN ('::', 10); + +DROP TABLE t1; + +--echo # +--echo # cmp_item_inet6: IN for non-constants +--echo # + +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('::1', '::2'); +SELECT * FROM t1 WHERE '::' IN (a, b); +SELECT * FROM t1 WHERE '::1' IN (a, b); +SELECT * FROM t1 WHERE '::01' IN (a, b); +SELECT * FROM t1 WHERE '00::01' IN (a, b); +DROP TABLE t1; + + +--echo # +--echo # cmp_item_inet6: DECODE_ORACLE +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (NULL),('::01'),('::02'); +SELECT a, DECODE_ORACLE(a, '::01', '01') AS d FROM t1; +SELECT + a, + DECODE_ORACLE(a, '::01', '01') AS d0, + DECODE_ORACLE(a, NULL, '<NULL>', '::01', '01') AS d1, + DECODE_ORACLE(a, 'garbage', '<NULL>', '::01', '01') AS d2 +FROM t1; +DROP TABLE t1; + + +--echo # +--echo # CASE abbreviations +--echo # + +CREATE TABLE t1 ( + c INET6, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext TEXT, + c_longtext LONGTEXT +); +CREATE TABLE t2 AS SELECT + COALESCE(c, c_char), + COALESCE(c, c_varchar), + COALESCE(c, c_tinytext), + COALESCE(c, c_text), + COALESCE(c, c_mediumtext), + COALESCE(c, c_longtext) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +CREATE TABLE t2 AS SELECT + LEAST(c, c_char), + LEAST(c, c_varchar), + LEAST(c, c_tinytext), + LEAST(c, c_text), + LEAST(c, c_mediumtext), + LEAST(c, c_longtext) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (NULL),('::1'),('::2'); +SELECT COALESCE(a, '::') FROM t1 ORDER BY a; +SELECT a, LEAST(a,'::0'), LEAST(a,'::f') FROM t1 ORDER BY a; +SELECT a, GREATEST(a,'::0'), GREATEST(a,'::f') FROM t1 ORDER BY a; + +CREATE TABLE t2 AS SELECT + COALESCE(a, '::'), + LEAST(a,'::'), + GREATEST(a,'::') +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +SELECT COALESCE(a, 0x00000000000000000000000000000000) FROM t1 ORDER BY a; +SELECT a, + LEAST(a, 0x00000000000000000000000000000000), + LEAST(a, 0x0000000000000000000000000000000f) +FROM t1 ORDER BY a; +SELECT a, + GREATEST(a, 0x00000000000000000000000000000000), + GREATEST(a, 0x0000000000000000000000000000000f) +FROM t1 ORDER BY a; + +CREATE TABLE t2 AS SELECT + COALESCE(a, 0x00000000000000000000000000000000), + LEAST(a,0x00000000000000000000000000000000), + GREATEST(a,0x00000000000000000000000000000000) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(a, 10) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(a, 10) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT GREATEST(a, 10) FROM t1; +DROP TABLE t1; + +SELECT COALESCE('garbage', CAST('::1' AS INET6)); +SELECT COALESCE(0x01, CAST('::1' AS INET6)); + + +--echo # +--echo # Uniqueness +--echo # + +CREATE TABLE t1 (a INET6 NOT NULL PRIMARY KEY); +INSERT INTO t1 VALUES ('41::1'),('61::1'); +--error ER_DUP_ENTRY +INSERT INTO t1 VALUES ('41::1'); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Indexes +--echo # + +--error ER_WRONG_SUB_KEY +CREATE TABLE t1 (a INET6, KEY(a(1))); + + +--echo # +--echo # Explicit CAST on INSERT +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES (CAST('1::1' AS INET6)); +INSERT INTO t1 VALUES (CAST('1::2' AS INET6)); +INSERT INTO t1 VALUES (CAST('1::3' AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::1') AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::2') AS INET6)); +INSERT INTO t1 VALUES (CAST(CONCAT('2','::3') AS INET6)); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + + +--echo # +--echo # Explicit CAST and implicit CAST on ALTER +--echo # + +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('garbage'),('::'),('::1'),('ffff::1'),('ffff::2'); +SELECT a, CAST(a AS INET6) FROM t1 ORDER BY a; +SELECT a, CAST(a AS INET6) FROM t1 ORDER BY CAST(a AS INET6); +--error ER_TRUNCATED_WRONG_VALUE +ALTER TABLE t1 MODIFY a INET6; +SET sql_mode=''; +ALTER TABLE t1 MODIFY a INET6; +SET sql_mode=DEFAULT; +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + + +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000002); +SELECT HEX(a), CAST(a AS INET6) FROM t1 ORDER BY a; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + + +--echo # +--echo # INSERT..SELECT, same data types +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +CREATE TABLE t2 (a INET6); +INSERT INTO t2 SELECT a FROM t1; +SELECT * FROM t2; +DROP TABLE t1,t2; + + +--echo # +--echo # Implicit CAST on INSERT..SELECT, text format +--echo # + +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('garbage'),('::'),('::1'),('ffff::1'),('ffff::2'); + +CREATE TABLE t2 (a INET6); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t2 SELECT a FROM t1; +SET sql_mode=''; +INSERT INTO t2 SELECT a FROM t1; +SELECT * FROM t2 ORDER BY a; +SET sql_mode=DEFAULT; +DROP TABLE t2; + +CREATE TABLE t2 (a INET6 NOT NULL); +--error ER_TRUNCATED_WRONG_VALUE +INSERT INTO t2 SELECT a FROM t1; +SET sql_mode=''; +INSERT INTO t2 SELECT a FROM t1; +SELECT * FROM t2 ORDER BY a; +SET sql_mode=DEFAULT; +DROP TABLE t2; + +DROP TABLE t1; + + +--echo # +--echo # Implicit CAST on INSERT..SELECT, binary format +--echo # + +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (0x00000000000000000000000000000000); +INSERT INTO t1 VALUES (0x00000000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000001); +INSERT INTO t1 VALUES (0xffff0000000000000000000000000002); +CREATE TABLE t2 (a INET6); +INSERT INTO t2 SELECT a FROM t1; +SELECT a FROM t2 ORDER BY a; +DROP TABLE t1,t2; + + +--echo # +--echo # CAST to other data types +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS DOUBLE); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS FLOAT); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS DECIMAL); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS SIGNED); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS UNSIGNED); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS TIME); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS DATE); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(CAST('::' AS INET6) AS DATETIME); + +SELECT CAST(CAST('::' AS INET6) AS CHAR); +CREATE TABLE t1 AS SELECT CAST(CAST('::' AS INET6) AS CHAR) AS a; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('ffff::ffff'); +CREATE TABLE t2 AS SELECT + CAST(a AS CHAR), + CAST(a AS CHAR(39)), + CAST(a AS CHAR(530)), + CAST(a AS CHAR(65535)), + CAST(a AS CHAR(66000)), + CAST(a AS CHAR(16777215)), + CAST(a AS CHAR(16777216)) +FROM t1; +SHOW CREATE TABLE t2; +--vertical_results +SELECT * FROM t2; +--horizontal_results +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('ffff::ffff'); +CREATE TABLE t2 AS SELECT + CAST(a AS BINARY(4)) AS cb4, + CAST(a AS BINARY) AS cb, + CAST(a AS BINARY(16)) AS cb16, + CAST(a AS BINARY(32)) AS cb32, + CAST(a AS BINARY(530)) AS cb530, + CAST(a AS BINARY(65535)) AS cb65535, + CAST(a AS BINARY(66000)) AS cb66000, + CAST(a AS BINARY(16777215)) AS cb16777215, + CAST(a AS BINARY(16777216)) AS cb16777216 +FROM t1 LIMIT 0; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + CAST(a AS BINARY(4)) AS cb4, + CAST(a AS BINARY) AS cb, + CAST(a AS BINARY(16)) AS cb16, + CAST(a AS BINARY(32)) AS cb32, + CAST(a AS BINARY(530)) AS cb530, + CAST(a AS BINARY(65535)) AS cb65535 +FROM t1; +SHOW CREATE TABLE t2; +--vertical_results +SELECT + HEX(cb4), + HEX(cb), + HEX(cb16), + HEX(cb32), + LENGTH(cb530), + LENGTH(cb65535) +FROM t2; +--horizontal_results +DROP TABLE t2; +DROP TABLE t1; + +--echo # +--echo # Implicit conversion to other types in INSERT +--echo # + +CREATE TABLE t1 (a INT); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; + +CREATE TABLE t1 (a DECIMAL(32,0)); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT); +INSERT INTO t1 VALUES (CAST('::' AS INET6)); +DROP TABLE t1; + + + +--echo # +--echo # Boolean context +--echo # + +SELECT + CAST('::' AS INET6) IS TRUE, + CAST('::' AS INET6) IS FALSE, + CAST('::1' AS INET6) IS TRUE, + CAST('::1' AS INET6) IS FALSE; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'); +SELECT a, a IS TRUE, a IS FALSE FROM t1 ORDER BY a; +DROP TABLE t1; + +# +# TODO: Error looks like a bug. This should return rows where a<>'::'. +# The same problem is repeatable with GEOMETRY. +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT * FROM t1 WHERE a; +DROP TABLE t1; + + +--echo # +--echo # GROUP BY +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +INSERT INTO t1 VALUES ('::1'),('::01'),('::0001'); +INSERT INTO t1 VALUES ('::2'),('::2'),('::2'),('::2'); +SELECT a, COUNT(*) FROM t1 GROUP BY a; +DROP TABLE t1; + +--echo # +--echo # Aggregate functions +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +INSERT INTO t1 VALUES ('::1'),('::01'),('::0001'); +INSERT INTO t1 VALUES ('::2'),('::2'),('::2'),('::2'); +SELECT MIN(a),MAX(a) FROM t1; + +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT AVG(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT AVG(DISTINCT a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SUM(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT SUM(DISTINCT a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT STDDEV(a) FROM t1; +SELECT GROUP_CONCAT(a ORDER BY a) FROM t1; +SELECT a, GROUP_CONCAT(a ORDER BY a) FROM t1 GROUP BY a; +DROP TABLE t1; + +--echo # +--echo # MDEV-21765 Possibly inconsistent behavior of BIT_xx functions with INET6 field +--echo # + +CREATE TABLE t1 (a INET6); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT BIT_AND(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT BIT_OR(a) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT BIT_XOR(a) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Window functions +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'),('::2'),('::3'),('::4'); +SELECT + a, + LAG(a) OVER (ORDER BY a), + LEAD(a) OVER (ORDER BY a) +FROM t1 ORDER BY a; + +SELECT + a, + FIRST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING), + LAST_VALUE(a) OVER (ORDER BY a ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) +FROM t1 ORDER BY a; +DROP TABLE t1; + + +--echo # +--echo # Prepared statements +--echo # + +EXECUTE IMMEDIATE 'CREATE TABLE t1 AS SELECT ? AS a' USING CAST('::' AS INET6); +SHOW CREATE TABLE t1; +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING '::1'; +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING CAST('::2' AS INET6); +EXECUTE IMMEDIATE 'INSERT INTO t1 VALUES (?)' USING 0x00000000000000000000000000000003; +SELECT a FROM t1 ORDER BY a; +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING '::1'; +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING CAST('::2' AS INET6); +EXECUTE IMMEDIATE 'SELECT * FROM t1 WHERE a=?' USING 0x00000000000000000000000000000003; +DROP TABLE t1; + + +--echo # +--echo # Character set and collation aggregation +--echo # + +CREATE TABLE t1 (a INET6); + +CREATE TABLE t2 AS SELECT + CONCAT(a) AS c1, + CONCAT(CAST('::' AS INET6)) AS c2 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + CONCAT(_utf8'1', a) AS c1, + CONCAT(_utf8'1', CAST('::1' AS INET6)) AS c2, + CONCAT(_utf8'1', COALESCE(a)) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT + CONCAT(_latin1'1', a) AS c1, + CONCAT(_latin1'1', CAST('::1' AS INET6)) AS c2, + CONCAT(_latin1'1', COALESCE(a)) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +DROP TABLE t1; + + +--echo # +--echo # UNION +--echo # + +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT CAST('::1' AS INET6); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT '::1'; +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT '::' AS c UNION SELECT CAST('::1' AS INET6); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT 0x00000000000000000000000000000001; +SELECT * FROM t1; +DROP TABLE t1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +CREATE TABLE t1 AS SELECT CAST('::' AS INET6) AS c UNION SELECT 1; + + +--echo # +--echo # Unary operators +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT -CAST('::' AS INET6); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ABS(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT ROUND(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CEILING(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FLOOR(CAST('::' AS INET6)); + + +--echo # +--echo # Arithmetic operators +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT CAST('::' AS INET6) + 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT CAST('::' AS INET6) - 1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT CAST('::' AS INET6) * 1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT CAST('::' AS INET6) / 1; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT CAST('::' AS INET6) MOD 1; + + +--echo # +--echo # Misc +--echo # + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RAND(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT FROM_UNIXTIME(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT HOUR(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT YEAR(CAST('::' AS INET6)); + +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT RELEASE_LOCK(CAST('::' AS INET6)); + + +SELECT JSON_LENGTH(CAST('::' AS INET6)); + +--echo # +--echo # Virtual columns +--echo # + +--error ER_GENERATED_COLUMN_FUNCTION_IS_NOT_ALLOWED +CREATE TABLE t1 ( + a INT, + b INET6 GENERATED ALWAYS AS (CAST(CONCAT(RAND(),a) AS INET6)), INDEX(b) +); + +CREATE TABLE t1 ( + a INT, + b INET6 GENERATED ALWAYS AS (CAST(CONCAT('::',HEX(a)) AS INET6)), INDEX(b) +); +INSERT INTO t1 (a) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # VIEW +--echo # + +CREATE TABLE t1 (a INT DEFAULT 0); +INSERT INTO t1 (a) VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15); +SELECT * FROM t1 ORDER BY a; +CREATE VIEW v1 AS SELECT (CAST(CONCAT('::',HEX(a)) AS INET6)) AS c FROM t1; +SELECT * FROM v1 ORDER BY c; +DROP VIEW v1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6 DEFAULT '::'); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +DESCRIBE v1; +INSERT INTO v1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1; +DROP VIEW v1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6 DEFAULT CAST('::' AS INET6)); +CREATE VIEW v1 AS SELECT * FROM t1; +SHOW CREATE VIEW v1; +DESCRIBE v1; +INSERT INTO v1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1; +DROP VIEW v1; +DROP TABLE t1; + + +--echo # +--echo # Subqueries +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::1'),('::2'); +SELECT * FROM t1 WHERE a=(SELECT MIN(a) FROM t1) ORDER BY a; +SELECT * FROM t1 WHERE a=(SELECT MAX(a) FROM t1) ORDER BY a; +SELECT * FROM t1 WHERE a IN (SELECT a FROM t1 WHERE a>'::') ORDER BY a; +DROP TABLE t1; + +--echo # +--echo # Stored routines +--echo # + +DELIMITER $$; +CREATE PROCEDURE p1(a INET6) +BEGIN + DECLARE b INET6 DEFAULT CONCAT('1', a); + SELECT a, b; +END; +$$ +DELIMITER ;$$ +CALL p1('::1'); +CALL p1(CAST('::2' AS INET6)); +DROP PROCEDURE p1; + +DELIMITER $$; +CREATE FUNCTION f1(a INET6) RETURNS INET6 +BEGIN + RETURN CONCAT('1',a); +END; +$$ +DELIMITER ;$$ +SELECT f1('::1'); +SELECT f1(CAST('::1' AS INET6)); +DROP FUNCTION f1; + +--echo # +--echo # Anchored data types in SP variables +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::1'); +DELIMITER $$; +CREATE PROCEDURE p1() +BEGIN + DECLARE va TYPE OF t1.a; + SELECT MAX(a) INTO va FROM t1; + SELECT va; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + + +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('::a', '::b'); +DELIMITER $$; +CREATE PROCEDURE p1() +BEGIN + DECLARE va ROW TYPE OF t1; + SELECT MAX(a), MAX(b) INTO va FROM t1; + SELECT va.a, va.b; +END; +$$ +DELIMITER ;$$ +CALL p1; +DROP PROCEDURE p1; +DROP TABLE t1; + + +--echo # +--echo # Optimizer: make_const_item_for_comparison +--echo # + +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=COALESCE(CAST('::1' AS INET6)) AND id>0; +DROP TABLE t1; + +--echo # +--echo # Optimizer: equal field propagation +--echo # + +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE a=COALESCE(CAST('::1' AS INET6)) + AND LENGTH(CONCAT(a,RAND()))>1; +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE a=COALESCE(CAST('::1' AS INET6)) + AND LENGTH(a)>1; +DROP TABLE t1; + + +--echo # +--echo # Optimizer: equal expression propagation +--echo # + + +CREATE TABLE t1 (id INT, a INET6); +INSERT INTO t1 VALUES (1,'::1'),(2,'::2'); +EXPLAIN EXTENDED SELECT * FROM t1 +WHERE COALESCE(a)='::1' AND COALESCE(a)=CONCAT(a); +DROP TABLE t1; + +--echo # +--echo # Subquery materialization +--echo # + +CREATE TABLE t1 (a INET6, b VARCHAR(32), KEY (a), KEY(b)) ; +INSERT INTO t1 VALUES ('::a','::a'),('::a','::b'); +SET @@optimizer_switch='semijoin=off,materialization=on,in_to_exists=off,subquery_cache=off'; +EXPLAIN SELECT * FROM t1 WHERE a IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner); +EXPLAIN SELECT * FROM t1 WHERE b IN (SELECT a AS a_inner FROM t1 GROUP BY a_inner); +SET @@optimizer_switch=DEFAULT; +DROP TABLE t1; + +--echo # +--echo # IS_IPV4_MAPPED(), IS_IPV4_COMPAT() now understand text notation +--echo # +CREATE TABLE t1 (id SERIAL, a VARCHAR(32)); +INSERT INTO t1 (a) VALUES ('::192.168.0.1'),('::192.168.10.111'),('::ffff:10.10.0.1'),('::ffff:192.168.0.1'); +--echo # This is a text notation +SELECT id, length(a), a, IS_IPV4_MAPPED(a) FROM t1 ORDER BY id; +SELECT id, length(a), a, IS_IPV4_COMPAT(a) FROM t1 ORDER BY id; +--echo # This is not a text notation: it is a binary input only looking like text notation +SELECT id, length(a), a, IS_IPV4_MAPPED(BINARY a) FROM t1 ORDER BY id; +SELECT id, length(a), a, IS_IPV4_COMPAT(BINARY a) FROM t1 ORDER BY id; +DROP TABLE t1; + + +--echo # +--echo # ALTER from INET6 to INET6 +--echo # + +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329', 1); +ALTER TABLE t1 MODIFY b DECIMAL(10,2); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # ALTER to character string data types +--echo # + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS CHAR(39)) FROM t1; +ALTER TABLE t1 MODIFY a CHAR(39); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a VARCHAR(39); +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TINYTEXT; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TEXT; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a MEDIUMTEXT; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a LONGTEXT; +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # ALTER from character string data types +--echo # + +CREATE OR REPLACE TABLE t1 (a CHAR(64)); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a VARCHAR(64)); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a TINYTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a TEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a MEDIUMTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a LONGTEXT); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS INET6) FROM t1; +ALTER TABLE t1 MODIFY a INET6; +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # ALTER to binary string data types +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(16); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(17); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +--error ER_DATA_TOO_LONG +ALTER TABLE t1 MODIFY a BINARY(15); +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a TINYBLOB; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BLOB; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a MEDIUMBLOB; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a LONGBLOB; +SELECT HEX(a) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # ALTER from binary string data types +--echo # + +CREATE TABLE t1 (a BINARY(16)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BINARY(17)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF000042832900'); +--error ER_TRUNCATED_WRONG_VALUE +ALTER TABLE t1 MODIFY a INET6; +DROP TABLE t1; + +CREATE TABLE t1 (a BINARY(15)); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF00004283'); +--error ER_TRUNCATED_WRONG_VALUE +ALTER TABLE t1 MODIFY a INET6; +DROP TABLE t1; + +CREATE TABLE t1 (a TINYBLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a MEDIUMBLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BLOB); +INSERT INTO t1 VALUES (X'20010DB8000000000000FF0000428329'); +ALTER TABLE t1 MODIFY a INET6; +SELECT a FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from INET6 to INET6 +--echo # + +CREATE TABLE t1 (a INET6, b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +--echo # +--echo # SET from INET6 to numeric +--echo # + +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b DOUBLE); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b DECIMAL(32,0)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b YEAR); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from numeric to INET6 +--echo # + +CREATE TABLE t1 (a INT, b INET6); +INSERT INTO t1 VALUES (1, NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DOUBLE, b INET6); +INSERT INTO t1 VALUES (1, NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DECIMAL(32,0), b INET6); +INSERT INTO t1 VALUES (1, NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a YEAR, b INET6); +INSERT INTO t1 VALUES (1, NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from INET6 to temporal +--echo # + +CREATE TABLE t1 (a INET6, b TIME); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b DATE); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b DATETIME); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b TIMESTAMP NULL DEFAULT NULL); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from temporal to INET6 +--echo # + +CREATE TABLE t1 (a TIME, b INET6); +INSERT INTO t1 VALUES ('00:00:00', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATE, b INET6); +INSERT INTO t1 VALUES ('2001-01:01', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a DATETIME, b INET6); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TIMESTAMP, b INET6); +INSERT INTO t1 VALUES ('2001-01-01 10:20:30', NULL); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from INET6 to character string +--echo # + +CREATE TABLE t1 (a INET6, b CHAR(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b VARCHAR(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b TEXT); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b ENUM('ffff::ffff')); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b SET('ffff::ffff')); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from character string to INET6 +--echo # + +CREATE TABLE t1 (a CHAR(39), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARCHAR(39), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEXT, b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a ENUM('ffff::ffff'), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a SET('ffff::ffff'), b INET6); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from INET6 to binary +--echo # + +CREATE TABLE t1 (a INET6, b BINARY(16)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b VARBINARY(39)); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a INET6, b BLOB); +INSERT INTO t1 VALUES ('ffff::ffff', NULL); +UPDATE t1 SET b=a; +SELECT HEX(b) FROM t1; +DROP TABLE t1; + + +--echo # +--echo # SET from binary to INET6 +--echo # + +CREATE TABLE t1 (a BINARY(16), b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a VARBINARY(16), b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a BLOB, b INET6); +INSERT INTO t1 VALUES (CONCAT(0xFFFF,REPEAT(0x0000,6),0xFFFF), NULL); +UPDATE t1 SET b=a; +SELECT b FROM t1; +DROP TABLE t1; + + +--echo # +--echo # Limit clause parameter +--echo # TODO: this should fail. +--echo # The test for a valid data type should be moved +--echo # from parse time to fix_fields() time, and performed +--echo # for both Item_splocal and Item_param. +--echo # + +EXECUTE IMMEDIATE 'SELECT 1 FROM DUAL LIMIT ?' USING CAST('::' AS INET6); + + +## TODO: +## - Add hooks to run mysql_client_test with pluggable data types +## +## - This should fail with the "illegal data type" error: +##SELECT CAST('::' AS INET6) DIV 1; +## +## - This should fail with the "illegal data type" error: +## EXTRACT(MINUTE...) +## + + +--echo # +--echo # MDEV-20785 Converting INET6 to CHAR(39) produces garbage without a warning +--echo # + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT CAST(a AS CHAR(39)) FROM t1; +ALTER TABLE t1 MODIFY a CHAR(39); +SELECT * FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-20783 INET6 cannot be converted to BINARY(16) (requires clarification in documentation) +--echo # + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +ALTER TABLE t1 MODIFY a BINARY(16); +SELECT HEX(a) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-20795 CAST(inet6 AS BINARY) returns wrong result +--echo # + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT HEX(CAST(a AS BINARY)) FROM t1; +SELECT HEX(CAST(a AS BINARY(16))) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-20808 CAST from INET6 to FLOAT does not produce an error +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT CAST(a AS FLOAT) FROM t1; +DROP TABLE t1; + +--echo # +--echo # MDEV-20798 Conversion from INET6 to other types performed without errors or warnings +--echo # + +CREATE TABLE t1 (a INET6, b INT); +INSERT INTO t1 (a) VALUES ('::'); +--error ER_TRUNCATED_WRONG_VALUE_FOR_FIELD +UPDATE t1 SET b=a; +SELECT * FROM t1; +DROP TABLE t1; + +SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30'); +CREATE TABLE t1 (a INET6, b TIMESTAMP); +INSERT INTO t1 (a) VALUES ('::'); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t1 SET b=a; +SELECT * FROM t1; +DROP TABLE t1; +SET timestamp=DEFAULT; + +CREATE OR REPLACE TABLE t1 (a INET6); +INSERT INTO t1 (a) VALUES ('::'); +--error ER_TRUNCATED_WRONG_VALUE +ALTER TABLE t1 MODIFY a DATE; +DROP TABLE t1; + +--echo # +--echo # MDEV-20818 ER_CRASHED_ON_USAGE or Assertion `length <= column->length' failed in write_block_record on temporary table +--echo # + +CREATE TABLE t1 (a INET6); +--enable_metadata +SELECT + CAST(a AS BINARY(0)), + CAST(a AS BINARY(1)), + CAST(a AS BINARY(16)), + CAST(a AS BINARY(255)), + CAST(a AS BINARY(256)), + CAST(a AS BINARY(512)), + CAST(a AS BINARY(513)), + CAST(a AS BINARY(65532)), + CAST(a AS BINARY(65533)), + CAST(a AS BINARY(65534)), + CAST(a AS BINARY(65535)), + CAST(a AS BINARY(65536)), + CAST(a AS BINARY(16777215)), + CAST(a AS BINARY(16777216)) +FROM t1; +--disable_metadata +DROP TABLE t1; + +--echo # +--echo # MDEV-20826 Wrong result of MIN(inet6) with GROUP BY +--echo # + +CREATE TABLE t1 (id INT, a INET6) ENGINE=MyISAM; +INSERT INTO t1 VALUES (1, 'fff::'),(1, '8888::'); +SELECT MIN(a), MAX(a) FROM t1 GROUP BY id; +DROP TABLE t1; + + +--echo # +--echo # MDEV-20809 EXTRACT from INET6 value does not produce any warnings +--echo # + +CREATE TABLE t1 (a INET6); +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT EXTRACT(DAY FROM a) FROM t1; +DROP TABLE t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPE_FOR_OPERATION +SELECT EXTRACT(DAY FROM CAST('::' AS INET6)); + + +--echo # +--echo # MDEV-22764 Crash with a stored aggregate function returning INET6 +--echo # + +DELIMITER $$; +CREATE OR REPLACE AGGREGATE FUNCTION aggregate_min_inet6(x INET6) RETURNS INET6 +BEGIN + DECLARE res INET6 DEFAULT NULL; + DECLARE CONTINUE HANDLER FOR NOT FOUND + RETURN res; + LOOP + FETCH GROUP NEXT ROW; + IF (res IS NULL) OR (res > x) THEN + SET res= x; + END IF; + END LOOP; +END; +$$ +DELIMITER ;$$ + +CREATE OR REPLACE TABLE t1 (name CHAR(30), val INET6); +INSERT INTO t1 VALUES ('a', '::05'); +INSERT INTO t1 VALUES ('a', '::03'); +INSERT INTO t1 VALUES ('b', '::01'); +INSERT INTO t1 VALUES ('b', '::02'); +INSERT INTO t1 VALUES ('b', '::05'); +SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name; + +CREATE OR REPLACE TABLE t2 (name CHAR(30), val INET6); +INSERT INTO t2 SELECT name, aggregate_min_inet6(val) pc FROM t1 GROUP BY name; +SELECT * FROM t2; +DROP TABLE t2; + +DROP TABLE t1; +DROP FUNCTION aggregate_min_inet6; + + +--echo # +--echo # MDEV-20280 PERCENTILE_DISC() rejects temporal and string input +--echo # + +CREATE TABLE t1 (name CHAR(30), star_rating INET6); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::5'); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', '::3'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::1'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::2'); +INSERT INTO t1 VALUES ('Lady of the Flies', '::5'); +SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SELECT name, PERCENTILE_DISC(0) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SELECT name, PERCENTILE_DISC(1) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +DROP TABLE t1; + + +--echo # +--echo # MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part +--echo # + +CREATE TABLE t1 (a VARCHAR(8) NOT NULL, b INET6 NOT NULL); +INSERT INTO t1 VALUES ('foo','::'),('bar','1::1'); +SELECT * FROM t1 ORDER BY CASE WHEN a THEN b ELSE a END; +DROP TABLE t1; + +CREATE OR REPLACE TABLE t1 (a VARCHAR(8) NOT NULL); +INSERT INTO t1 VALUES ('foo'),('bar'); +SELECT * FROM t1 ORDER BY CAST(a AS INET6); +DROP TABLE t1; + +CREATE TABLE t1 (a INET6 NOT NULL, b VARCHAR(32) NOT NULL); +CREATE TABLE t2 AS SELECT CAST(a AS INET6) AS ca, CAST(b AS INET6) AS cb FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT COALESCE(a,a), COALESCE(a,b) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +CREATE TABLE t2 AS SELECT a AS ca,a AS cb FROM t1 UNION SELECT a,b FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +DROP TABLE t1; + +--echo # +--echo # MDEV-22758 Assertion `!item->null_value' failed in Type_handler_inet6::make_sort_key_part +--echo # + +CREATE TABLE t1 (c INET6); +INSERT INTO t1 VALUES ('::'),(NULL); +SELECT * FROM t1 ORDER BY IFNULL(c, 'foo'); +DROP TABLE t1; + +CREATE TABLE t1 (c INET6); +INSERT INTO t1 VALUES ('::'),(NULL); + +# Expect a NULL column +CREATE TABLE t2 AS SELECT IFNULL(c, 'foo') FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2; +DROP TABLE t2; + +# Expect a NOT NULL column +CREATE TABLE t2 AS SELECT IFNULL(c, '::1') FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2; +DROP TABLE t2; + +DROP TABLE t1; + +--echo # +--echo # MDEV-26732 Assertion `0' failed in Item::val_native +--echo # + +# This tests Item_copy_inet6::val_native() +SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop('x') FROM dual HAVING f > ''; +SELECT CAST(CONCAT('::', REPEAT('',RAND())) AS INET6) AS f, var_pop(1) FROM dual HAVING f >= '::'; + +# This tests Item_copy_inet6::save_in_field() +CREATE TABLE t1(id INET6 NOT NULL PRIMARY KEY, dsc INET6); +INSERT INTO t1 VALUES ('::1', '1::1'),('::3', '1::3'),('::4', NULL); +CREATE TABLE t2 SELECT COALESCE(t1.dsc), COUNT(*) FROM t1 GROUP BY t1.id; +SELECT * FROM t2 ORDER BY 1,2; +DROP TABLE t1, t2; + +--echo # +--echo # MDEV-24619 Wrong result or Assertion `0' in Item::val_native / Type_handler_inet6::Item_val_native_with_conversion +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('::'),('::'); +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != ''; +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::'; +SELECT IF(1, '::', a) AS f FROM t1 GROUP BY 'foo' HAVING f != '::1'; +DROP TABLE t1; + + +--echo # +--echo # MDEV-28491 Uuid. "UPDATE/DELETE" not working "WHERE id IN (SELECT id FROM ..)" +--echo # + +CREATE TABLE companies (id INET6, name varchar(10)); +INSERT INTO companies (id) values ('00::01'); + +CREATE TABLE divisions (company_id INET6); +INSERT INTO divisions (company_id) values ('00::01'); +SELECT * FROM companies WHERE id IN (SELECT company_id FROM divisions); +UPDATE companies SET name = 'value' WHERE id IN (SELECT company_id FROM divisions); +SELECT * FROM companies; +DELETE FROM companies WHERE id IN (SELECT company_id FROM divisions); +SELECT * FROM companies; +DROP TABLE divisions; +DROP TABLE companies; + +--echo # +--echo # MDEV-27099 Subquery using the ALL keyword on INET6 columns produces a wrong result +--echo # + +CREATE TABLE t1 (d INET6); +INSERT INTO t1 VALUES ('1::0'), ('12::0'); +SELECT * FROM t1 ORDER BY d; +SELECT * FROM t1 WHERE d <= ALL (SELECT * FROM t1); +SELECT * FROM t1 WHERE d >= ALL (SELECT * FROM t1); +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.result new file mode 100644 index 00000000000..a2d7cea03cc --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.result @@ -0,0 +1,70 @@ +# +# Start of 10.5 tests +# +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +SET default_storage_engine=CSV; +CREATE TABLE t1 (a INET6 NOT NULL); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 NOT NULL +) ENGINE=CSV DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FOR i IN 0..255 +DO +INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +SELECT * FROM t1 WHERE a='::ff'; +a +::ff +SELECT * FROM t1 WHERE a>='::fe' ORDER BY a; +a +::fe +::ff +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0') ORDER BY a; +a +::80 +::a0 +::f0 +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81' ORDER BY a; +a +::80 +::81 +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +a +::ff +UPDATE t1 SET a=CONCAT('ffff', a) WHERE a LIKE '::a%'; +SELECT * FROM t1 WHERE a LIKE 'ffff::%' ORDER BY a; +a +ffff::a +ffff::a0 +ffff::a1 +ffff::a2 +ffff::a3 +ffff::a4 +ffff::a5 +ffff::a6 +ffff::a7 +ffff::a8 +ffff::a9 +ffff::aa +ffff::ab +ffff::ac +ffff::ad +ffff::ae +ffff::af +DROP TABLE t1; +# +# MDEV-20790 CSV table with INET6 can be created and inserted into, but cannot be read from +# +CREATE TABLE t1 (a INET6 NOT NULL) ENGINE=CSV; +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT * FROM t1; +a +2001:db8::ff00:42:8329 +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.test new file mode 100644 index 00000000000..65761cf0af7 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_csv.test @@ -0,0 +1,51 @@ +--source include/have_csv.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + +SET default_storage_engine=CSV; + +CREATE TABLE t1 (a INET6 NOT NULL); +SHOW CREATE TABLE t1; + +DELIMITER $$; +FOR i IN 0..255 +DO + INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +DELIMITER ;$$ + +SELECT * FROM t1 WHERE a='::ff'; + +SELECT * FROM t1 WHERE a>='::fe' ORDER BY a; + +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0') ORDER BY a; + +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81' ORDER BY a; + +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); + +UPDATE t1 SET a=CONCAT('ffff', a) WHERE a LIKE '::a%'; +SELECT * FROM t1 WHERE a LIKE 'ffff::%' ORDER BY a; + +DROP TABLE t1; + +--echo # +--echo # MDEV-20790 CSV table with INET6 can be created and inserted into, but cannot be read from +--echo # + +CREATE TABLE t1 (a INET6 NOT NULL) ENGINE=CSV; +INSERT INTO t1 VALUES ('2001:db8::ff00:42:8329'); +SELECT * FROM t1; +DROP TABLE t1; + + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_engines.inc b/plugin/type_inet/mysql-test/type_inet/type_inet6_engines.inc new file mode 100644 index 00000000000..596036fc0ee --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_engines.inc @@ -0,0 +1,38 @@ +--echo # +--echo # Range optimizer +--echo # + +CREATE TABLE t1 (a INET6, INDEX(a)); +SHOW CREATE TABLE t1; + +DELIMITER $$; +FOR i IN 0..255 +DO + INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +DELIMITER ;$$ +SELECT * FROM t1 WHERE a='::ff'; +EXPLAIN SELECT * FROM t1 WHERE a='::ff'; +SELECT * FROM t1 WHERE a='garbage'; +EXPLAIN SELECT * FROM t1 WHERE a='garbage'; + +SELECT * FROM t1 WHERE a>='::fe'; +EXPLAIN SELECT * FROM t1 WHERE a>='::fe'; +SELECT * FROM t1 WHERE a>='garbage'; +EXPLAIN SELECT * FROM t1 WHERE a>='garbage'; + +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); + +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; + +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); + +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.result new file mode 100644 index 00000000000..deb1c718b49 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.result @@ -0,0 +1,119 @@ +# +# Start of 10.5 tests +# +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +SET default_storage_engine=InnoDB; +# +# Range optimizer +# +CREATE TABLE t1 (a INET6, INDEX(a)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 DEFAULT NULL, + KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FOR i IN 0..255 +DO +INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +SELECT * FROM t1 WHERE a='::ff'; +a +::ff +EXPLAIN SELECT * FROM t1 WHERE a='::ff'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 17 const 1 Using where; Using index +SELECT * FROM t1 WHERE a='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a>='::fe'; +a +::fe +::ff +EXPLAIN SELECT * FROM t1 WHERE a>='::fe'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +SELECT * FROM t1 WHERE a>='garbage'; +a +EXPLAIN SELECT * FROM t1 WHERE a>='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +a +::80 +::a0 +::f0 +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 3 Using where; Using index +SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +a +::80 +::a0 +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +a +::80 +::81 +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +a +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +a +::ff +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref a a 17 const 1 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::ff' +DROP TABLE t1; +# +# MDEV-26742 Assertion `field->type_handler() == this' failed in FixedBinTypeBundle<NATIVE_LEN, MAX_CHAR_LEN>::Type_handler_fbt::stored_field_cmp_to_item +# +CREATE TABLE t1 (pk inet6, c text) engine=myisam; +INSERT INTO t1 VALUES ('::',1); +CREATE TABLE t2 (d text, KEY (d)) engine=innodb ; +Warnings: +Note 1071 Specified key was too long; max key length is 3072 bytes +INSERT INTO t2 VALUES (2); +SELECT * FROM t2 JOIN t1 ON ( t1.pk > t2.d); +d pk c +Warnings: +Warning 1292 Incorrect inet6 value: '2' +UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1; +ERROR 22007: Incorrect inet6 value: '2' +SET sql_mode=''; +UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1; +Warnings: +Warning 1292 Incorrect inet6 value: '2' +SET sql_mode=DEFAULT; +SELECT * FROM t1; +pk c +:: 1 +SELECT * FROM t2; +d +2 +DROP TABLE t1, t2; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.test new file mode 100644 index 00000000000..55826cc3e3f --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_innodb.test @@ -0,0 +1,36 @@ +--source include/have_innodb.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + + +SET default_storage_engine=InnoDB; +--source type_inet6_engines.inc + +--echo # +--echo # MDEV-26742 Assertion `field->type_handler() == this' failed in FixedBinTypeBundle<NATIVE_LEN, MAX_CHAR_LEN>::Type_handler_fbt::stored_field_cmp_to_item +--echo # + +CREATE TABLE t1 (pk inet6, c text) engine=myisam; +INSERT INTO t1 VALUES ('::',1); +CREATE TABLE t2 (d text, KEY (d)) engine=innodb ; +INSERT INTO t2 VALUES (2); +SELECT * FROM t2 JOIN t1 ON ( t1.pk > t2.d); +--error ER_TRUNCATED_WRONG_VALUE +UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1; +SET sql_mode=''; +UPDATE t2 JOIN t1 ON ( t1.pk > t2.d) SET t1.c = 1; +SET sql_mode=DEFAULT; +SELECT * FROM t1; +SELECT * FROM t2; +DROP TABLE t1, t2; + + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.result new file mode 100644 index 00000000000..e805b167136 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.result @@ -0,0 +1,159 @@ +# +# Start of 10.5 tests +# +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +SET default_storage_engine=MEMORY; +# +# Range optimizer +# +CREATE TABLE t1 (a INET6, INDEX(a)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 DEFAULT NULL, + KEY `a` (`a`) +) ENGINE=MEMORY DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FOR i IN 0..255 +DO +INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +SELECT * FROM t1 WHERE a='::ff'; +a +::ff +EXPLAIN SELECT * FROM t1 WHERE a='::ff'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 17 const 2 Using where +SELECT * FROM t1 WHERE a='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a>='::fe'; +a +::fe +::ff +EXPLAIN SELECT * FROM t1 WHERE a>='::fe'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL a NULL NULL NULL 256 Using where +SELECT * FROM t1 WHERE a>='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a>='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL a NULL NULL NULL 256 Using where +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +a +::80 +::a0 +::f0 +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 6 Using where +SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +a +::80 +::a0 +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 4 Using where +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +a +::80 +::81 +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL a NULL NULL NULL 256 Using where +SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ALL a NULL NULL NULL 256 Using where +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +a +::ff +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref a a 17 const 2 100.00 Using where +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::ff' +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.test new file mode 100644 index 00000000000..da3f83892dd --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_memory.test @@ -0,0 +1,16 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + + +SET default_storage_engine=MEMORY; +--source type_inet6_engines.inc + + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result new file mode 100644 index 00000000000..32aab121427 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.result @@ -0,0 +1,63 @@ +# +# MDEV-27018 IF and COALESCE lose "json" property +# +CREATE TABLE t1 (a INET6, b JSON, c LONGTEXT); +INSERT INTO t1 VALUES ('::', '{"b": "b"}', '{"c": "c"}'); +SELECT +COALESCE(a,b), COALESCE(a,c), +LEAST(a,b), LEAST(a,c) +FROM t1 LIMIT 0; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def COALESCE(a,b) 254 (type=inet6) 39 0 Y 32 0 8 +def COALESCE(a,c) 254 (type=inet6) 39 0 Y 32 0 8 +def LEAST(a,b) 254 (type=inet6) 39 0 Y 32 0 8 +def LEAST(a,c) 254 (type=inet6) 39 0 Y 32 0 8 +COALESCE(a,b) COALESCE(a,c) LEAST(a,b) LEAST(a,c) +CREATE TABLE t2 AS +SELECT +COALESCE(a,b), COALESCE(a,c), +LEAST(a,b), LEAST(a,c) +FROM t1 LIMIT 0; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a,b)` inet6 DEFAULT NULL, + `COALESCE(a,c)` inet6 DEFAULT NULL, + `LEAST(a,b)` inet6 DEFAULT NULL, + `LEAST(a,c)` inet6 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +SELECT * FROM t1 WHERE a=b; +a b c +Warnings: +Warning 1292 Incorrect inet6 value: '{"b": "b"}' +SELECT * FROM t1 WHERE a=c; +a b c +Warnings: +Warning 1292 Incorrect inet6 value: '{"c": "c"}' +SELECT a+b FROM t1; +ERROR HY000: Illegal parameter data types inet6 and longblob/json for operation '+' +SELECT a+c FROM t1; +ERROR HY000: Illegal parameter data types inet6 and longblob for operation '+' +DROP TABLE t1; +# +# MDEV-27668 Assertion `item->type_handler()->is_traditional_scalar_type() || item->type_handler() == type_handler()' failed in Field_inet6::can_optimize_keypart_ref +# +CREATE TABLE t1 (i INET6 PRIMARY KEY); +CREATE TABLE t2 (a VARCHAR(40) CHECK (JSON_VALID(a))); +SELECT * FROM t1 JOIN t2 ON (i = a); +i a +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +INSERT INTO t2 VALUES ('{}'),('[]'); +SELECT * FROM t1 JOIN t2 ON (i = a); +i a +DROP TABLE t1, t2; +CREATE TABLE t1 (i INET6 PRIMARY KEY); +SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b'); +i +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b'); +i +Warnings: +Warning 1292 Incorrect inet6 value: '{"c": "b"}' +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test new file mode 100644 index 00000000000..74a91ff9a05 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mix_json.test @@ -0,0 +1,68 @@ +--echo # +--echo # MDEV-27018 IF and COALESCE lose "json" property +--echo # + +# +# Testing that JSON data types inherit properties +# from their non-JSON counterparts when mixed to INET6. +# +# E.g. JSON acts exactly like LONGTEXT when mixed to INET6: +# +# - COALESCE(inet6,json) returns inet6 (type aggregation for result) +# - LEAST(inet6,json) returns inet6 (type aggregation for min/max) +# - inet6=json is compared as inet6 (type aggregation for comparison) +# - inet6+json returns an error (type aggregation for numeric op) +# +# Mixing INET6 and JSON is actually meaningless: +# Non of valid JSON values are valid INET6. +# +# Some queries below intentionally use LIMIT 0 to avoid errors. +# + +CREATE TABLE t1 (a INET6, b JSON, c LONGTEXT); +INSERT INTO t1 VALUES ('::', '{"b": "b"}', '{"c": "c"}'); + +--disable_ps_protocol +--enable_metadata +SELECT + COALESCE(a,b), COALESCE(a,c), + LEAST(a,b), LEAST(a,c) +FROM t1 LIMIT 0; +--disable_metadata +--enable_ps_protocol + +CREATE TABLE t2 AS +SELECT + COALESCE(a,b), COALESCE(a,c), + LEAST(a,b), LEAST(a,c) +FROM t1 LIMIT 0; +SHOW CREATE TABLE t2; +DROP TABLE t2; + +SELECT * FROM t1 WHERE a=b; +SELECT * FROM t1 WHERE a=c; + +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a+b FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT a+c FROM t1; + +DROP TABLE t1; + +--echo # +--echo # MDEV-27668 Assertion `item->type_handler()->is_traditional_scalar_type() || item->type_handler() == type_handler()' failed in Field_inet6::can_optimize_keypart_ref +--echo # + +CREATE TABLE t1 (i INET6 PRIMARY KEY); +CREATE TABLE t2 (a VARCHAR(40) CHECK (JSON_VALID(a))); +SELECT * FROM t1 JOIN t2 ON (i = a); +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +INSERT INTO t2 VALUES ('{}'),('[]'); +SELECT * FROM t1 JOIN t2 ON (i = a); +DROP TABLE t1, t2; + +CREATE TABLE t1 (i INET6 PRIMARY KEY); +SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b'); +INSERT INTO t1 VALUES ('::'),('ffff::ffff'); +SELECT * FROM t1 WHERE i<JSON_OBJECT('c','b'); +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result new file mode 100644 index 00000000000..c2577ef44df --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.result @@ -0,0 +1,111 @@ +# +# Start of 10.5 tests +# +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +SET default_storage_engine=MyISAM; +# +# Range optimizer +# +CREATE TABLE t1 (a INET6, INDEX(a)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` inet6 DEFAULT NULL, + KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +FOR i IN 0..255 +DO +INSERT INTO t1 VALUES (CONCAT('::', HEX(i))); +END FOR +$$ +SELECT * FROM t1 WHERE a='::ff'; +a +::ff +EXPLAIN SELECT * FROM t1 WHERE a='::ff'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 17 const 1 Using where; Using index +SELECT * FROM t1 WHERE a='garbage'; +a +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a>='::fe'; +a +::fe +::ff +EXPLAIN SELECT * FROM t1 WHERE a>='::fe'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +SELECT * FROM t1 WHERE a>='garbage'; +a +EXPLAIN SELECT * FROM t1 WHERE a>='garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +a +::80 +::a0 +::f0 +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','::f0'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 3 Using where; Using index +SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +a +::80 +::a0 +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +EXPLAIN SELECT * FROM t1 WHERE a IN ('::80','::a0','garbage'); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +Warnings: +Warning 1292 Incorrect inet6 value: 'garbage' +SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +a +::80 +::81 +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND '::81'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 range a a 17 NULL 2 Using where; Using index +SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +a +EXPLAIN SELECT * FROM t1 WHERE a BETWEEN '::80' AND 'garbage'; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE NULL NULL NULL NULL NULL NULL NULL Impossible WHERE noticed after reading const tables +SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +a +::ff +EXPLAIN EXTENDED SELECT * FROM t1 WHERE a=CAST('::ff' AS INET6); +id select_type table type possible_keys key key_len ref rows filtered Extra +1 SIMPLE t1 ref a a 17 const 1 100.00 Using where; Using index +Warnings: +Note 1003 select `test`.`t1`.`a` AS `a` from `test`.`t1` where `test`.`t1`.`a` = INET6'::ff' +DROP TABLE t1; +# +# MDEV-26742 Assertion `field->type_handler() == this' failed in FixedBinTypeBundle<NATIVE_LEN, MAX_CHAR_LEN>::Type_handler_fbt::stored_field_cmp_to_item +# +CREATE TABLE t1 (c varchar(64), key(c)) engine=myisam; +INSERT INTO t1 VALUES ('0::1'),('::1'),('::2'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +c +::2 +EXPLAIN SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index c c 67 NULL 3 Using where; Using index +SELECT * FROM t1 WHERE c=CAST('::1' AS INET6); +c +0::1 +::1 +EXPLAIN SELECT * FROM t1 WHERE c=CAST('::1' AS INET6); +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index c c 67 NULL 3 Using where; Using index +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.test new file mode 100644 index 00000000000..0ba8369ac95 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_myisam.test @@ -0,0 +1,28 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--echo # + + +SET default_storage_engine=MyISAM; +--source type_inet6_engines.inc + +--echo # +--echo # MDEV-26742 Assertion `field->type_handler() == this' failed in FixedBinTypeBundle<NATIVE_LEN, MAX_CHAR_LEN>::Type_handler_fbt::stored_field_cmp_to_item +--echo # + +CREATE TABLE t1 (c varchar(64), key(c)) engine=myisam; +INSERT INTO t1 VALUES ('0::1'),('::1'),('::2'); +SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +EXPLAIN SELECT * FROM t1 WHERE c>CAST('::1' AS INET6); +SELECT * FROM t1 WHERE c=CAST('::1' AS INET6); +EXPLAIN SELECT * FROM t1 WHERE c=CAST('::1' AS INET6); +DROP TABLE t1; + + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.result new file mode 100644 index 00000000000..7ed7b5c4422 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.result @@ -0,0 +1,42 @@ +CREATE TABLE t1 (a INET6); +Field 1: `a` +Org_field: `a` +Catalog: `def` +Database: `test` +Table: `t1` +Org_table: `t1` +Type: STRING (type=inet6) +Collation: latin1_swedish_ci (8) +Length: 39 +Max_length: 0 +Decimals: 0 +Flags: UNSIGNED BINARY + +Field 2: `b` +Org_field: `` +Catalog: `def` +Database: `` +Table: `` +Org_table: `` +Type: STRING (type=inet6) +Collation: latin1_swedish_ci (8) +Length: 39 +Max_length: 0 +Decimals: 0 +Flags: NOT_NULL UNSIGNED + +Field 3: `c` +Org_field: `` +Catalog: `def` +Database: `` +Table: `` +Org_table: `` +Type: STRING (type=inet6) +Collation: latin1_swedish_ci (8) +Length: 39 +Max_length: 0 +Decimals: 0 +Flags: UNSIGNED + + +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.test new file mode 100644 index 00000000000..dfb300816d9 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_mysql.test @@ -0,0 +1,6 @@ +-- source include/have_working_dns.inc +-- source include/not_embedded.inc + +CREATE TABLE t1 (a INET6); +--exec $MYSQL -t test --column-type-info -e "SELECT a, CAST('::' AS INET6) AS b, COALESCE(a) AS c FROM t1" 2>&1 +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.result new file mode 100644 index 00000000000..8b041e45bea --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.result @@ -0,0 +1,29 @@ +# +# Start of 10.5 tests +# +# +# MDEV-20913 sql_mode=ORACLE: INET6 does not work as a routine parameter type and return type +# +SET sql_mode=ORACLE; +CREATE OR REPLACE FUNCTION f1() RETURN INET6 AS +BEGIN +RETURN 'ffff::ffff'; +END; +$$ +SELECT f1(); +f1() +ffff::ffff +DROP FUNCTION f1; +SET sql_mode=ORACLE; +CREATE OR REPLACE FUNCTION f1(a INET6) RETURN INT AS +BEGIN +RETURN LENGTH(a); +END; +$$ +SELECT f1('0::0'); +f1('0::0') +2 +DROP FUNCTION f1; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.test new file mode 100644 index 00000000000..46754bf9fa5 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_oracle.test @@ -0,0 +1,35 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20913 sql_mode=ORACLE: INET6 does not work as a routine parameter type and return type +--echo # + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE OR REPLACE FUNCTION f1() RETURN INET6 AS +BEGIN + RETURN 'ffff::ffff'; +END; +$$ +DELIMITER ;$$ +SELECT f1(); +DROP FUNCTION f1; + + +SET sql_mode=ORACLE; +DELIMITER $$; +CREATE OR REPLACE FUNCTION f1(a INET6) RETURN INT AS +BEGIN + RETURN LENGTH(a); +END; +$$ +DELIMITER ;$$ +SELECT f1('0::0'); +DROP FUNCTION f1; + + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.result new file mode 100644 index 00000000000..48f10a39989 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.result @@ -0,0 +1,29 @@ +# +# MDEV-20831 Table partitioned by LIST/RANGE COLUMNS(inet6) can be created, but not inserted into +# +SET NAMES utf8; +CREATE TABLE t1 (a INET6) +PARTITION BY LIST COLUMNS(a) +(PARTITION p00 VALUES IN (10)); +ERROR HY000: Partition column values of incorrect type +CREATE TABLE t1 (a INET6) +PARTITION BY LIST COLUMNS(a) +(PARTITION p00 VALUES IN (TIME'10:20:30')); +ERROR HY000: Partition column values of incorrect type +CREATE TABLE t1 (a INET6) +PARTITION BY LIST COLUMNS(a) +(PARTITION p00 VALUES IN ('€')); +ERROR 22007: Incorrect inet6 value: '€' +CREATE TABLE t1 (a INET6) +PARTITION BY LIST COLUMNS(a) +(PARTITION p00 VALUES IN ('::'), +PARTITION pFF VALUES IN (0xFFFF000000000000000000000000FFFF)); +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('ffff::ffff'); +SELECT * FROM t1 PARTITION (p00); +a +:: +SELECT * FROM t1 PARTITION (pFF); +a +ffff::ffff +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.test new file mode 100644 index 00000000000..76ab24781f0 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_partition.test @@ -0,0 +1,32 @@ +--source include/have_partition.inc + +--echo # +--echo # MDEV-20831 Table partitioned by LIST/RANGE COLUMNS(inet6) can be created, but not inserted into +--echo # + +SET NAMES utf8; + +--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR +CREATE TABLE t1 (a INET6) + PARTITION BY LIST COLUMNS(a) + (PARTITION p00 VALUES IN (10)); + +--error ER_WRONG_TYPE_COLUMN_VALUE_ERROR +CREATE TABLE t1 (a INET6) + PARTITION BY LIST COLUMNS(a) + (PARTITION p00 VALUES IN (TIME'10:20:30')); + +--error ER_TRUNCATED_WRONG_VALUE +CREATE TABLE t1 (a INET6) + PARTITION BY LIST COLUMNS(a) + (PARTITION p00 VALUES IN ('€')); + +CREATE TABLE t1 (a INET6) + PARTITION BY LIST COLUMNS(a) + (PARTITION p00 VALUES IN ('::'), + PARTITION pFF VALUES IN (0xFFFF000000000000000000000000FFFF)); +INSERT INTO t1 VALUES ('::'); +INSERT INTO t1 VALUES ('ffff::ffff'); +SELECT * FROM t1 PARTITION (p00); +SELECT * FROM t1 PARTITION (pFF); +DROP TABLE t1; diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.result new file mode 100644 index 00000000000..200ab30768f --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.result @@ -0,0 +1,31 @@ +# +# Start of 10.5 tests +# +# +# MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +# +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='DATA TYPE' + AND PLUGIN_NAME='inet6'; +PLUGIN_NAME inet6 +PLUGIN_VERSION 1.0 +PLUGIN_STATUS ACTIVE +PLUGIN_TYPE DATA TYPE +PLUGIN_AUTHOR MariaDB Corporation +PLUGIN_DESCRIPTION Data type INET6 +PLUGIN_LICENSE GPL +PLUGIN_MATURITY Stable +PLUGIN_AUTH_VERSION 1.0 +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.test new file mode 100644 index 00000000000..ccc22b16f4f --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_plugin.test @@ -0,0 +1,27 @@ +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-274 The data type for IPv6/IPv4 addresses in MariaDB +--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='DATA TYPE' + AND PLUGIN_NAME='inet6'; +--horizontal_results + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.result b/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.result new file mode 100644 index 00000000000..1cbedad1c3c --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.result @@ -0,0 +1,31 @@ +# +# Start of 10.5 tests +# +# +# MDEV-20800 Server crashes in Field_inet6::store_warning upon updating table statistics +# +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('1::1'),('2::2'); +ANALYZE TABLE t1 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +INSERT INTO t1 VALUES ('3::3'); +DROP TABLE t1; +# +# MDEV-22509: Server crashes in Field_inet6::store_inet6_null_with_warn / Field::maybe_null +# +CREATE TABLE t1 (a INT, b INET6 NOT NULL); +INSERT INTO t1 VALUES (1,'::'),(2,'::'); +ANALYZE TABLE t1 PERSISTENT FOR ALL; +Table Op Msg_type Msg_text +test.t1 analyze status Engine-independent statistics collected +test.t1 analyze status OK +SELECT t1.a from t1; +a +1 +2 +DROP TABLE t1; +# +# End of 10.5 tests +# diff --git a/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.test b/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.test new file mode 100644 index 00000000000..063581b12f5 --- /dev/null +++ b/plugin/type_inet/mysql-test/type_inet/type_inet6_stat_tables.test @@ -0,0 +1,29 @@ +--source include/have_stat_tables.inc + +--echo # +--echo # Start of 10.5 tests +--echo # + +--echo # +--echo # MDEV-20800 Server crashes in Field_inet6::store_warning upon updating table statistics +--echo # + +CREATE TABLE t1 (a INET6); +INSERT INTO t1 VALUES ('1::1'),('2::2'); +ANALYZE TABLE t1 PERSISTENT FOR ALL; +INSERT INTO t1 VALUES ('3::3'); +DROP TABLE t1; + +--echo # +--echo # MDEV-22509: Server crashes in Field_inet6::store_inet6_null_with_warn / Field::maybe_null +--echo # + +CREATE TABLE t1 (a INT, b INET6 NOT NULL); +INSERT INTO t1 VALUES (1,'::'),(2,'::'); +ANALYZE TABLE t1 PERSISTENT FOR ALL; +SELECT t1.a from t1; +DROP TABLE t1; + +--echo # +--echo # End of 10.5 tests +--echo # diff --git a/plugin/type_inet/plugin.cc b/plugin/type_inet/plugin.cc new file mode 100644 index 00000000000..77804c82af6 --- /dev/null +++ b/plugin/type_inet/plugin.cc @@ -0,0 +1,311 @@ +/* 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.h> + + +Type_handler_inet6 type_handler_inet6; + + +static struct st_mariadb_data_type plugin_descriptor_type_inet6= +{ + MariaDB_DATA_TYPE_INTERFACE_VERSION, + &type_handler_inet6 +}; + + +/*************************************************************************/ + +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 Plugin_function + plugin_descriptor_function_inet_aton(BUILDER(Create_func_inet_aton)), + plugin_descriptor_function_inet_ntoa(BUILDER(Create_func_inet_ntoa)), + plugin_descriptor_function_inet6_aton(BUILDER(Create_func_inet6_aton)), + plugin_descriptor_function_inet6_ntoa(BUILDER(Create_func_inet6_ntoa)), + plugin_descriptor_function_is_ipv4(BUILDER(Create_func_is_ipv4)), + plugin_descriptor_function_is_ipv6(BUILDER(Create_func_is_ipv6)), + plugin_descriptor_function_is_ipv4_compat(BUILDER(Create_func_is_ipv4_compat)), + plugin_descriptor_function_is_ipv4_mapped(BUILDER(Create_func_is_ipv4_mapped)); + + +/*************************************************************************/ + +maria_declare_plugin(type_inet) +{ + MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_type_inet6,// pointer to type-specific plugin descriptor + "inet6", // plugin name + "MariaDB Corporation", // plugin author + "Data type INET6", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_inet_aton, // pointer to type-specific plugin descriptor + "inet_aton", // plugin name + "MariaDB Corporation", // plugin author + "Function INET_ATON()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_inet_ntoa, // pointer to type-specific plugin descriptor + "inet_ntoa", // plugin name + "MariaDB Corporation", // plugin author + "Function INET_NTOA()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_inet6_aton, // pointer to type-specific plugin descriptor + "inet6_aton", // plugin name + "MariaDB Corporation", // plugin author + "Function INET6_ATON()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_inet6_ntoa, // pointer to type-specific plugin descriptor + "inet6_ntoa", // plugin name + "MariaDB Corporation", // plugin author + "Function INET6_NTOA()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_is_ipv4, // pointer to type-specific plugin descriptor + "is_ipv4", // plugin name + "MariaDB Corporation", // plugin author + "Function IS_IPV4()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_is_ipv6, // pointer to type-specific plugin descriptor + "is_ipv6", // plugin name + "MariaDB Corporation", // plugin author + "Function IS_IPV6()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_is_ipv4_compat, // pointer to type-specific plugin descriptor + "is_ipv4_compat", // plugin name + "MariaDB Corporation", // plugin author + "Function IS_IPV4_COMPAT()", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_function_is_ipv4_mapped, // pointer to type-specific plugin descriptor + "is_ipv4_mapped", // plugin name + "MariaDB Corporation", // plugin author + "Function IS_IPV4_MAPPED()",// 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_STABLE// Maturity(see include/mysql/plugin.h)*/ +} +maria_declare_plugin_end; diff --git a/plugin/type_inet/sql_type_inet.cc b/plugin/type_inet/sql_type_inet.cc new file mode 100644 index 00000000000..1c6e0e02e73 --- /dev/null +++ b/plugin/type_inet/sql_type_inet.cc @@ -0,0 +1,1708 @@ +/* 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 "my_net.h" +#include "sql_class.h" // THD, SORT_FIELD_ATTR +#include "opt_range.h" // SEL_ARG +#include "sql_type_inet.h" + +/////////////////////////////////////////////////////////////////////////// + +static const char HEX_DIGITS[]= "0123456789abcdef"; + + +/////////////////////////////////////////////////////////////////////////// + +/** + Tries to convert given string to binary IPv4-address representation. + This is a portable alternative to inet_pton(AF_INET). + + @param str String to convert. + @param str_length String length. + + @return Completion status. + @retval true - error, the given string does not represent an IPv4-address. + @retval false - ok, the string has been converted sucessfully. + + @note The problem with inet_pton() is that it treats leading zeros in + IPv4-part differently on different platforms. +*/ + +bool Inet4::ascii_to_ipv4(const char *str, size_t str_length) +{ + if (str_length < 7) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): " + "invalid IPv4 address: too short.", + (int) str_length, str)); + return true; + } + + if (str_length > IN_ADDR_MAX_CHAR_LENGTH) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): " + "invalid IPv4 address: too long.", + (int) str_length, str)); + return true; + } + + unsigned char *ipv4_bytes= (unsigned char *) &m_buffer; + const char *str_end= str + str_length; + const char *p= str; + int byte_value= 0; + int chars_in_group= 0; + int dot_count= 0; + char c= 0; + + while (p < str_end && *p) + { + c= *p++; + + if (my_isdigit(&my_charset_latin1, c)) + { + ++chars_in_group; + + if (chars_in_group > 3) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "too many characters in a group.", + (int) str_length, str)); + return true; + } + + byte_value= byte_value * 10 + (c - '0'); + + if (byte_value > 255) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "invalid byte value.", + (int) str_length, str)); + return true; + } + } + else if (c == '.') + { + if (chars_in_group == 0) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "too few characters in a group.", + (int) str_length, str)); + return true; + } + + ipv4_bytes[dot_count]= (unsigned char) byte_value; + + ++dot_count; + byte_value= 0; + chars_in_group= 0; + + if (dot_count > 3) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "too many dots.", (int) str_length, str)); + return true; + } + } + else + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "invalid character at pos %d.", + (int) str_length, str, (int) (p - str))); + return true; + } + } + + if (c == '.') + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "ending at '.'.", (int) str_length, str)); + return true; + } + + if (dot_count != 3) + { + DBUG_PRINT("error", ("ascii_to_ipv4(%.*s): invalid IPv4 address: " + "too few groups.", + (int) str_length, str)); + return true; + } + + ipv4_bytes[3]= (unsigned char) byte_value; + + DBUG_PRINT("info", ("ascii_to_ipv4(%.*s): valid IPv4 address: %d.%d.%d.%d", + (int) str_length, str, + ipv4_bytes[0], ipv4_bytes[1], + ipv4_bytes[2], ipv4_bytes[3])); + return false; +} + + +/** + Tries to convert given string to binary IPv6-address representation. + This is a portable alternative to inet_pton(AF_INET6). + + @param str String to convert. + @param str_length String length. + + @return Completion status. + @retval true - error, the given string does not represent an IPv6-address. + @retval false - ok, the string has been converted sucessfully. + + @note The problem with inet_pton() is that it treats leading zeros in + IPv4-part differently on different platforms. +*/ + +bool Inet6::ascii_to_ipv6(const char *str, size_t str_length) +{ + if (str_length < 2) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: too short.", + (int) str_length, str)); + return true; + } + + if (str_length > IN6_ADDR_MAX_CHAR_LENGTH) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: too long.", + (int) str_length, str)); + return true; + } + + memset(m_buffer, 0, sizeof(m_buffer)); + + const char *p= str; + + if (*p == ':') + { + ++p; + + if (*p != ':') + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "can not start with ':x'.", (int) str_length, str)); + return true; + } + } + + const char *str_end= str + str_length; + char *ipv6_bytes_end= m_buffer + sizeof(m_buffer); + char *dst= m_buffer; + char *gap_ptr= NULL; + const char *group_start_ptr= p; + int chars_in_group= 0; + int group_value= 0; + + while (p < str_end && *p) + { + char c= *p++; + + if (c == ':') + { + group_start_ptr= p; + + if (!chars_in_group) + { + if (gap_ptr) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "too many gaps(::).", (int) str_length, str)); + return true; + } + + gap_ptr= dst; + continue; + } + + if (!*p || p >= str_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "ending at ':'.", (int) str_length, str)); + return true; + } + + if (dst + 2 > ipv6_bytes_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "too many groups (1).", (int) str_length, str)); + return true; + } + + dst[0]= (unsigned char) (group_value >> 8) & 0xff; + dst[1]= (unsigned char) group_value & 0xff; + dst += 2; + + chars_in_group= 0; + group_value= 0; + } + else if (c == '.') + { + if (dst + IN_ADDR_SIZE > ipv6_bytes_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "unexpected IPv4-part.", (int) str_length, str)); + return true; + } + + Inet4_null tmp(group_start_ptr, (size_t) (str_end - group_start_ptr), + &my_charset_latin1); + if (tmp.is_null()) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "invalid IPv4-part.", (int) str_length, str)); + return true; + } + + tmp.to_binary(dst, IN_ADDR_SIZE); + dst += IN_ADDR_SIZE; + chars_in_group= 0; + + break; + } + else + { + const char *hdp= strchr(HEX_DIGITS, my_tolower(&my_charset_latin1, c)); + + if (!hdp) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "invalid character at pos %d.", + (int) str_length, str, (int) (p - str))); + return true; + } + + if (chars_in_group >= 4) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "too many digits in group.", + (int) str_length, str)); + return true; + } + + group_value <<= 4; + group_value |= hdp - HEX_DIGITS; + + DBUG_ASSERT(group_value <= 0xffff); + + ++chars_in_group; + } + } + + if (chars_in_group > 0) + { + if (dst + 2 > ipv6_bytes_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "too many groups (2).", (int) str_length, str)); + return true; + } + + dst[0]= (unsigned char) (group_value >> 8) & 0xff; + dst[1]= (unsigned char) group_value & 0xff; + dst += 2; + } + + if (gap_ptr) + { + if (dst == ipv6_bytes_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "no room for a gap (::).", (int) str_length, str)); + return true; + } + + int bytes_to_move= (int)(dst - gap_ptr); + + for (int i= 1; i <= bytes_to_move; ++i) + { + ipv6_bytes_end[-i]= gap_ptr[bytes_to_move - i]; + gap_ptr[bytes_to_move - i]= 0; + } + + dst= ipv6_bytes_end; + } + + if (dst < ipv6_bytes_end) + { + DBUG_PRINT("error", ("ascii_to_ipv6(%.*s): invalid IPv6 address: " + "too few groups.", (int) str_length, str)); + return true; + } + + return false; +} + + +/** + Converts IPv4-binary-address to a string. This function is a portable + alternative to inet_ntop(AF_INET). + + @param[in] ipv4 IPv4-address data (byte array) + @param[out] dst A buffer to store string representation of IPv4-address. + @param[in] dstsize Number of bytes avaiable in "dst" + + @note The problem with inet_ntop() is that it is available starting from + Windows Vista, but the minimum supported version is Windows 2000. +*/ + +size_t Inet4::to_string(char *dst, size_t dstsize) const +{ + return (size_t) my_snprintf(dst, dstsize, "%d.%d.%d.%d", + (uchar) m_buffer[0], (uchar) m_buffer[1], + (uchar) m_buffer[2], (uchar) m_buffer[3]); +} + + +/** + Converts IPv6-binary-address to a string. This function is a portable + alternative to inet_ntop(AF_INET6). + + @param[in] ipv6 IPv6-address data (byte array) + @param[out] dst A buffer to store string representation of IPv6-address. + It must be at least of INET6_ADDRSTRLEN. + @param[in] dstsize Number of bytes available dst. + + @note The problem with inet_ntop() is that it is available starting from + Windows Vista, but out the minimum supported version is Windows 2000. +*/ + +size_t Inet6::to_string(char *dst, size_t dstsize) const +{ + struct Region + { + int pos; + int length; + }; + + const char *ipv6= m_buffer; + char *dstend= dst + dstsize; + const unsigned char *ipv6_bytes= (const unsigned char *) ipv6; + + // 1. Translate IPv6-address bytes to words. + // We can't just cast to short, because it's not guaranteed + // that sizeof (short) == 2. So, we have to make a copy. + + uint16 ipv6_words[IN6_ADDR_NUM_WORDS]; + + DBUG_ASSERT(dstsize > 0); // Need a space at least for the trailing '\0' + for (size_t i= 0; i < IN6_ADDR_NUM_WORDS; ++i) + ipv6_words[i]= (ipv6_bytes[2 * i] << 8) + ipv6_bytes[2 * i + 1]; + + // 2. Find "the gap" -- longest sequence of zeros in IPv6-address. + + Region gap= { -1, -1 }; + + { + Region rg= { -1, -1 }; + + for (size_t i= 0; i < IN6_ADDR_NUM_WORDS; ++i) + { + if (ipv6_words[i] != 0) + { + if (rg.pos >= 0) + { + if (rg.length > gap.length) + gap= rg; + + rg.pos= -1; + rg.length= -1; + } + } + else + { + if (rg.pos >= 0) + { + ++rg.length; + } + else + { + rg.pos= (int) i; + rg.length= 1; + } + } + } + + if (rg.pos >= 0) + { + if (rg.length > gap.length) + gap= rg; + } + } + + // 3. Convert binary data to string. + + char *p= dst; + + for (int i= 0; i < (int) IN6_ADDR_NUM_WORDS; ++i) + { + DBUG_ASSERT(dstend >= p); + size_t dstsize_available= dstend - p; + if (dstsize_available < 5) + break; + if (i == gap.pos) + { + // We're at the gap position. We should put trailing ':' and jump to + // the end of the gap. + + if (i == 0) + { + // The gap starts from the beginning of the data -- leading ':' + // should be put additionally. + + *p= ':'; + ++p; + } + + *p= ':'; + ++p; + + i += gap.length - 1; + } + else if (i == 6 && gap.pos == 0 && + (gap.length == 6 || // IPv4-compatible + (gap.length == 5 && ipv6_words[5] == 0xffff) // IPv4-mapped + )) + { + // The data represents either IPv4-compatible or IPv4-mapped address. + // The IPv6-part (zeros or zeros + ffff) has been already put into + // the string (dst). Now it's time to dump IPv4-part. + + return (size_t) (p - dst) + + Inet4_null((const char *) (ipv6_bytes + 12), 4). + to_string(p, dstsize_available); + } + else + { + // Usual IPv6-address-field. Print it out using lower-case + // hex-letters without leading zeros (recommended IPv6-format). + // + // If it is not the last field, append closing ':'. + + p += sprintf(p, "%x", ipv6_words[i]); + + if (i + 1 != IN6_ADDR_NUM_WORDS) + { + *p= ':'; + ++p; + } + } + } + + *p= 0; + return (size_t) (p - dst); +} + + +bool Inet6::fix_fields_maybe_null_on_conversion_to_inet6(Item *item) +{ + if (item->maybe_null) + return true; + if (item->type_handler() == &type_handler_inet6) + return false; + if (!item->const_item() || item->is_expensive()) + return true; + return Inet6_null(item, false).is_null(); +} + + +bool Inet6::make_from_item(Item *item, bool warn) +{ + if (item->type_handler() == &type_handler_inet6) + { + Native tmp(m_buffer, sizeof(m_buffer)); + bool rc= item->val_native(current_thd, &tmp); + if (rc) + return true; + DBUG_ASSERT(tmp.length() == sizeof(m_buffer)); + if (tmp.ptr() != m_buffer) + memcpy(m_buffer, tmp.ptr(), sizeof(m_buffer)); + return false; + } + StringBufferInet6 tmp; + String *str= item->val_str(&tmp); + return str ? make_from_character_or_binary_string(str, warn) : true; +} + + +bool Inet6::make_from_character_or_binary_string(const String *str, bool warn) +{ + static Name name= type_handler_inet6.name(); + if (str->charset() != &my_charset_bin) + { + bool rc= character_string_to_ipv6(str->ptr(), str->length(), + str->charset()); + if (rc && warn) + current_thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, + name.ptr(), + ErrConvString(str).ptr()); + return rc; + } + if (str->length() != sizeof(m_buffer)) + { + if (warn) + current_thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, + name.ptr(), + ErrConvString(str).ptr()); + return true; + } + DBUG_ASSERT(str->ptr() != m_buffer); + memcpy(m_buffer, str->ptr(), sizeof(m_buffer)); + return false; +}; + + +/********************************************************************/ + + +class cmp_item_inet6: public cmp_item_scalar +{ + Inet6 m_native; +public: + cmp_item_inet6() + :cmp_item_scalar(), + m_native(Inet6_zero()) + { } + void store_value(Item *item) override + { + m_native= Inet6(item, &m_null_value); + } + int cmp_not_null(const Value *val) override + { + DBUG_ASSERT(!val->is_null()); + DBUG_ASSERT(val->is_string()); + Inet6_null tmp(val->m_string); + DBUG_ASSERT(!tmp.is_null()); + return m_native.cmp(tmp); + } + int cmp(Item *arg) override + { + Inet6_null tmp(arg); + return m_null_value || tmp.is_null() ? UNKNOWN : m_native.cmp(tmp) != 0; + } + int compare(cmp_item *ci) override + { + cmp_item_inet6 *tmp= static_cast<cmp_item_inet6*>(ci); + DBUG_ASSERT(!m_null_value); + DBUG_ASSERT(!tmp->m_null_value); + return m_native.cmp(tmp->m_native); + } + cmp_item *make_same() override + { + return new cmp_item_inet6(); + } +}; + + +class Field_inet6: public Field +{ + static void set_min_value(char *ptr) + { + memset(ptr, 0, Inet6::binary_length()); + } + static void set_max_value(char *ptr) + { + memset(ptr, 0xFF, Inet6::binary_length()); + } + void store_warning(const ErrConv &str, + Sql_condition::enum_warning_level level) + { + static const Name type_name= type_handler_inet6.name(); + if (get_thd()->count_cuted_fields <= CHECK_FIELD_EXPRESSION) + return; + const TABLE_SHARE *s= table->s; + get_thd()->push_warning_truncated_value_for_field(level, type_name.ptr(), + str.ptr(), + s ? s->db.str : nullptr, + s ? s->table_name.str + : nullptr, + field_name.str); + } + int set_null_with_warn(const ErrConv &str) + { + store_warning(str, Sql_condition::WARN_LEVEL_WARN); + set_null(); + return 1; + } + int set_min_value_with_warn(const ErrConv &str) + { + store_warning(str, Sql_condition::WARN_LEVEL_WARN); + set_min_value((char*) ptr); + return 1; + } + int set_max_value_with_warn(const ErrConv &str) + { + store_warning(str, Sql_condition::WARN_LEVEL_WARN); + set_max_value((char*) ptr); + return 1; + } + int store_inet6_null_with_warn(const Inet6_null &inet6, + const ErrConvString &err) + { + DBUG_ASSERT(marked_for_write_or_computed()); + if (inet6.is_null()) + return maybe_null() ? set_null_with_warn(err) : + set_min_value_with_warn(err); + inet6.to_binary((char *) ptr, Inet6::binary_length()); + return 0; + } + +public: + Field_inet6(const LEX_CSTRING *field_name_arg, const Record_addr &rec) + :Field(rec.ptr(), Inet6::max_char_length(), + rec.null_ptr(), rec.null_bit(), Field::NONE, field_name_arg) + { + flags|= BINARY_FLAG | UNSIGNED_FLAG; + } + const Type_handler *type_handler() const override + { + return &type_handler_inet6; + } + uint32 max_display_length() const override { return field_length; } + bool str_needs_quotes() const override { return true; } + const DTCollation &dtcollation() const override + { + static DTCollation_numeric c; + return c; + } + CHARSET_INFO *charset(void) const override { return &my_charset_numeric; } + const CHARSET_INFO *sort_charset(void) const override { return &my_charset_bin; } + /** + This makes client-server protocol convert the value according + to @@character_set_client. + */ + bool binary() const override { return false; } + enum ha_base_keytype key_type() const override { return HA_KEYTYPE_BINARY; } + + bool is_equal(const Column_definition &new_field) const override + { + return new_field.type_handler() == type_handler(); + } + bool eq_def(const Field *field) const override + { + return Field::eq_def(field); + } + double pos_in_interval(Field *min, Field *max) override + { + return pos_in_interval_val_str(min, max, 0); + } + int cmp(const uchar *a, const uchar *b) const override + { return memcmp(a, b, pack_length()); } + + void sort_string(uchar *to, uint length) override + { + DBUG_ASSERT(length == pack_length()); + memcpy(to, ptr, length); + } + uint32 pack_length() const override + { + return Inet6::binary_length(); + } + uint pack_length_from_metadata(uint field_metadata) const override + { + return Inet6::binary_length(); + } + + void sql_type(String &str) const override + { + static Name name= type_handler_inet6.name(); + str.set_ascii(name.ptr(), name.length()); + } + + void make_send_field(Send_field *to) override + { + Field::make_send_field(to); + to->set_data_type_name(type_handler_inet6.name().lex_cstring()); + } + + bool validate_value_in_record(THD *thd, const uchar *record) const override + { + return false; + } + + String *val_str(String *val_buffer, + String *val_ptr __attribute__((unused))) override + { + DBUG_ASSERT(marked_for_read()); + Inet6_null tmp((const char *) ptr, pack_length()); + return tmp.to_string(val_buffer) ? NULL : val_buffer; + } + + my_decimal *val_decimal(my_decimal *to) override + { + DBUG_ASSERT(marked_for_read()); + my_decimal_set_zero(to); + return to; + } + + longlong val_int() override + { + DBUG_ASSERT(marked_for_read()); + return 0; + } + + double val_real() override + { + DBUG_ASSERT(marked_for_read()); + return 0; + } + + bool get_date(MYSQL_TIME *ltime, date_mode_t fuzzydate) override + { + DBUG_ASSERT(marked_for_read()); + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + return false; + } + + bool val_bool(void) override + { + DBUG_ASSERT(marked_for_read()); + return !Inet6::only_zero_bytes((const char *) ptr, Inet6::binary_length()); + } + + int store_native(const Native &value) override + { + DBUG_ASSERT(marked_for_write_or_computed()); + DBUG_ASSERT(value.length() == Inet6::binary_length()); + memcpy(ptr, value.ptr(), value.length()); + return 0; + } + + int store(const char *str, size_t length, CHARSET_INFO *cs) override + { + return cs == &my_charset_bin ? store_binary(str, length) : + store_text(str, length, cs); + } + + int store_text(const char *str, size_t length, CHARSET_INFO *cs) override + { + return store_inet6_null_with_warn(Inet6_null(str, length, cs), + ErrConvString(str, length, cs)); + } + + int store_binary(const char *str, size_t length) override + { + return store_inet6_null_with_warn(Inet6_null(str, length), + ErrConvString(str, length, + &my_charset_bin)); + } + + int store_hex_hybrid(const char *str, size_t length) override + { + return Field_inet6::store_binary(str, length); + } + + int store_decimal(const my_decimal *num) override + { + DBUG_ASSERT(marked_for_write_or_computed()); + return set_min_value_with_warn(ErrConvDecimal(num)); + } + + int store(longlong nr, bool unsigned_flag) override + { + DBUG_ASSERT(marked_for_write_or_computed()); + return set_min_value_with_warn( + ErrConvInteger(Longlong_hybrid(nr, unsigned_flag))); + } + + int store(double nr) override + { + DBUG_ASSERT(marked_for_write_or_computed()); + return set_min_value_with_warn(ErrConvDouble(nr)); + } + + int store_time_dec(const MYSQL_TIME *ltime, uint dec) override + { + DBUG_ASSERT(marked_for_write_or_computed()); + return set_min_value_with_warn(ErrConvTime(ltime)); + } + + /*** Field conversion routines ***/ + int store_field(Field *from) override + { + // INSERT INTO t1 (inet6_field) SELECT different_field_type FROM t2; + return from->save_in_field(this); + } + int save_in_field(Field *to) override + { + // INSERT INTO t2 (different_field_type) SELECT inet6_field FROM t1; + if (to->charset() == &my_charset_bin && + dynamic_cast<const Type_handler_general_purpose_string*> + (to->type_handler())) + { + NativeBufferInet6 res; + val_native(&res); + return to->store(res.ptr(), res.length(), &my_charset_bin); + } + return save_in_field_str(to); + } + Copy_func *get_copy_func(const Field *from) const override + { + // ALTER to INET6 from another field + return do_field_string; + } + + Copy_func *get_copy_func_to(const Field *to) const override + { + if (type_handler() == to->type_handler()) + { + // ALTER from INET6 to INET6 + DBUG_ASSERT(pack_length() == to->pack_length()); + DBUG_ASSERT(charset() == to->charset()); + DBUG_ASSERT(sort_charset() == to->sort_charset()); + return Field::do_field_eq; + } + // ALTER from INET6 to another data type + if (to->charset() == &my_charset_bin && + dynamic_cast<const Type_handler_general_purpose_string*> + (to->type_handler())) + { + /* + ALTER from INET6 to a binary string type, e.g.: + BINARY, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB + */ + return do_field_inet6_native_to_binary; + } + return do_field_string; + } + + static void do_field_inet6_native_to_binary(Copy_field *copy) + { + NativeBufferInet6 res; + copy->from_field->val_native(&res); + copy->to_field->store(res.ptr(), res.length(), &my_charset_bin); + } + + bool memcpy_field_possible(const Field *from) const override + { + // INSERT INTO t1 (inet6_field) SELECT field2 FROM t2; + return type_handler() == from->type_handler(); + } + enum_conv_type rpl_conv_type_from(const Conv_source &source, + const Relay_log_info *rli, + const Conv_param ¶m) const override + { + if (type_handler() == source.type_handler() || + (source.type_handler() == &type_handler_string && + source.type_handler()->max_display_length_for_field(source) == + Inet6::binary_length())) + return rpl_conv_type_from_same_data_type(source.metadata(), rli, param); + return CONV_TYPE_IMPOSSIBLE; + } + + /*** Optimizer routines ***/ + bool test_if_equality_guarantees_uniqueness(const Item *const_item) const override + { + /* + This condition: + WHERE inet6_field=const + should return a single distinct value only, + as comparison is done according to INET6. + */ + return true; + } + bool can_be_substituted_to_equal_item(const Context &ctx, + const Item_equal *item_equal) + override + { + switch (ctx.subst_constraint()) { + case ANY_SUBST: + return ctx.compare_type_handler() == item_equal->compare_type_handler(); + case IDENTITY_SUBST: + return true; + } + return false; + } + Item *get_equal_const_item(THD *thd, const Context &ctx, + Item *const_item) override; + bool can_optimize_keypart_ref(const Item_bool_func *cond, + const Item *item) const override + { + /* + Mixing of two different non-traditional types is currently prevented. + This may change in the future. For example, INET4 and INET6 + data types can be made comparable. + But we allow mixing INET6 to a data type directly inherited from + a traditional type, e.g. INET6=VARCHAR/JSON. + */ + DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()-> + is_traditional_scalar_type() || + item->type_handler() == type_handler()); + return true; + } + /** + Test if Field can use range optimizer for a standard comparison operation: + <=, <, =, <=>, >, >= + Note, this method does not cover spatial operations. + */ + bool can_optimize_range(const Item_bool_func *cond, + const Item *item, + bool is_eq_func) const override + { + // See the DBUG_ASSERT comment in can_optimize_keypart_ref() + DBUG_ASSERT(item->type_handler()->type_handler_base_or_self()-> + is_traditional_scalar_type() || + item->type_handler() == type_handler()); + return true; + } + SEL_ARG *get_mm_leaf(RANGE_OPT_PARAM *prm, KEY_PART *key_part, + const Item_bool_func *cond, + scalar_comparison_op op, Item *value) override + { + DBUG_ENTER("Field_inet6::get_mm_leaf"); + if (!can_optimize_scalar_range(prm, key_part, cond, op, value)) + DBUG_RETURN(0); + int err= value->save_in_field_no_warnings(this, 1); + if ((op != SCALAR_CMP_EQUAL && is_real_null()) || err < 0) + DBUG_RETURN(&null_element); + if (err > 0) + { + if (op == SCALAR_CMP_EQ || op == SCALAR_CMP_EQUAL) + DBUG_RETURN(new (prm->mem_root) SEL_ARG_IMPOSSIBLE(this)); + DBUG_RETURN(NULL); /* Cannot infer anything */ + } + DBUG_RETURN(stored_field_make_mm_leaf(prm, key_part, op, value)); + } + bool can_optimize_hash_join(const Item_bool_func *cond, + const Item *item) const override + { + return can_optimize_keypart_ref(cond, item); + } + bool can_optimize_group_min_max(const Item_bool_func *cond, + const Item *const_item) const override + { + return true; + } + + uint row_pack_length() const override { return pack_length(); } + + Binlog_type_info binlog_type_info() const override + { + DBUG_ASSERT(type() == binlog_type()); + return Binlog_type_info_fixed_string(Field_inet6::binlog_type(), + Inet6::binary_length(), + &my_charset_bin); + } + + uchar *pack(uchar *to, const uchar *from, uint max_length) override + { + DBUG_PRINT("debug", ("Packing field '%s'", field_name.str)); + return StringPack(&my_charset_bin, Inet6::binary_length()). + pack(to, from, max_length); + } + + const uchar *unpack(uchar *to, const uchar *from, const uchar *from_end, + uint param_data) override + { + return StringPack(&my_charset_bin, Inet6::binary_length()). + unpack(to, from, from_end, param_data); + } + + uint max_packed_col_length(uint max_length) override + { + return StringPack::max_packed_col_length(max_length); + } + + uint packed_col_length(const uchar *data_ptr, uint length) override + { + return StringPack::packed_col_length(data_ptr, length); + } + + /**********/ + uint size_of() const override { return sizeof(*this); } +}; + + +class Item_typecast_inet6: public Item_func +{ +public: + Item_typecast_inet6(THD *thd, Item *a) :Item_func(thd, a) {} + + const Type_handler *type_handler() const override + { return &type_handler_inet6; } + + enum Functype functype() const override { return CHAR_TYPECAST_FUNC; } + bool eq(const Item *item, bool binary_cmp) const override + { + if (this == item) + return true; + if (item->type() != FUNC_ITEM || + functype() != ((Item_func*)item)->functype()) + return false; + if (type_handler() != item->type_handler()) + return false; + Item_typecast_inet6 *cast= (Item_typecast_inet6*) item; + return args[0]->eq(cast->args[0], binary_cmp); + } + const char *func_name() const override { return "cast_as_inet6"; } + void print(String *str, enum_query_type query_type) override + { + str->append(STRING_WITH_LEN("cast(")); + args[0]->print(str, query_type); + str->append(STRING_WITH_LEN(" as inet6)")); + } + bool fix_length_and_dec() override + { + Type_std_attributes::operator=(Type_std_attributes_inet6()); + if (Inet6::fix_fields_maybe_null_on_conversion_to_inet6(args[0])) + maybe_null= true; + return false; + } + String *val_str(String *to) override + { + Inet6_null tmp(args[0]); + return (null_value= tmp.is_null() || tmp.to_string(to)) ? NULL : to; + } + longlong val_int() override + { + return 0; + } + double val_real() override + { + return 0; + } + my_decimal *val_decimal(my_decimal *to) override + { + my_decimal_set_zero(to); + return to; + } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override + { + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + return false; + } + bool val_native(THD *thd, Native *to) override + { + Inet6_null tmp(args[0]); + return null_value= tmp.is_null() || tmp.to_native(to); + } + Item *get_copy(THD *thd) override + { return get_item_copy<Item_typecast_inet6>(thd, this); } +}; + + +class Item_cache_inet6: public Item_cache +{ + NativeBufferInet6 m_value; +public: + Item_cache_inet6(THD *thd) + :Item_cache(thd, &type_handler_inet6) + { } + Item *get_copy(THD *thd) + { return get_item_copy<Item_cache_inet6>(thd, this); } + bool cache_value() + { + if (!example) + return false; + value_cached= true; + /* + Merge comments: in 10.7 this code migrated to + Item_cache_fbt in to sql/sql_type_fixedbin.h + */ + null_value_inside= null_value= + example->val_native_with_conversion_result(current_thd, + &m_value, + type_handler()); + return true; + } + String* val_str(String *to) + { + if (!has_value()) + return NULL; + Inet6_null tmp(m_value.ptr(), m_value.length()); + return tmp.is_null() || tmp.to_string(to) ? NULL : to; + } + my_decimal *val_decimal(my_decimal *to) + { + if (!has_value()) + return NULL; + my_decimal_set_zero(to); + return to; + } + longlong val_int() + { + if (!has_value()) + return 0; + return 0; + } + double val_real() + { + if (!has_value()) + return 0; + return 0; + } + longlong val_datetime_packed(THD *thd) + { + DBUG_ASSERT(0); + if (!has_value()) + return 0; + return 0; + } + longlong val_time_packed(THD *thd) + { + DBUG_ASSERT(0); + if (!has_value()) + return 0; + return 0; + } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) + { + if (!has_value()) + return true; + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + return false; + } + bool val_native(THD *thd, Native *to) + { + if (!has_value()) + return true; + return to->copy(m_value.ptr(), m_value.length()); + } +}; + + +class Item_literal_inet6: public Item_literal +{ + Inet6 m_value; +public: + Item_literal_inet6(THD *thd) + :Item_literal(thd), + m_value(Inet6_zero()) + { } + Item_literal_inet6(THD *thd, const Inet6 &value) + :Item_literal(thd), + m_value(value) + { } + const Type_handler *type_handler() const override + { + return &type_handler_inet6; + } + longlong val_int() override + { + return 0; + } + double val_real() override + { + return 0; + } + String *val_str(String *to) override + { + return m_value.to_string(to) ? NULL : to; + } + my_decimal *val_decimal(my_decimal *to) override + { + my_decimal_set_zero(to); + return to; + } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override + { + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + return false; + } + bool val_native(THD *thd, Native *to) override + { + return m_value.to_native(to); + } + void print(String *str, enum_query_type query_type) override + { + StringBufferInet6 tmp; + m_value.to_string(&tmp); + str->append("INET6'"); + str->append(tmp); + str->append('\''); + } + Item *get_copy(THD *thd) override + { return get_item_copy<Item_literal_inet6>(thd, this); } + + // Non-overriding methods + void set_value(const Inet6 &value) + { + m_value= value; + } +}; + + +class Item_copy_inet6: public Item_copy +{ + NativeBufferInet6 m_value; +public: + Item_copy_inet6(THD *thd, Item *item_arg): Item_copy(thd, item_arg) {} + + bool val_native(THD *thd, Native *to) override + { + if (null_value) + return true; + return to->copy(m_value.ptr(), m_value.length()); + } + String *val_str(String *to) override + { + if (null_value) + return NULL; + Inet6_null tmp(m_value.ptr(), m_value.length()); + return tmp.is_null() || tmp.to_string(to) ? NULL : to; + } + my_decimal *val_decimal(my_decimal *to) override + { + my_decimal_set_zero(to); + return to; + } + double val_real() override + { + return 0; + } + longlong val_int() override + { + return 0; + } + bool get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) override + { + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + return null_value; + } + void copy() override + { + null_value= item->val_native(current_thd, &m_value); + DBUG_ASSERT(null_value == item->null_value); + } + int save_in_field(Field *field, bool no_conversions) override + { + return Item::save_in_field(field, no_conversions); + } + Item *get_copy(THD *thd) override + { return get_item_copy<Item_copy_inet6>(thd, this); } +}; + + +class in_inet6 :public in_vector +{ + Inet6 m_value; + static int cmp_inet6(void *cmp_arg, Inet6 *a, Inet6 *b) + { + return a->cmp(*b); + } +public: + in_inet6(THD *thd, uint elements) + :in_vector(thd, elements, sizeof(Inet6), (qsort2_cmp) cmp_inet6, 0), + m_value(Inet6_zero()) + { } + const Type_handler *type_handler() const override + { + return &type_handler_inet6; + } + void set(uint pos, Item *item) override + { + Inet6 *buff= &((Inet6 *) base)[pos]; + Inet6_null value(item); + if (value.is_null()) + *buff= Inet6_zero(); + else + *buff= value; + } + uchar *get_value(Item *item) override + { + Inet6_null value(item); + if (value.is_null()) + return 0; + m_value= value; + return (uchar *) &m_value; + } + Item* create_item(THD *thd) override + { + return new (thd->mem_root) Item_literal_inet6(thd); + } + void value_to_item(uint pos, Item *item) override + { + const Inet6 &buff= (((Inet6*) base)[pos]); + static_cast<Item_literal_inet6*>(item)->set_value(buff); + } +}; + + +class Item_char_typecast_func_handler_inet6_to_binary: + public Item_handled_func::Handler_str +{ +public: + const Type_handler *return_type_handler(const Item_handled_func *item) + const override + { + if (item->max_length > MAX_FIELD_VARCHARLENGTH) + return Type_handler::blob_type_handler(item->max_length); + if (item->max_length > 255) + return &type_handler_varchar; + return &type_handler_string; + } + bool fix_length_and_dec(Item_handled_func *xitem) const override + { + return false; + } + String *val_str(Item_handled_func *item, String *to) const override + { + DBUG_ASSERT(dynamic_cast<const Item_char_typecast*>(item)); + return static_cast<Item_char_typecast*>(item)-> + val_str_binary_from_native(to); + } +}; + + +static Item_char_typecast_func_handler_inet6_to_binary + item_char_typecast_func_handler_inet6_to_binary; + + +bool Type_handler_inet6:: + Item_char_typecast_fix_length_and_dec(Item_char_typecast *item) const +{ + if (item->cast_charset() == &my_charset_bin) + { + item->fix_length_and_dec_native_to_binary(Inet6::binary_length()); + item->set_func_handler(&item_char_typecast_func_handler_inet6_to_binary); + return false; + } + item->fix_length_and_dec_str(); + return false; +} + + +bool +Type_handler_inet6::character_or_binary_string_to_native(THD *thd, + const String *str, + Native *to) const +{ + if (str->charset() == &my_charset_bin) + { + // Convert from a binary string + if (str->length() != Inet6::binary_length() || + to->copy(str->ptr(), str->length())) + { + thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, + name().ptr(), + ErrConvString(str).ptr()); + return true; + } + return false; + } + // Convert from a character string + Inet6_null tmp(*str); + if (tmp.is_null()) + thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, + name().ptr(), + ErrConvString(str).ptr()); + return tmp.is_null() || tmp.to_native(to); +} + + +bool +Type_handler_inet6::Item_save_in_value(THD *thd, + Item *item, + st_value *value) const +{ + value->m_type= DYN_COL_STRING; + String *str= item->val_str(&value->m_string); + if (str != &value->m_string && !item->null_value) + { + // "item" returned a non-NULL value + if (Inet6_null(*str).is_null()) + { + /* + The value was not-null, but conversion to INET6 failed: + SELECT a, DECODE_ORACLE(inet6col, 'garbage', '<NULL>', '::01', '01') + FROM t1; + */ + thd->push_warning_wrong_value(Sql_condition::WARN_LEVEL_WARN, + name().ptr(), + ErrConvString(str).ptr()); + value->m_type= DYN_COL_NULL; + return true; + } + // "item" returned a non-NULL value, and it was a valid INET6 + value->m_string.set(str->ptr(), str->length(), str->charset()); + } + return check_null(item, value); +} + + +void Type_handler_inet6::Item_param_setup_conversion(THD *thd, + Item_param *param) const +{ + param->setup_conversion_string(thd, thd->variables.character_set_client); +} + + +void Type_handler_inet6::make_sort_key_part(uchar *to, Item *item, + const SORT_FIELD_ATTR *sort_field, + Sort_param *param) const +{ + DBUG_ASSERT(item->type_handler() == this); + NativeBufferInet6 tmp; + item->val_native_result(current_thd, &tmp); + if (item->maybe_null) + { + if (item->null_value) + { + memset(to, 0, Inet6::binary_length() + 1); + return; + } + *to++= 1; + } + DBUG_ASSERT(!item->null_value); + DBUG_ASSERT(Inet6::binary_length() == tmp.length()); + DBUG_ASSERT(Inet6::binary_length() == sort_field->length); + memcpy(to, tmp.ptr(), tmp.length()); +} + +uint +Type_handler_inet6::make_packed_sort_key_part(uchar *to, Item *item, + const SORT_FIELD_ATTR *sort_field, + Sort_param *param) const +{ + DBUG_ASSERT(item->type_handler() == this); + NativeBufferInet6 tmp; + item->val_native_result(current_thd, &tmp); + if (item->maybe_null) + { + if (item->null_value) + { + *to++=0; + return 0; + } + *to++= 1; + } + DBUG_ASSERT(!item->null_value); + DBUG_ASSERT(Inet6::binary_length() == tmp.length()); + DBUG_ASSERT(Inet6::binary_length() == sort_field->length); + memcpy(to, tmp.ptr(), tmp.length()); + return tmp.length(); +} + +void Type_handler_inet6::sort_length(THD *thd, + const Type_std_attributes *item, + SORT_FIELD_ATTR *attr) const +{ + attr->original_length= attr->length= Inet6::binary_length(); + attr->suffix_length= 0; +} + + +cmp_item *Type_handler_inet6::make_cmp_item(THD *thd, CHARSET_INFO *cs) const +{ + return new (thd->mem_root) cmp_item_inet6; +} + + + +in_vector * +Type_handler_inet6::make_in_vector(THD *thd, const Item_func_in *func, + uint nargs) const +{ + return new (thd->mem_root) in_inet6(thd, nargs); +} + + +Item *Type_handler_inet6::create_typecast_item(THD *thd, Item *item, + const Type_cast_attributes &attr) + const +{ + return new (thd->mem_root) Item_typecast_inet6(thd, item); +} + + +Item_cache *Type_handler_inet6::Item_get_cache(THD *thd, const Item *item) const +{ + return new (thd->mem_root) Item_cache_inet6(thd); +} + + +Item_copy *Type_handler_inet6::create_item_copy(THD *thd, Item *item) const +{ + return new (thd->mem_root) Item_copy_inet6(thd, item); +} + + +Item * +Type_handler_inet6::make_const_item_for_comparison(THD *thd, + Item *src, + const Item *cmp) const +{ + Inet6_null tmp(src); + if (tmp.is_null()) + return new (thd->mem_root) Item_null(thd, src->name.str); + return new (thd->mem_root) Item_literal_inet6(thd, tmp); +} + + +Item *Field_inet6::get_equal_const_item(THD *thd, const Context &ctx, + Item *const_item) +{ + Inet6_null tmp(const_item); + if (tmp.is_null()) + return NULL; + return new (thd->mem_root) Item_literal_inet6(thd, tmp); +} + + +Field * +Type_handler_inet6::make_table_field_from_def( + TABLE_SHARE *share, + MEM_ROOT *mem_root, + const LEX_CSTRING *name, + const Record_addr &addr, + const Bit_addr &bit, + const Column_definition_attributes *attr, + uint32 flags) const +{ + return new (mem_root) Field_inet6(name, addr); +} + + +Field *Type_handler_inet6::make_table_field(MEM_ROOT *root, + const LEX_CSTRING *name, + const Record_addr &addr, + const Type_all_attributes &attr, + TABLE_SHARE *share) const +{ + return new (root) Field_inet6(name, addr); +} + + +Field *Type_handler_inet6::make_conversion_table_field(MEM_ROOT *root, + TABLE *table, + uint metadata, + const Field *target) + const +{ + const Record_addr tmp(NULL, Bit_addr(true)); + return new (table->in_use->mem_root) Field_inet6(&empty_clex_str, tmp); +} + + +bool Type_handler_inet6::partition_field_check(const LEX_CSTRING &field_name, + Item *item_expr) const +{ + if (item_expr->cmp_type() != STRING_RESULT) + { + my_error(ER_WRONG_TYPE_COLUMN_VALUE_ERROR, MYF(0)); + return true; + } + return false; +} + + +bool +Type_handler_inet6::partition_field_append_value( + String *to, + Item *item_expr, + CHARSET_INFO *field_cs, + partition_value_print_mode_t mode) + const +{ + StringBufferInet6 inet6str; + Inet6_null inet6(item_expr); + if (inet6.is_null()) + { + my_error(ER_PARTITION_FUNCTION_IS_NOT_ALLOWED, MYF(0)); + return true; + } + return inet6.to_string(&inet6str) || + to->append('\'') || + to->append(inet6str) || + to->append('\''); +} + + +/***************************************************************/ + + +class Type_collection_inet: public Type_collection +{ + const Type_handler *aggregate_common(const Type_handler *a, + const Type_handler *b) const + { + if (a == b) + return a; + return NULL; + } + const Type_handler *aggregate_if_string(const Type_handler *a, + const Type_handler *b) const + { + static const Type_aggregator::Pair agg[]= + { + {&type_handler_inet6, &type_handler_null, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_varchar, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_string, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_tiny_blob, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_blob, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_medium_blob, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_long_blob, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_hex_hybrid, &type_handler_inet6}, + {NULL,NULL,NULL} + }; + return Type_aggregator::find_handler_in_array(agg, a, b, true); + } +public: + const Type_handler *aggregate_for_result(const Type_handler *a, + const Type_handler *b) + const override + { + const Type_handler *h; + if ((h= aggregate_common(a, b)) || + (h= aggregate_if_string(a, b))) + return h; + return NULL; + } + + const Type_handler *aggregate_for_min_max(const Type_handler *a, + const Type_handler *b) + const override + { + return aggregate_for_result(a, b); + } + + const Type_handler *aggregate_for_comparison(const Type_handler *a, + const Type_handler *b) + const override + { + if (const Type_handler *h= aggregate_common(a, b)) + return h; + static const Type_aggregator::Pair agg[]= + { + {&type_handler_inet6, &type_handler_null, &type_handler_inet6}, + {&type_handler_inet6, &type_handler_long_blob, &type_handler_inet6}, + {NULL,NULL,NULL} + }; + return Type_aggregator::find_handler_in_array(agg, a, b, true); + } + + const Type_handler *aggregate_for_num_op(const Type_handler *a, + const Type_handler *b) + const override + { + return NULL; + } + + const Type_handler *handler_by_name(const LEX_CSTRING &name) const override + { + if (type_handler_inet6.name().eq(name)) + return &type_handler_inet6; + return NULL; + } +}; + + +const Type_collection *Type_handler_inet6::type_collection() const +{ + static Type_collection_inet type_collection_inet; + return &type_collection_inet; +} diff --git a/plugin/type_inet/sql_type_inet.h b/plugin/type_inet/sql_type_inet.h new file mode 100644 index 00000000000..c1abb11fc59 --- /dev/null +++ b/plugin/type_inet/sql_type_inet.h @@ -0,0 +1,1029 @@ +#ifndef SQL_TYPE_INET_H +#define SQL_TYPE_INET_H +/* 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 */ + + +static const size_t IN_ADDR_SIZE= 4; +static const size_t IN_ADDR_MAX_CHAR_LENGTH= 15; + +static const size_t IN6_ADDR_SIZE= 16; +static const size_t IN6_ADDR_NUM_WORDS= IN6_ADDR_SIZE / 2; + +/** + Non-abbreviated syntax is 8 groups, up to 4 digits each, + plus 7 delimiters between the groups. + Abbreviated syntax is even shorter. +*/ +static const uint IN6_ADDR_MAX_CHAR_LENGTH= 8 * 4 + 7; + + +class NativeBufferInet6: public NativeBuffer<IN6_ADDR_SIZE+1> +{ +}; + +class StringBufferInet6: public StringBuffer<IN6_ADDR_MAX_CHAR_LENGTH+1> +{ +}; + +/***********************************************************************/ + +class Inet4 +{ + char m_buffer[IN_ADDR_SIZE]; +protected: + bool ascii_to_ipv4(const char *str, size_t length); + bool character_string_to_ipv4(const char *str, size_t str_length, + CHARSET_INFO *cs) + { + if (cs->state & MY_CS_NONASCII) + { + char tmp[IN_ADDR_MAX_CHAR_LENGTH]; + String_copier copier; + uint length= copier.well_formed_copy(&my_charset_latin1, tmp, sizeof(tmp), + cs, str, str_length); + return ascii_to_ipv4(tmp, length); + } + return ascii_to_ipv4(str, str_length); + } + bool binary_to_ipv4(const char *str, size_t length) + { + if (length != sizeof(m_buffer)) + return true; + memcpy(m_buffer, str, length); + return false; + } + // Non-initializing constructor + Inet4() { } +public: + void to_binary(char *dst, size_t dstsize) const + { + DBUG_ASSERT(dstsize >= sizeof(m_buffer)); + memcpy(dst, m_buffer, sizeof(m_buffer)); + } + bool to_binary(String *to) const + { + return to->copy(m_buffer, sizeof(m_buffer), &my_charset_bin); + } + size_t to_string(char *dst, size_t dstsize) const; + bool to_string(String *to) const + { + to->set_charset(&my_charset_latin1); + if (to->alloc(INET_ADDRSTRLEN)) + return true; + to->length((uint32) to_string((char*) to->ptr(), INET_ADDRSTRLEN)); + return false; + } +}; + + +class Inet4_null: public Inet4, public Null_flag +{ +public: + // Initialize from a text representation + Inet4_null(const char *str, size_t length, CHARSET_INFO *cs) + :Null_flag(character_string_to_ipv4(str, length, cs)) + { } + Inet4_null(const String &str) + :Inet4_null(str.ptr(), str.length(), str.charset()) + { } + // Initialize from a binary representation + Inet4_null(const char *str, size_t length) + :Null_flag(binary_to_ipv4(str, length)) + { } + Inet4_null(const Binary_string &str) + :Inet4_null(str.ptr(), str.length()) + { } +public: + const Inet4& to_inet4() const + { + DBUG_ASSERT(!is_null()); + return *this; + } + void to_binary(char *dst, size_t dstsize) const + { + to_inet4().to_binary(dst, dstsize); + } + bool to_binary(String *to) const + { + return to_inet4().to_binary(to); + } + size_t to_string(char *dst, size_t dstsize) const + { + return to_inet4().to_string(dst, dstsize); + } + bool to_string(String *to) const + { + return to_inet4().to_string(to); + } +}; + + +class Inet6 +{ +protected: + char m_buffer[IN6_ADDR_SIZE]; + bool make_from_item(Item *item, bool warn); + bool ascii_to_ipv6(const char *str, size_t str_length); + bool character_string_to_ipv6(const char *str, size_t str_length, + CHARSET_INFO *cs) + { + if (cs->state & MY_CS_NONASCII) + { + char tmp[IN6_ADDR_MAX_CHAR_LENGTH]; + String_copier copier; + uint length= copier.well_formed_copy(&my_charset_latin1, tmp, sizeof(tmp), + cs, str, str_length); + return ascii_to_ipv6(tmp, length); + } + return ascii_to_ipv6(str, str_length); + } + bool make_from_character_or_binary_string(const String *str, bool warn); + bool binary_to_ipv6(const char *str, size_t length) + { + if (length != sizeof(m_buffer)) + return true; + memcpy(m_buffer, str, length); + return false; + } + + Inet6() { } + +public: + static uint binary_length() { return IN6_ADDR_SIZE; } + /** + Non-abbreviated syntax is 8 groups, up to 4 digits each, + plus 7 delimiters between the groups. + Abbreviated syntax is even shorter. + */ + static uint max_char_length() { return IN6_ADDR_MAX_CHAR_LENGTH; } + + static bool only_zero_bytes(const char *ptr, uint length) + { + for (uint i= 0 ; i < length; i++) + { + if (ptr[i] != 0) + return false; + } + return true; + } + + /* + Check at Item's fix_fields() time if "item" can return a nullable value + on conversion to INET6, or conversion produces a NOT NULL INET6 value. + */ + static bool fix_fields_maybe_null_on_conversion_to_inet6(Item *item); + +public: + + Inet6(Item *item, bool *error, bool warn= true) + { + *error= make_from_item(item, warn); + } + void to_binary(char *str, size_t str_size) const + { + DBUG_ASSERT(str_size >= sizeof(m_buffer)); + memcpy(str, m_buffer, sizeof(m_buffer)); + } + bool to_binary(String *to) const + { + return to->copy(m_buffer, sizeof(m_buffer), &my_charset_bin); + } + bool to_native(Native *to) const + { + return to->copy(m_buffer, sizeof(m_buffer)); + } + size_t to_string(char *dst, size_t dstsize) const; + bool to_string(String *to) const + { + to->set_charset(&my_charset_latin1); + if (to->alloc(INET6_ADDRSTRLEN)) + return true; + to->length((uint32) to_string((char*) to->ptr(), INET6_ADDRSTRLEN)); + return false; + } + bool is_v4compat() const + { + static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size"); + return IN6_IS_ADDR_V4COMPAT((struct in6_addr *) m_buffer); + } + bool is_v4mapped() const + { + static_assert(sizeof(in6_addr) == IN6_ADDR_SIZE, "unexpected in6_addr size"); + return IN6_IS_ADDR_V4MAPPED((struct in6_addr *) m_buffer); + } + int cmp(const char *str, size_t length) const + { + DBUG_ASSERT(length == sizeof(m_buffer)); + return memcmp(m_buffer, str, length); + } + int cmp(const Binary_string &other) const + { + return cmp(other.ptr(), other.length()); + } + int cmp(const Inet6 &other) const + { + return memcmp(m_buffer, other.m_buffer, sizeof(m_buffer)); + } +}; + + +class Inet6_zero: public Inet6 +{ +public: + Inet6_zero() + { + bzero(&m_buffer, sizeof(m_buffer)); + } +}; + + +class Inet6_null: public Inet6, public Null_flag +{ +public: + // Initialize from a text representation + Inet6_null(const char *str, size_t length, CHARSET_INFO *cs) + :Null_flag(character_string_to_ipv6(str, length, cs)) + { } + Inet6_null(const String &str) + :Inet6_null(str.ptr(), str.length(), str.charset()) + { } + // Initialize from a binary representation + Inet6_null(const char *str, size_t length) + :Null_flag(binary_to_ipv6(str, length)) + { } + Inet6_null(const Binary_string &str) + :Inet6_null(str.ptr(), str.length()) + { } + // Initialize from an Item + Inet6_null(Item *item, bool warn= true) + :Null_flag(make_from_item(item, warn)) + { } +public: + const Inet6& to_inet6() const + { + DBUG_ASSERT(!is_null()); + return *this; + } + void to_binary(char *str, size_t str_size) const + { + to_inet6().to_binary(str, str_size); + } + bool to_binary(String *to) const + { + return to_inet6().to_binary(to); + } + size_t to_string(char *dst, size_t dstsize) const + { + return to_inet6().to_string(dst, dstsize); + } + bool to_string(String *to) const + { + return to_inet6().to_string(to); + } + bool is_v4compat() const + { + return to_inet6().is_v4compat(); + } + bool is_v4mapped() const + { + return to_inet6().is_v4mapped(); + } +}; + + +class Type_std_attributes_inet6: public Type_std_attributes +{ +public: + Type_std_attributes_inet6() + :Type_std_attributes( + Type_numeric_attributes(Inet6::max_char_length(), 0, true), + DTCollation_numeric()) + { } +}; + + +class Type_handler_inet6: public Type_handler +{ + bool character_or_binary_string_to_native(THD *thd, const String *str, + Native *to) const; +public: + ~Type_handler_inet6() override {} + + const Type_collection *type_collection() const override; + const Name &default_value() const override + { + static Name def(STRING_WITH_LEN("::")); + return def; + } + protocol_send_type_t protocol_send_type() const override + { + return PROTOCOL_SEND_STRING; + } + bool Item_append_extended_type_info(Send_field_extended_metadata *to, + const Item *item) const override + { + return to->set_data_type_name(name().lex_cstring()); + } + + enum_field_types field_type() const override + { + return MYSQL_TYPE_STRING; + } + + Item_result result_type() const override + { + return STRING_RESULT; + } + + Item_result cmp_type() const override + { + return STRING_RESULT; + } + + enum_dynamic_column_type dyncol_type(const Type_all_attributes *attr) + const override + { + return DYN_COL_STRING; + } + + uint32 max_display_length_for_field(const Conv_source &src) const override + { + return Inet6::max_char_length(); + } + + const Type_handler *type_handler_for_comparison() const override + { + return this; + } + + int + stored_field_cmp_to_item(THD *thd, Field *field, Item *item) const override + { + DBUG_ASSERT(field->type_handler() == this); + Inet6_null ni(item); // Convert Item to INET6 + if (ni.is_null()) + return 0; + NativeBufferInet6 tmp; + if (field->val_native(&tmp)) + { + DBUG_ASSERT(0); + return 0; + } + return -ni.cmp(tmp); + } + CHARSET_INFO *charset_for_protocol(const Item *item) const override + { + return item->collation.collation; + } + + bool is_scalar_type() const override { return true; } + bool is_val_native_ready() const override { return true; } + bool can_return_int() const override { return false; } + bool can_return_decimal() const override { return false; } + bool can_return_real() const override { return false; } + bool can_return_str() const override { return true; } + bool can_return_text() const override { return true; } + bool can_return_date() const override { return false; } + bool can_return_time() const override { return false; } + bool convert_to_binary_using_val_native() const override { return true; } + + uint Item_time_precision(THD *thd, Item *item) const override + { + return 0; + } + uint Item_datetime_precision(THD *thd, Item *item) const override + { + return 0; + } + uint Item_decimal_scale(const Item *item) const override + { + return 0; + } + uint Item_decimal_precision(const Item *item) const override + { + /* + This will be needed if we ever allow cast from INET6 to DECIMAL. + Decimal precision of INET6 is 39 digits: + 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff' = + 340282366920938463463374607431768211456 = 39 digits + */ + return 39; + } + + /* + Returns how many digits a divisor adds into a division result. + See Item::divisor_precision_increment() in item.h for more comments. + */ + uint Item_divisor_precision_increment(const Item *) const override + { + return 0; + } + /** + Makes a temporary table Field to handle numeric aggregate functions, + e.g. SUM(DISTINCT expr), AVG(DISTINCT expr), etc. + */ + Field *make_num_distinct_aggregator_field(MEM_ROOT *, + const Item *) const override + { + DBUG_ASSERT(0); + return 0; + } + Field *make_conversion_table_field(MEM_ROOT *root, + TABLE *TABLE, + uint metadata, + const Field *target) const override; + // Fix attributes after the parser + bool Column_definition_fix_attributes(Column_definition *c) const override + { + c->length= Inet6::max_char_length(); + return false; + } + + bool Column_definition_prepare_stage1(THD *thd, + MEM_ROOT *mem_root, + Column_definition *def, + handler *file, + ulonglong table_flags, + const Column_derived_attributes + *derived_attr) + const override + { + def->prepare_stage1_simple(&my_charset_numeric); + return false; + } + + bool Column_definition_redefine_stage1(Column_definition *def, + const Column_definition *dup, + const handler *file) + const override + { + def->redefine_stage1_common(dup, file); + def->set_compression_method(dup->compression_method()); + def->create_length_to_internal_length_string(); + return false; + } + + bool Column_definition_prepare_stage2(Column_definition *def, + handler *file, + ulonglong table_flags) const override + { + def->pack_flag= FIELDFLAG_BINARY; + return false; + } + + bool partition_field_check(const LEX_CSTRING &field_name, + Item *item_expr) const override; + + bool partition_field_append_value(String *to, + Item *item_expr, + CHARSET_INFO *field_cs, + partition_value_print_mode_t mode) + const override; + + Field *make_table_field(MEM_ROOT *root, + const LEX_CSTRING *name, + const Record_addr &addr, + const Type_all_attributes &attr, + TABLE_SHARE *table) const override; + + Field * + make_table_field_from_def(TABLE_SHARE *share, + MEM_ROOT *mem_root, + const LEX_CSTRING *name, + const Record_addr &addr, + const Bit_addr &bit, + const Column_definition_attributes *attr, + uint32 flags) const override; + void + Column_definition_attributes_frm_pack(const Column_definition_attributes *def, + uchar *buff) const override + { + def->frm_pack_basic(buff); + def->frm_pack_charset(buff); + } + bool + Column_definition_attributes_frm_unpack(Column_definition_attributes *def, + TABLE_SHARE *share, + const uchar *buffer, + LEX_CUSTRING *gis_options) + const override + { + def->frm_unpack_basic(buffer); + return def->frm_unpack_charset(share, buffer); + } + void make_sort_key_part(uchar *to, Item *item, + const SORT_FIELD_ATTR *sort_field, + Sort_param *param) + const override; + uint make_packed_sort_key_part(uchar *to, Item *item, + const SORT_FIELD_ATTR *sort_field, + Sort_param *param) const override; + void sort_length(THD *thd, + const Type_std_attributes *item, + SORT_FIELD_ATTR *attr) const override; + uint32 max_display_length(const Item *item) const override + { + return Inet6::max_char_length(); + } + uint32 calc_pack_length(uint32 length) const override + { + return Inet6::binary_length(); + } + void Item_update_null_value(Item *item) const override + { + NativeBufferInet6 tmp; + item->val_native(current_thd, &tmp); + } + bool Item_save_in_value(THD *thd, Item *item, st_value *value) const override; + void Item_param_setup_conversion(THD *thd, Item_param *param) const override; + void Item_param_set_param_func(Item_param *param, + uchar **pos, ulong len) const override + { + param->set_param_str(pos, len); + } + bool Item_param_set_from_value(THD *thd, + Item_param *param, + const Type_all_attributes *attr, + const st_value *val) const override + { + param->unsigned_flag= false;//QQ + param->setup_conversion_string(thd, attr->collation.collation); + /* + Exact value of max_length is not known unless data is converted to + charset of connection, so we have to set it later. + */ + return param->set_str(val->m_string.ptr(), val->m_string.length(), + attr->collation.collation, + attr->collation.collation); + } + bool Item_param_val_native(THD *thd, Item_param *item, Native *to) + const override + { + StringBufferInet6 buffer; + String *str= item->val_str(&buffer); + if (!str) + return true; + Inet6_null tmp(*str); + return tmp.is_null() || tmp.to_native(to); + } + bool Item_send(Item *item, Protocol *p, st_value *buf) const override + { + return Item_send_str(item, p, buf); + } + int Item_save_in_field(Item *item, Field *field, bool no_conversions) + const override + { + if (field->type_handler() == this) + { + NativeBuffer<MAX_FIELD_WIDTH> tmp; + bool rc= item->val_native(current_thd, &tmp); + if (rc || item->null_value) + return set_field_to_null_with_conversions(field, no_conversions); + field->set_notnull(); + return field->store_native(tmp); + } + return item->save_str_in_field(field, no_conversions); + } + + String *print_item_value(THD *thd, Item *item, String *str) const override + { + StringBufferInet6 buf; + String *result= item->val_str(&buf); + /* + TODO: This should eventually use one of these notations: + 1. CAST('::' AS INET6) + Problem: CAST is not supported as a NAME_CONST() argument. + 2. INET6':: + Problem: This syntax is not supported by the parser yet. + */ + return !result || + str->realloc(result->length() + 2) || + str->append(STRING_WITH_LEN("'")) || + str->append(result->ptr(), result->length()) || + str->append(STRING_WITH_LEN("'")) ? + NULL : + str; + } + + /** + Check if + WHERE expr=value AND expr=const + can be rewritten as: + WHERE const=value AND expr=const + + "this" is the comparison handler that is used by "target". + + @param target - the predicate expr=value, + whose "expr" argument will be replaced to "const". + @param target_expr - the target's "expr" which will be replaced to "const". + @param target_value - the target's second argument, it will remain unchanged. + @param source - the equality predicate expr=const (or expr<=>const) + that can be used to rewrite the "target" part + (under certain conditions, see the code). + @param source_expr - the source's "expr". It should be exactly equal to + the target's "expr" to make condition rewrite possible. + @param source_const - the source's "const" argument, it will be inserted + into "target" instead of "expr". + */ + bool + can_change_cond_ref_to_const(Item_bool_func2 *target, + Item *target_expr, Item *target_value, + Item_bool_func2 *source, + Item *source_expr, Item *source_const) + const override + { + /* + WHERE COALESCE(inet6_col)='::1' AND COALESCE(inet6_col)=CONCAT(a); --> + WHERE COALESCE(inet6_col)='::1' AND '::1'=CONCAT(a); + */ + return target->compare_type_handler() == source->compare_type_handler(); + } + bool + subquery_type_allows_materialization(const Item *inner, + const Item *outer, bool) const override + { + /* + Example: + SELECT * FROM t1 WHERE a IN (SELECT inet6col FROM t1 GROUP BY inet6col); + Allow materialization only if the outer column is also INET6. + This can be changed for more relaxed rules in the future. + */ + DBUG_ASSERT(inner->type_handler() == this); + return outer->type_handler() == this; + } + /** + Make a simple constant replacement item for a constant "src", + so the new item can futher be used for comparison with "cmp", e.g.: + src = cmp -> replacement = cmp + + "this" is the type handler that is used to compare "src" and "cmp". + + @param thd - current thread, for mem_root + @param src - The item that we want to replace. It's a const item, + but it can be complex enough to calculate on every row. + @param cmp - The src's comparand. + @retval - a pointer to the created replacement Item + @retval - NULL, if could not create a replacement (e.g. on EOM). + NULL is also returned for ROWs, because instead of replacing + a Item_row to a new Item_row, Type_handler_row just replaces + its elements. + */ + Item *make_const_item_for_comparison(THD *thd, + Item *src, + const Item *cmp) const override; + Item_cache *Item_get_cache(THD *thd, const Item *item) const override; + + Item *create_typecast_item(THD *thd, Item *item, + const Type_cast_attributes &attr) const override; + + Item_copy *create_item_copy(THD *thd, Item *item) const override; + int cmp_native(const Native &a, const Native &b) const override + { + DBUG_ASSERT(a.length() == Inet6::binary_length()); + DBUG_ASSERT(b.length() == Inet6::binary_length()); + return memcmp(a.ptr(), b.ptr(), Inet6::binary_length()); + } + bool set_comparator_func(Arg_comparator *cmp) const override + { + return cmp->set_cmp_func_native(); + } + bool Item_const_eq(const Item_const *a, const Item_const *b, + bool binary_cmp) const override + { + return false;//QQ + } + bool Item_eq_value(THD *thd, const Type_cmp_attributes *attr, + Item *a, Item *b) const override + { + Inet6_null na(a); + Inet6_null nb(b); + return !na.is_null() && !nb.is_null() && !na.cmp(nb); + } + bool Item_hybrid_func_fix_attributes(THD *thd, + const char *name, + Type_handler_hybrid_field_type *h, + Type_all_attributes *attr, + Item **items, + uint nitems) const override + { + attr->Type_std_attributes::operator=(Type_std_attributes_inet6()); + h->set_handler(this); + /* + If some of the arguments cannot be safely converted to "INET6 NOT NULL", + then mark the entire function nullability as NULL-able. + Otherwise, keep the generic nullability calculated by earlier stages: + - either by the most generic way in Item_func::fix_fields() + - or by Item_func_xxx::fix_length_and_dec() before the call of + Item_hybrid_func_fix_attributes() + IFNULL() is special. It does not need to test args[0]. + */ + uint first= dynamic_cast<Item_func_ifnull*>(attr) ? 1 : 0; + for (uint i= first; i < nitems; i++) + { + if (Inet6::fix_fields_maybe_null_on_conversion_to_inet6(items[i])) + { + attr->set_maybe_null(true); + break; + } + } + return false; + } + bool Item_func_min_max_fix_attributes(THD *thd, + Item_func_min_max *func, + Item **items, + uint nitems) const override + { + return Item_hybrid_func_fix_attributes(thd, func->func_name(), + func, func, items, nitems); + + } + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const override + { + func->Type_std_attributes::operator=(Type_std_attributes_inet6()); + func->set_handler(this); + return false; + } + bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + + bool Item_val_native_with_conversion(THD *thd, Item *item, + Native *to) const override + { + if (item->type_handler() == this) + return item->val_native(thd, to); // No conversion needed + StringBufferInet6 buffer; + String *str= item->val_str(&buffer); + return str ? character_or_binary_string_to_native(thd, str, to) : true; + } + bool Item_val_native_with_conversion_result(THD *thd, Item *item, + Native *to) const override + { + if (item->type_handler() == this) + return item->val_native_result(thd, to); // No conversion needed + StringBufferInet6 buffer; + String *str= item->str_result(&buffer); + return str ? character_or_binary_string_to_native(thd, str, to) : true; + } + + bool Item_val_bool(Item *item) const override + { + NativeBufferInet6 tmp; + if (item->val_native(current_thd, &tmp)) + return false; + return !Inet6::only_zero_bytes(tmp.ptr(), tmp.length()); + } + void Item_get_date(THD *thd, Item *item, + Temporal::Warn *buff, MYSQL_TIME *ltime, + date_mode_t fuzzydate) const override + { + set_zero_time(ltime, MYSQL_TIMESTAMP_TIME); + } + + longlong Item_val_int_signed_typecast(Item *item) const override + { + DBUG_ASSERT(0); + return 0; + } + + longlong Item_val_int_unsigned_typecast(Item *item) const override + { + DBUG_ASSERT(0); + return 0; + } + + String *Item_func_hex_val_str_ascii(Item_func_hex *item, String *str) + const override + { + NativeBufferInet6 tmp; + if ((item->null_value= item->arguments()[0]->val_native(current_thd, &tmp))) + return NULL; + DBUG_ASSERT(tmp.length() == Inet6::binary_length()); + if (str->set_hex(tmp.ptr(), tmp.length())) + { + str->length(0); + str->set_charset(item->collation.collation); + } + return str; + } + + String *Item_func_hybrid_field_type_val_str(Item_func_hybrid_field_type *item, + String *str) const override + { + NativeBufferInet6 native; + if (item->val_native(current_thd, &native)) + { + DBUG_ASSERT(item->null_value); + return NULL; + } + DBUG_ASSERT(native.length() == Inet6::binary_length()); + Inet6_null tmp(native.ptr(), native.length()); + return tmp.is_null() || tmp.to_string(str) ? NULL : str; + } + double Item_func_hybrid_field_type_val_real(Item_func_hybrid_field_type *) + const override + { + return 0; + } + longlong Item_func_hybrid_field_type_val_int(Item_func_hybrid_field_type *) + const override + { + return 0; + } + my_decimal * + Item_func_hybrid_field_type_val_decimal(Item_func_hybrid_field_type *, + my_decimal *to) const override + { + my_decimal_set_zero(to); + return to; + } + void Item_func_hybrid_field_type_get_date(THD *, + Item_func_hybrid_field_type *, + Temporal::Warn *, + MYSQL_TIME *to, + date_mode_t fuzzydate) + const override + { + set_zero_time(to, MYSQL_TIMESTAMP_TIME); + } + // WHERE is Item_func_min_max_val_native??? + String *Item_func_min_max_val_str(Item_func_min_max *func, String *str) + const override + { + Inet6_null tmp(func); + return tmp.is_null() || tmp.to_string(str) ? NULL : str; + } + double Item_func_min_max_val_real(Item_func_min_max *) const override + { + return 0; + } + longlong Item_func_min_max_val_int(Item_func_min_max *) const override + { + return 0; + } + my_decimal *Item_func_min_max_val_decimal(Item_func_min_max *, + my_decimal *to) const override + { + my_decimal_set_zero(to); + return to; + } + bool Item_func_min_max_get_date(THD *thd, Item_func_min_max*, + MYSQL_TIME *to, date_mode_t fuzzydate) + const override + { + set_zero_time(to, MYSQL_TIMESTAMP_TIME); + return false; + } + + bool + Item_func_between_fix_length_and_dec(Item_func_between *func) const override + { + return false; + } + longlong Item_func_between_val_int(Item_func_between *func) const override + { + return func->val_int_cmp_native(); + } + + cmp_item *make_cmp_item(THD *thd, CHARSET_INFO *cs) const override; + + in_vector *make_in_vector(THD *thd, const Item_func_in *func, + uint nargs) const override; + + bool Item_func_in_fix_comparator_compatible_types(THD *thd, + Item_func_in *func) + const override + { + if (func->compatible_types_scalar_bisection_possible()) + { + return func->value_list_convert_const_to_int(thd) || + func->fix_for_scalar_comparison_using_bisection(thd); + } + return + func->fix_for_scalar_comparison_using_cmp_items(thd, + 1U << (uint) STRING_RESULT); + } + bool + Item_func_round_fix_length_and_dec(Item_func_round *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + bool + Item_func_int_val_fix_length_and_dec(Item_func_int_val *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + + bool Item_func_abs_fix_length_and_dec(Item_func_abs *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + + bool Item_func_neg_fix_length_and_dec(Item_func_neg *func) const override + { + return Item_func_or_sum_illegal_param(func); + } + + bool + Item_func_signed_fix_length_and_dec(Item_func_signed *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_unsigned_fix_length_and_dec(Item_func_unsigned *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_double_typecast_fix_length_and_dec(Item_double_typecast *item) + const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_float_typecast_fix_length_and_dec(Item_float_typecast *item) + const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_decimal_typecast_fix_length_and_dec(Item_decimal_typecast *item) + const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_char_typecast_fix_length_and_dec(Item_char_typecast *item) + const override; + bool + Item_time_typecast_fix_length_and_dec(Item_time_typecast *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_date_typecast_fix_length_and_dec(Item_date_typecast *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_datetime_typecast_fix_length_and_dec(Item_datetime_typecast *item) + const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_plus_fix_length_and_dec(Item_func_plus *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_minus_fix_length_and_dec(Item_func_minus *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_mul_fix_length_and_dec(Item_func_mul *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_div_fix_length_and_dec(Item_func_div *item) const override + { + return Item_func_or_sum_illegal_param(item); + } + bool + Item_func_mod_fix_length_and_dec(Item_func_mod *item) const override + { + return Item_func_or_sum_illegal_param(item); + } +}; + + +extern MYSQL_PLUGIN_IMPORT Type_handler_inet6 type_handler_inet6; + + +#endif /* SQL_TYPE_INET_H */ diff --git a/plugin/type_mysql_json/CMakeLists.txt b/plugin/type_mysql_json/CMakeLists.txt new file mode 100644 index 00000000000..ac0a1783012 --- /dev/null +++ b/plugin/type_mysql_json/CMakeLists.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2020, MariaDB Foundation. +# +# 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_mysql_json + mysql_json.cc type.cc + MODULE_ONLY RECOMPILE_FOR_EMBEDDED) diff --git a/plugin/type_mysql_json/mysql_json.cc b/plugin/type_mysql_json/mysql_json.cc new file mode 100644 index 00000000000..4a75cae3909 --- /dev/null +++ b/plugin/type_mysql_json/mysql_json.cc @@ -0,0 +1,515 @@ +/* + Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2020 MariaDB Foundation + + + 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 */ + +#include "mysql_json.h" +#include "my_global.h" +#include "compat56.h" +#include "my_decimal.h" +#include "sql_time.h" + +static void TIME_from_longlong_date_packed(MYSQL_TIME *ltime, longlong tmp) +{ + TIME_from_longlong_datetime_packed(ltime, tmp); + ltime->time_type= MYSQL_TIMESTAMP_DATE; +} + + +/* + Json values in MySQL comprises the standard set of JSON values plus a MySQL + specific set. A JSON number type is subdivided into int, uint, double and + decimal. + + MySQL also adds four built-in date/time values: date, time, datetime and + timestamp. An additional opaque value can store any other MySQL type. +*/ + +enum JSONB_LITERAL_TYPES { + JSONB_NULL_LITERAL= 0x0, + JSONB_TRUE_LITERAL= 0x1, + JSONB_FALSE_LITERAL= 0x2, +}; + +/* + The size of offset or size fields in the small and the large storage + format for JSON objects and JSON arrays. +*/ +static const uchar SMALL_OFFSET_SIZE= 2; +static const uchar LARGE_OFFSET_SIZE= 4; + +/* + The size of key entries for objects when using the small storage + format or the large storage format. In the small format it is 4 + bytes (2 bytes for key length and 2 bytes for key offset). In the + large format it is 6 (2 bytes for length, 4 bytes for offset). +*/ +static const uchar KEY_ENTRY_SIZE_SMALL= (2 + SMALL_OFFSET_SIZE); +static const uchar KEY_ENTRY_SIZE_LARGE= (2 + LARGE_OFFSET_SIZE); + +/* + The size of value entries for objects or arrays. When using the + small storage format, the entry size is 3 (1 byte for type, 2 bytes + for offset). When using the large storage format, it is 5 (1 byte + for type, 4 bytes for offset). +*/ +static const uchar VALUE_ENTRY_SIZE_SMALL= (1 + SMALL_OFFSET_SIZE); +static const uchar VALUE_ENTRY_SIZE_LARGE= (1 + LARGE_OFFSET_SIZE); + +/* The maximum number of nesting levels allowed in a JSON document. */ +static const uchar JSON_DOCUMENT_MAX_DEPTH= 150; + +/** + Read an offset or size field from a buffer. The offset could be either + a two byte unsigned integer or a four byte unsigned integer. + + @param data the buffer to read from + @param large tells if the large or small storage format is used; true + means read four bytes, false means read two bytes +*/ +static inline size_t read_offset_or_size(const uchar *data, bool large) +{ + return large ? uint4korr(data) : uint2korr(data); +} + +static inline size_t key_size(bool large) +{ + return large ? KEY_ENTRY_SIZE_LARGE : KEY_ENTRY_SIZE_SMALL; +} + +static inline size_t value_size(bool large) +{ + return large ? VALUE_ENTRY_SIZE_LARGE : VALUE_ENTRY_SIZE_SMALL; +} + +/** + Inlined values are a space optimization. The actual value is stored + instead of the offset pointer to the location where a non-inlined + value would be located. + + @param[in] type The type to check. + @param[in] large tells if the large or small storage format is used; +*/ +static inline bool type_is_stored_inline(JSONB_TYPES type, bool large) +{ + return (type == JSONB_TYPE_INT16 || + type == JSONB_TYPE_UINT16 || + type == JSONB_TYPE_LITERAL || + (large && (type == JSONB_TYPE_INT32 || + type == JSONB_TYPE_UINT32))); +} + +/** + Read a variable length integer. A variable length integer uses the 8th bit in + each byte to mark if there are more bytes needed to store the integer. The + other 7 bits in the byte are used to store the actual integer's bits. + + @param[in] data the buffer to read from + @param[in] data_length the maximum number of bytes to read from data + @param[out] length the length that was read + @param[out] num the number of bytes needed to represent the length + @return false on success, true on error +*/ +static inline bool read_variable_length(const uchar *data, size_t data_length, + size_t *length, size_t *num) +{ + /* + It takes five bytes to represent UINT_MAX32, which is the largest + supported length, so don't look any further. + + Use data_length as max value to prevent segfault when reading a corrupted + JSON document. + */ + const size_t MAX_BYTES= MY_MIN(data_length, 5); + size_t len= 0; + for (size_t i= 0; i < MAX_BYTES; i++) + { + /* Get the next 7 bits of the length. */ + len|= (data[i] & 0x7f) << (7 * i); + if ((data[i] & 0x80) == 0) + { + /* The length shouldn't exceed 32 bits. */ + if (len > UINT_MAX32) + return true; + + /* This was the last byte. Return successfully. */ + *num= i + 1; + *length= len; + return false; + } + } + + /* No more available bytes. Return true to signal error. This implies a + corrupted JSON document. */ + return true; +} + +/** + JSON formatting in MySQL escapes a few special characters to prevent + ambiguity. +*/ +static bool append_string_json(String *buffer, const uchar *data, size_t len) +{ + const uchar *last= data + len; + for (; data < last; data++) + { + const uchar c= *data; + switch (c) { + case '\\': + buffer->append("\\\\"); + break; + case '\n': + buffer->append("\\n"); + break; + case '\r': + buffer->append("\\r"); + break; + case '"': + buffer->append("\\\""); + break; + case '\b': + buffer->append("\\b"); + break; + case '\f': + buffer->append("\\f"); + break; + case '\t': + buffer->append("\\t"); + break; + default: + buffer->append(c); + break; + } + } + return false; +} + +/* + Function used for JSON_OPAQUE type. +*/ +static bool print_mysql_datetime_value(String *buffer, enum_field_types type, + const uchar *data, size_t len) +{ + if (len < 8) + return true; + + MYSQL_TIME t; + switch (type) + { + case MYSQL_TYPE_TIME: + TIME_from_longlong_time_packed(&t, sint8korr(data)); + break; + case MYSQL_TYPE_DATE: + TIME_from_longlong_date_packed(&t, sint8korr(data)); + break; + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + TIME_from_longlong_datetime_packed(&t, sint8korr(data)); + break; + default: + DBUG_ASSERT(0); + return true; + } + /* Wrap all datetime strings within double quotes. */ + buffer->append('\"'); + buffer->reserve(MAX_DATE_STRING_REP_LENGTH); + buffer->length(buffer->length() + + my_TIME_to_str(&t, const_cast<char *>(buffer->end()), 6)); + buffer->append('\"'); + return false; +} + +static bool parse_mysql_scalar(String *buffer, size_t value_json_type, + const uchar *data, size_t len) +{ + switch (value_json_type) { + case JSONB_TYPE_LITERAL: + { + if (len < 1) + return true; + switch (static_cast<JSONB_LITERAL_TYPES>(*data)) { + case JSONB_NULL_LITERAL: + return buffer->append("null"); + case JSONB_TRUE_LITERAL: + return buffer->append("true"); + case JSONB_FALSE_LITERAL: + return buffer->append("false"); + default: /* Invalid literal constant, malformed JSON. */ + return true; + } + } + case JSONB_TYPE_INT16: + return len < 2 || buffer->append_longlong(sint2korr(data)); + case JSONB_TYPE_INT32: + return len < 4 || buffer->append_longlong(sint4korr(data)); + case JSONB_TYPE_INT64: + return len < 8 || buffer->append_longlong(sint8korr(data)); + case JSONB_TYPE_UINT16: + return len < 2 || buffer->append_ulonglong(uint2korr(data)); + case JSONB_TYPE_UINT32: + return len < 4 || buffer->append_ulonglong(uint4korr(data)); + case JSONB_TYPE_UINT64: + return len < 8 || buffer->append_ulonglong(uint8korr(data)); + case JSONB_TYPE_DOUBLE: + if (len < 8) + return true; + buffer->reserve(FLOATING_POINT_BUFFER, 2 * FLOATING_POINT_BUFFER); + buffer->qs_append(reinterpret_cast<const double *>(data)); + return false; + case JSONB_TYPE_STRING: + { + size_t string_length, store_bytes; + + return read_variable_length(data, len, &string_length, &store_bytes) || + len < store_bytes + string_length || + buffer->append('"') || + append_string_json(buffer, data + store_bytes, string_length) || + buffer->append('"'); + } + case JSONB_TYPE_OPAQUE: + { + /* The field_type maps directly to enum_field_types. */ + const uchar type_value= *data; + const enum_field_types field_type= static_cast<enum_field_types>(type_value); + + size_t UNINIT_VAR(blob_length), length_bytes; + const uchar *blob_start; + + if (read_variable_length(data + 1, len, &blob_length, &length_bytes) || + len < length_bytes + blob_length) + return true; + blob_start= data + length_bytes + 1; + + switch (field_type) { + case MYSQL_TYPE_TIME: + case MYSQL_TYPE_DATE: + case MYSQL_TYPE_DATETIME: + case MYSQL_TYPE_TIMESTAMP: + return print_mysql_datetime_value(buffer, field_type, + blob_start, blob_length); + case MYSQL_TYPE_NEWDECIMAL: + { + /* Expect at least two bytes, which contain precision and scale. */ + if (blob_length < 2) + return true; + + const int precision= blob_start[0]; + const int scale= blob_start[1]; + + my_decimal d; + + /* The decimal value is encoded after the two prec/scale bytes. */ + const size_t dec_size= my_decimal_get_binary_size(precision, scale); + if (dec_size != blob_length - 2 || + binary2my_decimal(E_DEC_ERROR, + reinterpret_cast<const uchar *>(blob_start + 2), + &d, precision, scale) != E_DEC_OK) + return true; + + if (d.to_string_native(buffer, 0, 0, ' ', E_DEC_ERROR) != E_DEC_OK) + return true; + return false; + } + default: + { + /* Any other MySQL type is presented as a base64 encoded string. */ + if (buffer->append("\"base64:type") || + buffer->append_longlong(field_type) || + buffer->append(':')) + return true; + + const size_t needed= my_base64_needed_encoded_length( + static_cast<int>(blob_length)); + if (buffer->reserve(needed) || + my_base64_encode(blob_start, blob_length, + const_cast<char*>(buffer->end()))) + return true; + /* -1 to override the null terminator from my_base64_encode */ + DBUG_ASSERT(*(buffer->end() + needed) == '\0'); + buffer->length(buffer->length() + needed - 1); + return buffer->append('"'); + } + } + } + default: + return true; + } +} + + +/** + Read a value from a JSON Object or Array, given the position of it. + This function handles both inlined values as well as values stored at + an offset. + + @param[out] buffer Where to print the results. + @param[in] data The raw binary data of the Object or Array. + @param[in] len The length of the binary data. + @param[in] value_type_offset Where the type of the value is stored. + @param[in] large true if the large storage format is used; + @param[in] depth How deep the JSON object is in the hierarchy. +*/ +static bool parse_mysql_scalar_or_value(String *buffer, const uchar *data, + size_t len, size_t value_type_offset, + bool large, size_t depth) +{ + /* Get the type of the value stored at the key. */ + const JSONB_TYPES value_type= + static_cast<JSONB_TYPES>(data[value_type_offset]); + + if (type_is_stored_inline(value_type, large)) + { + const size_t value_start = value_type_offset + 1; + if (parse_mysql_scalar(buffer, value_type, data + value_start, + len - value_start)) + return true; + } + else + { + /* The offset to where the value is stored is relative to the start + of the Object / Array */ + const size_t value_start= read_offset_or_size( + data + value_type_offset + 1, large); + if (parse_mysql_json_value(buffer, value_type, data + value_start, + len - value_start, depth)) + return true; + } + return false; +} + +static bool parse_array_or_object(String *buffer, const uchar *data, size_t len, + bool handle_as_object, bool large, + size_t depth) +{ + if (++depth > JSON_DOCUMENT_MAX_DEPTH) + return true; + + /* + Make sure the document is long enough to contain the two length fields + (both number of elements or members, and number of bytes). + */ + const size_t offset_size= large ? LARGE_OFFSET_SIZE : SMALL_OFFSET_SIZE; + /* The length has to be at least double offset size (header). */ + if (len < 2 * offset_size) + return true; + + + /* + Every JSON Object or Array contains two numbers in the header: + - The number of elements in the Object / Array (Keys) + - The total number of bytes occupied by the JSON Object / Array, including + the two numbers in the header. + Depending on the Object / Array type (small / large) the numbers are stored + in 2 bytes or 4 bytes each. + */ + const size_t element_count= read_offset_or_size(data, large); + const size_t bytes= read_offset_or_size(data + offset_size, large); + + /* The value can't have more bytes than what's available in the buffer. */ + if (bytes > len) + return true; + + if (buffer->append(handle_as_object ? '{' : '[')) + return true; + + + for (size_t i= 0; i < element_count; i++) + { + if (handle_as_object) + { + /* + The JSON Object is stored as a header part and a data part. + Header consists of: + - two length fields, + - an array of pointers to keys. + - an array of tuples (type, pointer to values) + * For certain types, the pointer to values is replaced by the actual + value. (see type_is_stored_inline) + Data consists of: + - All Key data, in order + - All Value data, in order + */ + const size_t key_offset= 2 * offset_size + i * key_size(large); + const size_t key_start= read_offset_or_size(data + key_offset, large); + /* The length of keys is always stored in 2 bytes (large == false) */ + const size_t key_len= read_offset_or_size( + data + key_offset + offset_size, false); + + const size_t value_type_offset=(2 * offset_size + + element_count * key_size(large) + + i * value_size(large)); + + /* First print the key. */ + if (buffer->append('"') || + append_string_json(buffer, data + key_start, key_len) || + buffer->append("\": ")) + { + return true; + } + + /* Then print the value. */ + if (parse_mysql_scalar_or_value(buffer, data, bytes, value_type_offset, + large, depth)) + return true; + } + else + { + /* + Arrays do not have the keys vector and its associated data. + We jump straight to reading values. + */ + const size_t value_type_offset= 2 * offset_size + value_size(large) * i; + + if (parse_mysql_scalar_or_value(buffer, data, bytes, value_type_offset, + large, depth)) + return true; + } + + if (i != element_count - 1 && buffer->append(", ")) + return true; + } + + return buffer->append(handle_as_object ? '}' : ']'); +} + +/** + Check the first byte of data which is the enum structure and based on it + perform parsing of object or array where each can have small or large + representation. + + @param[out] buffer Where to print the results. + @param[in] type Type of value {object, array, scalar}. + @param[in] data Raw data for parsing. + @param[in] length Length of data. + @param[in] depth Depth size. +*/ +bool parse_mysql_json_value(String *buffer, JSONB_TYPES type, const uchar *data, + size_t len, size_t depth) +{ + const bool IS_OBJECT=true, IS_LARGE=true; + switch (type) { + case JSONB_TYPE_SMALL_OBJECT: + return parse_array_or_object(buffer, data, len, IS_OBJECT, !IS_LARGE, depth); + case JSONB_TYPE_LARGE_OBJECT: + return parse_array_or_object(buffer, data, len, IS_OBJECT, IS_LARGE, depth); + case JSONB_TYPE_SMALL_ARRAY: + return parse_array_or_object(buffer, data, len, !IS_OBJECT, !IS_LARGE, depth); + case JSONB_TYPE_LARGE_ARRAY: + return parse_array_or_object(buffer, data, len, !IS_OBJECT, IS_LARGE, depth); + default: + return parse_mysql_scalar(buffer, type, data, len); + } +} diff --git a/plugin/type_mysql_json/mysql_json.h b/plugin/type_mysql_json/mysql_json.h new file mode 100644 index 00000000000..afbacafc9c8 --- /dev/null +++ b/plugin/type_mysql_json/mysql_json.h @@ -0,0 +1,45 @@ +/* + Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2020 MariaDB Foundation + + + 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 */ + +#ifndef MYSQL_JSON_INCLUDED +#define MYSQL_JSON_INCLUDED + +#include "my_global.h" +#include "sql_string.h" // String + +enum JSONB_TYPES { + JSONB_TYPE_SMALL_OBJECT= 0x0, + JSONB_TYPE_LARGE_OBJECT= 0x1, + JSONB_TYPE_SMALL_ARRAY= 0x2, + JSONB_TYPE_LARGE_ARRAY= 0x3, + JSONB_TYPE_LITERAL= 0x4, + JSONB_TYPE_INT16= 0x5, + JSONB_TYPE_UINT16= 0x6, + JSONB_TYPE_INT32= 0x7, + JSONB_TYPE_UINT32= 0x8, + JSONB_TYPE_INT64= 0x9, + JSONB_TYPE_UINT64= 0xA, + JSONB_TYPE_DOUBLE= 0xB, + JSONB_TYPE_STRING= 0xC, + JSONB_TYPE_OPAQUE= 0xF +}; + +bool parse_mysql_json_value(String *buffer, JSONB_TYPES type, const uchar *data, + size_t len, size_t depth); + +#endif /* MYSQL_JSON_INCLUDED */ diff --git a/plugin/type_mysql_json/type.cc b/plugin/type_mysql_json/type.cc new file mode 100644 index 00000000000..2b3c415f346 --- /dev/null +++ b/plugin/type_mysql_json/type.cc @@ -0,0 +1,216 @@ +/* + Copyright (c) 2020 MariaDB Foundation + + 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 */ + +#include <mysql/plugin_data_type.h> +#include <my_global.h> +#include <sql_type.h> +#include <field.h> +#include <mysqld_error.h> +#include "mysql_json.h" + +const LEX_CSTRING empty_clex_str= {"", 0}; + +class Type_handler_mysql_json: public Type_handler_blob +{ +public: + Field *make_conversion_table_field(MEM_ROOT *, TABLE *, uint, const Field *) + const override; + const Type_collection *type_collection() const override; + Field *make_table_field_from_def(TABLE_SHARE *, MEM_ROOT *, + const LEX_CSTRING *, const Record_addr &, + const Bit_addr &, + const Column_definition_attributes *, + uint32) const override; + Field *make_table_field(MEM_ROOT *, const LEX_CSTRING *, + const Record_addr &, const Type_all_attributes &, + TABLE_SHARE *) const override; + void Column_definition_reuse_fix_attributes(THD *thd, + Column_definition *def, + const Field *field) const override; +}; + +Type_handler_mysql_json type_handler_mysql_json; + + +class Field_mysql_json: public Field_blob +{ +public: + Field_mysql_json(uchar *ptr_arg, uchar *null_ptr_arg, + uchar null_bit_arg, enum utype unireg_check_arg, + const LEX_CSTRING *field_name_arg, TABLE_SHARE *share, + uint blob_pack_length, const DTCollation &collation) + : Field_blob(ptr_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, + field_name_arg, share, blob_pack_length, + &my_charset_utf8mb4_bin) + {} + + String *val_str(String *val_buffer, String *val_str); + const Type_handler *type_handler() const { return &type_handler_mysql_json; } + bool parse_mysql(String *dest, const char *data, size_t length) const; + bool send(Protocol *protocol) { return Field::send(protocol); } + void sql_type(String &s) const + { s.set_ascii(STRING_WITH_LEN("json /* MySQL 5.7 */")); } + /* this will make ALTER TABLE to consider it different from built-in field */ + Compression_method *compression_method() const { return (Compression_method*)1; } +}; + +Field *Type_handler_mysql_json::make_conversion_table_field(MEM_ROOT *root, + TABLE *table, uint metadata, const Field *target) const +{ + uint pack_length= metadata & 0x00ff; + if (pack_length < 1 || pack_length > 4) + return NULL; // Broken binary log? + return new (root) + Field_mysql_json(NULL, (uchar *) "", 1, Field::NONE, &empty_clex_str, + table->s, pack_length, target->charset()); +} + +Field *Type_handler_mysql_json::make_table_field_from_def(TABLE_SHARE *share, + MEM_ROOT *root, const LEX_CSTRING *name, + const Record_addr &addr, const Bit_addr &bit, + const Column_definition_attributes *attr, uint32 flags) const +{ + return new (root) Field_mysql_json(addr.ptr(), addr.null_ptr(), + addr.null_bit(), attr->unireg_check, name, share, + attr->pack_flag_to_pack_length(), attr->charset); +} + +void Type_handler_mysql_json:: + Column_definition_reuse_fix_attributes(THD *thd, + Column_definition *def, + const Field *field) const +{ + Type_handler_blob::Column_definition_reuse_fix_attributes(thd, def, field); + def->decimals= 0; +} + + + +Field *Type_handler_mysql_json::make_table_field(MEM_ROOT *root, + const LEX_CSTRING *name, const Record_addr &addr, + const Type_all_attributes &attr, TABLE_SHARE *share) const +{ + return new (root) Field_mysql_json(addr.ptr(), addr.null_ptr(), + addr.null_bit(), Field::NONE, name, share, 2, attr.collation); +} + + +String *Field_mysql_json::val_str(String *val_buffer, String *val_ptr) +{ + String *raw_value= Field_blob::val_str(val_buffer, val_ptr); + String data; + + data.copy(*raw_value); + + val_ptr->length(0); + if (parse_mysql(val_ptr, data.ptr(), data.length())) + { + val_ptr->length(0); + my_printf_error(ER_UNKNOWN_ERROR, + "Error parsing MySQL JSON format, please dump this table from MySQL " + "and then restore it to be able to use it in MariaDB.", MYF(0)); + } + return val_ptr; +} + +bool Field_mysql_json::parse_mysql(String *dest, + const char *data, size_t length) const +{ + if (!data) + return false; + + /* Each JSON blob must start with a type specifier. */ + if (length < 2) + return true; + + if (parse_mysql_json_value(dest, static_cast<JSONB_TYPES>(data[0]), + reinterpret_cast<const uchar*>(data) + 1, + length - 1, 0)) + return true; + + return false; +} + +class Type_collection_mysql_json: public Type_collection +{ +public: + const Type_handler *aggregate_for_result(const Type_handler *a, + const Type_handler *b) + const override + { + if (a == b) + return a; + return NULL; + } + + const Type_handler *aggregate_for_min_max(const Type_handler *a, + const Type_handler *b) + const override + { + return aggregate_for_result(a, b); + } + + const Type_handler *aggregate_for_comparison(const Type_handler *a, + const Type_handler *b) + const override + { + return aggregate_for_result(a, b); + } + + const Type_handler *aggregate_for_num_op(const Type_handler *a, + const Type_handler *b) + const override + { + return NULL; + } + + const Type_handler *handler_by_name(const LEX_CSTRING &name) const override + { + if (type_handler_mysql_json.name().eq(name)) + return &type_handler_mysql_json; + return NULL; + } +}; + +const Type_collection *Type_handler_mysql_json::type_collection() const +{ + static Type_collection_mysql_json type_collection_mysql_json; + return &type_collection_mysql_json; +} + +static struct st_mariadb_data_type plugin_descriptor_type_mysql_json= +{ + MariaDB_DATA_TYPE_INTERFACE_VERSION, + &type_handler_mysql_json +}; + +maria_declare_plugin(type_mysql_json) +{ + MariaDB_DATA_TYPE_PLUGIN, + &plugin_descriptor_type_mysql_json, + "MYSQL_JSON", + "Anel Husaković, VicenÈ›iu Ciorbaru", + "Data type MYSQL_JSON", + PLUGIN_LICENSE_GPL, + 0, + 0, + 0x0001, + NULL, + NULL, + "0.1", + MariaDB_PLUGIN_MATURITY_STABLE +} +maria_declare_plugin_end; diff --git a/plugin/type_test/CMakeLists.txt b/plugin/type_test/CMakeLists.txt new file mode 100644 index 00000000000..132458cb719 --- /dev/null +++ b/plugin/type_test/CMakeLists.txt @@ -0,0 +1,17 @@ +# 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 Street, Fifth Floor, Boston, MA 02110-1335 USA + +MYSQL_ADD_PLUGIN(type_test plugin.cc RECOMPILE_FOR_EMBEDDED + MODULE_ONLY COMPONENT Test) diff --git a/plugin/type_test/mysql-test/type_test/suite.opt b/plugin/type_test/mysql-test/type_test/suite.opt new file mode 100644 index 00000000000..edf6d838a78 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/suite.opt @@ -0,0 +1 @@ +--plugin-load-add=$TYPE_TEST_SO diff --git a/plugin/type_test/mysql-test/type_test/suite.pm b/plugin/type_test/mysql-test/type_test/suite.pm new file mode 100644 index 00000000000..fe38ca57650 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/suite.pm @@ -0,0 +1,10 @@ +package My::Suite::Type_test; + +@ISA = qw(My::Suite); + +return "No TYPE_TEST plugin" unless $ENV{TYPE_TEST_SO}; + +sub is_default { 1 } + +bless { }; + diff --git a/plugin/type_test/mysql-test/type_test/type_test_double-debug.result b/plugin/type_test/mysql-test/type_test/type_test_double-debug.result new file mode 100644 index 00000000000..3493fb827ba --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_double-debug.result @@ -0,0 +1,35 @@ +# +# MDEV-20016 Add MariaDB_DATA_TYPE_PLUGIN +# +# Testing that a user-defined handler is resolved by name +# when opening a FRM file. +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_DOUBLE); +Warnings: +Note 1105 build_frm_image: Field data type info length: 13 +Note 1105 DBUG: [0] name='a' type_info='test_double' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +Warnings: +Note 1105 DBUG: [0] name='a' type_info='test_double' +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; +# Testing what happens on failure to resolve a type handler by name +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_DOUBLE); +Warnings: +Note 1105 build_frm_image: Field data type info length: 13 +Note 1105 DBUG: [0] name='a' type_info='test_double' +FLUSH TABLES; +SET @@debug_dbug="+d,emulate_handler_by_name_or_error_failure"; +SHOW CREATE TABLE t1; +ERROR HY000: Unknown data type: 'test_double' +SELECT * FROM t1; +ERROR HY000: Unknown data type: 'test_double' +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; diff --git a/plugin/type_test/mysql-test/type_test/type_test_double-debug.test b/plugin/type_test/mysql-test/type_test/type_test_double-debug.test new file mode 100644 index 00000000000..ee5cf430cfe --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_double-debug.test @@ -0,0 +1,32 @@ +--source include/have_debug.inc + +--echo # +--echo # MDEV-20016 Add MariaDB_DATA_TYPE_PLUGIN +--echo # + +--echo # Testing that a user-defined handler is resolved by name +--echo # when opening a FRM file. + +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_DOUBLE); +--enable_prepare_warnings +SHOW CREATE TABLE t1; +--disable_prepare_warnings +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; + + +--echo # Testing what happens on failure to resolve a type handler by name + +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_DOUBLE); +FLUSH TABLES; +SET @@debug_dbug="+d,emulate_handler_by_name_or_error_failure"; +--error ER_UNKNOWN_DATA_TYPE +SHOW CREATE TABLE t1; +--error ER_UNKNOWN_DATA_TYPE +SELECT * FROM t1; +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; diff --git a/plugin/type_test/mysql-test/type_test/type_test_double.result b/plugin/type_test/mysql-test/type_test/type_test_double.result new file mode 100644 index 00000000000..6241ff95b8a --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_double.result @@ -0,0 +1,704 @@ +# +# MDEV-20016 Add MariaDB_DATA_TYPE_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='DATA TYPE' + AND PLUGIN_NAME='test_double'; +PLUGIN_NAME test_double +PLUGIN_VERSION 1.0 +PLUGIN_STATUS ACTIVE +PLUGIN_TYPE DATA TYPE +PLUGIN_AUTHOR MariaDB Corporation +PLUGIN_DESCRIPTION Data type TEST_DOUBLE +PLUGIN_LICENSE GPL +PLUGIN_MATURITY Experimental +PLUGIN_AUTH_VERSION 1.0 +CREATE TABLE t1 (a TEST_DOUBLE); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(4)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(4,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(10)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(10,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(20)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(20,0) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(4,2)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(4,2) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(10,5)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(10,5) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE(20,10)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double(20,10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +SELECT CAST('100' AS TEST_DOUBLE) AS cast; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def cast 5 22 3 Y 32896 31 63 +cast +100 +BEGIN NOT ATOMIC +DECLARE a TEST_DOUBLE DEFAULT 256; +SELECT HEX(a), a; +END; +$$ +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def HEX(a) 253 44 3 Y 0 0 8 +def a a 5 22 3 Y 32768 31 63 +HEX(a) a +100 256 +CREATE FUNCTION f1(p TEST_DOUBLE) RETURNS TEST_DOUBLE RETURN 1; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `f1`(p TEST_DOUBLE) RETURNS test_double +RETURN 1 latin1 latin1_swedish_ci latin1_swedish_ci +SELECT f1(10); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def f1(10) f1(10) 5 22 1 Y 32768 31 63 +f1(10) +1 +DROP FUNCTION f1; +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT COALESCE(a,a) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a,a)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `LEAST(a,a)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 MIN(a) MIN(a) 5 22 1 Y 32768 31 63 +def test t2 t2 MAX(a) MAX(a) 5 22 1 Y 32768 31 63 +MIN(a) MAX(a) +1 2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `MIN(a)` test_double DEFAULT NULL, + `MAX(a)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (id INT, a TEST_DOUBLE); +INSERT INTO t1 VALUES (1,1),(1,2),(2,1),(2,2); +CREATE TABLE t2 AS SELECT id, MIN(a), MAX(a) FROM t1 GROUP BY id; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 id id 3 11 1 Y 32768 0 63 +def test t2 t2 MIN(a) MIN(a) 5 22 1 Y 32768 31 63 +def test t2 t2 MAX(a) MAX(a) 5 22 1 Y 32768 31 63 +id MIN(a) MAX(a) +1 1 2 +2 1 2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) DEFAULT NULL, + `MIN(a)` test_double DEFAULT NULL, + `MAX(a)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT DISTINCT a FROM t1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 a a 5 22 1 Y 32768 31 63 +a +1 +2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 AS SELECT (SELECT a FROM t1) AS c1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 c1 c1 5 22 1 Y 32768 31 63 +c1 +1 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing CREATE..LIKE +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing CREATE..SELECT +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing ALTER +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (10),(20); +SELECT * FROM t1; +a +10 +20 +ALTER TABLE t1 MODIFY a INT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t1; +a +10 +20 +ALTER TABLE t1 MODIFY a TEST_DOUBLE; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t1; +a +10 +20 +DROP TABLE t1; +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (10),(20); +ALTER TABLE t1 ADD b TEST_DOUBLE DEFAULT 0; +SELECT * FROM t1; +a b +10 0 +20 0 +DROP TABLE t1; +# Testing metadata views +CREATE TABLE t1 (a TEST_DOUBLE); +SELECT +TABLE_CATALOG, +TABLE_SCHEMA, +TABLE_NAME, +COLUMN_NAME, +ORDINAL_POSITION, +COLUMN_DEFAULT, +IS_NULLABLE, +DATA_TYPE, +CHARACTER_MAXIMUM_LENGTH, +CHARACTER_OCTET_LENGTH, +NUMERIC_PRECISION, +NUMERIC_SCALE, +DATETIME_PRECISION, +CHARACTER_SET_NAME, +COLLATION_NAME, +COLUMN_TYPE, +EXTRA +FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test'; +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME a +ORDINAL_POSITION 1 +COLUMN_DEFAULT NULL +IS_NULLABLE YES +DATA_TYPE test_double +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 22 +NUMERIC_SCALE 31 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE test_double +EXTRA +SHOW COLUMNS FROM t1; +Field Type Null Key Default Extra +a test_double YES NULL +DROP TABLE t1; +# Testing indexing +CREATE TABLE t1 (a TEST_DOUBLE, KEY(a)); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +EXPLAIN SELECT * FROM t1 WHERE a=3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 9 const 1 Using index +DROP TABLE t1; +# Testing aggregation for result +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +COALESCE(a,1) AS c1, +COALESCE(a,1.0) AS c2, +COALESCE(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_double DEFAULT NULL, + `c2` test_double DEFAULT NULL, + `c3` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0 0 +1 1 1 +2 2 2 +3 3 3 +4 4 4 +5 5 5 +6 6 6 +7 7 7 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +COALESCE(c,c_tinyint), +COALESCE(c,c_smallint), +COALESCE(c,c_mediumint), +COALESCE(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(c,c_tinyint)` test_double DEFAULT NULL, + `COALESCE(c,c_smallint)` test_double DEFAULT NULL, + `COALESCE(c,c_mediumint)` test_double DEFAULT NULL, + `COALESCE(c,c_bigint)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT COALESCE(c, c_time) FROM t1; +ERROR HY000: Illegal parameter data types test_double and time for operation 'coalesce' +SELECT COALESCE(c, c_date) FROM t1; +ERROR HY000: Illegal parameter data types test_double and date for operation 'coalesce' +SELECT COALESCE(c, c_datetime) FROM t1; +ERROR HY000: Illegal parameter data types test_double and datetime for operation 'coalesce' +SELECT COALESCE(c, c_timestamp) FROM t1; +ERROR HY000: Illegal parameter data types test_double and timestamp for operation 'coalesce' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT COALESCE(c, c_char) FROM t1; +ERROR HY000: Illegal parameter data types test_double and char for operation 'coalesce' +SELECT COALESCE(c, c_varchar) FROM t1; +ERROR HY000: Illegal parameter data types test_double and varchar for operation 'coalesce' +SELECT COALESCE(c, c_tinytext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and tinyblob for operation 'coalesce' +SELECT COALESCE(c, c_text) FROM t1; +ERROR HY000: Illegal parameter data types test_double and blob for operation 'coalesce' +SELECT COALESCE(c, c_mediumtext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and mediumblob for operation 'coalesce' +SELECT COALESCE(c, c_longtext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and longblob for operation 'coalesce' +DROP TABLE t1; +# Testing aggregation for min/max +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +LEAST(a,1) AS c1, +LEAST(a,1.0) AS c2, +LEAST(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_double DEFAULT NULL, + `c2` test_double DEFAULT NULL, + `c3` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0 0 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +1 1 1 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +LEAST(c,c_tinyint), +LEAST(c,c_smallint), +LEAST(c,c_mediumint), +LEAST(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `LEAST(c,c_tinyint)` test_double DEFAULT NULL, + `LEAST(c,c_smallint)` test_double DEFAULT NULL, + `LEAST(c,c_mediumint)` test_double DEFAULT NULL, + `LEAST(c,c_bigint)` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT LEAST(c, c_time) FROM t1; +ERROR HY000: Illegal parameter data types test_double and time for operation 'least' +SELECT LEAST(c, c_date) FROM t1; +ERROR HY000: Illegal parameter data types test_double and date for operation 'least' +SELECT LEAST(c, c_datetime) FROM t1; +ERROR HY000: Illegal parameter data types test_double and datetime for operation 'least' +SELECT LEAST(c, c_timestamp) FROM t1; +ERROR HY000: Illegal parameter data types test_double and timestamp for operation 'least' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT LEAST(c, c_char) FROM t1; +ERROR HY000: Illegal parameter data types test_double and char for operation 'least' +SELECT LEAST(c, c_varchar) FROM t1; +ERROR HY000: Illegal parameter data types test_double and varchar for operation 'least' +SELECT LEAST(c, c_tinytext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and tinyblob for operation 'least' +SELECT LEAST(c, c_text) FROM t1; +ERROR HY000: Illegal parameter data types test_double and blob for operation 'least' +SELECT LEAST(c, c_mediumtext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and mediumblob for operation 'least' +SELECT LEAST(c, c_longtext) FROM t1; +ERROR HY000: Illegal parameter data types test_double and longblob for operation 'least' +DROP TABLE t1; +# Testing aggregation for numeric operation - plus +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +a+1 AS c1, +a+1.0 AS c2, +a+1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_double DEFAULT NULL, + `c2` test_double DEFAULT NULL, + `c3` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +1 1 1 +2 2 2 +3 3 3 +4 4 4 +5 5 5 +6 6 6 +7 7 7 +8 8 8 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +c + c_tinyint, +c + c_smallint, +c + c_mediumint, +c + c_bigint +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c + c_tinyint` test_double DEFAULT NULL, + `c + c_smallint` test_double DEFAULT NULL, + `c + c_mediumint` test_double DEFAULT NULL, + `c + c_bigint` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT c + c_time FROM t1; +ERROR HY000: Illegal parameter data types test_double and time for operation '+' +SELECT c + c_date FROM t1; +ERROR HY000: Illegal parameter data types test_double and date for operation '+' +SELECT c + c_datetime FROM t1; +ERROR HY000: Illegal parameter data types test_double and datetime for operation '+' +SELECT c + c_timestamp FROM t1; +ERROR HY000: Illegal parameter data types test_double and timestamp for operation '+' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT c + c_char FROM t1; +ERROR HY000: Illegal parameter data types test_double and char for operation '+' +SELECT c + c_varchar FROM t1; +ERROR HY000: Illegal parameter data types test_double and varchar for operation '+' +SELECT c + c_tinytext FROM t1; +ERROR HY000: Illegal parameter data types test_double and tinyblob for operation '+' +SELECT c + c_text FROM t1; +ERROR HY000: Illegal parameter data types test_double and blob for operation '+' +SELECT c + c_mediumtext FROM t1; +ERROR HY000: Illegal parameter data types test_double and mediumblob for operation '+' +SELECT c + c_longtext FROM t1; +ERROR HY000: Illegal parameter data types test_double and longblob for operation '+' +DROP TABLE t1; +# Testing aggregation for numeric operation - minus +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +CREATE TABLE t2 AS SELECT +a-1 AS c1, +a-1.0 AS c2, +a-1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_double DEFAULT NULL, + `c2` test_double DEFAULT NULL, + `c3` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0 0 +1 1 1 +2 2 2 +3 3 3 +4 4 4 +5 5 5 +6 6 6 +7 7 7 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +c - c_tinyint, +c - c_smallint, +c - c_mediumint, +c - c_bigint +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c - c_tinyint` test_double DEFAULT NULL, + `c - c_smallint` test_double DEFAULT NULL, + `c - c_mediumint` test_double DEFAULT NULL, + `c - c_bigint` test_double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT c - c_time FROM t1; +ERROR HY000: Illegal parameter data types test_double and time for operation '-' +SELECT c - c_date FROM t1; +ERROR HY000: Illegal parameter data types test_double and date for operation '-' +SELECT c - c_datetime FROM t1; +ERROR HY000: Illegal parameter data types test_double and datetime for operation '-' +SELECT c - c_timestamp FROM t1; +ERROR HY000: Illegal parameter data types test_double and timestamp for operation '-' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_DOUBLE, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT c - c_char FROM t1; +ERROR HY000: Illegal parameter data types test_double and char for operation '-' +SELECT c - c_varchar FROM t1; +ERROR HY000: Illegal parameter data types test_double and varchar for operation '-' +SELECT c - c_tinytext FROM t1; +ERROR HY000: Illegal parameter data types test_double and tinyblob for operation '-' +SELECT c - c_text FROM t1; +ERROR HY000: Illegal parameter data types test_double and blob for operation '-' +SELECT c - c_mediumtext FROM t1; +ERROR HY000: Illegal parameter data types test_double and mediumblob for operation '-' +SELECT c - c_longtext FROM t1; +ERROR HY000: Illegal parameter data types test_double and longblob for operation '-' +DROP TABLE t1; +# Testing CAST to other data types +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (20000102); +CREATE TABLE t2 AS SELECT +a, +CAST(a AS CHAR), +CAST(a AS DECIMAL), +CAST(a AS DOUBLE), +CAST(a AS SIGNED), +CAST(a AS UNSIGNED), +CAST(a AS TIME), +CAST(a AS DATETIME), +CAST(a AS DATE) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_double DEFAULT NULL, + `CAST(a AS CHAR)` varchar(22) DEFAULT NULL, + `CAST(a AS DECIMAL)` decimal(10,0) DEFAULT NULL, + `CAST(a AS DOUBLE)` double DEFAULT NULL, + `CAST(a AS SIGNED)` bigint(20) DEFAULT NULL, + `CAST(a AS UNSIGNED)` bigint(20) unsigned DEFAULT NULL, + `CAST(a AS TIME)` time DEFAULT NULL, + `CAST(a AS DATETIME)` datetime DEFAULT NULL, + `CAST(a AS DATE)` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2; +a 20000102 +CAST(a AS CHAR) 20000102 +CAST(a AS DECIMAL) 20000102 +CAST(a AS DOUBLE) 20000102 +CAST(a AS SIGNED) 20000102 +CAST(a AS UNSIGNED) 20000102 +CAST(a AS TIME) 00:00:00 +CAST(a AS DATETIME) 2000-01-02 00:00:00 +CAST(a AS DATE) 2000-01-02 +DROP TABLE t2; +DROP TABLE t1; diff --git a/plugin/type_test/mysql-test/type_test/type_test_double.test b/plugin/type_test/mysql-test/type_test/type_test_double.test new file mode 100644 index 00000000000..993eab95af7 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_double.test @@ -0,0 +1,530 @@ +--echo # +--echo # MDEV-20016 Add MariaDB_DATA_TYPE_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='DATA TYPE' + AND PLUGIN_NAME='test_double'; +--horizontal_results + +CREATE TABLE t1 (a TEST_DOUBLE); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE(4)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE(10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE(20)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +CREATE TABLE t1 (a TEST_DOUBLE(4,2)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE(10,5)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE(20,10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--disable_ps_protocol +--enable_metadata +SELECT CAST('100' AS TEST_DOUBLE) AS cast; +--disable_metadata +--enable_ps_protocol + +--disable_ps_protocol +--enable_metadata +DELIMITER $$; +BEGIN NOT ATOMIC + DECLARE a TEST_DOUBLE DEFAULT 256; + SELECT HEX(a), a; +END; +$$ +DELIMITER ;$$ +--disable_metadata +--enable_ps_protocol + +CREATE FUNCTION f1(p TEST_DOUBLE) RETURNS TEST_DOUBLE RETURN 1; +SHOW CREATE FUNCTION f1; +--disable_ps_protocol +--enable_metadata +SELECT f1(10); +--disable_metadata +--enable_ps_protocol +DROP FUNCTION f1; + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT a FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT COALESCE(a,a) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (id INT, a TEST_DOUBLE); +INSERT INTO t1 VALUES (1,1),(1,2),(2,1),(2,2); +CREATE TABLE t2 AS SELECT id, MIN(a), MAX(a) FROM t1 GROUP BY id; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT DISTINCT a FROM t1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 AS SELECT (SELECT a FROM t1) AS c1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +--echo # Testing CREATE..LIKE + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +--echo # Testing CREATE..SELECT + +CREATE TABLE t1 (a TEST_DOUBLE); +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + + +--echo # Testing ALTER + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (10),(20); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY a INT; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +ALTER TABLE t1 MODIFY a TEST_DOUBLE; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (10),(20); +ALTER TABLE t1 ADD b TEST_DOUBLE DEFAULT 0; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # Testing metadata views + +CREATE TABLE t1 (a TEST_DOUBLE); +--vertical_results +SELECT + TABLE_CATALOG, + TABLE_SCHEMA, + TABLE_NAME, + COLUMN_NAME, + ORDINAL_POSITION, + COLUMN_DEFAULT, + IS_NULLABLE, + DATA_TYPE, + CHARACTER_MAXIMUM_LENGTH, + CHARACTER_OCTET_LENGTH, + NUMERIC_PRECISION, + NUMERIC_SCALE, + DATETIME_PRECISION, + CHARACTER_SET_NAME, + COLLATION_NAME, + COLUMN_TYPE, + EXTRA +FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test'; +--horizontal_results +SHOW COLUMNS FROM t1; +DROP TABLE t1; + + +--echo # Testing indexing + +CREATE TABLE t1 (a TEST_DOUBLE, KEY(a)); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +EXPLAIN SELECT * FROM t1 WHERE a=3; +DROP TABLE t1; + +--echo # Testing aggregation for result + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + COALESCE(a,1) AS c1, + COALESCE(a,1.0) AS c2, + COALESCE(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + COALESCE(c,c_tinyint), + COALESCE(c,c_smallint), + COALESCE(c,c_mediumint), + COALESCE(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_time) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_date) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_datetime) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_timestamp) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_char) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_varchar) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_tinytext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_text) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_mediumtext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_longtext) FROM t1; +DROP TABLE t1; + +--echo # Testing aggregation for min/max + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + LEAST(a,1) AS c1, + LEAST(a,1.0) AS c2, + LEAST(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + LEAST(c,c_tinyint), + LEAST(c,c_smallint), + LEAST(c,c_mediumint), + LEAST(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_time) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_date) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_datetime) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_timestamp) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_char) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_varchar) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_tinytext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_text) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_mediumtext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_longtext) FROM t1; +DROP TABLE t1; + + +--echo # Testing aggregation for numeric operation - plus + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + a+1 AS c1, + a+1.0 AS c2, + a+1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + c + c_tinyint, + c + c_smallint, + c + c_mediumint, + c + c_bigint +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_time FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_date FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_datetime FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_timestamp FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_char FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_varchar FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_tinytext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_text FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_mediumtext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_longtext FROM t1; +DROP TABLE t1; + +--echo # Testing aggregation for numeric operation - minus + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +CREATE TABLE t2 AS SELECT + a-1 AS c1, + a-1.0 AS c2, + a-1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + c - c_tinyint, + c - c_smallint, + c - c_mediumint, + c - c_bigint +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_time FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_date FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_datetime FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_timestamp FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_DOUBLE, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_char FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_varchar FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_tinytext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_text FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_mediumtext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_longtext FROM t1; +DROP TABLE t1; + +--echo # Testing CAST to other data types + +CREATE TABLE t1 (a TEST_DOUBLE); +INSERT INTO t1 VALUES (20000102); +CREATE TABLE t2 AS SELECT + a, + CAST(a AS CHAR), + CAST(a AS DECIMAL), + CAST(a AS DOUBLE), + CAST(a AS SIGNED), + CAST(a AS UNSIGNED), + CAST(a AS TIME), + CAST(a AS DATETIME), + CAST(a AS DATE) +FROM t1; +SHOW CREATE TABLE t2; +--vertical_results +SELECT * FROM t2; +--horizontal_results +DROP TABLE t2; +DROP TABLE t1; diff --git a/plugin/type_test/mysql-test/type_test/type_test_int8-debug.result b/plugin/type_test/mysql-test/type_test/type_test_int8-debug.result new file mode 100644 index 00000000000..c4abda77423 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_int8-debug.result @@ -0,0 +1,35 @@ +# +# MDEV-20016 Add MariaDB_DATA_TYPE_PLUGIN +# +# Testing that a user-defined handler is resolved by name +# when opening a FRM file. +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_INT8); +Warnings: +Note 1105 build_frm_image: Field data type info length: 11 +Note 1105 DBUG: [0] name='a' type_info='test_int8' +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +Warnings: +Note 1105 DBUG: [0] name='a' type_info='test_int8' +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; +# Testing what happens on failure to resolve a type handler by name +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_INT8); +Warnings: +Note 1105 build_frm_image: Field data type info length: 11 +Note 1105 DBUG: [0] name='a' type_info='test_int8' +FLUSH TABLES; +SET @@debug_dbug="+d,emulate_handler_by_name_or_error_failure"; +SHOW CREATE TABLE t1; +ERROR HY000: Unknown data type: 'test_int8' +SELECT * FROM t1; +ERROR HY000: Unknown data type: 'test_int8' +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; diff --git a/plugin/type_test/mysql-test/type_test/type_test_int8-debug.test b/plugin/type_test/mysql-test/type_test/type_test_int8-debug.test new file mode 100644 index 00000000000..7e60bf3efd1 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_int8-debug.test @@ -0,0 +1,32 @@ +--source include/have_debug.inc + +--echo # +--echo # MDEV-20016 Add MariaDB_DATA_TYPE_PLUGIN +--echo # + +--echo # Testing that a user-defined handler is resolved by name +--echo # when opening a FRM file. + +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_INT8); +--enable_prepare_warnings +SHOW CREATE TABLE t1; +--disable_prepare_warnings +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; + + +--echo # Testing what happens on failure to resolve a type handler by name + +SET @old_debug_dbug=@@debug_dbug; +SET @@debug_dbug="+d,frm_data_type_info"; +CREATE TABLE t1 (a TEST_INT8); +FLUSH TABLES; +SET @@debug_dbug="+d,emulate_handler_by_name_or_error_failure"; +--error ER_UNKNOWN_DATA_TYPE +SHOW CREATE TABLE t1; +--error ER_UNKNOWN_DATA_TYPE +SELECT * FROM t1; +DROP TABLE t1; +SET @@debug_dbug=@old_debug_dbug; diff --git a/plugin/type_test/mysql-test/type_test/type_test_int8.result b/plugin/type_test/mysql-test/type_test/type_test_int8.result new file mode 100644 index 00000000000..75fcf1f2f5e --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_int8.result @@ -0,0 +1,683 @@ +# +# MDEV-20016 Add MariaDB_DATA_TYPE_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='DATA TYPE' + AND PLUGIN_NAME='test_int8'; +PLUGIN_NAME test_int8 +PLUGIN_VERSION 1.0 +PLUGIN_STATUS ACTIVE +PLUGIN_TYPE DATA TYPE +PLUGIN_AUTHOR MariaDB Corporation +PLUGIN_DESCRIPTION Data type TEST_INT8 +PLUGIN_LICENSE GPL +PLUGIN_MATURITY Experimental +PLUGIN_AUTH_VERSION 1.0 +CREATE TABLE t1 (a TEST_INT8); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8(4)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(4) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8(10)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8(20)); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t1; +SELECT CAST('100' AS TEST_INT8) AS cast; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def cast 3 3 3 N 32897 0 63 +cast +100 +BEGIN NOT ATOMIC +DECLARE a TEST_INT8 DEFAULT 256; +SELECT HEX(a), a; +END; +$$ +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def HEX(a) 253 40 3 Y 0 0 8 +def a a 8 20 3 Y 32768 0 63 +HEX(a) a +100 256 +CREATE FUNCTION f1(p TEST_INT8) RETURNS TEST_INT8 RETURN 1; +SHOW CREATE FUNCTION f1; +Function sql_mode Create Function character_set_client collation_connection Database Collation +f1 STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION CREATE DEFINER=`root`@`localhost` FUNCTION `f1`(p TEST_INT8) RETURNS test_int8(20) +RETURN 1 latin1 latin1_swedish_ci latin1_swedish_ci +SELECT f1(10); +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def f1(10) f1(10) 8 20 1 Y 32768 0 63 +f1(10) +1 +DROP FUNCTION f1; +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT COALESCE(a,a) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(a,a)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `LEAST(a,a)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 MIN(a) MIN(a) 8 20 1 Y 32768 0 63 +def test t2 t2 MAX(a) MAX(a) 8 20 1 Y 32768 0 63 +MIN(a) MAX(a) +1 2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `MIN(a)` test_int8(20) DEFAULT NULL, + `MAX(a)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (id INT, a TEST_INT8); +INSERT INTO t1 VALUES (1,1),(1,2),(2,1),(2,2); +CREATE TABLE t2 AS SELECT id, MIN(a), MAX(a) FROM t1 GROUP BY id; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 id id 3 11 1 Y 32768 0 63 +def test t2 t2 MIN(a) MIN(a) 8 20 1 Y 32768 0 63 +def test t2 t2 MAX(a) MAX(a) 8 20 1 Y 32768 0 63 +id MIN(a) MAX(a) +1 1 2 +2 1 2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `id` int(11) DEFAULT NULL, + `MIN(a)` test_int8(20) DEFAULT NULL, + `MAX(a)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT DISTINCT a FROM t1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 a a 8 20 1 Y 32768 0 63 +a +1 +2 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 AS SELECT (SELECT a FROM t1) AS c1; +SELECT * FROM t2; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def test t2 t2 c1 c1 8 20 1 Y 32768 0 63 +c1 +1 +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing CREATE..LIKE +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing CREATE..SELECT +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +# Testing ALTER +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (10),(20); +SELECT * FROM t1; +a +10 +20 +ALTER TABLE t1 MODIFY a INT; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t1; +a +10 +20 +ALTER TABLE t1 MODIFY a TEST_INT8; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t1; +a +10 +20 +DROP TABLE t1; +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (10),(20); +ALTER TABLE t1 ADD b TEST_INT8 DEFAULT 0; +SELECT * FROM t1; +a b +10 0 +20 0 +DROP TABLE t1; +# Testing metadata views +CREATE TABLE t1 (a TEST_INT8); +SELECT +TABLE_CATALOG, +TABLE_SCHEMA, +TABLE_NAME, +COLUMN_NAME, +ORDINAL_POSITION, +COLUMN_DEFAULT, +IS_NULLABLE, +DATA_TYPE, +CHARACTER_MAXIMUM_LENGTH, +CHARACTER_OCTET_LENGTH, +NUMERIC_PRECISION, +NUMERIC_SCALE, +DATETIME_PRECISION, +CHARACTER_SET_NAME, +COLLATION_NAME, +COLUMN_TYPE, +EXTRA +FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test'; +TABLE_CATALOG def +TABLE_SCHEMA test +TABLE_NAME t1 +COLUMN_NAME a +ORDINAL_POSITION 1 +COLUMN_DEFAULT NULL +IS_NULLABLE YES +DATA_TYPE test_int8 +CHARACTER_MAXIMUM_LENGTH NULL +CHARACTER_OCTET_LENGTH NULL +NUMERIC_PRECISION 19 +NUMERIC_SCALE 0 +DATETIME_PRECISION NULL +CHARACTER_SET_NAME NULL +COLLATION_NAME NULL +COLUMN_TYPE test_int8(20) +EXTRA +SHOW COLUMNS FROM t1; +Field Type Null Key Default Extra +a test_int8(20) YES NULL +DROP TABLE t1; +# Testing indexing +CREATE TABLE t1 (a TEST_INT8, KEY(a)); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +EXPLAIN SELECT * FROM t1 WHERE a=3; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref a a 9 const 1 Using index +DROP TABLE t1; +# Testing aggregation for result +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +COALESCE(a,1) AS c1, +COALESCE(a,1.0) AS c2, +COALESCE(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_int8(20) DEFAULT NULL, + `c2` decimal(20,1) DEFAULT NULL, + `c3` double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0.0 0 +1 1.0 1 +2 2.0 2 +3 3.0 3 +4 4.0 4 +5 5.0 5 +6 6.0 6 +7 7.0 7 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +COALESCE(c,c_tinyint), +COALESCE(c,c_smallint), +COALESCE(c,c_mediumint), +COALESCE(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `COALESCE(c,c_tinyint)` test_int8(20) DEFAULT NULL, + `COALESCE(c,c_smallint)` test_int8(20) DEFAULT NULL, + `COALESCE(c,c_mediumint)` test_int8(20) DEFAULT NULL, + `COALESCE(c,c_bigint)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT COALESCE(c, c_time) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and time for operation 'coalesce' +SELECT COALESCE(c, c_date) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and date for operation 'coalesce' +SELECT COALESCE(c, c_datetime) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and datetime for operation 'coalesce' +SELECT COALESCE(c, c_timestamp) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and timestamp for operation 'coalesce' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT COALESCE(c, c_char) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and char for operation 'coalesce' +SELECT COALESCE(c, c_varchar) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and varchar for operation 'coalesce' +SELECT COALESCE(c, c_tinytext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and tinyblob for operation 'coalesce' +SELECT COALESCE(c, c_text) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and blob for operation 'coalesce' +SELECT COALESCE(c, c_mediumtext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and mediumblob for operation 'coalesce' +SELECT COALESCE(c, c_longtext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and longblob for operation 'coalesce' +DROP TABLE t1; +# Testing aggregation for min/max +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +LEAST(a,1) AS c1, +LEAST(a,1.0) AS c2, +LEAST(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` test_int8(20) DEFAULT NULL, + `c2` decimal(20,1) DEFAULT NULL, + `c3` double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0.0 0 +1 1.0 1 +1 1.0 1 +1 1.0 1 +1 1.0 1 +1 1.0 1 +1 1.0 1 +1 1.0 1 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +LEAST(c,c_tinyint), +LEAST(c,c_smallint), +LEAST(c,c_mediumint), +LEAST(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `LEAST(c,c_tinyint)` test_int8(20) DEFAULT NULL, + `LEAST(c,c_smallint)` test_int8(20) DEFAULT NULL, + `LEAST(c,c_mediumint)` test_int8(20) DEFAULT NULL, + `LEAST(c,c_bigint)` test_int8(20) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT LEAST(c, c_time) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and time for operation 'least' +SELECT LEAST(c, c_date) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and date for operation 'least' +SELECT LEAST(c, c_datetime) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and datetime for operation 'least' +SELECT LEAST(c, c_timestamp) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and timestamp for operation 'least' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT LEAST(c, c_char) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and char for operation 'least' +SELECT LEAST(c, c_varchar) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and varchar for operation 'least' +SELECT LEAST(c, c_tinytext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and tinyblob for operation 'least' +SELECT LEAST(c, c_text) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and blob for operation 'least' +SELECT LEAST(c, c_mediumtext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and mediumblob for operation 'least' +SELECT LEAST(c, c_longtext) FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and longblob for operation 'least' +DROP TABLE t1; +# Testing aggregation for numeric operation - plus +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT +a+1 AS c1, +a+1.0 AS c2, +a+1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` bigint(21) DEFAULT NULL, + `c2` decimal(21,1) DEFAULT NULL, + `c3` double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +1 1.0 1 +2 2.0 2 +3 3.0 3 +4 4.0 4 +5 5.0 5 +6 6.0 6 +7 7.0 7 +8 8.0 8 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +c + c_tinyint, +c + c_smallint, +c + c_mediumint, +c + c_bigint +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c + c_tinyint` bigint(21) DEFAULT NULL, + `c + c_smallint` bigint(21) DEFAULT NULL, + `c + c_mediumint` bigint(21) DEFAULT NULL, + `c + c_bigint` bigint(21) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT c + c_time FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and time for operation '+' +SELECT c + c_date FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and date for operation '+' +SELECT c + c_datetime FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and datetime for operation '+' +SELECT c + c_timestamp FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and timestamp for operation '+' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT c + c_char FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and char for operation '+' +SELECT c + c_varchar FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and varchar for operation '+' +SELECT c + c_tinytext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and tinyblob for operation '+' +SELECT c + c_text FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and blob for operation '+' +SELECT c + c_mediumtext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and mediumblob for operation '+' +SELECT c + c_longtext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and longblob for operation '+' +DROP TABLE t1; +# Testing aggregation for numeric operation - minus +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +CREATE TABLE t2 AS SELECT +a-1 AS c1, +a-1.0 AS c2, +a-1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c1` bigint(21) DEFAULT NULL, + `c2` decimal(21,1) DEFAULT NULL, + `c3` double DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2 ORDER BY c1; +c1 c2 c3 +0 0.0 0 +1 1.0 1 +2 2.0 2 +3 3.0 3 +4 4.0 4 +5 5.0 5 +6 6.0 6 +7 7.0 7 +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_tinyint TINYINT, +c_smallint SMALLINT, +c_mediumint MEDIUMINT, +c_int INT, +c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT +c - c_tinyint, +c - c_smallint, +c - c_mediumint, +c - c_bigint +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c - c_tinyint` bigint(21) DEFAULT NULL, + `c - c_smallint` bigint(21) DEFAULT NULL, + `c - c_mediumint` bigint(21) DEFAULT NULL, + `c - c_bigint` bigint(21) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_time TIME, +c_date DATE, +c_datetime DATETIME, +c_timestamp TIMESTAMP +); +SELECT c - c_time FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and time for operation '-' +SELECT c - c_date FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and date for operation '-' +SELECT c - c_datetime FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and datetime for operation '-' +SELECT c - c_timestamp FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and timestamp for operation '-' +DROP TABLE t1; +CREATE TABLE t1 ( +c TEST_INT8, +c_char CHAR(32), +c_varchar VARCHAR(32), +c_tinytext TINYTEXT, +c_text TEXT, +c_mediumtext MEDIUMTEXT, +c_longtext LONGTEXT +); +SELECT c - c_char FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and char for operation '-' +SELECT c - c_varchar FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and varchar for operation '-' +SELECT c - c_tinytext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and tinyblob for operation '-' +SELECT c - c_text FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and blob for operation '-' +SELECT c - c_mediumtext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and mediumblob for operation '-' +SELECT c - c_longtext FROM t1; +ERROR HY000: Illegal parameter data types test_int8 and longblob for operation '-' +DROP TABLE t1; +# Testing CAST to other data types +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (20000102); +CREATE TABLE t2 AS SELECT +a, +CAST(a AS CHAR), +CAST(a AS DECIMAL), +CAST(a AS DOUBLE), +CAST(a AS SIGNED), +CAST(a AS UNSIGNED), +CAST(a AS TIME), +CAST(a AS DATETIME), +CAST(a AS DATE) +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `a` test_int8(20) DEFAULT NULL, + `CAST(a AS CHAR)` varchar(20) DEFAULT NULL, + `CAST(a AS DECIMAL)` decimal(10,0) DEFAULT NULL, + `CAST(a AS DOUBLE)` double DEFAULT NULL, + `CAST(a AS SIGNED)` bigint(20) DEFAULT NULL, + `CAST(a AS UNSIGNED)` bigint(20) unsigned DEFAULT NULL, + `CAST(a AS TIME)` time DEFAULT NULL, + `CAST(a AS DATETIME)` datetime DEFAULT NULL, + `CAST(a AS DATE)` date DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci +SELECT * FROM t2; +a 20000102 +CAST(a AS CHAR) 20000102 +CAST(a AS DECIMAL) 20000102 +CAST(a AS DOUBLE) 20000102 +CAST(a AS SIGNED) 20000102 +CAST(a AS UNSIGNED) 20000102 +CAST(a AS TIME) 00:00:00 +CAST(a AS DATETIME) 2000-01-02 00:00:00 +CAST(a AS DATE) 2000-01-02 +DROP TABLE t2; +DROP TABLE t1; diff --git a/plugin/type_test/mysql-test/type_test/type_test_int8.test b/plugin/type_test/mysql-test/type_test/type_test_int8.test new file mode 100644 index 00000000000..6b5496c30fa --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_int8.test @@ -0,0 +1,518 @@ +--echo # +--echo # MDEV-20016 Add MariaDB_DATA_TYPE_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='DATA TYPE' + AND PLUGIN_NAME='test_int8'; +--horizontal_results + +CREATE TABLE t1 (a TEST_INT8); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8(4)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8(10)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8(20)); +SHOW CREATE TABLE t1; +DROP TABLE t1; + + +--disable_ps_protocol +--enable_metadata +SELECT CAST('100' AS TEST_INT8) AS cast; +--disable_metadata +--enable_ps_protocol + +--disable_ps_protocol +--enable_metadata +DELIMITER $$; +BEGIN NOT ATOMIC + DECLARE a TEST_INT8 DEFAULT 256; + SELECT HEX(a), a; +END; +$$ +DELIMITER ;$$ +--disable_metadata +--enable_ps_protocol + +CREATE FUNCTION f1(p TEST_INT8) RETURNS TEST_INT8 RETURN 1; +SHOW CREATE FUNCTION f1; +--disable_ps_protocol +--enable_metadata +SELECT f1(10); +--disable_metadata +--enable_ps_protocol +DROP FUNCTION f1; + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT a FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT COALESCE(a,a) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT LEAST(a,a) FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT MIN(a), MAX(a) FROM t1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (id INT, a TEST_INT8); +INSERT INTO t1 VALUES (1,1),(1,2),(2,1),(2,2); +CREATE TABLE t2 AS SELECT id, MIN(a), MAX(a) FROM t1 GROUP BY id; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2); +CREATE TABLE t2 AS SELECT DISTINCT a FROM t1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1); +CREATE TABLE t2 AS SELECT (SELECT a FROM t1) AS c1; +--disable_ps_protocol +--enable_metadata +SELECT * FROM t2; +--disable_metadata +--enable_ps_protocol +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT a FROM t1 UNION SELECT a FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +--echo # Testing CREATE..LIKE + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 LIKE t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +--echo # Testing CREATE..SELECT + +CREATE TABLE t1 (a TEST_INT8); +CREATE TABLE t2 AS SELECT * FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + + +--echo # Testing ALTER + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (10),(20); +SELECT * FROM t1; +ALTER TABLE t1 MODIFY a INT; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +ALTER TABLE t1 MODIFY a TEST_INT8; +SHOW CREATE TABLE t1; +SELECT * FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (10),(20); +ALTER TABLE t1 ADD b TEST_INT8 DEFAULT 0; +SELECT * FROM t1; +DROP TABLE t1; + +--echo # Testing metadata views + +CREATE TABLE t1 (a TEST_INT8); +--vertical_results +SELECT + TABLE_CATALOG, + TABLE_SCHEMA, + TABLE_NAME, + COLUMN_NAME, + ORDINAL_POSITION, + COLUMN_DEFAULT, + IS_NULLABLE, + DATA_TYPE, + CHARACTER_MAXIMUM_LENGTH, + CHARACTER_OCTET_LENGTH, + NUMERIC_PRECISION, + NUMERIC_SCALE, + DATETIME_PRECISION, + CHARACTER_SET_NAME, + COLLATION_NAME, + COLUMN_TYPE, + EXTRA +FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='t1' AND TABLE_SCHEMA='test'; +--horizontal_results +SHOW COLUMNS FROM t1; +DROP TABLE t1; + + +--echo # Testing indexing + +CREATE TABLE t1 (a TEST_INT8, KEY(a)); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +EXPLAIN SELECT * FROM t1 WHERE a=3; +DROP TABLE t1; + +--echo # Testing aggregation for result + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + COALESCE(a,1) AS c1, + COALESCE(a,1.0) AS c2, + COALESCE(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + COALESCE(c,c_tinyint), + COALESCE(c,c_smallint), + COALESCE(c,c_mediumint), + COALESCE(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_time) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_date) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_datetime) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_timestamp) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_char) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_varchar) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_tinytext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_text) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_mediumtext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT COALESCE(c, c_longtext) FROM t1; +DROP TABLE t1; + +--echo # Testing aggregation for min/max + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + LEAST(a,1) AS c1, + LEAST(a,1.0) AS c2, + LEAST(a,1e0) AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + LEAST(c,c_tinyint), + LEAST(c,c_smallint), + LEAST(c,c_mediumint), + LEAST(c,c_bigint) +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_time) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_date) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_datetime) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_timestamp) FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_char) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_varchar) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_tinytext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_text) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_mediumtext) FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT LEAST(c, c_longtext) FROM t1; +DROP TABLE t1; + + +--echo # Testing aggregation for numeric operation - plus + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7); +CREATE TABLE t2 AS SELECT + a+1 AS c1, + a+1.0 AS c2, + a+1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + c + c_tinyint, + c + c_smallint, + c + c_mediumint, + c + c_bigint +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_time FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_date FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_datetime FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_timestamp FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_char FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_varchar FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_tinytext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_text FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_mediumtext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c + c_longtext FROM t1; +DROP TABLE t1; + +--echo # Testing aggregation for numeric operation - minus + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (1),(2),(3),(4),(5),(6),(7),(8); +CREATE TABLE t2 AS SELECT + a-1 AS c1, + a-1.0 AS c2, + a-1e0 AS c3 +FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY c1; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_tinyint TINYINT, + c_smallint SMALLINT, + c_mediumint MEDIUMINT, + c_int INT, + c_bigint BIGINT +); +CREATE TABLE t2 AS SELECT + c - c_tinyint, + c - c_smallint, + c - c_mediumint, + c - c_bigint +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_time TIME, + c_date DATE, + c_datetime DATETIME, + c_timestamp TIMESTAMP +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_time FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_date FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_datetime FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_timestamp FROM t1; +DROP TABLE t1; + +CREATE TABLE t1 ( + c TEST_INT8, + c_char CHAR(32), + c_varchar VARCHAR(32), + c_tinytext TINYTEXT, + c_text TEXT, + c_mediumtext MEDIUMTEXT, + c_longtext LONGTEXT +); +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_char FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_varchar FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_tinytext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_text FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_mediumtext FROM t1; +--error ER_ILLEGAL_PARAMETER_DATA_TYPES2_FOR_OPERATION +SELECT c - c_longtext FROM t1; +DROP TABLE t1; + + +--echo # Testing CAST to other data types + +CREATE TABLE t1 (a TEST_INT8); +INSERT INTO t1 VALUES (20000102); +CREATE TABLE t2 AS SELECT + a, + CAST(a AS CHAR), + CAST(a AS DECIMAL), + CAST(a AS DOUBLE), + CAST(a AS SIGNED), + CAST(a AS UNSIGNED), + CAST(a AS TIME), + CAST(a AS DATETIME), + CAST(a AS DATE) +FROM t1; +SHOW CREATE TABLE t2; +--vertical_results +SELECT * FROM t2; +--horizontal_results +DROP TABLE t2; +DROP TABLE t1; diff --git a/plugin/type_test/mysql-test/type_test/type_test_mysql.result b/plugin/type_test/mysql-test/type_test/type_test_mysql.result new file mode 100644 index 00000000000..7dfbfce3340 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_mysql.result @@ -0,0 +1,29 @@ +CREATE TABLE t1 (a TEST_INT8, b TEST_DOUBLE); +Field 1: `a` +Org_field: `a` +Catalog: `def` +Database: `test` +Table: `t1` +Org_table: `t1` +Type: LONGLONG +Collation: binary (63) +Length: 20 +Max_length: 0 +Decimals: 0 +Flags: NUM + +Field 2: `b` +Org_field: `b` +Catalog: `def` +Database: `test` +Table: `t1` +Org_table: `t1` +Type: DOUBLE +Collation: binary (63) +Length: 22 +Max_length: 0 +Decimals: 31 +Flags: NUM + + +DROP TABLE t1; diff --git a/plugin/type_test/mysql-test/type_test/type_test_mysql.test b/plugin/type_test/mysql-test/type_test/type_test_mysql.test new file mode 100644 index 00000000000..93a0e08eab3 --- /dev/null +++ b/plugin/type_test/mysql-test/type_test/type_test_mysql.test @@ -0,0 +1,10 @@ +-- source include/have_working_dns.inc +-- source include/not_embedded.inc + +CREATE TABLE t1 (a TEST_INT8, b TEST_DOUBLE); +# +# doesn't report the correct type name yet +# to be fixed +# +--exec $MYSQL -t test --column-type-info -e "SELECT * FROM t1" 2>&1 +DROP TABLE t1; diff --git a/plugin/type_test/plugin.cc b/plugin/type_test/plugin.cc new file mode 100644 index 00000000000..4c26c35f976 --- /dev/null +++ b/plugin/type_test/plugin.cc @@ -0,0 +1,322 @@ +/* + 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-1301 USA */ + +#include <my_global.h> +#include <sql_class.h> // THD +#include <mysql/plugin_data_type.h> +#include "sql_type.h" + + +class Type_collection_test: public Type_collection +{ +protected: + const Type_handler *aggregate_common(const Type_handler *h1, + const Type_handler *h2) const; +public: + const Type_handler *handler_by_name(const LEX_CSTRING &name) const override + { + return NULL; + } + const Type_handler *aggregate_for_result(const Type_handler *h1, + const Type_handler *h2) + const override; + const Type_handler *aggregate_for_comparison(const Type_handler *h1, + const Type_handler *h2) + const override; + const Type_handler *aggregate_for_min_max(const Type_handler *h1, + const Type_handler *h2) + const override; + const Type_handler *aggregate_for_num_op(const Type_handler *h1, + const Type_handler *h2) + const override; +}; + + +static Type_collection_test type_collection_test; + + +class Field_test_int8 :public Field_longlong +{ +public: + Field_test_int8(const LEX_CSTRING &name, const Record_addr &addr, + enum utype unireg_check_arg, + uint32 len_arg, bool zero_arg, bool unsigned_arg) + :Field_longlong(addr.ptr(), len_arg, addr.null_ptr(), addr.null_bit(), + Field::NONE, &name, zero_arg, unsigned_arg) + {} + const Type_handler *type_handler() const override; +}; + + +class Type_handler_test_int8: public Type_handler_longlong +{ +public: + const Type_collection *type_collection() const override + { + return &type_collection_test; + } + const Type_handler *type_handler_signed() const override + { + return this; + } + Field *make_table_field_from_def(TABLE_SHARE *share, MEM_ROOT *root, + const LEX_CSTRING *name, + const Record_addr &rec, const Bit_addr &bit, + const Column_definition_attributes *attr, + uint32 flags) const override + { + return new (root) + Field_test_int8(*name, rec, attr->unireg_check, + (uint32) attr->length, + f_is_zerofill(attr->pack_flag) != 0, + f_is_dec(attr->pack_flag) == 0); + } +}; + +static Type_handler_test_int8 type_handler_test_int8; + + +const Type_handler *Field_test_int8::type_handler() const +{ + return &type_handler_test_int8; +} + + +static struct st_mariadb_data_type plugin_descriptor_type_test_int8= +{ + MariaDB_DATA_TYPE_INTERFACE_VERSION, + &type_handler_test_int8 +}; + + +/*************************************************************************/ + +class Field_test_double :public Field_double +{ +public: + Field_test_double(const LEX_CSTRING &name, const Record_addr &addr, + enum utype unireg_check_arg, + uint32 len_arg, uint8 dec_arg, + bool zero_arg, bool unsigned_arg) + :Field_double(addr.ptr(), len_arg, addr.null_ptr(), addr.null_bit(), + Field::NONE, &name, dec_arg, zero_arg, unsigned_arg) + {} + const Type_handler *type_handler() const override; +}; + + +class Type_handler_test_double: public Type_handler_double +{ +public: + const Type_collection *type_collection() const override + { + return &type_collection_test; + } + const Type_handler *type_handler_signed() const override + { + return this; + } + bool Column_definition_data_type_info_image(Binary_string *to, + const Column_definition &def) + const override + { + return to->append(Type_handler_test_double::name().lex_cstring()); + } + Field *make_table_field_from_def(TABLE_SHARE *share, MEM_ROOT *root, + const LEX_CSTRING *name, + const Record_addr &rec, const Bit_addr &bit, + const Column_definition_attributes *attr, + uint32 flags) const override + { + return new (root) + Field_test_double(*name, rec, attr->unireg_check, + (uint32) attr->length, (uint8) attr->decimals, + f_is_zerofill(attr->pack_flag) != 0, + f_is_dec(attr->pack_flag) == 0); + } +}; + +static Type_handler_test_double type_handler_test_double; + + +const Type_handler *Field_test_double::type_handler() const +{ + return &type_handler_test_double; +} + + +static struct st_mariadb_data_type plugin_descriptor_type_test_double= +{ + MariaDB_DATA_TYPE_INTERFACE_VERSION, + &type_handler_test_double +}; + + +/*************************************************************************/ +const Type_handler * +Type_collection_test::aggregate_common(const Type_handler *h1, + const Type_handler *h2) const +{ + if (h1 == h2) + return h1; + + static const Type_aggregator::Pair agg[]= + { + { + &type_handler_slong, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_newdecimal, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_double, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_slong, + &type_handler_test_int8, + &type_handler_test_int8 + }, + { + &type_handler_newdecimal, + &type_handler_test_int8, + &type_handler_newdecimal + }, + { + &type_handler_double, + &type_handler_test_int8, + &type_handler_double + }, + { + &type_handler_stiny, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_sshort, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_sint24, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_slonglong, + &type_handler_test_double, + &type_handler_test_double + }, + { + &type_handler_stiny, + &type_handler_test_int8, + &type_handler_test_int8 + }, + { + &type_handler_sshort, + &type_handler_test_int8, + &type_handler_test_int8 + }, + { + &type_handler_sint24, + &type_handler_test_int8, + &type_handler_test_int8 + }, + { + &type_handler_slonglong, + &type_handler_test_int8, + &type_handler_test_int8 + }, + {NULL,NULL,NULL} + }; + + return Type_aggregator::find_handler_in_array(agg, h1, h2, true); +} + + +const Type_handler * +Type_collection_test::aggregate_for_result(const Type_handler *h1, + const Type_handler *h2) const +{ + return aggregate_common(h1, h2); +} + + +const Type_handler * +Type_collection_test::aggregate_for_min_max(const Type_handler *h1, + const Type_handler *h2) const +{ + return aggregate_common(h1, h2); +} + + +const Type_handler * +Type_collection_test::aggregate_for_num_op(const Type_handler *h1, + const Type_handler *h2) const +{ + return aggregate_common(h1, h2); +} + + +const Type_handler * +Type_collection_test::aggregate_for_comparison(const Type_handler *h1, + const Type_handler *h2) const +{ + DBUG_ASSERT(h1 == h1->type_handler_for_comparison()); + DBUG_ASSERT(h2 == h2->type_handler_for_comparison()); + return aggregate_common(h1, h2); +} + + +/*************************************************************************/ + +maria_declare_plugin(type_test) +{ + MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_type_test_int8, // pointer to type-specific plugin descriptor + "test_int8", // plugin name + "MariaDB Corporation", // plugin author + "Data type TEST_INT8", // 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 version + NULL, // Status variables + NULL, // System variables + "1.0", // String version representation + MariaDB_PLUGIN_MATURITY_EXPERIMENTAL // Maturity(see include/mysql/plugin.h)*/ +}, +{ + MariaDB_DATA_TYPE_PLUGIN, // the plugin type (see include/mysql/plugin.h) + &plugin_descriptor_type_test_double, // pointer to type-specific plugin descriptor + "test_double", // plugin name + "MariaDB Corporation", // plugin author + "Data type TEST_DOUBLE", // 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 version + 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; diff --git a/plugin/user_variables/user_variables.cc b/plugin/user_variables/user_variables.cc index bee8b1feccc..f820e4ad890 100644 --- a/plugin/user_variables/user_variables.cc +++ b/plugin/user_variables/user_variables.cc @@ -16,7 +16,7 @@ #define MYSQL_SERVER #include <my_global.h> #include <sql_class.h> -#include <table.h> +#include <sql_i_s.h> #include <sql_show.h> @@ -42,16 +42,18 @@ static const LEX_CSTRING unsigned_result_types[]= }; +namespace Show { + static ST_FIELD_INFO user_variables_fields_info[] = { - { "VARIABLE_NAME", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, "Variable_name", 0 }, - { "VARIABLE_VALUE", 2048, MYSQL_TYPE_STRING, 0, MY_I_S_MAYBE_NULL, "Value", 0 }, - { "VARIABLE_TYPE", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 0, 0, 0 }, - { "CHARACTER_SET_NAME", MY_CS_NAME_SIZE, MYSQL_TYPE_STRING, 0, - MY_I_S_MAYBE_NULL, 0, 0 }, - { 0, 0, MYSQL_TYPE_NULL, 0, 0, 0, 0 } + Column("VARIABLE_NAME", Name(), NOT_NULL, "Variable_name"), + Column("VARIABLE_VALUE", Varchar(2048), NULLABLE, "Value"), + Column("VARIABLE_TYPE", Name(), NOT_NULL), + Column("CHARACTER_SET_NAME", CSName(), NULLABLE), + CEnd() }; +} // namespace Show static int user_variables_fill(THD *thd, TABLE_LIST *tables, COND *cond) { @@ -110,7 +112,7 @@ int user_variables_reset(void) static int user_variables_init(void *p) { ST_SCHEMA_TABLE *is= (ST_SCHEMA_TABLE *) p; - is->fields_info= user_variables_fields_info; + is->fields_info= Show::user_variables_fields_info; is->fill_table= user_variables_fill; is->reset_table= user_variables_reset; return 0; diff --git a/plugin/userstat/client_stats.cc b/plugin/userstat/client_stats.cc index a1835384ad1..72c71785606 100644 --- a/plugin/userstat/client_stats.cc +++ b/plugin/userstat/client_stats.cc @@ -1,33 +1,37 @@ +namespace Show { + static ST_FIELD_INFO client_stats_fields[]= { - {"CLIENT", LIST_PROCESS_HOST_LEN, MYSQL_TYPE_STRING, 0, 0, "Client", 0}, - {"TOTAL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Total_connections", 0}, - {"CONCURRENT_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Concurrent_connections", 0}, - {"CONNECTED_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Connected_time", 0}, - {"BUSY_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Busy_time", 0}, - {"CPU_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Cpu_time", 0}, - {"BYTES_RECEIVED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_received", 0}, - {"BYTES_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_sent", 0}, - {"BINLOG_BYTES_WRITTEN", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Binlog_bytes_written", 0}, - {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read", 0}, - {"ROWS_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_sent", 0}, - {"ROWS_DELETED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_deleted", 0}, - {"ROWS_INSERTED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_inserted", 0}, - {"ROWS_UPDATED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_updated", 0}, - {"SELECT_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Select_commands", 0}, - {"UPDATE_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Update_commands", 0}, - {"OTHER_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Other_commands", 0}, - {"COMMIT_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Commit_transactions", 0}, - {"ROLLBACK_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rollback_transactions", 0}, - {"DENIED_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Denied_connections", 0}, - {"LOST_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Lost_connections", 0}, - {"ACCESS_DENIED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Access_denied", 0}, - {"EMPTY_QUERIES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Empty_queries", 0}, - {"TOTAL_SSL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "Total_ssl_connections", 0}, - {"MAX_STATEMENT_TIME_EXCEEDED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Max_statement_time_exceeded",SKIP_OPEN_TABLE}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("CLIENT",Varchar(LIST_PROCESS_HOST_LEN), NOT_NULL, "Client"), + Column("TOTAL_CONNECTIONS", SLonglong(), NOT_NULL, "Total_connections"), + Column("CONCURRENT_CONNECTIONS", SLonglong(), NOT_NULL, "Concurrent_connections"), + Column("CONNECTED_TIME", SLonglong(), NOT_NULL, "Connected_time"), + Column("BUSY_TIME", Double(MY_INT64_NUM_DECIMAL_DIGITS), NOT_NULL, "Busy_time"), + Column("CPU_TIME", Double(MY_INT64_NUM_DECIMAL_DIGITS), NOT_NULL, "Cpu_time"), + Column("BYTES_RECEIVED", SLonglong(), NOT_NULL, "Bytes_received"), + Column("BYTES_SENT", SLonglong(), NOT_NULL, "Bytes_sent"), + Column("BINLOG_BYTES_WRITTEN", SLonglong(), NOT_NULL, "Binlog_bytes_written"), + Column("ROWS_READ", SLonglong(), NOT_NULL, "Rows_read"), + Column("ROWS_SENT", SLonglong(), NOT_NULL, "Rows_sent"), + Column("ROWS_DELETED", SLonglong(), NOT_NULL, "Rows_deleted"), + Column("ROWS_INSERTED", SLonglong(), NOT_NULL, "Rows_inserted"), + Column("ROWS_UPDATED", SLonglong(), NOT_NULL, "Rows_updated"), + Column("SELECT_COMMANDS", SLonglong(), NOT_NULL, "Select_commands"), + Column("UPDATE_COMMANDS", SLonglong(), NOT_NULL, "Update_commands"), + Column("OTHER_COMMANDS", SLonglong(), NOT_NULL, "Other_commands"), + Column("COMMIT_TRANSACTIONS", SLonglong(), NOT_NULL, "Commit_transactions"), + Column("ROLLBACK_TRANSACTIONS", SLonglong(), NOT_NULL, "Rollback_transactions"), + Column("DENIED_CONNECTIONS", SLonglong(), NOT_NULL, "Denied_connections"), + Column("LOST_CONNECTIONS", SLonglong(), NOT_NULL, "Lost_connections"), + Column("ACCESS_DENIED", SLonglong(), NOT_NULL, "Access_denied"), + Column("EMPTY_QUERIES", SLonglong(), NOT_NULL, "Empty_queries"), + Column("TOTAL_SSL_CONNECTIONS", ULonglong(), NOT_NULL, "Total_ssl_connections"), + Column("MAX_STATEMENT_TIME_EXCEEDED", SLonglong(), NOT_NULL, "Max_statement_time_exceeded"), + CEnd() }; +} // namespace Show + static int send_user_stats(THD* thd, HASH *all_user_stats, TABLE *table) { mysql_mutex_lock(&LOCK_global_user_client_stats); @@ -74,7 +78,7 @@ static int send_user_stats(THD* thd, HASH *all_user_stats, TABLE *table) static int client_stats_fill(THD* thd, TABLE_LIST* tables, COND* cond) { - if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true)) + if (check_global_access(thd, PROCESS_ACL, true)) return 0; return send_user_stats(thd, &global_client_stats, tables->table); @@ -92,7 +96,7 @@ static int client_stats_reset() static int client_stats_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= client_stats_fields; + schema->fields_info= Show::client_stats_fields; schema->fill_table= client_stats_fill; schema->reset_table= client_stats_reset; return 0; diff --git a/plugin/userstat/index_stats.cc b/plugin/userstat/index_stats.cc index da0d4060b98..97305e894bb 100644 --- a/plugin/userstat/index_stats.cc +++ b/plugin/userstat/index_stats.cc @@ -1,12 +1,16 @@ +namespace Show { + static ST_FIELD_INFO index_stats_fields[]= { - {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema",SKIP_OPEN_TABLE}, - {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name",SKIP_OPEN_TABLE}, - {"INDEX_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Index_name",SKIP_OPEN_TABLE}, - {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read",SKIP_OPEN_TABLE}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0,0} + Column("TABLE_SCHEMA", Varchar(NAME_LEN), NOT_NULL, "Table_schema"), + Column("TABLE_NAME", Varchar(NAME_LEN), NOT_NULL, "Table_name"), + Column("INDEX_NAME", Varchar(NAME_LEN), NOT_NULL, "Index_name"), + Column("ROWS_READ", SLonglong(), NOT_NULL, "Rows_read"), + CEnd() }; +} // namespace Show + static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) { TABLE *table= tables->table; @@ -25,7 +29,7 @@ static int index_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) tmp_table.db.length= strlen(index_stats->index); tmp_table.table_name.str= index_stats->index + tmp_table.db.length + 1; tmp_table.table_name.length= strlen(tmp_table.table_name.str); - tmp_table.grant.privilege= 0; + tmp_table.grant.privilege= NO_ACL; if (check_access(thd, SELECT_ACL, tmp_table.db.str, &tmp_table.grant.privilege, NULL, 0, 1) || check_grant(thd, SELECT_ACL, &tmp_table, 1, 1, 1)) @@ -63,7 +67,7 @@ static int index_stats_reset() static int index_stats_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= index_stats_fields; + schema->fields_info= Show::index_stats_fields; schema->fill_table= index_stats_fill; schema->reset_table= index_stats_reset; return 0; diff --git a/plugin/userstat/table_stats.cc b/plugin/userstat/table_stats.cc index f3150d81fa8..0a656793063 100644 --- a/plugin/userstat/table_stats.cc +++ b/plugin/userstat/table_stats.cc @@ -1,13 +1,17 @@ +namespace Show { + static ST_FIELD_INFO table_stats_fields[]= { - {"TABLE_SCHEMA", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_schema",SKIP_OPEN_TABLE}, - {"TABLE_NAME", NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Table_name",SKIP_OPEN_TABLE}, - {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read",SKIP_OPEN_TABLE}, - {"ROWS_CHANGED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_changed",SKIP_OPEN_TABLE}, - {"ROWS_CHANGED_X_INDEXES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_changed_x_#indexes",SKIP_OPEN_TABLE}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("TABLE_SCHEMA", Varchar(NAME_LEN), NOT_NULL, "Table_schema"), + Column("TABLE_NAME", Varchar(NAME_LEN), NOT_NULL, "Table_name"), + Column("ROWS_READ", SLonglong(), NOT_NULL, "Rows_read"), + Column("ROWS_CHANGED", SLonglong(), NOT_NULL, "Rows_changed"), + Column("ROWS_CHANGED_X_INDEXES",SLonglong(), NOT_NULL, "Rows_changed_x_#indexes"), + CEnd() }; +} // namespace Show + static int table_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) { TABLE *table= tables->table; @@ -30,7 +34,7 @@ static int table_stats_fill(THD *thd, TABLE_LIST *tables, COND *cond) tmp_table.db.length= schema_length; tmp_table.table_name.str= end_of_schema+1; tmp_table.table_name.length= table_name_length; - tmp_table.grant.privilege= 0; + tmp_table.grant.privilege= NO_ACL; if (check_access(thd, SELECT_ACL, tmp_table.db.str, &tmp_table.grant.privilege, NULL, 0, 1) || check_grant(thd, SELECT_ACL, &tmp_table, 1, 1, 1)) @@ -66,7 +70,7 @@ static int table_stats_reset() static int table_stats_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= table_stats_fields; + schema->fields_info= Show::table_stats_fields; schema->fill_table= table_stats_fill; schema->reset_table= table_stats_reset; return 0; diff --git a/plugin/userstat/user_stats.cc b/plugin/userstat/user_stats.cc index 12e2372e5cf..de3d4e12fb1 100644 --- a/plugin/userstat/user_stats.cc +++ b/plugin/userstat/user_stats.cc @@ -1,36 +1,40 @@ +namespace Show { + static ST_FIELD_INFO user_stats_fields[]= { - {"USER", USERNAME_CHAR_LENGTH, MYSQL_TYPE_STRING, 0, 0, "User", 0}, - {"TOTAL_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Total_connections", 0}, - {"CONCURRENT_CONNECTIONS", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Concurrent_connections", 0}, - {"CONNECTED_TIME", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Connected_time", 0}, - {"BUSY_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Busy_time", 0}, - {"CPU_TIME", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_DOUBLE, 0, 0, "Cpu_time", 0}, - {"BYTES_RECEIVED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_received", 0}, - {"BYTES_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Bytes_sent", 0}, - {"BINLOG_BYTES_WRITTEN", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Binlog_bytes_written", 0}, - {"ROWS_READ", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_read", 0}, - {"ROWS_SENT", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_sent", 0}, - {"ROWS_DELETED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_deleted", 0}, - {"ROWS_INSERTED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_inserted", 0}, - {"ROWS_UPDATED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rows_updated", 0}, - {"SELECT_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Select_commands", 0}, - {"UPDATE_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Update_commands", 0}, - {"OTHER_COMMANDS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Other_commands", 0}, - {"COMMIT_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Commit_transactions", 0}, - {"ROLLBACK_TRANSACTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Rollback_transactions", 0}, - {"DENIED_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Denied_connections", 0}, - {"LOST_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Lost_connections", 0}, - {"ACCESS_DENIED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Access_denied", 0}, - {"EMPTY_QUERIES", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Empty_queries", 0}, - {"TOTAL_SSL_CONNECTIONS", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, MY_I_S_UNSIGNED, "Total_ssl_connections", 0}, - {"MAX_STATEMENT_TIME_EXCEEDED", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, 0, 0, "Max_statement_time_exceeded",SKIP_OPEN_TABLE}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("USER",Varchar(USERNAME_CHAR_LENGTH),NOT_NULL, "User"), + Column("TOTAL_CONNECTIONS", SLong(), NOT_NULL, "Total_connections"), + Column("CONCURRENT_CONNECTIONS",SLong(), NOT_NULL, "Concurrent_connections"), + Column("CONNECTED_TIME", SLong(), NOT_NULL, "Connected_time"), + Column("BUSY_TIME", Double(MY_INT64_NUM_DECIMAL_DIGITS), NOT_NULL, "Busy_time"), + Column("CPU_TIME", Double(MY_INT64_NUM_DECIMAL_DIGITS), NOT_NULL, "Cpu_time"), + Column("BYTES_RECEIVED", SLonglong(), NOT_NULL, "Bytes_received"), + Column("BYTES_SENT", SLonglong(), NOT_NULL, "Bytes_sent"), + Column("BINLOG_BYTES_WRITTEN", SLonglong(), NOT_NULL, "Binlog_bytes_written"), + Column("ROWS_READ", SLonglong(), NOT_NULL, "Rows_read"), + Column("ROWS_SENT", SLonglong(), NOT_NULL, "Rows_sent"), + Column("ROWS_DELETED", SLonglong(), NOT_NULL, "Rows_deleted"), + Column("ROWS_INSERTED", SLonglong(), NOT_NULL, "Rows_inserted"), + Column("ROWS_UPDATED", SLonglong(), NOT_NULL, "Rows_updated"), + Column("SELECT_COMMANDS", SLonglong(), NOT_NULL, "Select_commands"), + Column("UPDATE_COMMANDS", SLonglong(), NOT_NULL, "Update_commands"), + Column("OTHER_COMMANDS", SLonglong(), NOT_NULL, "Other_commands"), + Column("COMMIT_TRANSACTIONS", SLonglong(), NOT_NULL, "Commit_transactions"), + Column("ROLLBACK_TRANSACTIONS",SLonglong(), NOT_NULL, "Rollback_transactions"), + Column("DENIED_CONNECTIONS", SLonglong(), NOT_NULL, "Denied_connections"), + Column("LOST_CONNECTIONS", SLonglong(), NOT_NULL, "Lost_connections"), + Column("ACCESS_DENIED", SLonglong(), NOT_NULL, "Access_denied"), + Column("EMPTY_QUERIES", SLonglong(), NOT_NULL, "Empty_queries"), + Column("TOTAL_SSL_CONNECTIONS",ULonglong(), NOT_NULL, "Total_ssl_connections"), + Column("MAX_STATEMENT_TIME_EXCEEDED",SLonglong(),NOT_NULL, "Max_statement_time_exceeded"), + CEnd() }; +} // namespace Show + static int user_stats_fill(THD* thd, TABLE_LIST* tables, COND* cond) { - if (check_global_access(thd, SUPER_ACL | PROCESS_ACL, true)) + if (check_global_access(thd, PROCESS_ACL, true)) return 0; return send_user_stats(thd, &global_user_stats, tables->table); @@ -48,7 +52,7 @@ static int user_stats_reset() static int user_stats_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= user_stats_fields; + schema->fields_info= Show::user_stats_fields; schema->fill_table= user_stats_fill; schema->reset_table= user_stats_reset; return 0; diff --git a/plugin/versioning/versioning.cc b/plugin/versioning/versioning.cc index fd0e7099666..6d8f77550f6 100644 --- a/plugin/versioning/versioning.cc +++ b/plugin/versioning/versioning.cc @@ -22,7 +22,8 @@ #include "sql_plugin.h" // st_plugin_int #include "sql_class.h" #include "item.h" -#include "vers_utils.h" +#include "table.h" +#include "vers_string.h" /* System Versioning: TRT_TRX_ID(), TRT_COMMIT_ID(), TRT_BEGIN_TS(), TRT_COMMIT_TS(), TRT_ISO_LEVEL() */ template <TR_table::field_id_t TRT_FIELD> diff --git a/plugin/wsrep_info/plugin.cc b/plugin/wsrep_info/plugin.cc index f78ecdcb68c..51eadc9d3cf 100644 --- a/plugin/wsrep_info/plugin.cc +++ b/plugin/wsrep_info/plugin.cc @@ -19,7 +19,7 @@ #include <my_global.h> #include <mysql/plugin.h> -#include <table.h> /* ST_SCHEMA_TABLE */ +#include <sql_i_s.h> /* ST_SCHEMA_TABLE */ #include <sql_show.h> #include <sql_acl.h> /* check_global_access() */ #include <wsrep_mysqld.h> @@ -55,35 +55,32 @@ /* Application protocol version */ #define COLUMN_WSREP_STATUS_PROTO_VERSION 7 +namespace Show { static ST_FIELD_INFO wsrep_memb_fields[]= { - {"INDEX", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, 0, 0, "Index", 0}, - {"UUID", WSREP_UUID_STR_LEN, MYSQL_TYPE_STRING, 0, 0, "Uuid", 0}, - {"NAME", WSREP_MEMBER_NAME_LEN, MYSQL_TYPE_STRING, 0, 0, "Name", 0}, - {"ADDRESS", WSREP_INCOMING_LEN, MYSQL_TYPE_STRING, 0, 0, "Address", 0}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("INDEX", SLong(), NOT_NULL, "Index"), + Column("UUID", Varchar(WSREP_UUID_STR_LEN), NOT_NULL, "Uuid"), + Column("NAME", Varchar(WSREP_MEMBER_NAME_LEN), NOT_NULL, "Name"), + Column("ADDRESS", Varchar(WSREP_INCOMING_LEN), NOT_NULL, "Address"), + CEnd() }; static ST_FIELD_INFO wsrep_status_fields[]= { - {"NODE_INDEX", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, - 0, 0, "Node_Index", 0}, - {"NODE_STATUS", 16, MYSQL_TYPE_STRING, 0, 0, "Node_Status", 0}, - {"CLUSTER_STATUS", 16, MYSQL_TYPE_STRING, 0, 0, "Cluster_Status", 0}, - {"CLUSTER_SIZE", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, - 0, 0, "Cluster_Size", 0}, - {"CLUSTER_STATE_UUID", WSREP_UUID_STR_LEN, MYSQL_TYPE_STRING, - 0, 0, 0, 0}, - {"CLUSTER_STATE_SEQNO", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, - 0, 0, 0, 0}, - {"CLUSTER_CONF_ID", MY_INT64_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONGLONG, - 0, 0, 0, 0}, - {"PROTOCOL_VERSION", MY_INT32_NUM_DECIMAL_DIGITS, MYSQL_TYPE_LONG, - 0, 0, 0, 0}, - {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, 0} + Column("NODE_INDEX", SLong(), NOT_NULL, "Node_Index"), + Column("NODE_STATUS", Varchar(16), NOT_NULL, "Node_Status"), + Column("CLUSTER_STATUS", Varchar(16), NOT_NULL, "Cluster_Status"), + Column("CLUSTER_SIZE", SLong(), NOT_NULL, "Cluster_Size"), + Column("CLUSTER_STATE_UUID", Varchar(WSREP_UUID_STR_LEN), NOT_NULL), + Column("CLUSTER_STATE_SEQNO", SLonglong(), NOT_NULL), + Column("CLUSTER_CONF_ID", SLonglong(), NOT_NULL), + Column("PROTOCOL_VERSION", SLong(), NOT_NULL), + CEnd() }; +} // namespace Show + static int wsrep_memb_fill_table(THD *thd, TABLE_LIST *tables, COND *cond) { int rc= 0; @@ -131,7 +128,7 @@ static int wsrep_memb_plugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= wsrep_memb_fields; + schema->fields_info= Show::wsrep_memb_fields; schema->fill_table= wsrep_memb_fill_table; return 0; @@ -189,7 +186,7 @@ static int wsrep_status_plugin_init(void *p) { ST_SCHEMA_TABLE *schema= (ST_SCHEMA_TABLE *)p; - schema->fields_info= wsrep_status_fields; + schema->fields_info= Show::wsrep_status_fields; schema->fill_table= wsrep_status_fill_table; return 0; |