MySQL auto_increment与max [英] MySQL auto_increment vs max

查看:110
本文介绍了MySQL auto_increment与max的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,哪一种更快更好用?

Alright, which is faster and better to use?

自动增量

调用一个执行最大值的sql,然后添加一个

Call an sql which which does a max and then add one

因此,最终的问题是,您应该使用mysql还是自己使用mysql?

So ultimately the question is should you use mysql to do it or do it yourself?

推荐答案

使用MAX的问题是

The problem with using MAX is the isolation level - at best, there's a chance of the value getting over-inflated due to reading records that may be incorrect. At worst, the query to fetch the current max value is reading the table before a previous insert occurs - causing a collision.

另一个考虑因素是必须滚动自己的ID生成器和东西来检索ID,因为您不能使用LAST_INSERT_ID().

Another consideration is having to roll your own id generator and stuff to retrieve the id because you can't use LAST_INSERT_ID().

这篇关于MySQL auto_increment与max的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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