summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2021-09-14 12:08:01 +0200
committerSergei Golubchik <serg@mariadb.org>2021-09-14 12:08:01 +0200
commitf4b4b58edcb760dabe89ce6cc5d4c0c727602810 (patch)
tree858c95940c71fcfc8d03dea8fb68750e9d17885d
parent1a2397a9d73dfd562df6dde45b120789c7f8e1ff (diff)
downloadmariadb-git-preview-10.7-MDEV-4958-uuid_triggerBB.tar.gz
UUID() function should return UUID, not VARCHAR(36)preview-10.7-MDEV-4958-uuid_triggerBB
-rw-r--r--mysql-test/main/func_misc.result5
-rw-r--r--mysql-test/main/func_misc.test1
-rw-r--r--plugin/type_uuid/item_uuidfunc.cc41
-rw-r--r--plugin/type_uuid/item_uuidfunc.h35
-rw-r--r--plugin/type_uuid/plugin.cc4
5 files changed, 54 insertions, 32 deletions
diff --git a/mysql-test/main/func_misc.result b/mysql-test/main/func_misc.result
index b2c08989854..7597da95f3d 100644
--- a/mysql-test/main/func_misc.result
+++ b/mysql-test/main/func_misc.result
@@ -118,9 +118,12 @@ create table t1 as select uuid(), length(uuid());
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
- `uuid()` varchar(36) DEFAULT NULL,
+ `uuid()` uuid DEFAULT NULL,
`length(uuid())` int(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
+select length(`uuid()`) from t1;
+length(`uuid()`)
+36
drop table t1;
create table t1 select INET_ATON('255.255.0.1') as `a`;
show create table t1;
diff --git a/mysql-test/main/func_misc.test b/mysql-test/main/func_misc.test
index 56e7a996f94..5e8118d4cef 100644
--- a/mysql-test/main/func_misc.test
+++ b/mysql-test/main/func_misc.test
@@ -106,6 +106,7 @@ select export_set(3, _latin1'foo', _utf8'bar', ',', 4);
create table t1 as select uuid(), length(uuid());
--enable_warnings
show create table t1;
+select length(`uuid()`) from t1;
drop table t1;
#
diff --git a/plugin/type_uuid/item_uuidfunc.cc b/plugin/type_uuid/item_uuidfunc.cc
index 0c79cbbd5b8..725b696f905 100644
--- a/plugin/type_uuid/item_uuidfunc.cc
+++ b/plugin/type_uuid/item_uuidfunc.cc
@@ -18,26 +18,29 @@
#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)
+String *Item_func_sys_guid::val_str(String *str)
{
DBUG_ASSERT(fixed());
- if (!UUID_generated().to_string(str, with_separators))
- return str;
- str->set("", 0, collation.collation);
+ str->alloc(uuid_len()+1);
+ str->length(uuid_len());
+ str->set_charset(collation.collation);
+
+ uchar buf[MY_UUID_SIZE];
+ my_uuid(buf);
+ my_uuid2str(buf, const_cast<char*>(str->ptr()), with_dashes);
return str;
}
+
+const Type_handler *Item_func_uuid::type_handler() const
+{
+ return UUIDBundle::type_handler_fbt();
+}
+
+bool Item_func_uuid::val_native(THD *, Native *to)
+{
+ DBUG_ASSERT(fixed());
+ to->alloc(MY_UUID_SIZE);
+ to->length(MY_UUID_SIZE);
+ my_uuid((uchar*)to->ptr());
+ return 0;
+}
diff --git a/plugin/type_uuid/item_uuidfunc.h b/plugin/type_uuid/item_uuidfunc.h
index 3756d70ba3d..add4f202784 100644
--- a/plugin/type_uuid/item_uuidfunc.h
+++ b/plugin/type_uuid/item_uuidfunc.h
@@ -19,33 +19,48 @@
#include "item.h"
-class Item_func_uuid: public Item_str_func
+class Item_func_sys_guid: public Item_str_func
{
- bool with_separators;
+protected:
+ bool with_dashes;
+ size_t uuid_len() const
+ { return MY_UUID_BARE_STRING_LENGTH + with_dashes*MY_UUID_SEPARATORS; }
public:
- Item_func_uuid(THD *thd, bool with_separators_arg):
- Item_str_func(thd), with_separators(with_separators_arg) {}
+ Item_func_sys_guid(THD *thd): Item_str_func(thd), with_dashes(false) {}
bool fix_length_and_dec()
{
collation.set(DTCollation_numeric());
- fix_char_length(with_separators ? MY_UUID_STRING_LENGTH
- : MY_UUID_BARE_STRING_LENGTH);
+ fix_char_length(uuid_len());
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;
+ static LEX_CSTRING name= {STRING_WITH_LEN("sys_guid") };
+ return name;
}
- String *val_str(String *);
+ String *val_str(String *) override;
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_sys_guid>(thd, this); }
+};
+
+class Item_func_uuid: public Item_func_sys_guid
+{
+public:
+ Item_func_uuid(THD *thd): Item_func_sys_guid(thd) { with_dashes= true; }
+ const Type_handler *type_handler() const override;
+ LEX_CSTRING func_name_cstring() const override
+ {
+ static LEX_CSTRING name= {STRING_WITH_LEN("uuid") };
+ return name;
+ }
+ bool val_native(THD *thd, Native *to) override;
+ Item *get_copy(THD *thd)
{ return get_item_copy<Item_func_uuid>(thd, this); }
};
diff --git a/plugin/type_uuid/plugin.cc b/plugin/type_uuid/plugin.cc
index ae511b95456..6e7df8897fb 100644
--- a/plugin/type_uuid/plugin.cc
+++ b/plugin/type_uuid/plugin.cc
@@ -37,7 +37,7 @@ public:
DBUG_ENTER("Create_func_uuid::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, true));
+ DBUG_RETURN(new (thd->mem_root) Item_func_uuid(thd));
}
static Create_func_uuid s_singleton;
@@ -55,7 +55,7 @@ public:
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, false));
+ DBUG_RETURN(new (thd->mem_root) Item_func_sys_guid(thd));
}
static Create_func_sys_guid s_singleton;