性能:uuid vs cakephp-mysql中的自动递增 [英] Performance: UUID vs auto-increment in cakephp-mysql

查看:228
本文介绍了性能:uuid vs cakephp-mysql中的自动递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在搜索如果通过cakePHP(32字符长)生成的UUID的性能比自动增量更快。插入和选择操作的比较。
我应该使用通过cakePHP生成的UUID或者使用MySQL的简单自动增量

I was searching if UUID generated by cakePHP (32 char long) is faster in performance compared to auto-increment. Comparison in both inserts and Select operation. Which one should I use UUID generated by cakePHP or by using simple auto-increment of MySQL

这是一个我发现的案例研究, cakePHP

Here's is a case-study I found but its not specific to cakePHP

http://krow.livejournal.com /497839.html

推荐答案

我怀疑您会选择主要的性能问题键。您的瓶颈将在其他地方,几乎可以保证。

I doubt you're going to notice much of a performance issue in choice of primary key. Your bottlenecks will be somewhere else, almost guaranteed.

默认情况下,我建议只使用自动增量主键。这是有道理的 - 你会知道哪些订单记录被一目了然地插入,所以你可以更容易删除它们,如果测试数据等。此外,它更容易背诵一个数字比32字符的UUID。因此,可用性是自动递增的INT。

By default, I recommend just using an auto-increment primary key. This makes sense -- you will know which order records were inserted in at a glance, so you can more easily delete them if test data, etc. Also, it's easier to recite a number than a 32 char UUID. So usability goes to auto incremented INTs.

那么什么时候使用UUID?任何情况下,你要确保密钥是全球唯一的(或漂亮附近它)。一个例子是在一个分片数据库; db1和db2。您不能使用自动递增INT,因为那样您可能最终有2个记录(一个在db1,一个在db2)具有相同的主键,这将导致噩梦,如果你需要结合或转发。这是一个例子,当使用UUID是必要的。

So when would you use an UUID? Any situation where you want to make sure that the key is globally unique (or pretty darn near it). One example would be on a sharded database; db1 and db2. You can't use auto increment INTs, because then you could end up having 2 records (one in db1, one in db2) that have the same primary key, which will lead to nightmares if you ever need to combine or reshard. So that's one example when using an UUID is necessary.

但通常只是坚持使用自动增量的INT。它只是让生活更美好。

But generally just stick with auto incremented INTs. It just makes life better.

这篇关于性能:uuid vs cakephp-mysql中的自动递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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