java UUID and auto-increment primary key strengths and weaknesses

Auto-increment primary keys

Self-energizing ID is id without specifying table when the design value of the id field is in the form of the self-energizing, so that when inserted into a row of data is automatically filled according to the previous value + 1'd ID field. In a MySQL database, may be used to enable self-energizing self-energizing assignment ID as the primary key, to guarantee atomicity for a particular field by field sql statement AUTO_INCREMENT.


advantage


Database automatic numbering, fast, and incremental growth, in order to store, retrieve very beneficial;

Digital type, small space, it is easy to sort, in the program transfer is also convenient;

If the increase in the recording by a non-system can not specify the field, do not worry about the primary key duplication.

Shortcoming


Because the automatic increase in the manual to insert records specified ID will appear trouble, especially when the system with other systems integration, data is needed to import, it is difficult to ensure the ID of the original system's primary key violation does not occur (provided that the old system is digital Type). When the line especially in the new system, old and new systems exist in parallel, and in the case of heterogeneous databases different library bidirectional synchronization when required, the self-energizing primary key will be your nightmare;

Or when cutover system integration, if the new and old systems of different primary key is a numeric key will lead to modify the primary data type, there are other modifications which will lead to the foreign key table, equally serious consequences;

If the system is digital type, when imported, in order to distinguish between the old and new data, you may want to unify plus a character ID before the old data of the primary key (for example, "o", old) to indicate that this is old data, then the automatic growth of digital type facing a challenge.

UUID

Meaning UUID Universally Unique Identifier (Universally Unique Identifier) ​​uuid project application www.1b23.com, refers to the number in a machine-generated, which ensures the same for all machines in space and time are unique. Usually the platform will provide an API generated. In other words to ensure unique primary keys id within a certain range.


advantage


When data appears split, merge storage, can achieve global uniqueness of


Shortcoming


Effect insertion speed, and causes the hard disk to use low

Comparison of the relative size of numbers between uuid a lot slower, affect the query speed.

uuid occupy a large space, more if you build the index, the more seriously affected


Guess you like

Origin blog.51cto.com/14558453/2450575