Commit b8c31595 authored by Monty's avatar Monty Committed by Sergei Golubchik

MDEV-24285 support oracle build-in function: sys_guid

SYS_GUID() returns same as UUID(), but without any '-'

author: woqutech
parent be093c81
...@@ -1017,10 +1017,12 @@ int my_msync(int, void *, size_t, int); ...@@ -1017,10 +1017,12 @@ int my_msync(int, void *, size_t, int);
#define MY_UUID_SIZE 16 #define MY_UUID_SIZE 16
#define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12) #define MY_UUID_STRING_LENGTH (8+1+4+1+4+1+4+1+12)
#define MY_UUID_ORACLE_STRING_LENGTH (8+4+4+4+12)
void my_uuid_init(ulong seed1, ulong seed2); void my_uuid_init(ulong seed1, ulong seed2);
void my_uuid(uchar *guid); void my_uuid(uchar *guid);
void my_uuid2str(const uchar *guid, char *s); void my_uuid2str(const uchar *guid, char *s);
void my_uuid2str_oracle(const uchar *guid, char *s);
void my_uuid_end(void); void my_uuid_end(void);
const char *my_dlerror(const char *dlpath); const char *my_dlerror(const char *dlpath);
......
...@@ -23,6 +23,17 @@ hex(inet_aton('127.1.1')) ...@@ -23,6 +23,17 @@ hex(inet_aton('127.1.1'))
select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8''))); select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8'')));
length(uuid()) charset(uuid()) length(unhex(replace(uuid(),_utf8'-',_utf8''))) length(uuid()) charset(uuid()) length(unhex(replace(uuid(),_utf8'-',_utf8'')))
36 latin1 16 36 latin1 16
select length(sys_guid()) = length(uuid()) -2;
length(sys_guid()) = length(uuid()) -2
0
select sys_guid() != sys_guid();
sys_guid() != sys_guid()
1
explain extended select uuid() = "", sys_guid() = "";
id select_type table type possible_keys key key_len ref rows filtered Extra
1 SIMPLE NULL NULL NULL NULL NULL NULL NULL NULL No tables used
Warnings:
Note 1003 select uuid() = '' AS `uuid() = ""`,sys_guid() = '' AS `sys_guid() = ""`
set @a= uuid_short(); set @a= uuid_short();
set @b= uuid_short(); set @b= uuid_short();
select @b - @a; select @b - @a;
......
...@@ -19,6 +19,11 @@ select hex(inet_aton('127.1.1')); ...@@ -19,6 +19,11 @@ select hex(inet_aton('127.1.1'));
select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8''))); select length(uuid()), charset(uuid()), length(unhex(replace(uuid(),_utf8'-',_utf8'')));
select length(sys_guid()) = length(uuid()) -2;
select sys_guid() != sys_guid();
explain extended select uuid() = "", sys_guid() = "";
# As we can assume we are the only user for the mysqld server, the difference # As we can assume we are the only user for the mysqld server, the difference
# between two calls should be -1 # between two calls should be -1
set @a= uuid_short(); set @a= uuid_short();
......
...@@ -236,6 +236,17 @@ void my_uuid2str(const uchar *guid, char *s) ...@@ -236,6 +236,17 @@ void my_uuid2str(const uchar *guid, char *s)
} }
} }
void my_uuid2str_oracle(const uchar *guid, char *s)
{
int i;
for (i=0; i < MY_UUID_SIZE; i++)
{
*s++= _dig_vec_upper[guid[i] >>4];
*s++= _dig_vec_upper[guid[i] & 15];
}
}
void my_uuid_end() void my_uuid_end()
{ {
if (my_uuid_inited) if (my_uuid_inited)
......
...@@ -2234,6 +2234,17 @@ class Create_func_uuid : public Create_func_arg0 ...@@ -2234,6 +2234,17 @@ class Create_func_uuid : public Create_func_arg0
virtual ~Create_func_uuid() {} virtual ~Create_func_uuid() {}
}; };
class Create_func_sys_guid : public Create_func_arg0
{
public:
virtual Item *create_builder(THD *thd);
static Create_func_sys_guid s_singleton;
protected:
Create_func_sys_guid() {}
virtual ~Create_func_sys_guid() {}
};
class Create_func_uuid_short : public Create_func_arg0 class Create_func_uuid_short : public Create_func_arg0
{ {
...@@ -5229,7 +5240,18 @@ Create_func_uuid::create_builder(THD *thd) ...@@ -5229,7 +5240,18 @@ Create_func_uuid::create_builder(THD *thd)
DBUG_ENTER("Create_func_uuid::create"); DBUG_ENTER("Create_func_uuid::create");
thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION); thd->lex->set_stmt_unsafe(LEX::BINLOG_STMT_UNSAFE_SYSTEM_FUNCTION);
thd->lex->safe_to_cache_query= 0; thd->lex->safe_to_cache_query= 0;
DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd)); DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd, 0));
}
Create_func_sys_guid Create_func_sys_guid::s_singleton;
Item*
Create_func_sys_guid::create_builder(THD *thd)
{
DBUG_ENTER("Create_func_sys_guid::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(thd, 1));
} }
...@@ -5573,6 +5595,7 @@ static Native_func_registry func_array[] = ...@@ -5573,6 +5595,7 @@ static Native_func_registry func_array[] =
BUILDER(Create_func_substr_oracle)}, BUILDER(Create_func_substr_oracle)},
{ { STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)}, { { STRING_WITH_LEN("SUBSTRING_INDEX") }, BUILDER(Create_func_substr_index)},
{ { STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)}, { { STRING_WITH_LEN("SUBTIME") }, BUILDER(Create_func_subtime)},
{ { STRING_WITH_LEN("SYS_GUID") }, BUILDER(Create_func_sys_guid)},
{ { STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)}, { { STRING_WITH_LEN("TAN") }, BUILDER(Create_func_tan)},
{ { STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)}, { { STRING_WITH_LEN("TIMEDIFF") }, BUILDER(Create_func_timediff)},
{ { STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)}, { { STRING_WITH_LEN("TIME_FORMAT") }, BUILDER(Create_func_time_format)},
......
...@@ -4370,13 +4370,18 @@ String *Item_func_uuid::val_str(String *str) ...@@ -4370,13 +4370,18 @@ String *Item_func_uuid::val_str(String *str)
{ {
DBUG_ASSERT(fixed()); DBUG_ASSERT(fixed());
uchar guid[MY_UUID_SIZE]; uchar guid[MY_UUID_SIZE];
size_t length= (without_separators ?
MY_UUID_ORACLE_STRING_LENGTH :
MY_UUID_STRING_LENGTH);
str->alloc(MY_UUID_STRING_LENGTH+1); str->alloc(length+1);
str->length(MY_UUID_STRING_LENGTH); str->length(length);
str->set_charset(system_charset_info); str->set_charset(system_charset_info);
my_uuid(guid); my_uuid(guid);
my_uuid2str(guid, (char *)str->ptr()); if (without_separators)
my_uuid2str_oracle(guid, (char *)str->ptr());
else
my_uuid2str(guid, (char *)str->ptr());
return str; return str;
} }
......
...@@ -1998,20 +1998,26 @@ class Item_func_uncompress: public Item_str_binary_checksum_func ...@@ -1998,20 +1998,26 @@ class Item_func_uncompress: public Item_str_binary_checksum_func
class Item_func_uuid: public Item_str_func class Item_func_uuid: public Item_str_func
{ {
/* Set if uuid should be returned without separators (Oracle sys_guid) */
bool without_separators;
public: public:
Item_func_uuid(THD *thd): Item_str_func(thd) {} Item_func_uuid(THD *thd, bool without_separators_arg): Item_str_func(thd),
without_separators(without_separators_arg)
{}
bool fix_length_and_dec() override bool fix_length_and_dec() override
{ {
collation.set(DTCollation_numeric()); collation.set(DTCollation_numeric());
fix_char_length(MY_UUID_STRING_LENGTH); fix_char_length(without_separators ? MY_UUID_ORACLE_STRING_LENGTH :
MY_UUID_STRING_LENGTH);
return FALSE; return FALSE;
} }
bool const_item() const override { return false; } bool const_item() const override { return false; }
table_map used_tables() const override { return RAND_TABLE_BIT; } table_map used_tables() const override { return RAND_TABLE_BIT; }
LEX_CSTRING func_name_cstring() const override LEX_CSTRING func_name_cstring() const override
{ {
static LEX_CSTRING name= {STRING_WITH_LEN("uuid") }; static LEX_CSTRING mariadb_name= {STRING_WITH_LEN("uuid") };
return name; static LEX_CSTRING oracle_name= {STRING_WITH_LEN("sys_guid") };
return without_separators ? oracle_name : mariadb_name;
} }
String *val_str(String *) override; String *val_str(String *) override;
bool check_vcol_func_processor(void *arg) override bool check_vcol_func_processor(void *arg) override
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment