What are practical differences between `REPLACE` and `INSERT … ON DUPLICATE KEY UPDATE` in MySQL?

前端 未结 8 1412
清酒与你
清酒与你 2020-11-28 06:59

What I need is to set the values of all the fields of a record with a particular key (the key is composite actually), inserting the record if there is no record with such a

相关标签:
8条回答
  • 2020-11-28 07:34

    When using REPLACE instead of INSERT ... ON DUPLICATE KEY UPDATE, I sometimes observe key locking or deadlock problems when multiple queries arrive quickly for a given key. The atomicity of the latter (in addition to not causing cascade deletes) is all the more reason to use it.

    0 讨论(0)
  • 2020-11-28 07:38

    Replace seems that it does two operations in the case that the key already exists. Perhaps that implies there is a speed difference between the two?

    (INSERT)one update vs one delete + one insert(REPLACE)

    EDIT: My implication that replace might be slower is actually completely wrong. Well, according to this blog post anyway... http://www.tokutek.com/2010/07/why-insert-on-duplicate-key-update-may-be-slow-by-incurring-disk-seeks/

    0 讨论(0)
提交回复
热议问题