question
When designing tables in MySQL, MySQL officially recommends not to use uuid or discontinuous and non-repeating snowflake ids (long type and unique), but recommends continuous self-increasing primary key ids. The official recommendation is auto_increment, so why is it not recommended? uuid, what are the disadvantages of using uuid?
MySQL and program examples
1. To explain this problem, we first create three tables
They are user_auto_key, user_uuid, and user_random_key, which respectively represent the automatically growing primary key, uuid as the primary key, random key as the primary key, and we keep the others completely unchanged. According to the control variable method, we only generate the primary key of each table using different strategies, while the other fields are exactly the same, and then test the insertion speed and query speed of the table. Note: The random key here actually refers to the discontinuous, non-repeating and irregular ID calculated using the snowflake algorithm: a string of 18-bit long values. id automatically generates table:
User uuid table
Random primary key table: