Current location - Education and Training Encyclopedia - Resume - Advantages and disadvantages of snowflake algorithm and Mysql self-increasing
Advantages and disadvantages of snowflake algorithm and Mysql self-increasing
The advantages and disadvantages of snowflake algorithm and Mysql automatic increment are as follows:

The advantages of snowflake algorithm are:

1, so it won't be repeated.

2, orderly, will not cause space waste and random insertion affect performance.

3, the generation is very fast, especially much faster than UUid.

4, smaller than UUid.

Disadvantages: time callback causes confusion.

The advantages of Mysql's self-growth are:

1, with small storage space.

2. High insertion and query performance.

Disadvantages are:

The range of 1 and int may not be large enough.

2. It will be very troublesome to migrate data, and the primary keys are easy to conflict.

3. due to the increase of id, the growth of its own business is easy to be mastered by others.

4. Self-increasing has poor performance in the case of high concurrency.

The code to generate the id is:

The reason why autoincrement is different from UUid is that we usually use Innodb to support transactions in mysql database and B+ number index in Innodb. The storage structure of Innodb is a clustered index. The sequential primary key and random primary key of clustered index have great influence on efficiency.

Self-increment is a sequential primary key storage, which is convenient to find and insert (the insertion will be inserted after the previous one in sequence), but UUid is out of order, and the calculated hashcode will also be out of order (the storage location is selected according to hashcode).

So the search efficiency for him is very low, and because he is out of order, his insertion may be inserted into the previous data, which will cause many other operations, greatly affect the performance or waste a lot of storage space because of disorderly storage.