MySQL: Difference between UPDATE and REPLACE
Tagged with: MySQL • programming • Technical
This one still has me baffled a little, as from what I can gather the differences seem very miniscule. From the MySQL 5.0 Reference Manual, scroll down to the comments and find “Eric Stevens”:
Please note that REPLACE INTO is a much slower performer than an UPDATE statement. Keep in mind that a REPLACE INTO requires a test on the keys, and if a matching unique key is found on any or all columns, a DELETE FROM is executed, then an INSERT is executed. There’s a lot of management of rows involved in this, and if you’re doing it frequently, you’ll hurt your performance unless you simply cannot do with any other syntax.
The only time when I can see where you’d actually need a REPLACE INTO is when you have multiple unique constraints on a table, and need to drop any rows that would match any of the constraints. Then REPLACE INTO becomes more efficient from DELETE FROM… INSERT INTO…
Makes sense to me. I also found another link, I have now lost, that alluded to REPLACE being useful for older versions of MySQL and when a different database structure was used. I have no way to verify that, but it sounded scholarly.
Anyways, It seems to make more sense to use UPDATE to me. Does anyone else have thoughts or know more? I guess that’s the wrong question since everyone knows more about MySQL than me… Does someone with more knowledge want to weigh in?

Welcome to my blog! Topics tend to focus on Science and Technology, but I throw in personal stuff too. I hope you enjoy!





