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

前端 未结 2 1303
星月不相逢
星月不相逢 2020-12-16 12:23

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

相关标签:
2条回答
  • 2020-12-16 13:05

    Just a general comment. Insertion implies that what was there before remains. Replacing implies that something that is there already is targeted for removal and the item for insertion is installed in its place. The replacing action must inherently target a item that is already there, remove it and install the new item.

    0 讨论(0)
  • 2020-12-16 13:16

    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

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