Get the App
SLTechnology News&Howtos  ›  Database  › 

The uuid () function and uuid_short () function obtained by MySQL's server_uuid

Shulou Source: shulou.com Published: 2022-06-01 07:07:19 09月25日 Update

1. Uuid () function

Mysql > select uuid (), uuid () +-+-+ | uuid () | uuid () | +-- -+ | 50120c25-d75c-11e7-9484-000c29c9278a | 50120c53-d75c-11e7-9484-000c29c9278a | +-- +- -+ 1 row in set (0.00 sec) String * Item_func_uuid::val_str (String * str) {. Mac\ rand get...uint32 time_low= (uint32) (tv & 0xFFFFFFFF) Uint16 time_mid= (uint16) ((tv > > 32) & 0xFFFF); uint16 time_hi_and_version= (uint16) ((tv > 48) | UUID_VERSION); s [8] = s [13] ='-'; tohex (s, time_low, 8); tohex (swarm 9, time_mid, 4); tohex (swarm 14, time_hi_and_version, 4); strmov (swarm 18, clock_seq_and_node_str) .} detailed generation of uuid process, refer to the above function for analysis.

Time_low, time_mid and time_high_and_version correspond to paragraph 123 respectively when they are converted to hexadecimal.

This time is the 100ns value from 1582-10-1500 to the current time. (in fact, the system can only get the exact us and multiply it by 10). So if you execute continuously for a short period of time, it is more likely that only the first value is changing, in fact, 1 / 2 / 3 may change. Paragraph 4 is the random number when you execute select uuid () for the first time after you start the MySQL, which will change each time you restart. Paragraph 5 is the Mac value turned around, and multiple instances of the same machine are generally the same. If the Mac value is not available, it is a random value. So this value can be thought of as different for each execution. And there is only a very small probability of repetition between different instances.

2. Uuid_short () function

Mysql > select uuid_short (), uuid_short () +-+ | uuid_short () | uuid_short () | +-+ | 818004335832072194 | 818004335832072195 | +- -+ 1 row in set (0.00 sec) function call procedure:

Main- > init_common_variables ()-> server_start_time= flush_status_time= my_time (0); / / obtain the timestamp of server startup ulonglong uuid_value;main- > init_common_variables- > item_init- > void uuid_short_init () {uuid_value= (ulonglong) server_id))

Tags: Function file time different same only instance actual actually first time procedure tiny precise between unit character string form machine probability Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL OPPO Reno Shulou Technology NVidia