UUID与主键的自动递增编号 [英] UUID versus auto increment number for primary key

查看:293
本文介绍了UUID与主键的自动递增编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我应该为实体的主键选择UUID而不是自动递增号?优点和缺点是什么?

解决方案

安德烈(Andrey)和姆吉(Mjg)都不错,但是我会添加一个重要的性能问题.

通过数据库和密钥生成的分离,还允许对象之间具有复杂关系的应用程序使用适当的密钥来创建它们,从而可以进行大容量插入.

对于自动增量,拥有关系的所有对象(即具有外键的表)必须等待关系的另一端(即外键来自的表)进行保存,查询分配的ID,然后分别更新记录的先前记录.

Why should I choose UUID over an auto increment number for my entity's primary key? What are the pros and cons?

解决方案

Andrey and Mjg both had good points, but I would add a related performance issue that is significant.

With the decoupling of database and key generation also allows applications that have complex relationships between objects to create them all with the keys in place, so that bulk inserts are possible.

In the case of auto-increment, all of the objects that own relationships (ie the tables with foreign keys) have to wait for the other side of the relationship (ie the table the foreign key comes from) to save, query the assigned ids, and then individually update the records former records.

这篇关于UUID与主键的自动递增编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆