MySQL UUID()何时不唯一? [英] MySQL UUID() when not unique?

查看:608
本文介绍了MySQL UUID()何时不唯一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当MySQL生成的UUID()不唯一时会发生什么?如果这是作为主键的列,MySQL是否会出错,还是会尝试生成另一个UUID,直到找到一个真正唯一的UUID?

What happens when a UUID() generated by MySQL is not unique? If this is for a column that is a primary key, does MySQL error out, or does it try generating another UUID until a truly unique one is found?

推荐答案

好吧,如果您两次调用UUID()并获得相同的结果,那么最有问题的事情就是东西坏了"(tm).据我所知,它应该是唯一的,并且应该一直如此.

Well, if you call UUID() twice and get the same results, the most problematic thing would be that "stuff is broken" (tm). It's supposed to be unique and it should be always, as far as I know.

将没有可用的重新生成"代码:该功能旨在即使在整个计算机上也可以创建唯一的密钥,那么它怎么甚至知道结果不是唯一的?

There would be no "regenerate" code available: the function is designed to create unique keys even across computers, so how could it even know its result was not unique?

来自 http://dev.mysql.com /doc/refman/5.0/en/miscellaneous-functions.html#function_uuid

UUID被设计为在空间和空间上全局唯一的数字 时间.两次调用UUID()会产生两个不同的结果 值,即使这些调用是在两台单独的计算机上执行的也是如此 彼此没有连接.

A UUID is designed as a number that is globally unique in space and time. Two calls to UUID() are expected to generate two different values, even if these calls are performed on two separate computers that are not connected to each other.

也许您还有其他意思?例如,如果您使用UUID()生成应该是唯一的内容(例如主键或唯一"字段等),并且您之前已经添加了相同的数字(例如您曾经调用过UUID()两次),那么您只会在将非唯一内容添加到应该唯一的地方时得到默认错误.您不会得到一个新的.

Maybe you mean something else? For instance, if you use UUID() to generate somethingthat should be unique (like a primary key, or a Unique field etc), and you've previously added the same number (like for instance you called UUID() once, but inserted something twice), then you'll just get the default error you get when adding non-unique content to a place that should be unique. You will not get a new one.

一些关于独特性的阅读材料:

some reading material about the uniqueness:

  1. 手册.阅读它,以及它如何使用各个部分来生成uuid .: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_uuid

检查该手册上的链接以获取实际定义(但这是一本必读的书,因此您可能会跳过此链接):

Check the link on that manual for the actual definition (but that's quite a read, so you might skip this one): https://www2.opengroup.org/ogsys/jsp/publications/PublicationDetails.jsp?catalogno=c706

一些更容易理解的关于重复概率的指标: http://en.wikipedia. org/wiki/Universally_unique_identifier

Some easier to understand metrics on probability of dubplicates here: http://en.wikipedia.org/wiki/Universally_unique_identifier

在mysql网站(论坛等)上也有一些关于使用它作为主键的话题,但是由于我上班时间很短,您需要自己搜索:)

there is some talk on the mysql site (forums etc) too, about using it as primary key, but as i'm at work and short on time, you need to search for that yourself :)

这篇关于MySQL UUID()何时不唯一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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