Jean-Philippe Caruana
Jean-Philippe Caruana

Reputation: 2706

What is the performance difference between "insert ignore" and replace in MySQL?

I would like to know if there is a difference in terms of performance between insert ignore and replace orders in MySQL.

I am using MySQL 5.0.31. All my tables are in InnoDB.

Upvotes: 22

Views: 22547

Answers (1)

ajreal
ajreal

Reputation: 47321

insert ignore - if key/row exists, skip insertion

replace - if key/row exists, delete the match row, and insert again

So, replace should be slower.
But insert ignore does not do the update

details : http://dev.mysql.com/doc/refman/5.5/en/replace.html

REPLACE works exactly like INSERT, except that if an old row in the table has the same value as a new row for a PRIMARY KEY or a UNIQUE index, the old row is deleted before the new row is inserted

Upvotes: 49

Related Questions