存储 MySQL GUID/UUID
这是我能想到的将 UUID() 生成的 MySQL GUID/UUID 转换为二进制 (16) 的最佳方法:
This is the best way I could come up with to convert a MySQL GUID/UUID generated by UUID() to a binary(16):
UNHEX(REPLACE(UUID(),'-',''))
然后将其存储在 BINARY(16) 中
And then storing it in a BINARY(16)
这样做有什么我应该知道的含义吗?
Are there any implications of doing it this way that I should know of?
推荐答案
影响不大.它会稍微减慢查询速度,但您几乎不会注意到它.
Not many implications. It will slow down the queries a little, but you will hardly notice it.
UNIQUEIDENTIFIER 无论如何都会在内部存储为 16 字节二进制.
UNIQUEIDENTIFIER is stored as 16-byte binary internally anyway.
如果您要将二进制文件加载到客户端并在那里解析,请注意 bit order,它可能具有不同于初始 NEWID() 的其他字符串表示.
If you are going to load the binary into a client and parse it there, note the bit order, it may have other string representation than the initial NEWID().
Oracle 的 SYS_GUID() 函数很容易出现这个问题,将其转换为字符串会在客户端和服务器上产生不同的结果.
Oracle's SYS_GUID() function is prone to this issue, converting it to a string gives different results on client and on server.
相关文章