-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add uuid_version() to uuid type #4732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8888a59
91ebd3f
812b3c5
c6659e1
134d1af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # | ||
| # Start of 13.0 test | ||
| # | ||
| # | ||
| # MDEV-38983 Adding UUID_VERSION() | ||
| # | ||
| # | ||
| # UUIDv1 | ||
| # | ||
| SELECT UUID_VERSION(uuid()) AS version; | ||
| version | ||
| 1 | ||
| # | ||
| # UUIDv4 | ||
| # | ||
| SELECT UUID_VERSION(uuid_v4()) AS version; | ||
| version | ||
| 4 | ||
| # | ||
| # UUIDv7 | ||
| # | ||
| SELECT UUID_VERSION(uuid_v7()) AS version; | ||
| version | ||
| 7 | ||
| # | ||
| # UUIDv5 | ||
| # | ||
| SELECT UUID_VERSION("3e1f44c0-1c3d-535d-ac3f-5218a74bf2df") AS version; | ||
| version | ||
| 5 | ||
| # | ||
| # not valid with text | ||
| # | ||
| SELECT UUID_VERSION("lefred") AS version; | ||
| ERROR 22007: Incorrect uuid value: 'lefred' | ||
| # | ||
| # not valid with wrong uuid (version 8) | ||
| # | ||
| SELECT UUID_VERSION("AF39A01C-E29D-8C4C-8072-60CEB26A82F1") AS version; | ||
| ERROR 22007: Incorrect uuid value: 'AF39A01C-E29D-8C4C-8072-60CEB26A82F1' | ||
| # | ||
| # not valid with wrong uuid (version 9) | ||
| # | ||
| SELECT UUID_VERSION("AF39A01C-E29D-8C4C-8072-60CEB26A82F1") AS version; | ||
| ERROR 22007: Incorrect uuid value: 'AF39A01C-E29D-8C4C-8072-60CEB26A82F1' | ||
| # | ||
| # no argument | ||
| # | ||
| SELECT UUID_VERSION() AS version; | ||
| ERROR 42000: Incorrect parameter count in the call to native function 'UUID_VERSION' | ||
| # | ||
| # multiple arguments | ||
| # | ||
| SELECT UUID_VERSION(uuid(), 1) AS version; | ||
| ERROR 42000: Incorrect parameter count in the call to native function 'UUID_VERSION' | ||
| # | ||
| # use it in check constraint to force uuid_v1 | ||
| # | ||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 1)); | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| DROP TABLE t1; | ||
| # | ||
| # use it in check constraint to force uuid_v4 | ||
| # | ||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 4)); | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| DROP TABLE t1; | ||
| # | ||
| # use it in check constraint to force uuid_v7 | ||
| # | ||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 7)); | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| ERROR 23000: CONSTRAINT `t1.uuid` failed for `test`.`t1` | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| DROP TABLE t1; | ||
| End of 13.0 test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| --echo # | ||
| --echo # Start of 13.0 test | ||
| --echo # | ||
|
|
||
| --echo # | ||
| --echo # MDEV-38983 Adding UUID_VERSION() | ||
| --echo # | ||
|
|
||
| --echo # | ||
| --echo # UUIDv1 | ||
| --echo # | ||
| SELECT UUID_VERSION(uuid()) AS version; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv4 | ||
| --echo # | ||
| SELECT UUID_VERSION(uuid_v4()) AS version; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv7 | ||
| --echo # | ||
| SELECT UUID_VERSION(uuid_v7()) AS version; | ||
|
|
||
| --echo # | ||
| --echo # UUIDv5 | ||
| --echo # | ||
| SELECT UUID_VERSION("3e1f44c0-1c3d-535d-ac3f-5218a74bf2df") AS version; | ||
|
|
||
| --echo # | ||
| --echo # not valid with text | ||
| --echo # | ||
| --error ER_TRUNCATED_WRONG_VALUE | ||
| SELECT UUID_VERSION("lefred") AS version; | ||
|
|
||
| --echo # | ||
| --echo # not valid with wrong uuid (version 8) | ||
| --echo # | ||
| --error ER_TRUNCATED_WRONG_VALUE | ||
| SELECT UUID_VERSION("AF39A01C-E29D-8C4C-8072-60CEB26A82F1") AS version; | ||
|
|
||
| --echo # | ||
| --echo # not valid with wrong uuid (version 9) | ||
| --echo # | ||
| --error ER_TRUNCATED_WRONG_VALUE | ||
| SELECT UUID_VERSION("AF39A01C-E29D-8C4C-8072-60CEB26A82F1") AS version; | ||
|
|
||
| --echo # | ||
| --echo # no argument | ||
| --echo # | ||
| --error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT | ||
| SELECT UUID_VERSION() AS version; | ||
|
|
||
| --echo # | ||
| --echo # multiple arguments | ||
| --echo # | ||
| --error ER_WRONG_PARAMCOUNT_TO_NATIVE_FCT | ||
| SELECT UUID_VERSION(uuid(), 1) AS version; | ||
|
|
||
| --echo # | ||
| --echo # use it in check constraint to force uuid_v1 | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 1)); | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| DROP TABLE t1; | ||
|
|
||
| --echo # | ||
| --echo # use it in check constraint to force uuid_v4 | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 4)); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| DROP TABLE t1; | ||
|
|
||
| --echo # | ||
| --echo # use it in check constraint to force uuid_v7 | ||
| --echo # | ||
|
|
||
| CREATE TABLE t1 (uuid CHAR(36) PRIMARY KEY CHECK(uuid_version(uuid) = 7)); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID()); | ||
| --error ER_CONSTRAINT_FAILED | ||
| INSERT INTO t1 VALUES(UUID_v4()); | ||
| INSERT INTO t1 VALUES(UUID_v7()); | ||
| DROP TABLE t1; | ||
|
|
||
| --echo End of 13.0 test |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -180,16 +180,33 @@ class Create_func_uuid_v7 : public Create_func_arg0 | |
| virtual ~Create_func_uuid_v7() {} | ||
| }; | ||
|
|
||
| class Create_func_uuid_version : public Create_func_arg1 | ||
| { | ||
| public: | ||
| Item *create_1_arg(THD *thd, Item *arg1) override | ||
| { | ||
| DBUG_ENTER("Create_func_uuid_version::create_1_arg"); | ||
| DBUG_RETURN(new (thd->mem_root) Item_func_uuid_version(thd, arg1)); | ||
| } | ||
| static Create_func_uuid_version s_singleton; | ||
|
|
||
| protected: | ||
| Create_func_uuid_version() {} | ||
| virtual ~Create_func_uuid_version() {} | ||
| }; | ||
|
|
||
| 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; | ||
| Create_func_uuid_v7 Create_func_uuid_v7::s_singleton; | ||
| Create_func_uuid_version Create_func_uuid_version::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_uuid_v4(&Create_func_uuid_v4::s_singleton), | ||
| plugin_descriptor_function_uuid_v7(&Create_func_uuid_v7::s_singleton); | ||
| plugin_descriptor_function_uuid_v7(&Create_func_uuid_v7::s_singleton), | ||
| plugin_descriptor_function_uuid_version(&Create_func_uuid_version::s_singleton); | ||
|
|
||
| static constexpr Name type_name={STRING_WITH_LEN("uuid")}; | ||
|
|
||
|
|
@@ -301,5 +318,20 @@ maria_declare_plugin(type_uuid) | |
| NULL, // System variables | ||
| "1.0.1", // 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_version, // pointer to type-specific plugin descriptor | ||
| "uuid_version", // plugin name | ||
| "lefred", // plugin author | ||
| "Function UUID_VERSION()", // the plugin description | ||
| PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sigh, not your fault, but we should fix the fact that "GPL" isn't a license.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really know what to use there then?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave it for now, it needs to be addressed at a higher level. |
||
| 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_BETA // Maturity(see include/mysql/plugin.h)*/ | ||
| } | ||
| maria_declare_plugin_end; | ||
Uh oh!
There was an error while loading. Please reload this page.