(MYSQL) Is there any significant performance differences, or other reasons not to use the INSERT ... ON DUPLICATE UPDATE sql to update by PK/insert new stuff?
(MYSQL) Is there any significant performance differences, or other reasons not to use the
Share
No, there is none.
INSERT ON DUPLICATE KEY UPDATEwill locate the record and update it just as a simpleUPDATEwould do.In fact this is just a
UPDATE, followed by anINSERTshould theUPDATEfail.INSERT ON DUPLICATE KEY UPDATEcan be a faster alternative to a grouped update (when you have a source table with multiple records per key and want to increment the target table once per record).If there are few values per key, this query:
will be more efficient than this one:
See this article in my blog for more detail: