Storing MySQL GUID/UUIDs(存储 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.
这篇关于存储 MySQL GUID/UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:存储 MySQL GUID/UUID
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
