主键作为 INT,全局键作为 GUID 以提高性能

发布于 2024-08-16 04:26:56 字数 155 浏览 1 评论 0原文

在决定表的键时,为表设置一个 INT 主键(自动增量)并为数据库范围设置一个 GUID(除了 INT 之外)是否合适?考虑到表 DML 语句会更多,在 INT 上操作会更快,而如果要执行任何泛数据库 DML 语句,GUID 就会派上用场。请注意,我正在使用 MySQL,以防万一。请大家发表意见。

While deciding upon the keys for a table, is it good to have an INT primary key (autoincrement) for the table and a GUID (in addition to the INT) for the scope of the database? Given that there will be more table DML statements it will be faster to operate on INT whereas if any pan-database DMLs statements are to be executed, GUID will come handy. Please note I am using MySQL, just in case if it matters. Please opine.

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

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

发布评论

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

评论(1

宛菡 2024-08-23 04:26:56

我之前已经这样做过并且成功运行:正如您所指出的,使用 GUID 意味着我们在将一个数据库中的数据与另一个数据库合并时避免了冲突,并且 int< /code> 为我们提供了高效的连接等。当您处理 OLAP 时,我绝不会使用 GUID 作为键,因为这会影响性能。

I've done that before and it worked successfully: as you point out, using a GUID meant that we avoided conflicts when merging, say, data from one database with another, and the int provided us with efficient joining etc. I would just never use a GUID as a key when you're dealing with OLAP, as that will performance.

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