Skip to content

Commit

Permalink
MDEV-4958 Adding datatype UUID
Browse files Browse the repository at this point in the history
  • Loading branch information
abarkov authored and vuvova committed Oct 29, 2021
1 parent 72fb37e commit 7ab11f2
Show file tree
Hide file tree
Showing 43 changed files with 5,334 additions and 99 deletions.
18 changes: 18 additions & 0 deletions plugin/type_uuid/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2019,2021, 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_uuid
plugin.cc sql_type_uuid.cc item_uuidfunc.cc
MANDATORY RECOMPILE_FOR_EMBEDDED)
43 changes: 43 additions & 0 deletions plugin/type_uuid/item_uuidfunc.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (c) 2019,2021, 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_uuidfunc.h"
#include "sql_type_uuid.h"

class UUID_generated : public UUIDBundle::Fbt
{
public:
UUID_generated() { my_uuid((uchar *) m_buffer); }
bool to_string(String *to, bool with_separators) const
{
if (to->alloc(max_char_length() + 1))
return true;
to->set_charset(system_charset_info);
to->length(MY_UUID_BARE_STRING_LENGTH + with_separators*MY_UUID_SEPARATORS);
my_uuid2str((const uchar *) m_buffer, (char *) to->ptr(), with_separators);
return false;
}
};

String *Item_func_uuid::val_str(String *str)
{
DBUG_ASSERT(fixed());
if (!UUID_generated().to_string(str, with_separators))
return str;
str->set("", 0, collation.collation);
return str;
}
52 changes: 52 additions & 0 deletions plugin/type_uuid/item_uuidfunc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef ITEM_UUIDFUNC_INCLUDED
#define ITEM_UUIDFUNC_INCLUDED

/* Copyright (c) 2019,2021, 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"

class Item_func_uuid: public Item_str_func
{
bool with_separators;
public:
Item_func_uuid(THD *thd, bool with_separators_arg):
Item_str_func(thd), with_separators(with_separators_arg) {}
bool fix_length_and_dec()
{
collation.set(DTCollation_numeric());
fix_char_length(with_separators ? MY_UUID_STRING_LENGTH
: MY_UUID_BARE_STRING_LENGTH);
return FALSE;
}
bool const_item() const { return false; }
table_map used_tables() const { return RAND_TABLE_BIT; }
LEX_CSTRING func_name_cstring() const override
{
static LEX_CSTRING name1= {STRING_WITH_LEN("uuid") };
static LEX_CSTRING name2= {STRING_WITH_LEN("sys_guid") };
return with_separators ? name1 : name2;
}
String *val_str(String *);
bool check_vcol_func_processor(void *arg)
{
return mark_unsupported_function(func_name(), "()", arg, VCOL_NON_DETERMINISTIC);
}
Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_uuid>(thd, this); }
};

#endif // ITEM_UUIDFUNC_INCLUDED
37 changes: 37 additions & 0 deletions plugin/type_uuid/mysql-test/type_uuid/binlog_stm_type_uuid.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# MDEV-4958 Adding datatype UUID
#
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000000');
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff');
PREPARE stmt FROM 'INSERT INTO t1 VALUES (?)';
EXECUTE stmt USING CAST('00000000-0000-0000-0000-000000000001' AS UUID);
EXECUTE stmt USING CAST(CONCAT(REPEAT(0x00,15), 0x02) AS UUID);
DEALLOCATE PREPARE stmt;
BEGIN NOT ATOMIC
DECLARE a UUID DEFAULT '00000000-0000-0000-0000-000000000003';
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 UUID)
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000000')
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff')
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000001')
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000002')
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # BEGIN GTID #-#-#
master-bin.000001 # Query # # use `test`; INSERT INTO t1 VALUES ( NAME_CONST('a','00000000-0000-0000-0000-000000000003'))
master-bin.000001 # Query # # COMMIT
master-bin.000001 # Gtid # # GTID #-#-#
master-bin.000001 # Query # # use `test`; DROP TABLE `t1` /* generated by server */
32 changes: 32 additions & 0 deletions plugin/type_uuid/mysql-test/type_uuid/binlog_stm_type_uuid.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
--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

--echo #
--echo # MDEV-4958 Adding datatype UUID
--echo #

CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES ('00000000-0000-0000-0000-000000000000');
INSERT INTO t1 VALUES ('ffffffff-ffff-ffff-ffff-ffffffffffff');

PREPARE stmt FROM 'INSERT INTO t1 VALUES (?)';
EXECUTE stmt USING CAST('00000000-0000-0000-0000-000000000001' AS UUID);
EXECUTE stmt USING CAST(CONCAT(REPEAT(0x00,15), 0x02) AS UUID);
DEALLOCATE PREPARE stmt;

DELIMITER $$;
BEGIN NOT ATOMIC
DECLARE a UUID DEFAULT '00000000-0000-0000-0000-000000000003';
INSERT INTO t1 VALUES (a);
END;
$$
DELIMITER ;$$

DROP TABLE t1;

--let $binlog_file = LAST
source include/show_binlog_events.inc;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# Start of 10.5 tests
#
#
# MDEV-4958 Adding datatype UUID
#
# Using DEFAULT_CHARSET format
RESET MASTER;
SET GLOBAL binlog_row_metadata = NO_LOG;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES('123e4567-e89b-12d3-a456-426655440000');
# Columns(BINARY(16))
DROP TABLE t1;
RESET MASTER;
RESET MASTER;
SET GLOBAL binlog_row_metadata = MINIMAL;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000');
# Columns(BINARY(16))
DROP TABLE t1;
RESET MASTER;
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000');
# 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 UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
# Columns(BINARY(16),
# BINARY(16),
# BINARY(48))
DROP TABLE t1;
RESET MASTER;
RESET MASTER;
SET GLOBAL binlog_row_metadata = MINIMAL;
CREATE TABLE t1 (a UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
# Columns(BINARY(16),
# CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci,
# CHAR(16) CHARSET utf8mb3 COLLATE utf8mb3_general_ci)
DROP TABLE t1;
RESET MASTER;
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
CREATE TABLE t1 (a UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
# Columns(`a` BINARY(16),
# `b` CHAR(16) CHARSET latin1 COLLATE latin1_swedish_ci,
# `c` CHAR(16) CHARSET utf8mb3 COLLATE utf8mb3_general_ci)
DROP TABLE t1;
RESET MASTER;
SET GLOBAL binlog_row_metadata = DEFAULT;
#
# End of 10.5 tests
#
Original file line number Diff line number Diff line change
@@ -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-4958 Adding datatype UUID
--echo #

--echo # Using DEFAULT_CHARSET format

RESET MASTER;
SET GLOBAL binlog_row_metadata = NO_LOG;
CREATE TABLE t1 (a UUID);
INSERT INTO t1 VALUES('123e4567-e89b-12d3-a456-426655440000');
--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 UUID);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000');
--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 UUID);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000');
--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 UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
--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 UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
--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 UUID, b CHAR(16) CHARACTER SET latin1, c CHAR(16) CHARACTER SET utf8);
INSERT INTO t1 VALUES('12334567-8888-9999-aaaa-000000000000','','');
--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 #
35 changes: 35 additions & 0 deletions plugin/type_uuid/mysql-test/type_uuid/func_uuid_plugin.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Start of 10.5 tests
#
#
# MDEV-4958 Adding datatype UUID
#
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
('uuid')
ORDER BY PLUGIN_NAME;
---- ----
PLUGIN_NAME uuid
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR MariaDB Corporation
PLUGIN_DESCRIPTION Function UUID()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Beta
PLUGIN_AUTH_VERSION 1.0
#
# End of 10.5 tests
#
30 changes: 30 additions & 0 deletions plugin/type_uuid/mysql-test/type_uuid/func_uuid_plugin.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--echo #
--echo # Start of 10.5 tests
--echo #

--echo #
--echo # MDEV-4958 Adding datatype UUID
--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
('uuid')
ORDER BY PLUGIN_NAME;
--horizontal_results

--echo #
--echo # End of 10.5 tests
--echo #
Loading

0 comments on commit 7ab11f2

Please sign in to comment.