Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
287589ce
Commit
287589ce
authored
11 months ago
by
StefanoPetrilli
Committed by
Sergei Golubchik
5 months ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
MDEV-11339 Implement native UUID4 function
parent
fe3432b3
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
266 additions
and
2 deletions
+266
-2
plugin/type_uuid/item_uuidfunc.cc
plugin/type_uuid/item_uuidfunc.cc
+28
-0
plugin/type_uuid/item_uuidfunc.h
plugin/type_uuid/item_uuidfunc.h
+15
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result
.../type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result
+35
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test
...in/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test
+30
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.result
.../type_uuid/mysql-test/type_uuid/func_uuidv4_random.result
+15
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test
...in/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test
+18
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.result
.../mysql-test/type_uuid/func_uuidv4_version_revision.result
+12
-0
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.test
...id/mysql-test/type_uuid/func_uuidv4_version_revision.test
+13
-0
plugin/type_uuid/plugin.cc
plugin/type_uuid/plugin.cc
+36
-2
plugin/type_uuid/sql_type_uuid.h
plugin/type_uuid/sql_type_uuid.h
+2
-0
plugin/type_uuid/sql_type_uuid_v4.h
plugin/type_uuid/sql_type_uuid_v4.h
+62
-0
No files found.
plugin/type_uuid/item_uuidfunc.cc
View file @
287589ce
...
...
@@ -29,3 +29,31 @@ String *Item_func_sys_guid::val_str(String *str)
my_uuid2str
(
buf
,
const_cast
<
char
*>
(
str
->
ptr
()),
0
);
return
str
;
}
String
*
Item_func_uuid_v4
::
val_str
(
String
*
str
)
{
DBUG_ASSERT
(
fixed
());
str
->
alloc
(
MY_UUID_STRING_LENGTH
+
1
);
str
->
length
(
MY_UUID_STRING_LENGTH
);
str
->
set_charset
(
collation
.
collation
);
uchar
buf
[
MY_UUID_SIZE
];
if
(
!
my_uuid_v4
(
buf
))
{
my_error
(
ER_INTERNAL_ERROR
,
MYF
(
0
),
"Failed to generate a random value for UUIDv4"
);
}
my_uuid2str
(
buf
,
const_cast
<
char
*>
(
str
->
ptr
()),
1
);
return
str
;
}
bool
Item_func_uuid_v4
::
val_native
(
THD
*
,
Native
*
to
)
{
DBUG_ASSERT
(
fixed
());
to
->
alloc
(
MY_UUID_SIZE
);
to
->
length
(
MY_UUID_SIZE
);
if
(
!
my_uuid_v4
((
uchar
*
)
to
->
ptr
()))
{
my_error
(
ER_INTERNAL_ERROR
,
MYF
(
0
),
"Failed to generate a random value for UUIDv4"
);
}
return
0
;
}
This diff is collapsed.
Click to expand it.
plugin/type_uuid/item_uuidfunc.h
View file @
287589ce
...
...
@@ -78,4 +78,19 @@ class Item_func_uuid: public Type_handler_uuid_new::Item_fbt_func
{
return
get_item_copy
<
Item_func_uuid
>
(
thd
,
this
);
}
};
class
Item_func_uuid_v4
:
public
Item_func_uuid
{
public:
Item_func_uuid_v4
(
THD
*
thd
)
:
Item_func_uuid
(
thd
)
{
}
LEX_CSTRING
func_name_cstring
()
const
override
{
static
LEX_CSTRING
name
=
{
STRING_WITH_LEN
(
"uuidv4"
)
};
return
name
;
}
String
*
val_str
(
String
*
)
override
;
bool
val_native
(
THD
*
thd
,
Native
*
to
)
override
;
Item
*
do_get_copy
(
THD
*
thd
)
const
override
{
return
get_item_copy
<
Item_func_uuid_v4
>
(
thd
,
this
);
}
};
#endif // ITEM_UUIDFUNC_INCLUDED
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result
0 → 100644
View file @
287589ce
#
# Start of 11.6 tests
#
#
# MDEV-11339 Support UUID v4 generation
#
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
('uuidv4')
ORDER BY PLUGIN_NAME;
---- ----
PLUGIN_NAME uuidv4
PLUGIN_VERSION 1.0
PLUGIN_STATUS ACTIVE
PLUGIN_TYPE FUNCTION
PLUGIN_AUTHOR Stefano Petrilli
PLUGIN_DESCRIPTION Function UUIDv4()
PLUGIN_LICENSE GPL
PLUGIN_MATURITY Experimental
PLUGIN_AUTH_VERSION 1.0
#
# End of 11.6 tests
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test
0 → 100644
View file @
287589ce
--
echo
#
--
echo
# Start of 11.6 tests
--
echo
#
--
echo
#
--
echo
# MDEV-11339 Support UUID v4 generation
--
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
(
'uuidv4'
)
ORDER
BY
PLUGIN_NAME
;
--
horizontal_results
--
echo
#
--
echo
# End of 11.6 tests
--
echo
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.result
0 → 100644
View file @
287589ce
#
# Start of 11.6 tests
#
#
# MDEV-11339 Support UUID v4 generation
#
CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv4(), unique key(u));
insert into t1(a) select seq from seq_1_to_100;
select count(distinct u) AS distinct_uuid_count from t1;
distinct_uuid_count
100
drop table t1;
#
# End of 11.6 tests
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test
0 → 100644
View file @
287589ce
source
include
/
have_sequence
.
inc
;
--
echo
#
--
echo
# Start of 11.6 tests
--
echo
#
--
echo
#
--
echo
# MDEV-11339 Support UUID v4 generation
--
echo
#
CREATE
TABLE
t1
(
a
int
primary
key
not
null
,
u
UUID
DEFAULT
UUIDv4
(),
unique
key
(
u
));
insert
into
t1
(
a
)
select
seq
from
seq_1_to_100
;
select
count
(
distinct
u
)
AS
distinct_uuid_count
from
t1
;
drop
table
t1
;
--
echo
#
--
echo
# End of 11.6 tests
--
echo
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.result
0 → 100644
View file @
287589ce
#
# Start of 11.6 tests
#
#
# MDEV-11339 Support UUID v4 generation
#
SELECT UUIDv4() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision;
is_correct_version_and_revision
1
#
# End of 11.6 tests
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.test
0 → 100644
View file @
287589ce
--
echo
#
--
echo
# Start of 11.6 tests
--
echo
#
--
echo
#
--
echo
# MDEV-11339 Support UUID v4 generation
--
echo
#
SELECT
UUIDv4
()
REGEXP
'[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}'
AS
is_correct_version_and_revision
;
--
echo
#
--
echo
# End of 11.6 tests
--
echo
#
This diff is collapsed.
Click to expand it.
plugin/type_uuid/plugin.cc
View file @
287589ce
...
...
@@ -144,12 +144,31 @@ class Create_func_sys_guid : public Create_func_arg0
virtual
~
Create_func_sys_guid
()
{}
};
class
Create_func_uuid_v4
:
public
Create_func_arg0
{
public:
Item
*
create_builder
(
THD
*
thd
)
override
{
DBUG_ENTER
(
"Create_func_uuid_v4::create"
);
thd
->
lex
->
set_stmt_unsafe
(
LEX
::
BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION
);
thd
->
lex
->
safe_to_cache_query
=
0
;
DBUG_RETURN
(
new
(
thd
->
mem_root
)
Item_func_uuid_v4
(
thd
));
}
static
Create_func_uuid_v4
s_singleton
;
protected:
Create_func_uuid_v4
()
{}
virtual
~
Create_func_uuid_v4
()
{}
};
Create_func_uuid
Create_func_uuid
::
s_singleton
;
Create_func_sys_guid
Create_func_sys_guid
::
s_singleton
;
Create_func_uuid_v4
Create_func_uuid_v4
::
s_singleton
;
static
Plugin_function
plugin_descriptor_function_uuid
(
&
Create_func_uuid
::
s_singleton
),
plugin_descriptor_function_sys_guid
(
&
Create_func_sys_guid
::
s_singleton
);
plugin_descriptor_function_sys_guid
(
&
Create_func_sys_guid
::
s_singleton
),
plugin_descriptor_function_uuid_v4
(
&
Create_func_uuid_v4
::
s_singleton
);
static
constexpr
Name
type_name
=
{
STRING_WITH_LEN
(
"uuid"
)};
...
...
@@ -207,5 +226,20 @@ maria_declare_plugin(type_uuid)
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_uuid_v4
,
// pointer to type-specific plugin descriptor
"uuidv4"
,
// plugin name
"Stefano Petrilli"
,
// plugin author
"Function UUIDv4()"
,
// 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
;
maria_declare_plugin_end
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugin/type_uuid/sql_type_uuid.h
View file @
287589ce
...
...
@@ -347,5 +347,7 @@ class UUIDv1: public Type_handler_uuid_new::Fbt
}
};
#include "sql_type_uuid_v4.h"
#endif // SQL_TYPE_UUID_INCLUDED
This diff is collapsed.
Click to expand it.
plugin/type_uuid/sql_type_uuid_v4.h
0 → 100644
View file @
287589ce
#ifndef SQL_TYPE_UUID_V4_INCLUDED
#define SQL_TYPE_UUID_V4_INCLUDED
/* Copyright (c) 2024, Stefano Petrilli
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 */
/*
Implements Universal Unique Identifiers version 4, as described in
draft-ietf-uuidrev-rfc4122bis-14.
Field Octet # Note
random_a 0-5 Random CSPRNG 48 bits.
ver 6 The 4 bit version field, set to
0b0100. Occupies bits 48 through 51 of
octet 6.
random_b 6-7 Random CSPRNG 12 bits.
var 8 The 2 bit variant field, set to 0b10.
Occupies bits 64 and 65 of octet 8.
random_c 8-15 Random CSPRNG 62 bits.
The structure of an UUIDv4 is: llllllll-mmmm-Vhhh-vsss-nnnnnnnnnnnn
The replacement of the version and variant field bits results in 122
bits of random data.
*/
#include "my_rnd.h"
#define UUID_VERSION 0x40
#define UUID_VERSION_MASK 0x0F
#define UUID_VARIANT 0x80
#define UUID_VARIANT_MASK 0x3F
/**
Create a global unique identifier version 4 (uuidv4)
@func my_uuid_v4()
@param to Store uuidv4 here. Must be of size MY_UUID_SIZE (16)
@return 1 in case of success and 0 in case of failure
*/
static
inline
bool
my_uuid_v4
(
uchar
*
to
)
{
if
(
my_random_bytes
(
to
,
16
)
!=
MY_AES_OK
)
return
0
;
to
[
6
]
=
((
to
[
6
]
&
UUID_VERSION_MASK
)
|
UUID_VERSION
);
to
[
8
]
=
((
to
[
8
]
&
UUID_VARIANT_MASK
)
|
UUID_VARIANT
);
return
1
;
}
#endif // SQL_TYPE_UUID_V4_INCLUDED
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment