What's your opinion on using UUIDs as database row identifiers, particularly in web apps?

后端 未结 15 2187
深忆病人
深忆病人 2020-12-12 12:43

I\'ve always preferred to use long integers as primary keys in databases, for simplicity and (assumed) speed. But when using a REST or Rails-like URL scheme for object insta

15条回答
  •  一个人的身影
    2020-12-12 13:32

    I can't say about the web side of your question. But uuids are great for n-tier applications. PK generation can be decentralized: each client generates it's own pk without risk of collision. And the speed difference is generally small.

    Make sure your database supports an efficient storage datatype (16 bytes, 128 bits). At the very least you can encode the uuid string in base64 and use char(22).

    I've used them extensively with Firebird and do recommend.

提交回复
热议问题