MySQL INSERT …ON DUPLICATE UPDATE - Adds one to the autoincrement

后端 未结 4 572
星月不相逢
星月不相逢 2020-12-09 11:32

I keep track of all the http_user_agents that visit me, with a simple hit counter. The below insert the http_user_agent in the DB, this field is Case Insensitive and is Uniq

4条回答
  •  眼角桃花
    2020-12-09 11:51

    The storage engine must increment the AUTO_INCREMENT value before inserting a row. It does not know if the insert will fail yet at that point. It cannot simply roll back the increment because there may be other inserts happening on other connections concurrently. This is normal behavior and not something you should (or can) change. The purpose of AUTO_INCREMENT is to provide unique identifiers, not an unbroken sequence of numbers.

提交回复
热议问题