生成唯一标识符,主要类似于 UUID,但具有名称空间检查

发布于 2024-09-09 07:58:08 字数 547 浏览 2 评论 0原文

我正在设计一个数据库,该数据库可能会保存数百万条记录。每条记录只有几条数据(例如,大约十五个五十字符的字符串)。

不同的记录属于同一类对象,但来自不同的“源”;命名空间将捕获这种关系。例如,对象1属于命名空间1,对象12321属于命名空间2,等等。

我想为这些记录设计唯一标识符。

如果我使用 UUID 版本 5,生成附加到命名空间的 UUID 将很简单。但是,无法知道给定的 UUID 是否属于给定的命名空间。

然后我想到了一种类似于 Luhn 算法 的算法(用于信用卡号码的算法) )它检查一个数字是“正确”还是“不”。

你会怎么做呢?

要求:

  1. 所有 UUID 要求
  2. 能够检查 UUID 是否属于给定命名空间

I am working on the design of a database which will potentially hold millions of records. Each record will have only a few pieces of data (say, about fifteen fifty-character strings).

The different records belong to the same class of object, but from a different "source"; a namespace would capture this relationship. For instance, object 1 belongs to namespace 1, object 12321 to namespace 2, etc.

I want to design the unique identifiers for these records.

If I were to use UUID version 5, generating the UUID attached to the namespace would be trivial. However, there is no way of knowing wether a given UUID belongs or not to a given namespace.

Then I thought of an algorithm along the lines of Luhn's Algorithm (the one used for credit card numbers) which checks wether a number is "correct" or "not".

How would you go about this?

Requirements:

  1. All the UUID requirements
  2. Ability to check that a UUID belongs to a given namespace

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你没皮卡萌 2024-09-16 07:58:08

如果您将命名空间存储在同一个表中并为其建立索引,一个简单的查询将告诉您 uuid 是否存在于给定命名空间中。但 uuid 不应该是唯一的吗?所以重复项不应该存在。

If you store the namespace in the same table and index it, one simple query will tell you if the uuid exists in a given namespace. But aren't uuid suppodes to be unique anyway? So duplicates should not exist.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文