diff --git a/mysys/my_init.c b/mysys/my_init.c index 206abcbc2b1..1dd2e6e8100 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -469,8 +469,7 @@ PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, key_THR_LOCK_lock, key_THR_LOCK_malloc, key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, key_THR_LOCK_open, key_THR_LOCK_threads, - key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_uuid_generator, - key_LOCK_uuid_v7_generator; + key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_uuid_generator; static PSI_mutex_info all_mysys_mutexes[]= { @@ -497,8 +496,7 @@ static PSI_mutex_info all_mysys_mutexes[]= { &key_THR_LOCK_threads, "THR_LOCK_threads", PSI_FLAG_GLOBAL}, { &key_TMPDIR_mutex, "TMPDIR_mutex", PSI_FLAG_GLOBAL}, { &key_THR_LOCK_myisam_mmap, "THR_LOCK_myisam_mmap", PSI_FLAG_GLOBAL}, - { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL }, - { &key_LOCK_uuid_v7_generator, "LOCK_uuid_v7_generator", PSI_FLAG_GLOBAL } + { &key_LOCK_uuid_generator, "LOCK_uuid_generator", PSI_FLAG_GLOBAL } }; PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond, diff --git a/mysys/mysys_priv.h b/mysys/mysys_priv.h index 579d1c2aa04..efeb0c65af3 100644 --- a/mysys/mysys_priv.h +++ b/mysys/mysys_priv.h @@ -48,8 +48,7 @@ extern PSI_mutex_key key_BITMAP_mutex, key_IO_CACHE_append_buffer_lock, key_THR_LOCK_lock, key_THR_LOCK_malloc, key_THR_LOCK_mutex, key_THR_LOCK_myisam, key_THR_LOCK_net, key_THR_LOCK_open, key_THR_LOCK_threads, key_LOCK_uuid_generator, - key_LOCK_uuid_v7_generator, key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, - key_LOCK_timer; + key_TMPDIR_mutex, key_THR_LOCK_myisam_mmap, key_LOCK_timer; extern PSI_cond_key key_COND_timer, key_IO_CACHE_SHARE_cond, key_IO_CACHE_SHARE_cond_writer, key_my_thread_var_suspend, diff --git a/mysys_ssl/my_crypt.cc b/mysys_ssl/my_crypt.cc index 0356b64ccfb..346eff51b1b 100644 --- a/mysys_ssl/my_crypt.cc +++ b/mysys_ssl/my_crypt.cc @@ -27,7 +27,8 @@ #include #include -#include + +#include #define CTX_ALIGN 16 @@ -359,10 +360,25 @@ unsigned int my_aes_ctx_size(enum my_aes_mode) return MY_AES_CTX_SIZE; } +static std::mt19937 rnd; + int my_random_bytes(uchar *buf, int num) { if (RAND_bytes(buf, num) != 1) + { /* shouldn't happen */ + uchar *end= buf + num - 3; + uint r= rnd(); + for (; buf < end; buf+= 4, r= rnd()) + int4store(buf, r); + switch (num % 4) + { + case 0: break; + case 1: *buf= rnd(); break; + case 2: r=rnd(); int2store(buf, r); break; + case 3: r=rnd(); int3store(buf, r); break; + } return MY_AES_OPENSSL_ERROR; + } return MY_AES_OK; } diff --git a/plugin/type_uuid/item_uuidfunc.h b/plugin/type_uuid/item_uuidfunc.h index f01b2a54678..5de03746a3a 100644 --- a/plugin/type_uuid/item_uuidfunc.h +++ b/plugin/type_uuid/item_uuidfunc.h @@ -96,7 +96,7 @@ public: using Item_func_uuid_vx::Item_func_uuid_vx; LEX_CSTRING func_name_cstring() const override { - static LEX_CSTRING name= {STRING_WITH_LEN("uuidv4") }; + static LEX_CSTRING name= {STRING_WITH_LEN("uuid_v4") }; return name; } Item *do_get_copy(THD *thd) const override @@ -109,7 +109,7 @@ public: using Item_func_uuid_vx::Item_func_uuid_vx; LEX_CSTRING func_name_cstring() const override { - static LEX_CSTRING name= {STRING_WITH_LEN("uuidv7") }; + static LEX_CSTRING name= {STRING_WITH_LEN("uuid_v7") }; return name; } Item *do_get_copy(THD *thd) const override diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.result index 3bd22a20734..2c4b6188105 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.result @@ -1,10 +1,10 @@ # # MDEV-33827 UUID() returns a NULL-able result # -CREATE TABLE t1 AS SELECT UUIDv4(); +CREATE TABLE t1 AS SELECT UUID_v4(); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `UUIDv4()` uuid NOT NULL + `UUID_v4()` uuid NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.test index 734936388c4..8f725ee4c2d 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4.test @@ -2,6 +2,6 @@ --echo # MDEV-33827 UUID() returns a NULL-able result --echo # -CREATE TABLE t1 AS SELECT UUIDv4(); +CREATE TABLE t1 AS SELECT UUID_v4(); SHOW CREATE TABLE t1; DROP TABLE t1; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.result new file mode 100644 index 00000000000..6228adf3338 --- /dev/null +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.result @@ -0,0 +1,39 @@ +SET debug_dbug="+d,simulate_uuidv4_my_random_bytes_failure"; +# +# MDEV-11339 Support UUID v4 generation +# +CREATE TABLE t1 ( +a int primary key not null, +u UUID DEFAULT UUID_v4(), +unique key(u) +); +INSERT INTO t1(a) SELECT seq FROM seq_1_to_16; +Warnings: +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v4: RANDOM_BYTES() failed, using fallback +SELECT COUNT(DISTINCT u) AS distinct_uuid_count FROM t1; +distinct_uuid_count +16 +SELECT +u 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, +COUNT(*) +FROM t1 GROUP BY is_correct_version_and_revision; +is_correct_version_and_revision COUNT(*) +1 16 +DROP TABLE t1; +# End of 11.7 tests +SET debug_dbug=""; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.test similarity index 83% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.test index ebd9ce72bb3..03ee7957d1f 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_debug.test @@ -4,17 +4,13 @@ SET debug_dbug="+d,simulate_uuidv4_my_random_bytes_failure"; 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(), + u UUID DEFAULT UUID_v4(), unique key(u) ); INSERT INTO t1(a) SELECT seq FROM seq_1_to_16; @@ -25,8 +21,6 @@ SELECT FROM t1 GROUP BY is_correct_version_and_revision; DROP TABLE t1; ---echo # ---echo # End of 11.6 tests ---echo # +--echo # End of 11.7 tests SET debug_dbug=""; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.result similarity index 80% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.result index 51e935c02c7..5faeef70c33 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.result @@ -1,7 +1,4 @@ # -# Start of 11.6 tests -# -# # MDEV-11339 Support UUID v4 generation # SELECT @@ -18,18 +15,16 @@ PLUGIN_AUTH_VERSION FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_TYPE='FUNCTION' AND PLUGIN_NAME IN -('uuidv4') +('uuid_v4') ORDER BY PLUGIN_NAME; ---- ---- -PLUGIN_NAME uuidv4 +PLUGIN_NAME uuid_v4 PLUGIN_VERSION 1.0 PLUGIN_STATUS ACTIVE PLUGIN_TYPE FUNCTION PLUGIN_AUTHOR Stefano Petrilli -PLUGIN_DESCRIPTION Function UUIDv4() +PLUGIN_DESCRIPTION Function UUID_v4() PLUGIN_LICENSE GPL PLUGIN_MATURITY Experimental PLUGIN_AUTH_VERSION 1.0 -# -# End of 11.6 tests -# +# End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.test similarity index 78% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.test index 1e2209f19d9..51c4d3608f5 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_plugin.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_plugin.test @@ -1,7 +1,3 @@ ---echo # ---echo # Start of 11.6 tests ---echo # - --echo # --echo # MDEV-11339 Support UUID v4 generation --echo # @@ -21,10 +17,8 @@ SELECT FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_TYPE='FUNCTION' AND PLUGIN_NAME IN - ('uuidv4') + ('uuid_v4') ORDER BY PLUGIN_NAME; --horizontal_results ---echo # ---echo # End of 11.6 tests ---echo # +--echo # End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.result similarity index 77% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.result rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.result index d6b3bc7ad59..2cdcaf3d2d8 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.result @@ -1,15 +1,10 @@ # -# 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)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v4(), 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 -# +# End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.test similarity index 71% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.test index 67687a3e4e5..690a14fffab 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_random.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_random.test @@ -1,18 +1,12 @@ 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)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v4(), 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 # +--echo # End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.result new file mode 100644 index 00000000000..ef2428f3dbd --- /dev/null +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.result @@ -0,0 +1,7 @@ +# +# MDEV-11339 Support UUID v4 generation +# +SELECT UUID_v4() 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.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.test new file mode 100644 index 00000000000..29168a3e6b1 --- /dev/null +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v4_version_revision.test @@ -0,0 +1,7 @@ +--echo # +--echo # MDEV-11339 Support UUID v4 generation +--echo # + +SELECT UUID_v4() 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 # End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.result index ae8392cd786..92d767542fe 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.result @@ -1,10 +1,10 @@ # # MDEV-33827 UUID() returns a NULL-able result # -CREATE TABLE t1 AS SELECT UUIDv7(); +CREATE TABLE t1 AS SELECT UUID_v7(); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE `t1` ( - `UUIDv7()` uuid NOT NULL + `UUID_v7()` uuid NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DROP TABLE t1; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.test index f50310a1f7e..a571deed4e8 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7.test @@ -2,6 +2,6 @@ --echo # MDEV-33827 UUID() returns a NULL-able result --echo # -CREATE TABLE t1 AS SELECT UUIDv7(); +CREATE TABLE t1 AS SELECT UUID_v7(); SHOW CREATE TABLE t1; DROP TABLE t1; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.result new file mode 100644 index 00000000000..5d32374115c --- /dev/null +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.result @@ -0,0 +1,44 @@ +SET debug_dbug="+d,simulate_uuidv7_my_random_bytes_failure"; +# +# Start of 11.7 tests +# +# +# MDEV-32637 Implement native UUID7 function +# +CREATE TABLE t1 ( +a int primary key not null, +u UUID DEFAULT UUID_v7(), +unique key(u) +); +INSERT INTO t1(a) SELECT seq FROM seq_1_to_16; +Warnings: +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +Note 1105 UUID_v7: RANDOM_BYTES() failed, using fallback +SELECT COUNT(DISTINCT u) AS distinct_uuid_count FROM t1; +distinct_uuid_count +16 +SELECT +u REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision, +COUNT(*) +FROM t1 GROUP BY is_correct_version_and_revision; +is_correct_version_and_revision COUNT(*) +1 16 +DROP TABLE t1; +# +# End of 11.7 tests +# +SET debug_dbug=""; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.test similarity index 96% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.test index 125bf0f22b9..8eccc606483 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_debug.test @@ -14,7 +14,7 @@ source include/have_sequence.inc; CREATE TABLE t1 ( a int primary key not null, - u UUID DEFAULT UUIDv7(), + u UUID DEFAULT UUID_v7(), unique key(u) ); INSERT INTO t1(a) SELECT seq FROM seq_1_to_16; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.result similarity index 88% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.result rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.result index 0c34860f4af..d5f165368aa 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.result @@ -18,15 +18,15 @@ PLUGIN_AUTH_VERSION FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_TYPE='FUNCTION' AND PLUGIN_NAME IN -('uuidv7') +('uuid_v7') ORDER BY PLUGIN_NAME; ---- ---- -PLUGIN_NAME uuidv7 +PLUGIN_NAME uuid_v7 PLUGIN_VERSION 1.0 PLUGIN_STATUS ACTIVE PLUGIN_TYPE FUNCTION PLUGIN_AUTHOR Stefano Petrilli -PLUGIN_DESCRIPTION Function UUIDv7() +PLUGIN_DESCRIPTION Function UUID_v7() PLUGIN_LICENSE GPL PLUGIN_MATURITY Experimental PLUGIN_AUTH_VERSION 1.0 diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.test similarity index 96% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.test index 21b640eb9cb..821ad48bfd7 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_plugin.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_plugin.test @@ -21,7 +21,7 @@ SELECT FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_TYPE='FUNCTION' AND PLUGIN_NAME IN - ('uuidv7') + ('uuid_v7') ORDER BY PLUGIN_NAME; --horizontal_results diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.result similarity index 93% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.result rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.result index 803b41f7732..7d48208a6f3 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.result @@ -4,7 +4,7 @@ # # MDEV-32637 Implement native UUID7 function # -CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv7(), unique key(u)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v7(), 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 diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.test similarity index 94% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.test index de07a42abef..d6eb4895f76 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_random.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_random.test @@ -8,7 +8,7 @@ source include/have_sequence.inc; --echo # MDEV-32637 Implement native UUID7 function --echo # -CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv7(), unique key(u)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v7(), 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; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.result similarity index 50% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.result rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.result index 948e472bf9a..654f964beb5 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.result +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.result @@ -4,7 +4,7 @@ # # MDEV-32637 Implement native UUID7 function # -SELECT UUIDv7() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision; +SELECT UUID_v7() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[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 # diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.test similarity index 55% rename from plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.test rename to plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.test index 078d22bcf2d..d4a18ba2654 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_version_revision.test +++ b/plugin/type_uuid/mysql-test/type_uuid/func_uuid_v7_version_revision.test @@ -6,7 +6,7 @@ --echo # MDEV-32637 Implement native UUID7 function --echo # -SELECT UUIDv7() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision; +SELECT UUID_v7() REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision; --echo # --echo # End of 11.7 tests diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.result deleted file mode 100644 index 9975e8c3358..00000000000 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_debug.result +++ /dev/null @@ -1,44 +0,0 @@ -SET debug_dbug="+d,simulate_uuidv4_my_random_bytes_failure"; -# -# 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_16; -Warnings: -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -Note 1105 UUIDv4 generation failed; using a my_rnd fallback -SELECT COUNT(DISTINCT u) AS distinct_uuid_count FROM t1; -distinct_uuid_count -16 -SELECT -u 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, -COUNT(*) -FROM t1 GROUP BY is_correct_version_and_revision; -is_correct_version_and_revision COUNT(*) -1 16 -DROP TABLE t1; -# -# End of 11.6 tests -# -SET debug_dbug=""; diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.result deleted file mode 100644 index 075704b7e00..00000000000 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.result +++ /dev/null @@ -1,12 +0,0 @@ -# -# 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 -# diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.test b/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.test deleted file mode 100644 index f977578b1ce..00000000000 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv4_version_revision.test +++ /dev/null @@ -1,13 +0,0 @@ ---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 # diff --git a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.result b/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.result deleted file mode 100644 index 534c836e8ef..00000000000 --- a/plugin/type_uuid/mysql-test/type_uuid/func_uuidv7_debug.result +++ /dev/null @@ -1,44 +0,0 @@ -SET debug_dbug="+d,simulate_uuidv7_my_random_bytes_failure"; -# -# Start of 11.7 tests -# -# -# MDEV-32637 Implement native UUID7 function -# -CREATE TABLE t1 ( -a int primary key not null, -u UUID DEFAULT UUIDv7(), -unique key(u) -); -INSERT INTO t1(a) SELECT seq FROM seq_1_to_16; -Warnings: -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -Note 1105 UUIDv7 generation failed; using a my_rnd fallback -SELECT COUNT(DISTINCT u) AS distinct_uuid_count FROM t1; -distinct_uuid_count -16 -SELECT -u REGEXP '[a-f0-9]{8}-[a-f0-9]{4}-7[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}' AS is_correct_version_and_revision, -COUNT(*) -FROM t1 GROUP BY is_correct_version_and_revision; -is_correct_version_and_revision COUNT(*) -1 16 -DROP TABLE t1; -# -# End of 11.7 tests -# -SET debug_dbug=""; diff --git a/plugin/type_uuid/mysql-test/type_uuid/order.result b/plugin/type_uuid/mysql-test/type_uuid/order.result index 922a24cf618..f89aa256cfa 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/order.result +++ b/plugin/type_uuid/mysql-test/type_uuid/order.result @@ -834,7 +834,7 @@ drop table t1; # # MDEV-32637 Implement native UUID7 function # -CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv7(), unique key(u)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v7(), unique key(u)); insert into t1(a) select seq from seq_1_to_10; select a from t1 order by u asc; a diff --git a/plugin/type_uuid/mysql-test/type_uuid/order.test b/plugin/type_uuid/mysql-test/type_uuid/order.test index 446d73b840b..9cdac8b6194 100644 --- a/plugin/type_uuid/mysql-test/type_uuid/order.test +++ b/plugin/type_uuid/mysql-test/type_uuid/order.test @@ -67,7 +67,7 @@ drop table t1; # Verify that UUIDv7 are time-ordered and unique -CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUIDv7(), unique key(u)); +CREATE TABLE t1 (a int primary key not null, u UUID DEFAULT UUID_v7(), unique key(u)); insert into t1(a) select seq from seq_1_to_10; select a from t1 order by u asc; drop table t1; diff --git a/mysql-test/suite/rpl/r/rpl_row_UUIDv7.result b/plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.result similarity index 77% rename from mysql-test/suite/rpl/r/rpl_row_UUIDv7.result rename to plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.result index 025b6038b8d..834b0166b4a 100644 --- a/mysql-test/suite/rpl/r/rpl_row_UUIDv7.result +++ b/plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.result @@ -5,18 +5,18 @@ include/master-slave.inc # connection master; CREATE TABLE test.t1 (a INT, blob_column LONGBLOB, vchar_column VARCHAR(100), PRIMARY KEY(a)) engine=myisam; -INSERT INTO test.t1 VALUES(1,UUIDv7(),UUIDv7()); +INSERT INTO test.t1 VALUES(1,UUID_v7(),UUID_v7()); create procedure test.p1() begin -INSERT INTO test.t1 VALUES(2,UUIDv7(),UUIDv7()); -INSERT INTO test.t1 VALUES(3,UUIDv7(),UUIDv7()); +INSERT INTO test.t1 VALUES(2,UUID_v7(),UUID_v7()); +INSERT INTO test.t1 VALUES(3,UUID_v7(),UUID_v7()); end| CALL test.p1(); create function test.fn1(x int) returns int begin -insert into t1 values (4+x,UUIDv7(),UUIDv7()); -insert into t1 values (5+x,UUIDv7(),UUIDv7()); +insert into t1 values (4+x,UUID_v7(),UUID_v7()); +insert into t1 values (5+x,UUID_v7(),UUID_v7()); return 0; end| select fn1(0); diff --git a/mysql-test/suite/rpl/t/rpl_row_UUIDv7.test b/plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.test similarity index 75% rename from mysql-test/suite/rpl/t/rpl_row_UUIDv7.test rename to plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.test index 9e29f5dcae7..225e6b3c1db 100644 --- a/mysql-test/suite/rpl/t/rpl_row_UUIDv7.test +++ b/plugin/type_uuid/mysql-test/type_uuid/rpl_row_uuid_v7.test @@ -10,12 +10,12 @@ connection master; # Start the actual test CREATE TABLE test.t1 (a INT, blob_column LONGBLOB, vchar_column VARCHAR(100), PRIMARY KEY(a)) engine=myisam; -INSERT INTO test.t1 VALUES(1,UUIDv7(),UUIDv7()); +INSERT INTO test.t1 VALUES(1,UUID_v7(),UUID_v7()); delimiter |; create procedure test.p1() begin - INSERT INTO test.t1 VALUES(2,UUIDv7(),UUIDv7()); - INSERT INTO test.t1 VALUES(3,UUIDv7(),UUIDv7()); + INSERT INTO test.t1 VALUES(2,UUID_v7(),UUID_v7()); + INSERT INTO test.t1 VALUES(3,UUID_v7(),UUID_v7()); end| delimiter ;| @@ -25,8 +25,8 @@ delimiter |; create function test.fn1(x int) returns int begin - insert into t1 values (4+x,UUIDv7(),UUIDv7()); - insert into t1 values (5+x,UUIDv7(),UUIDv7()); + insert into t1 values (4+x,UUID_v7(),UUID_v7()); + insert into t1 values (5+x,UUID_v7(),UUID_v7()); return 0; end| @@ -46,8 +46,8 @@ SHOW CREATE TABLE test.t1; # then LOAD DATA INFILE in slave, and use a query to compare. # This would have the advantage that it would not assume # the system has a 'diff' ---exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_master.sql ---exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_slave.sql +--exec $MYSQL_DUMP --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_master.sql +--exec $MYSQL_DUMP_SLAVE --compact --order-by-primary --skip-extended-insert --no-create-info test > $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_slave.sql connection master; @@ -61,10 +61,10 @@ DROP TABLE test.t2; # will be created. You will need to go to the mysql-test dir and diff # the files your self to see what is not matching :-) -diff_files $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_master.sql $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_slave.sql; +diff_files $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_master.sql $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_slave.sql; -remove_file $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_master.sql; -remove_file $MYSQLTEST_VARDIR/tmp/rpl_row_UUIDv7_slave.sql; +remove_file $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_master.sql; +remove_file $MYSQLTEST_VARDIR/tmp/rpl_row_UUID_v7_slave.sql; --echo # End of 11.7 tests diff --git a/plugin/type_uuid/plugin.cc b/plugin/type_uuid/plugin.cc index e5e7910be39..3d6d2e6660e 100644 --- a/plugin/type_uuid/plugin.cc +++ b/plugin/type_uuid/plugin.cc @@ -202,7 +202,19 @@ int uuid_init(void*) int uuidv7_init(void*) { - mysql_mutex_init(0, &LOCK_uuid_v7_generator, MY_MUTEX_INIT_FAST); +#ifdef HAVE_PSI_INTERFACE + static PSI_mutex_key key_LOCK_uuid_v7_generator; + static PSI_mutex_info psi_mutexes[]= + { + { &key_LOCK_uuid_v7_generator, "LOCK_uuid_v7_generator", PSI_FLAG_GLOBAL } + }; + mysql_mutex_register("uuid_v7", psi_mutexes, 1); +#else +#define key_LOCK_uuid_v7_generator 0 +#endif + + mysql_mutex_init(key_LOCK_uuid_v7_generator, &LOCK_uuid_v7_generator, + MY_MUTEX_INIT_FAST); return 0; } @@ -263,9 +275,9 @@ maria_declare_plugin(type_uuid) { 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 + "uuid_v4", // plugin name "Stefano Petrilli", // plugin author - "Function UUIDv4()", // the plugin description + "Function UUID_v4()", // 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 @@ -278,9 +290,9 @@ maria_declare_plugin(type_uuid) { MariaDB_FUNCTION_PLUGIN, // the plugin type (see include/mysql/plugin.h) &plugin_descriptor_function_uuid_v7, // pointer to type-specific plugin descriptor - "uuidv7", // plugin name + "uuid_v7", // plugin name "Stefano Petrilli", // plugin author - "Function UUIDv7()", // the plugin description + "Function UUID_v7()", // the plugin description PLUGIN_LICENSE_GPL, // the plugin license (see include/mysql/plugin.h) uuidv7_init, // Pointer to plugin initialization function uuidv7_terminate, // Pointer to plugin deinitialization function diff --git a/plugin/type_uuid/sql_type_uuid.h b/plugin/type_uuid/sql_type_uuid.h index abb539b2ce5..1fbf1c13261 100644 --- a/plugin/type_uuid/sql_type_uuid.h +++ b/plugin/type_uuid/sql_type_uuid.h @@ -18,6 +18,9 @@ #include "sql_type_fixedbin_storage.h" +static constexpr uchar UUID_VERSION_MASK() { return 0x0F; } +static constexpr uchar UUID_VARIANT_MASK() { return 0x3F; } + template class UUID: public FixedBinTypeStorage { diff --git a/plugin/type_uuid/sql_type_uuid_v4.h b/plugin/type_uuid/sql_type_uuid_v4.h index dbb7f1ca0ce..85bcd5e8b38 100644 --- a/plugin/type_uuid/sql_type_uuid_v4.h +++ b/plugin/type_uuid/sql_type_uuid_v4.h @@ -18,7 +18,7 @@ /* Implements Universal Unique Identifiers version 4, as described in - draft-ietf-uuidrev-rfc4122bis-14. + RFC 9562. Field Octet # Note random_a 0-5 Random CSPRNG 48 bits. @@ -36,14 +36,11 @@ */ #include "sql_type_uuid.h" -#include "my_rnd.h" class UUIDv4: public Type_handler_uuid_new::Fbt { static constexpr uchar UUID_VERSION() { return 0x40; } - static constexpr uchar UUID_VERSION_MASK() { return 0x0F; } static constexpr uchar UUID_VARIANT() { return 0x80; } - static constexpr uchar UUID_VARIANT_MASK() { return 0x3F; } static void inject_version_and_variant(uchar *to) { @@ -51,13 +48,6 @@ class UUIDv4: public Type_handler_uuid_new::Fbt to[8]= ((to[8] & UUID_VARIANT_MASK()) | UUID_VARIANT()); } - // Construct using a my_rnd()-based fallback method - static void construct_fallback(char *to) - { - for (uint i= 0; i < 4; i++) - int4store(&to[i * 4], (uint32) (my_rnd(&sql_rand)*0xFFFFFFFF)); - } - static void construct(char *to) { bool error= my_random_bytes((uchar*) to, 16) != MY_AES_OK; @@ -67,8 +57,7 @@ class UUIDv4: public Type_handler_uuid_new::Fbt { push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, - "UUIDv4 generation failed; using a my_rnd fallback"); - construct_fallback(to); + "UUID_v4: RANDOM_BYTES() failed, using fallback"); } /* We have random bytes at to[6] and to[8]. diff --git a/plugin/type_uuid/sql_type_uuid_v7.h b/plugin/type_uuid/sql_type_uuid_v7.h index 2e643165a06..c9ff8ca35e4 100644 --- a/plugin/type_uuid/sql_type_uuid_v7.h +++ b/plugin/type_uuid/sql_type_uuid_v7.h @@ -41,7 +41,6 @@ */ #include "sql_type_uuid.h" -#include #include #include /* mi_int2store, mi_int6store */ #include @@ -52,10 +51,7 @@ extern mysql_mutex_t LOCK_uuid_v7_generator; class UUIDv7: public Type_handler_uuid_new::Fbt { static constexpr uchar UUID_VERSION() { return 0x70; } - static constexpr uchar UUID_VERSION_MASK() { return 0x0F; } static constexpr uchar UUID_VARIANT() { return 0x80; } - static constexpr uchar UUID_VARIANT_MASK() { return 0x3F; } - static constexpr double MICROSECONDS_TO_12BIT_MAPPING_FACTOR() { return 4.096; } static void inject_version_and_variant(uchar *to) { @@ -63,13 +59,6 @@ class UUIDv7: public Type_handler_uuid_new::Fbt to[8]= ((to[8] & UUID_VARIANT_MASK()) | UUID_VARIANT()); } - // Construct using a my_rnd()-based fallback method - static void construct_fallback(char *to) - { - for (uint i= 0; i < 4; i++) - int4store(&to[i * 4], (uint32) (my_rnd(&sql_rand)*0xFFFFFFFF)); - } - static void construct(char *to) { bool error= my_random_bytes((uchar*) to+8, 8) != MY_AES_OK; @@ -79,23 +68,22 @@ class UUIDv7: public Type_handler_uuid_new::Fbt { push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_NOTE, ER_UNKNOWN_ERROR, - "UUIDv7 generation failed; using a my_rnd fallback"); - construct_fallback(to); + "UUID_v7: RANDOM_BYTES() failed, using fallback"); } - uint64 tv= my_hrtime().val; + /* + We have 12 bits for to ensure monotonocity. Let's store microseconds + there (from 0 to 999) as described in section 6.2, Method 3 of RFC 9562, + and use two remaining bits as a counter, thus allowing 4000 UUIDv7 + values to be generated within one millisecond. + */ + uint64 tv= my_hrtime().val * 4; mysql_mutex_lock(&LOCK_uuid_v7_generator); last_uuidv7_timestamp= tv= MY_MAX(last_uuidv7_timestamp+1, tv); mysql_mutex_unlock(&LOCK_uuid_v7_generator); - mi_int6store(to, tv / 1000); - - /** - Map all the possible microseconds values (from 0 to 999) to all the - values that can be represented in 12 bits (from 0 to 4095) as - described in section 6.2, Method 3 of RFC 9562. - */ - mi_int2store(to+6, MICROSECONDS_TO_12BIT_MAPPING_FACTOR() * (tv % 1000)); + mi_int6store(to, tv / 4000); + mi_int2store(to+6, tv % 4000); /* Let's inject proper version and variant to make it good UUIDv7.